forked from RootFu/ctf-scorebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsenix.py
More file actions
executable file
·147 lines (110 loc) · 3.49 KB
/
Usenix.py
File metadata and controls
executable file
·147 lines (110 loc) · 3.49 KB
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
145
146
147
#!/usr/bin/env python2
import sys
import time
from scorebot.config.Config import Config
from scorebot.config.ConfigIniParser import ConfigIniParser
from scorebot.standard.servicebot.ServiceBot import ServiceBot
from scorebot.attackengine.attackbot.AttackBot import AttackBot
from scorebot.common.gamestatebot.GameStateBot import GameStateBot
from scorebot.usenix.UsenixLogic import UsenixLogic
from scorebot.usenix.UsenixPublicLogic import UsenixPublicLogic
from scorebot.usenix.UsenixConfig import UsenixExploitConfigHandler
from scorebot.usenix.UsenixConfig import UsenixConfigHandler
from scorebot.usenix.usenixexploitbot.UsenixExploitBot import UsenixExploitBot
from scorebot.usenix.usenixreportbot.UsenixReportBot import UsenixReportBot
from scorebot.standard.servicebot.ServiceBotConfig import ServiceBotConfigHandler, ServiceConfigHandler
#from scorebot.attackengine.attackbot.AttackConfig import AttackConfigHandler
def usage(argv):
return "Usage: %s [all server service scoreboard public] [init]" % argv[0]
def checkInit():
ans = raw_input("Are you sure you want to reinitialize the game? ")
if(ans.upper().startswith("Y")):
return True
return False
def startBot(bot,init):
if(bot == "all"):
startAll(init)
elif(bot == "public"):
startPublic(init)
elif(bot == "server"):
print "FIXME: Should start Server"
elif(bot == "attack"):
print "FIXME: Should start Attack"
elif(bot == "scoreboard"):
print "FIXME: Should start Scoreboard"
else:
print usage(sys.argv)
def startPublic(init):
cip = ConfigIniParser()
cip.addHandler(ServiceBotConfigHandler())
cip.addHandler(ServiceConfigHandler())
cip.addHandler(UsenixConfigHandler())
config_path = "config/usenix_public.ini"
conf = cip.load(config_path)
conf.setFlagPhrase("flags wave in the wind")
assert(conf.isValid())
#Create Game Logic
usenixlogic = UsenixPublicLogic(conf,init)
#Create GameStateBot
game_state_bot = GameStateBot(conf,usenixlogic)
game_state_bot.start()
time.sleep(1)
#Create ServiceBot
servicebot = ServiceBot(conf,init)
servicebot.start()
#Create UsenixReportBot
reportbot = UsenixReportBot(conf,8081)
reportbot.start()
servicebot.join()
reportbot.join()
game_state_bot.join()
def startAll(init):
#Setup config
cip = ConfigIniParser()
cip.addHandler(ServiceBotConfigHandler())
cip.addHandler(ServiceConfigHandler())
cip.addHandler(UsenixConfigHandler())
cip.addHandler(UsenixExploitConfigHandler())
#cip.addHandler(AttackConfigHandler(False))
#Load conf file
config_path = "config/usenix.ini"
conf = cip.load(config_path)
#Temporary hack - this should be in config file..
conf.setFlagPhrase("flags wave in the wind")
assert(conf.isValid())
#Create Game Logic
usenixlogic = UsenixLogic(conf,init)
#Create GameStateBot
game_state_bot = GameStateBot(conf,usenixlogic)
game_state_bot.start()
time.sleep(1)
#Create ServiceBot
servicebot = ServiceBot(conf,init)
servicebot.start()
#Create Scoreboard
#Create UsenixExploitBot
usenix_exploit_bot = UsenixExploitBot(conf,init)
usenix_exploit_bot.start()
#Create UsenixReportBot
reportbot = UsenixReportBot(conf,8082)
reportbot.start()
reportbot.join()
usenix_exploit_bot.join()
servicebot.join()
game_state_bot.join()
def main(argv):
if(len(argv) == 2):
startBot(argv[1],False)
elif(len(argv) == 3):
if(argv[2] == "init"):
if(checkInit()):
startBot(argv[1],True)
else:
print "Not going to do anything..."
return
else:
print usage(argv)
else:
print usage(argv)
if __name__ == "__main__":
main(sys.argv)