11import datetime
22
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 )
55from markupsafe import escape
66
77from flags import stages # import everything from flags.py
@@ -28,8 +28,8 @@ def flags():
2828 submitted_flags = session ["submitted_flags" ]
2929 hint_index = session ["hint_index" ]
3030
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
3333
3434 if request .method == "POST" :
3535 if "submit_flag" in request .form :
@@ -39,23 +39,27 @@ def flags():
3939 if not submitted_flag .isascii ():
4040 flash ("Invalid flag. Please try again." , "danger" )
4141 return redirect (url_for ("ctf.flags" ))
42-
42+
4343 if submitted_flag in submitted_flags :
4444 flash ("You already submitted this flag." , "info" )
4545 elif submitted_flag == stages [current_stage ]["flag" ]:
4646 flash (f"Correct flag for Stage { current_stage } !" , "success" )
4747 if submitted_flag not in submitted_flags :
4848 submitted_flags .append (submitted_flag )
4949 session ["submitted_flags" ] = submitted_flags
50-
50+
5151 if current_stage < len (stages ):
5252 current_stage += 1
5353 hint_index = 0
5454 elif current_stage == len (stages ):
5555 flash (
5656 "You have completed all the stages. Congratulations!" ,
5757 "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+ )
5963 # if the user has completed all the stages, then flash a
6064 # message
6165 session ["current_stage" ] = current_stage
@@ -70,18 +74,23 @@ def flags():
7074 current_stage = stage
7175 hint_index = 0
7276 found = True
73-
77+
7478 if submitted_flag not in submitted_flags :
7579 submitted_flags .append (submitted_flag )
7680 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+ ):
8087 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. " ,
8393 )
84- return render_template ("message.html" , title = "Congratulations!" , message = "You have completed all the stages of the CTF. " )
8594 # if the user has completed all the stages, then flash a
8695 # message
8796 break
@@ -91,27 +100,30 @@ def flags():
91100
92101 elif "reveal_hint" in request .form :
93102 # 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" ]
96105 ): # if there are more hints to reveal
97106 hint_index += 1
98107 else :
99108 # if the user exhausted all the hints, have it show from the
100109 # beginning
101110 # hint_index = 0
102111 # 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" )
104114 # hide the button till they get to next stage
105115 session ["hint_index" ] = hint_index
106- hints = stages [current_stage ]["hints" ][: hint_index ]
116+ hints = stages [current_stage ]["hints" ][:hint_index ]
107117 notes = stages [current_stage ].get ("notes" )
108118 return render_template (
109- "flags.html" ,title = f"CTFlask - Stage { current_stage } " ,
119+ "flags.html" ,
120+ title = f"CTFlask - Stage { current_stage } " ,
110121 stage = current_stage ,
111122 hints = hints ,
112123 hint_index = hint_index ,
113124 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 ,
115127 )
116128
117129
@@ -127,7 +139,7 @@ def index():
127139 session ["current_stage" ] = 1
128140 if "hint_index" not in session :
129141 session ["hint_index" ] = 0
130-
142+
131143 flash ("Welcome to the CTF, please read the following:" , "info" )
132144 brief = """
133145 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():
176188 """
177189 used for the footer to display the current year
178190 """
179- return {"year" : datetime .date .today ().year }
191+ return {"year" : datetime .date .today ().year }
0 commit comments