Skip to content

Commit 37baf7c

Browse files
author
Jonathan
committed
Corrected bug with port and delete the flag content in cheat monitor
1 parent 44b6a55 commit 37baf7c

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

__init__.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
PLUGIN_PATH = os.path.dirname(__file__)
3636
CONFIG = json.load(open("{}/config.json".format(PLUGIN_PATH)))
3737

38-
directory_name = PLUGIN_PATH.split(os.sep)[-1]
38+
directory_name = PLUGIN_PATH.split(os.sep)[-1] # Get the directory name of this file
3939

4040
red = Blueprint(directory_name, __name__, template_folder="templates")
4141

@@ -84,28 +84,30 @@ def create(request):
8484
# Check if there is teams that are created
8585
teams = Teams.query.all()
8686
if len(teams) > 0:
87+
88+
# Get the last port used
89+
last_container = Containers.query.order_by(Containers.port.desc()).first()
90+
if last_container_port is None:
91+
port = globals.PORT_CONTAINERS_START
92+
else:
93+
port = last_container.port + 1
94+
8795
# For each team, create a flag and a container for the challenge
8896
for team in teams:
8997
generated_flag = generate_flag()
9098

91-
# Get the last port used
92-
last_container_port = Containers.query.order_by(Containers.port.desc()).first()
93-
94-
if last_container_port is None:
95-
port = globals.PORT_CONTAINERS_START
96-
else:
97-
port = last_container_port.port + 1
98-
9999
# Generate the container
100100
container_name = create_docker_container(buildfile=buildfile, flag=generated_flag, port=port, challenge_name=challenge.name, team_id=team.id)
101101

102102
# Save the container in the database
103103
container = Containers(name=container_name, port=port, dockerfile=buildfile, challengeid=challenge.id, teamid=team.id)
104+
port += 1
104105
db.session.add(container)
105106

106107
# Save the flag in the database
107108
flag = Flags(challenge_id = challenge.id, type = "red_herring", content = generated_flag, data = team.id)
108109
db.session.add(flag)
110+
109111

110112
db.session.commit()
111113

hooks.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ def on_team_create(mapper, conn, team):
99
# When a team is created, create a new flag for each challenge that is a "red_herring" type
1010
red_herring_challenges = Challenges.query.filter_by(type="red_herring").all()
1111

12+
port = globals.PORT_CONTAINERS_START
13+
if len(red_herring_challenges) != 0:
14+
15+
# Get the last port used
16+
last_container = Containers.query.order_by(Containers.port.desc()).first()
17+
if last_container is not None:
18+
port = last_container.port + 1
19+
1220
for challenge in red_herring_challenges:
1321
generated_flag = generate_flag()
1422

@@ -17,14 +25,6 @@ def on_team_create(mapper, conn, team):
1725
db.session.add(flag)
1826

1927
# Create the container
20-
# Get the next port to use
21-
last_container_port = Containers.query.order_by(Containers.port.desc()).first()
22-
23-
if last_container_port is None:
24-
port = globals.PORT_CONTAINERS_START
25-
else:
26-
port = last_container_port.port + 1
27-
2828
# Get the buildfile of the challenge
2929
buildfile = challenge.dockerfile
3030

@@ -33,6 +33,7 @@ def on_team_create(mapper, conn, team):
3333

3434
# Save the container in the database
3535
container = Containers(name=container_name, port=port, dockerfile=buildfile, challengeid=challenge.id, teamid=team.id)
36+
port += 1
3637
db.session.add(container)
3738

3839
def load_hooks():

models.py

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def shared_team_name(self):
5858

5959
def challenge_name(self):
6060
return Challenges.query.filter_by(id=self.challengeid).first().name
61-
62-
def flag_content(self):
63-
return Flags.query.filter_by(id=self.flagid).first().content
6461

6562
class Containers(db.Model):
6663
id = db.Column(db.Integer, primary_key=True)

templates/red_herring.html

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ <h1>RedHerring - Cheat Monitor</h1>
1919
<td scope="col"><b>Challenge</b></td>
2020
<td scope="col"><b>Cheat Team</b></td>
2121
<td scope="col"><b>Sharer Team</b></td>
22-
<td scope="col"><b>Flag shared</b></td>
2322
<td scope="col"><b>Date</b></td>
2423
</tr>
2524
</thead>
@@ -30,7 +29,6 @@ <h1>RedHerring - Cheat Monitor</h1>
3029
<td><a href="{{ request.script_root }}/admin/challenges/{{ cheater.challengeid }}">{{ cheater.challenge_name() }}</a></td>
3130
<td><a href="{{ request.script_root }}/teams/{{ cheater.cheatteamid }}">{{ cheater.cheated_team_name() }}</a></td>
3231
<td><a href="{{ request.script_root }}/teams/{{ cheater.sharerteamid }}">{{ cheater.shared_team_name() }}</a></td>
33-
<td>{{ cheater.flag_content() }}</td>
3432
<td>{{ cheater.date}}</td>
3533
</tr>
3634
{% endfor %}

0 commit comments

Comments
 (0)