Skip to content

Commit 021d30b

Browse files
committed
Revamp reversing-python and web-css
1 parent bcf39e9 commit 021d30b

File tree

8 files changed

+27
-74
lines changed

8 files changed

+27
-74
lines changed
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
1+
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS base
22

33
RUN apt-get update \
44
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
5-
socat \
6-
python3
5+
python3 \
6+
socat
77

8-
RUN install -d -m 0700 /challenge
8+
RUN mkdir /challenge && chmod 700 /challenge
99

10-
COPY picker-I.py /app/
11-
COPY setup-challenge.py /app/
10+
COPY picker-I.py setup-challenge.py /app/
11+
COPY start.sh /opt/
1212
WORKDIR /app/
13+
RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
1314

14-
15-
ARG FLAG_FORMAT
15+
FROM base AS challenge
1616
ARG FLAG
17-
ARG SEED
1817

1918
RUN python3 setup-challenge.py
20-
RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
21-
22-
23-
COPY start.sh /opt/start.sh
2419

20+
# The start.sh script starts a socat listener on port 5555, that connects to the
21+
# python script.
2522
EXPOSE 5555
2623
# PUBLISH 5555 AS socat
2724
CMD ["/opt/start.sh"]
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
1+
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS base
22

33
RUN apt-get update \
44
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
5-
socat \
6-
python3
5+
python3 \
6+
socat
77

8-
RUN install -d -m 0700 /challenge
8+
RUN mkdir /challenge && chmod 700 /challenge
99

10-
COPY picker-I.py /app/
11-
COPY setup-challenge.py /app/
10+
COPY picker-I.py setup-challenge.py /app/
11+
COPY start.sh /opt/
1212
WORKDIR /app/
13+
RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
1314

14-
15-
ARG FLAG_FORMAT
15+
FROM base AS challenge
1616
ARG FLAG
17-
ARG SEED
1817

1918
RUN python3 /challenge/setup-challenge.py
20-
RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
21-
22-
23-
COPY start.sh /opt/start.sh
2419

20+
# The start.sh script starts a socat listener on port 5555, that connects to the
21+
# python script.
2522
EXPOSE 5555
2623
# PUBLISH 5555 AS socat
2724
CMD ["/opt/start.sh"]

example-problems/reversing-python/setup-challenge.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
################################################################################
2-
# Setup level 4 password cracking challenge for multiple instances
2+
# Setup flag and metadata for the challenge
33
################################################################################
44

5-
65
import sys
76
import subprocess
87
import os
98
import re
10-
import zlib
119
import json
12-
import random
13-
import hashlib
14-
15-
1610

1711
def main():
1812

@@ -40,7 +34,6 @@ def main():
4034

4135
# =====================================================================
4236

43-
4437
# Create and update metadata.json =====================================
4538

4639
metadata = {}
@@ -56,10 +49,7 @@ def main():
5649
print("A subprocess got an error")
5750
sys.exit(1)
5851

59-
6052
# =============================================================================
6153

62-
6354
if __name__ == "__main__":
6455
main()
65-

example-problems/reversing-python/start.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
set -e
44

55
socat tcp-listen:5555,reuseaddr,fork SYSTEM:"python3 /app/picker-I.py"
6-

example-problems/web-css/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN mkdir /challenge && \
1313
COPY ./public-html/ /usr/share/nginx/html/
1414

1515
# Copy box configuration script to challenge directory
16-
COPY config-box.py /challenge/
16+
COPY setup-challenge.py /challenge/
1717

1818
WORKDIR /challenge/
1919

@@ -26,7 +26,7 @@ ARG FLAG
2626
# Configuring the box can be nicer in Python rather than in Docker RUN commands,
2727
# but this particular config just does stuff (creating the flag and
2828
# metadata.json) that we have been doing in the Dockerfile so far.
29-
RUN python3 config-box.py
29+
RUN python3 setup-challenge.py
3030

3131
# Open up this port for the web server
3232
EXPOSE 80

example-problems/web-css/Dockerfile.old

Lines changed: 0 additions & 28 deletions
This file was deleted.

example-problems/web-css/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ challenge.
3939
1. [public-html](/example-problems/web-css/public-html) this directory holds
4040
all the files that our web server hosts.
4141

42-
1. [config-box.py](/example-problems/web-css/config-box.py) This script
43-
generates the flag and appends it to the end of the stylesheet as well as
44-
generating metadata.json that holds the flag's correct value. In previous
42+
1. [setup-challenge.py](/example-problems/web-css/setup-challenge.py) This
43+
script generates the flag and appends it to the end of the stylesheet as well
44+
as generating metadata.json that holds the flag's correct value. In previous
4545
challenges, this was done in the Dockerfile, but this example shows how to
4646
use Python instead, which opens up some doors to creativity.
4747

example-problems/web-css/config-box.py renamed to example-problems/web-css/setup-challenge.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def main():
2424
else:
2525
flag_rand = flag_rand.group()
2626
flag_rand = flag_rand[1:-1]
27+
flag_rand = flag_rand.zfill(8)
2728

2829
new_flag = "picoCTF{1n5p3t0r_ftw_" + flag_rand + "}"
2930

@@ -32,7 +33,6 @@ def main():
3233

3334
# =====================================================================
3435

35-
3636
# Create and update metadata.json =====================================
3737

3838
metadata = {}
@@ -44,9 +44,7 @@ def main():
4444

4545
# =====================================================================
4646

47-
4847
# =============================================================================
4948

50-
5149
if __name__ == "__main__":
5250
main()

0 commit comments

Comments
 (0)