-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchecker.py
executable file
·84 lines (62 loc) · 1.69 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import inspect
import os
import sys
from enum import Enum
""" <config> """
# SERVICE INFO
PORT = 8084
# DEBUG -- logs to stderr, TRACE -- verbose log
DEBUG = os.getenv("DEBUG", False)
TRACE = os.getenv("TRACE", False)
""" </config> """
def check(host):
die(ExitStatus.CHECKER_ERROR, "Not implemented")
def put(host, flag_id, flag, vuln):
die(ExitStatus.CHECKER_ERROR, "Not implemented")
def get(host, flag_id, flag, vuln):
die(ExitStatus.CHECKER_ERROR, "Not implemented")
""" <common> """
class ExitStatus(Enum):
OK = 101
CORRUPT = 102
MUMBLE = 103
DOWN = 104
CHECKER_ERROR = 110
def _log(obj):
if DEBUG and obj:
caller = inspect.stack()[1].function
print(f"[{caller}] {obj}", file=sys.stderr, flush=True)
return obj
def die(code: ExitStatus, msg: str):
if msg:
print(msg, file=sys.stderr, flush=True)
exit(code.value)
def _main():
action, *args = sys.argv[1:]
try:
if action == "check":
host, = args
check(host)
elif action == "put":
host, flag_id, flag, vuln = args
put(host, flag_id, flag, vuln)
elif action == "get":
host, flag_id, flag, vuln = args
get(host, flag_id, flag, vuln)
else:
raise IndexError
except ValueError:
die(
ExitStatus.CHECKER_ERROR,
f"Usage: {sys.argv[0]} check|put|get IP FLAGID FLAG",
)
except Exception as e:
die(
ExitStatus.CHECKER_ERROR,
f"Exception: {e}. Stack:\n {inspect.stack()}",
)
""" </common> """
if __name__ == "__main__":
_main()