File tree Expand file tree Collapse file tree 8 files changed +27
-74
lines changed Expand file tree Collapse file tree 8 files changed +27
-74
lines changed Original file line number Diff line number Diff line change 1
- FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
1
+ FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS base
2
2
3
3
RUN apt-get update \
4
4
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
5
- socat \
6
- python3
5
+ python3 \
6
+ socat
7
7
8
- RUN install -d -m 0700 /challenge
8
+ RUN mkdir /challenge && chmod 700 /challenge
9
9
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 /
12
12
WORKDIR /app/
13
+ RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
13
14
14
-
15
- ARG FLAG_FORMAT
15
+ FROM base AS challenge
16
16
ARG FLAG
17
- ARG SEED
18
17
19
18
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
24
19
20
+ # The start.sh script starts a socat listener on port 5555, that connects to the
21
+ # python script.
25
22
EXPOSE 5555
26
23
# PUBLISH 5555 AS socat
27
24
CMD ["/opt/start.sh" ]
Original file line number Diff line number Diff line change 1
- FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
1
+ FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS base
2
2
3
3
RUN apt-get update \
4
4
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
5
- socat \
6
- python3
5
+ python3 \
6
+ socat
7
7
8
- RUN install -d -m 0700 /challenge
8
+ RUN mkdir /challenge && chmod 700 /challenge
9
9
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 /
12
12
WORKDIR /app/
13
+ RUN tar czvf /challenge/artifacts.tar.gz picker-I.py
13
14
14
-
15
- ARG FLAG_FORMAT
15
+ FROM base AS challenge
16
16
ARG FLAG
17
- ARG SEED
18
17
19
18
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
24
19
20
+ # The start.sh script starts a socat listener on port 5555, that connects to the
21
+ # python script.
25
22
EXPOSE 5555
26
23
# PUBLISH 5555 AS socat
27
24
CMD ["/opt/start.sh"]
Original file line number Diff line number Diff line change 1
1
################################################################################
2
- # Setup level 4 password cracking challenge for multiple instances
2
+ # Setup flag and metadata for the challenge
3
3
################################################################################
4
4
5
-
6
5
import sys
7
6
import subprocess
8
7
import os
9
8
import re
10
- import zlib
11
9
import json
12
- import random
13
- import hashlib
14
-
15
-
16
10
17
11
def main ():
18
12
@@ -40,7 +34,6 @@ def main():
40
34
41
35
# =====================================================================
42
36
43
-
44
37
# Create and update metadata.json =====================================
45
38
46
39
metadata = {}
@@ -56,10 +49,7 @@ def main():
56
49
print ("A subprocess got an error" )
57
50
sys .exit (1 )
58
51
59
-
60
52
# =============================================================================
61
53
62
-
63
54
if __name__ == "__main__" :
64
55
main ()
65
-
Original file line number Diff line number Diff line change 3
3
set -e
4
4
5
5
socat tcp-listen:5555,reuseaddr,fork SYSTEM:" python3 /app/picker-I.py"
6
-
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ RUN mkdir /challenge && \
13
13
COPY ./public-html/ /usr/share/nginx/html/
14
14
15
15
# Copy box configuration script to challenge directory
16
- COPY config-box .py /challenge/
16
+ COPY setup-challenge .py /challenge/
17
17
18
18
WORKDIR /challenge/
19
19
@@ -26,7 +26,7 @@ ARG FLAG
26
26
# Configuring the box can be nicer in Python rather than in Docker RUN commands,
27
27
# but this particular config just does stuff (creating the flag and
28
28
# metadata.json) that we have been doing in the Dockerfile so far.
29
- RUN python3 config-box .py
29
+ RUN python3 setup-challenge .py
30
30
31
31
# Open up this port for the web server
32
32
EXPOSE 80
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -39,9 +39,9 @@ challenge.
39
39
1 . [ public-html] ( /example-problems/web-css/public-html ) this directory holds
40
40
all the files that our web server hosts.
41
41
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
45
45
challenges, this was done in the Dockerfile, but this example shows how to
46
46
use Python instead, which opens up some doors to creativity.
47
47
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ def main():
24
24
else :
25
25
flag_rand = flag_rand .group ()
26
26
flag_rand = flag_rand [1 :- 1 ]
27
+ flag_rand = flag_rand .zfill (8 )
27
28
28
29
new_flag = "picoCTF{1n5p3t0r_ftw_" + flag_rand + "}"
29
30
@@ -32,7 +33,6 @@ def main():
32
33
33
34
# =====================================================================
34
35
35
-
36
36
# Create and update metadata.json =====================================
37
37
38
38
metadata = {}
@@ -44,9 +44,7 @@ def main():
44
44
45
45
# =====================================================================
46
46
47
-
48
47
# =============================================================================
49
48
50
-
51
49
if __name__ == "__main__" :
52
50
main ()
You can’t perform that action at this time.
0 commit comments