forked from wapiflapi/CaH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintchalls.py
executable file
·83 lines (65 loc) · 2.03 KB
/
printchalls.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
#!/usr/bin/env python3
## genflag.py for in /home/eax/dev/cq-ctf
##
## Made by eax
## Login <[email protected]>
##
## Started on Wed Apr 15 18:12:11 2015 eax
## Last update Thu Apr 16 10:22:15 2015 Wannes Rombouts
##
import configparser
import glob
import re
def flag_to_regex(f):
if not (f.startswith('flag{') and f.endswith('}')):
raise ValueError("not a valid flag")
regex = '^(flag{)?%s}?$' % re.escape(f[5:-1])
# let's make sure this works:
if not re.match(regex, f):
raise RuntimeError("regex fail")
if not re.match(regex, f[5:-1]):
raise RuntimeError("regex fail")
if re.match(regex, f[5:-5]):
raise RuntimeError("regex fail")
if re.match(regex, f[5:] + "foo"):
raise RuntimeError("regex fail")
if re.match(regex, f[5:-1] + "foo"):
raise RuntimeError("regex fail")
if re.match(regex, f[5:-5] + "foo"):
raise RuntimeError("regex fail")
if re.match(regex, "foo" + f[5:]):
raise RuntimeError("regex fail")
if re.match(regex, "foo" + f[5:-1]):
raise RuntimeError("regex fail")
if re.match(regex, "foo" + f[5:-5]):
raise RuntimeError("regex fail")
return regex
def print_challs(c):
config = configparser.ConfigParser()
config.read(c + "/chall.cfg")
name = config["chall"]["name"]
flag = config["chall"]["flag"]
desc = open(c + "/desc.txt").read().strip()
ip = "<ip>"
if "ip" in config["chall"]:
ip = config["chall"]["ip"]
port = "<port>"
if "port" in config["chall"]:
port = config["chall"]["port"]
desc = desc.replace("<ip>", ip).replace("<port>", port)
print("#" * 31)
print("#%s#" % name.center(29))
print("#%s#" % c.split("/")[1].center(29))
print("#" * 31)
print("-" * 31)
print(flag_to_regex(flag))
print("-" * 31)
print(desc)
print("-" * 31)
print("\n"*3)
if __name__ == "__main__":
challs = glob.glob("challs/*/*")
for c in challs:
if "ex_category" in c:
continue
print_challs(c)