generated from C4T-BuT-S4D/ad-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
executable file
·76 lines (54 loc) · 2.4 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
#!/usr/bin/env python3
import sys
import string
import itertools
import random
import time
import requests
from checklib import *
from simple_lib import *
class Checker(BaseChecker):
vulns: int = 1
timeout: int = 10
uses_attack_data: bool = True
mch: CheckMachine
def __init__(self, *args, **kwargs):
super(Checker, self).__init__(*args, **kwargs)
self.mch = CheckMachine(self)
def action(self, action, *args, **kwargs):
try:
super(Checker, self).action(action, *args, **kwargs)
except requests.exceptions.ConnectionError:
self.cquit(Status.DOWN, 'Connection error', 'Got requests connection error')
def check(self):
session = get_initialized_session()
username, password = rnd_username(), rnd_password()
note_text = rnd_string(20)
self.mch.register(session, username, password, Status.MUMBLE)
note_id = self.mch.put_note(session, note_text, Status.MUMBLE)
notes = self.mch.list_notes(session, Status.MUMBLE)
self.assert_in(note_id, notes, "note missing", Status.MUMBLE)
service_note_text = self.mch.get_note(session, note_id, Status.MUMBLE)
self.assert_eq(note_text, service_note_text, "invalid note", Status.MUMBLE)
self.cquit(Status.OK)
def put(self, flag_id: str, flag: str, vuln: str):
session = get_initialized_session()
username, password = rnd_username(), rnd_password()
self.mch.register(session, username, password, Status.MUMBLE)
note_id = self.mch.put_note(session, flag, Status.MUMBLE)
notes = self.mch.list_notes(session, Status.MUMBLE)
self.assert_in(note_id, notes, "note missing", Status.MUMBLE)
self.cquit(Status.OK, f"{note_id}", f"{username}:{password}:{note_id}")
def get(self, flag_id: str, flag: str, vuln: str):
session = get_initialized_session()
username, password, note_id = flag_id.split(':')
self.mch.login(session, username, password, Status.CORRUPT)
note_text = self.mch.get_note(session, note_id, Status.CORRUPT)
self.assert_eq(flag, note_text, "invalid note", Status.CORRUPT)
self.cquit(Status.OK)
if __name__ == '__main__':
c = Checker(sys.argv[2])
try:
c.action(sys.argv[1], *sys.argv[3:])
except c.get_check_finished_exception():
cquit(Status(c.status), c.public, c.private)