1
1
import datetime
2
2
3
- from flask import (Blueprint , flash , redirect , render_template ,
4
- request , session , url_for )
3
+ from flask import (Blueprint , flash , redirect , render_template , request ,
4
+ session , url_for )
5
5
from markupsafe import escape
6
6
7
7
from flags import stages # import everything from flags.py
@@ -28,8 +28,8 @@ def flags():
28
28
submitted_flags = session ["submitted_flags" ]
29
29
hint_index = session ["hint_index" ]
30
30
31
-
32
- # need to verify that the user didn't try to skip stages or trick the system
31
+ # need to verify that the user didn't try to skip stages or trick the
32
+ # system
33
33
34
34
if request .method == "POST" :
35
35
if "submit_flag" in request .form :
@@ -39,23 +39,27 @@ def flags():
39
39
if not submitted_flag .isascii ():
40
40
flash ("Invalid flag. Please try again." , "danger" )
41
41
return redirect (url_for ("ctf.flags" ))
42
-
42
+
43
43
if submitted_flag in submitted_flags :
44
44
flash ("You already submitted this flag." , "info" )
45
45
elif submitted_flag == stages [current_stage ]["flag" ]:
46
46
flash (f"Correct flag for Stage { current_stage } !" , "success" )
47
47
if submitted_flag not in submitted_flags :
48
48
submitted_flags .append (submitted_flag )
49
49
session ["submitted_flags" ] = submitted_flags
50
-
50
+
51
51
if current_stage < len (stages ):
52
52
current_stage += 1
53
53
hint_index = 0
54
54
elif current_stage == len (stages ):
55
55
flash (
56
56
"You have completed all the stages. Congratulations!" ,
57
57
"success" )
58
- return render_template ("message.html" , title = "Congratulations!" , message = "You have completed all the stages of the CTF. " )
58
+ return render_template (
59
+ "message.html" ,
60
+ title = "Congratulations!" ,
61
+ message = "You have completed all the stages of the CTF. " ,
62
+ )
59
63
# if the user has completed all the stages, then flash a
60
64
# message
61
65
session ["current_stage" ] = current_stage
@@ -70,18 +74,23 @@ def flags():
70
74
current_stage = stage
71
75
hint_index = 0
72
76
found = True
73
-
77
+
74
78
if submitted_flag not in submitted_flags :
75
79
submitted_flags .append (submitted_flag )
76
80
session ["submitted_flags" ] = submitted_flags
77
-
78
- # check if they got all the flags (even if they are out of order)
79
- if sorted (submitted_flags ) == sorted ([stage_data ["flag" ] for stage_data in stages .values ()]):
81
+
82
+ # check if they got all the flags (even if they are out
83
+ # of order)
84
+ if sorted (submitted_flags ) == sorted (
85
+ [stage_data ["flag" ] for stage_data in stages .values ()]
86
+ ):
80
87
flash (
81
- "You have completed all the stages. Congratulations!" ,
82
- "success" ,
88
+ "You have completed all the stages. Congratulations!" , "success" , )
89
+ return render_template (
90
+ "message.html" ,
91
+ title = "Congratulations!" ,
92
+ message = "You have completed all the stages of the CTF. " ,
83
93
)
84
- return render_template ("message.html" , title = "Congratulations!" , message = "You have completed all the stages of the CTF. " )
85
94
# if the user has completed all the stages, then flash a
86
95
# message
87
96
break
@@ -91,27 +100,30 @@ def flags():
91
100
92
101
elif "reveal_hint" in request .form :
93
102
# hint_num = request.form.get("reveal_hint")
94
- if (
95
- hint_index < len ( stages [current_stage ]["hints" ])
103
+ if hint_index < len (
104
+ stages [current_stage ]["hints" ]
96
105
): # if there are more hints to reveal
97
106
hint_index += 1
98
107
else :
99
108
# if the user exhausted all the hints, have it show from the
100
109
# beginning
101
110
# hint_index = 0
102
111
# flash a message to the user
103
- flash ("Exhausted all hints for this stage :( Try harder!" , "warning" )
112
+ flash (
113
+ "Exhausted all hints for this stage :( Try harder!" , "warning" )
104
114
# hide the button till they get to next stage
105
115
session ["hint_index" ] = hint_index
106
- hints = stages [current_stage ]["hints" ][: hint_index ]
116
+ hints = stages [current_stage ]["hints" ][:hint_index ]
107
117
notes = stages [current_stage ].get ("notes" )
108
118
return render_template (
109
- "flags.html" ,title = f"CTFlask - Stage { current_stage } " ,
119
+ "flags.html" ,
120
+ title = f"CTFlask - Stage { current_stage } " ,
110
121
stage = current_stage ,
111
122
hints = hints ,
112
123
hint_index = hint_index ,
113
124
submitted_flags = submitted_flags ,
114
- num_hints = len (stages [current_stage ]["hints" ]),notes = notes
125
+ num_hints = len (stages [current_stage ]["hints" ]),
126
+ notes = notes ,
115
127
)
116
128
117
129
@@ -127,7 +139,7 @@ def index():
127
139
session ["current_stage" ] = 1
128
140
if "hint_index" not in session :
129
141
session ["hint_index" ] = 0
130
-
142
+
131
143
flash ("Welcome to the CTF, please read the following:" , "info" )
132
144
brief = """
133
145
Using this site is not required to solve the CTF challenge and is not a part of the CTF challenge itself, but a tool to help you keep track of your progress. You need to find the flags on your own and not via this site itself. Good luck!
@@ -176,4 +188,4 @@ def inject_today_date():
176
188
"""
177
189
used for the footer to display the current year
178
190
"""
179
- return {"year" : datetime .date .today ().year }
191
+ return {"year" : datetime .date .today ().year }
0 commit comments