Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions 2023/idekCTF_2022/Pwn_Sofire=good/distribution/remote/run.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/usr/bin/env python3

import urllib.request
import subprocess
import requests
import os
import uuid
from urllib.parse import urlparse
fname = str(uuid.uuid4())

# Asking user for an exploit executable to load inside the qemu instance.
url = input("Give me the URL to your exploit executable (press enter to skip): ")
if url == "":
path = ""
else:
parsed = urlparse(url)
if parsed.scheme not in ("http", "https"):
print("Only http/https URLs are allowed.\n")
exit(-1)
path = f"/tmp/{fname}"

# Downloading the user's exploit executable.
try:
with urllib.request.urlopen(url) as f:
exploit = f.read()
response = requests.get(url, timeout=30)
response.raise_for_status()
exploit = response.content
except Exception:
print("Some error occurred while downloading your exploit executable. Try again or contact support :(\n")
exit(-1)
Expand All @@ -26,7 +31,12 @@
f.write(exploit)

try:
subprocess.run(["./run.sh", path])
pid = os.fork()
if pid == 0:
os.execv("./run.sh", ["./run.sh", path])
os._exit(1)
else:
os.waitpid(pid, 0)
except Exception:
print("Some error occurred while running qemu. Try again or contact support :(\n")

Expand Down