forked from emilytouchingcomputers/CTFium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·48 lines (39 loc) · 1.28 KB
/
run
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
#!/usr/bin/python3 -u
import os
import sys
import random
import subprocess
import string
def random_string(n):
return ''.join(random.choice(string.ascii_lowercase) for _ in range(n))
def check_pow(bits):
r = random_string(10)
print(f"hashcash -mb{bits} {r}")
solution = input("Solution:").strip()
if subprocess.call(["hashcash", f"-cdb{bits}", "-r", r, solution],
cwd="/tmp",
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) != 0:
raise Exception("Invalid PoW")
POW_BITS = 25
def main():
check_pow(POW_BITS)
fsize = int(input("Size of initramfs in bytes: "))
MAX_SIZE = 10 * 1024 * 1024
data = sys.stdin.buffer.read(fsize)[:MAX_SIZE]
print(f"Read {len(data)} bytes")
with open("/tmp/initramfs.cpio.gz", "wb") as initramfs:
initramfs.write(data)
os.execvp("qemu-system-x86_64",
["qemu-system-x86_64",
"-kernel", "./bzImage",
"-initrd", "/tmp/initramfs.cpio.gz",
"-cdrom", "./secrets.iso",
"-enable-kvm",
"-m", "64m",
"-nographic",
"-append", "console=ttyS0",
"-monitor", "/dev/null"]
)
if __name__ == "__main__":
main()