-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathchecker.py
41 lines (35 loc) · 1012 Bytes
/
checker.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
import subprocess
import hashlib
if __name__ == "__main__":
code = input("Your one line python code to exec(): ")
print()
if not code:
print("Code must not be empty")
exit(-1)
p = subprocess.run(
["su", "nobody", "-s", "/bin/bash", "-c", "/usr/local/bin/python3 /runner.py"],
input=code.encode(),
stdout=subprocess.PIPE,
)
if p.returncode != 0:
print()
print("Your code did not run successfully")
exit(-1)
output = p.stdout.decode()
print("Your code is:")
print(repr(code))
print()
print("Output of your code is:")
print(repr(output))
print()
print("Checking reversed(code) == output")
if code[::-1] == output:
print(open("/root/flag1").read())
else:
print("Failed!")
print()
print("Checking sha256(code) == output")
if hashlib.sha256(code.encode()).hexdigest() == output:
print(open("/root/flag2").read())
else:
print("Failed!")