-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.py
65 lines (52 loc) · 1.56 KB
/
exploit.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pwn import *
import requests
import argparse
import tempfile
import os
def get_url():
parser = argparse.ArgumentParser()
parser.add_argument("url", help="The URL of the ELF file.")
args = parser.parse_args()
return args.url
def fetch_file(url):
response = requests.get(url)
if response.status_code == 200:
return response.content
else:
print("Failed to fetch the file!!!")
print(f"Status code: {response.status_code}")
exit(1)
def get_flag(url):
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
elf_data = fetch_file(url)
tmp_file.write(elf_data)
tmp_file.flush()
tmp_file_path = tmp_file.name
# set the file as executable
os.chmod(tmp_file_path, 0o755)
# load the ELF file
elf = ELF(tmp_file_path)
# dissamble the main function
function_name = 'main'
if function_name in elf.symbols:
function_addr = elf.symbols[function_name]
print("-"*50)
print(f"Disassembly of the function '{function_name}':")
disassembly = elf.disasm(function_addr, 64)
print(disassembly)
print("-"*50)
# define break point & location of 0x2262c96b
break_point = "0x40111c"
flag = "($rbp-0x4)"
# run gdb
gdb_commands = f"""
break *{break_point}
continue
x/4xb {flag}
"""
gdb.debug(tmp_file_path, gdbscript=gdb_commands)
if __name__ == "__main__":
url = get_url()
get_flag(url)
print("-"*50)
print("Flag: picoCTF{{{0x6bc96222}}}")