-
Notifications
You must be signed in to change notification settings - Fork 1
/
checklib.py
51 lines (42 loc) · 1.19 KB
/
checklib.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
import os
import sys
import requests
from enum import Enum
class Status(Enum):
OK = 101
DOWN = 104
CHECKER_DISABLED = 109
ERROR = 110
class Action(Enum):
CHECK_SLA = 'CHECK_SLA'
PUT_FLAG = 'PUT_FLAG'
GET_FLAG = 'GET_FLAG'
def __str__(self):
return str(self.value)
def get_data():
data = {
'action': os.environ['ACTION'],
'teamId': os.environ['TEAM_ID'],
'round': os.environ['ROUND'],
'vulnboxId': os.environ['VULNBOX_ID']
}
if data['action'] == Action.PUT_FLAG.name or data['action'] == Action.GET_FLAG.name:
data['flag'] = os.environ['FLAG']
else:
data['flag'] = None
return data
def quit(exit_code, comment='', debug=''):
if isinstance(exit_code, Status):
exit_code = exit_code.value
print(comment)
print(debug, file=sys.stderr)
exit(exit_code)
def post_flag_id(service_id, team_id, flag_id):
r = requests.post(os.environ['FLAGID_SERVICE'] + '/postFlagId', json={
'token': os.environ['FLAGID_TOKEN'],
'serviceId': service_id,
'teamId': team_id,
'round': int(os.environ['ROUND']),
'flagId': flag_id
})
r.raise_for_status()