forked from TowerofHanoi/CTFsubmitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitter.py
120 lines (91 loc) · 3.22 KB
/
submitter.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
from __future__ import print_function
from importlib import import_module
from config import config
from logger import log
from config import STATUS
from time import sleep
class SubmitterBase(object):
def submit(self, flags):
""" this function will submit the flags to the scoreboard
returns: a list containing the status for every flag"""
raise NotImplementedError()
class DummySubmitter(SubmitterBase):
def __init__(self):
self.lose_flags = 1
self.sleep = import_module('time').sleep
self.t = 0.2
def submit(self, flags):
status = []
self.sleep(self.t)
ff = []
for flag in flags:
status.append(STATUS["accepted"])
ff.append(flag['flag'])
print("FLAAAAAAAGS %s" % ff)
return status
class iCTFSubmitter(SubmitterBase):
def __init__(self):
self.token = config.get("token")
self.email = config.get("email")
self.ictf = import_module('ictf')
super(Submitter, self).__init__()
def submit(self, flags):
while(1):
try:
ictf = self.ictf.iCTF()
self.t = ictf.login(self.email, self.token)
sleep(20)
break
except:
sleep(20)
status = []
try:
out = self.t.submit_flag(flags)
except Exception as e:
log.error(e.message)
return [STATUS['unsubmitted']]*len(flags)
for stat in out:
if stat == "correct":
status.append(STATUS['accepted'])
elif stat == "alreadysubmitted":
status.append(STATUS['rejected'])
log.warning("the flag has already been submitted!")
elif stat == "incorrect":
status.append(STATUS['rejected'])
log.error("wrong flags submitted!")
elif stat == "notactive":
status.append(STATUS['old'])
log.error("unactive!")
else:
status.append(STATUS['unsubmitted'])
log.error("too many incorrect STAHP!!!")
if len(status) < len(flags):
status += [STATUS['unsubmitted'] for i in range(
len(flags)-len(status))]
return status
class ruCTFeSubmitter(SubmitterBase):
def __init__(self):
pwn = import_module('pwn')
self.remote = pwn.remote
super(Submitter, self).__init__()
def submit(self, flags):
""" this function will submit the flags to the scoreboard"""
status = []
try:
with self.remote("flags.e.ructf.org", 31337) as r:
r.read()
for flag in flags:
r.send(flag + "\n")
output = r.recv()
if "Accepted" in output:
s = STATUS["accepted"]
elif "Old" in output:
s = STATUS["old"]
else:
s = STATUS["rejected"]
status.append(s)
except Exception as e:
log.exception(e)
return status
# choose the submit function here :)
Submitter = iCTFSubmitter