-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
executable file
·106 lines (91 loc) · 2.47 KB
/
configure.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
#!/usr/bin/env python3
import os
import sys
import json
# get the team name
cname = ''
if len(sys.argv) < 2:
print('run again like this:\n\n{} "<name of this challenge>"\n\nnotice the double quotes (needed if you use any spaces)'.format(sys.argv[0]))
exit(1)
cname = sys.argv[1]
contents = {}
files = os.listdir('./web/scripts')
# ask before overwriting json file
if os.path.isfile('./web/json/vulns.json'):
answer = ''
while answer != 'n' and answer != 'y':
answer = input('web/json/vulns.json already exists, overwrite? (y/n): ')
if answer == 'n':
exit(1)
# ensure scripts directory exists before proceeding
if not os.path.isdir('./web/scripts'):
print('cannot find web/scripts/')
exit(1)
# get names of script files
if files == []:
print('web/scripts/ is empty')
exit(1)
# iterate script filenames
for file in files:
# read file
try:
f = open('./web/scripts/' + file, 'r')
except IsADirectoryError:
continue
data = f.readlines()
f.close()
# default values
shell = '/bin/bash'
name = file.split('.')[0]
points = 2
setup = ''
# get shell
try:
if data[0][0] + data[0][1] == '#!':
shell = data[0][2:len(data[0])-1]
except IndexError:
pass
# get name
try:
if data[1][0] == '#':
if data[1][1] == ' ':
name = data[1][2:]
else:
name = data[1][1:]
split = name.split(' ')
name = ' '.join(split[:len(split)-1])
# get points
try:
points = int(split[-1])
except TypeError:
pass
except IndexError:
pass
# get setup
try:
if data[2][0] == '#':
if data[2][1] == ' ':
setup = data[2][2:]
else:
setup = data[2][1:]
split = setup.split(' ')
setup = ' '.join(split)
setup = setup[:len(setup)-1]
except IndexError:
pass
# set data
contents[name] = {
'shell': shell,
'url': '{}'.format(file),
'points': points,
'setup_url': setup,
'name': name
}
# make json directory if it does not exist
if not os.path.isdir('./web/json'):
os.mkdir('./web/json')
# write data
with open('./web/json/vulns.json', 'w') as e:
json.dump(contents, e)
with open('./web/config.py', 'w') as e:
e.write('game_name = "{}"'.format(cname))