generated from C4T-BuT-S4D/ad-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
executable file
·146 lines (107 loc) · 5.49 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import random
import re
import sys
import requests
import checklib
from qrlib import CheckMachine
import segno
import tempfile
class Checker(checklib.BaseChecker):
vulns: int = 1
timeout: int = 20
uses_attack_data: bool = True
external_web_storage = "http://kek.spok.live:5555"
def __init__(self, *args, **kwargs):
super(Checker, self).__init__(*args, **kwargs)
self.c = CheckMachine(self)
self.uuid_regexp = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$')
def validate_uuid(self, uuid):
self.assert_eq(bool(self.uuid_regexp.fullmatch(uuid)), True, 'Invalid uuid returned')
def put_in_external_web_storage(self, token: str, key: str, value: str):
sess = checklib.get_initialized_session()
resp = sess.get(f"{self.external_web_storage}/put", params={"token": token, "key": key, "value": value})
self.check_response(resp, 'Internal error', status=checklib.Status.ERROR)
def action(self, action, *args, **kwargs):
try:
super(Checker, self).action(action, *args, **kwargs)
except requests.exceptions.ConnectionError:
self.cquit(checklib.Status.DOWN, 'Connection error', 'Got requests connection error')
def check(self):
sess = checklib.get_initialized_session()
username, password = checklib.rnd_username(), checklib.rnd_password()
self.c.signup(sess, username, password)
self.c.signin(sess, username, password)
token = self.c.add_token(sess, "token_" + checklib.rnd_string(2)).get('token')
sess = checklib.get_initialized_session()
if random.randint(0, 5) <= 3:
self.decode_text(sess, token)
else:
self.decode_url(sess, token)
self.cquit(checklib.Status.OK)
def decode_text(self, sess, token):
for _ in range(10):
example_text = checklib.rnd_string(32)
decode_res = self.try_generate_and_upload(sess, token, example_text)
if decode_res is not None:
break
else:
self.cquit(checklib.Status.MUMBLE, 'Failed to decode qr code')
self.assert_eq(decode_res.get('content'), example_text, 'Content mismatch')
self.validate_uuid(decode_res.get('id'))
results = self.c.results(sess, token).get('results', [])
self.assert_in(example_text, [r.get('content') for r in results], 'Content not found in results')
def decode_url(self, sess, token):
content = checklib.rnd_string(32)
for _ in range(10):
key = checklib.rnd_string(15)
self.put_in_external_web_storage("stupidTokenForChecker", key, content)
decode_res = self.try_generate_and_upload(sess, token, f"{self.external_web_storage}/{key}", parse=True)
if decode_res is not None:
break
else:
self.cquit(checklib.Status.MUMBLE, 'Failed to decode qr code')
self.assert_eq(decode_res.get('content'), content, 'Content mismatch')
results = self.c.results(sess, token).get('results', [])
self.assert_in(content, [r.get('content') for r in results], 'Content not found in results')
def put(self, flag_id: str, flag: str, vuln: int):
sess = checklib.get_initialized_session()
username, password = checklib.rnd_username(), checklib.rnd_password()
self.c.signup(sess, username, password)
uid = self.c.signin(sess, username, password).get('uid')
token = self.c.add_token(sess, "token_" + checklib.rnd_string(3)).get('token')
sess = checklib.get_initialized_session()
for attempt in range(10):
content = flag + '\n' + ' ' * attempt
decode_res = self.try_generate_and_upload(sess, token, content)
if decode_res is not None:
break
else:
self.cquit(checklib.Status.MUMBLE, 'Failed to decode qr code')
qr_id = decode_res.get('id')
self.assert_eq(decode_res.get('content').strip(), flag, 'Content mismatch')
self.validate_uuid(qr_id)
self.cquit(checklib.Status.OK, f"{username}:{uid}:{qr_id}", f"{username}:{qr_id}:{password}")
def get(self, flag_id: str, flag: str, vuln: int):
username, qr_id, password = flag_id.split(':')
sess = checklib.get_initialized_session()
self.c.signin(sess, username, password)
tokens = self.c.tokens(sess, status=checklib.Status.CORRUPT)
self.assert_gt(len(tokens), 0, 'No tokens found', status=checklib.Status.CORRUPT)
token = tokens[0].get('token')
results = self.c.results(sess, token)
self.assert_in(flag, [r.get('content').strip() for r in results.get('results', [])], 'Content not found in results')
self.cquit(checklib.Status.OK)
def try_generate_and_upload(self, sess: requests.Session, token:str, text: str, parse: bool = False):
with tempfile.NamedTemporaryFile(suffix=".png") as f:
segno.make(text).save(f.name, scale=5, border=4)
resp = self.c.try_decode(sess, token, f.name, parse=parse)
if resp.status_code != 200:
return None
return self.get_json(resp, 'Failed to decode qr code')
if __name__ == '__main__':
c = Checker(sys.argv[2])
try:
c.action(sys.argv[1], *sys.argv[3:])
except c.get_check_finished_exception():
checklib.cquit(checklib.Status(c.status), c.public, c.private)