Skip to content

Commit 83f528f

Browse files
committed
Revamp general-ssh mechanics
1 parent 131f3e4 commit 83f528f

File tree

4 files changed

+27
-89
lines changed

4 files changed

+27
-89
lines changed

example-problems/general-ssh/Dockerfile

+21-28
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,48 @@
1-
# LAUNCH sshHost
2-
3-
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS builder
1+
# LAUNCH ssh_host
42

3+
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS builder_base
54

65
# Install challenge dependencies within the image
76
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
87
python3
98

10-
119
# Create challenge dir for metadata.json and other file artifacts
12-
RUN mkdir /challenge
13-
10+
RUN mkdir /challenge && chmod 700 /challenge
11+
COPY config-builder.py /challenge/
1412

15-
# Bring in all environment vars from cmgr
13+
FROM builder_base as builder
14+
# Bring in cmgr args
1615
ARG SEED
17-
ARG FLAG_FORMAT
1816
ARG FLAG
1917

20-
21-
COPY config-builder.py /challenge/config-builder.py
22-
2318
RUN python3 /challenge/config-builder.py
2419

25-
26-
2720
#######################
2821
#### Host: sshHost ####
2922
#######################
30-
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS sshHost
31-
23+
FROM ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS ssh_host_base
3224

3325
# Install challenge dependencies within the image
3426
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
3527
openssh-server \
36-
socat \
37-
python3
28+
python3 \
29+
socat
3830

31+
COPY config-sshhost.py /challenge/
32+
COPY start.sh /opt/
33+
COPY profile /home/ctf-player/.profile
34+
COPY instructions-to-2of3.txt /home/ctf-player/drop-in/
35+
COPY instructions-to-3of3.txt /
36+
COPY --from=builder /challenge/1of3.flag.txt /home/ctf-player/drop-in/
37+
COPY --from=builder /challenge/2of3.flag.txt /
3938

40-
COPY --from=builder /challenge/password.txt /tmp/password.txt
41-
COPY config-sshhost.py /challenge/config-sshhost.py
42-
COPY start.sh /opt/start.sh
39+
FROM ssh_host_base AS ssh_host
40+
COPY --from=builder /challenge/password.txt /tmp/
4341

44-
RUN python3 /challenge/config-sshhost.py
45-
RUN rm -rf /challenge/
42+
RUN python3 /challenge/config-sshhost.py && \
43+
rm -rf /challenge/
4644

47-
COPY profile /home/ctf-player/.profile
48-
COPY instructions-to-2of3.txt /home/ctf-player/drop-in/instructions-to-2of3.txt
49-
COPY instructions-to-3of3.txt /instructions-to-3of3.txt
50-
COPY --from=builder /challenge/1of3.flag.txt /home/ctf-player/drop-in/1of3.flag.txt
51-
COPY --from=builder /challenge/2of3.flag.txt /2of3.flag.txt
52-
COPY --from=builder /challenge/3of3.flag.txt /home/ctf-player/3of3.flag.txt
45+
COPY --from=builder /challenge/3of3.flag.txt /home/ctf-player/
5346

5447
EXPOSE 5555
5548
# PUBLISH 5555 AS ssh

example-problems/general-ssh/Dockerfile.test

-39
This file was deleted.

example-problems/general-ssh/config-builder.py

-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
# Configure a box for the general ssh example challenge.
33
################################################################################
44

5-
65
import sys
76
import os
87
import subprocess
98
import re
109
import zlib
1110
import json
1211

13-
14-
1512
def main():
1613

1714
try:
@@ -62,7 +59,6 @@ def main():
6259

6360
# =====================================================================
6461

65-
6662
# Create and update metadata.json =====================================
6763

6864
metadata = {}
@@ -79,11 +75,8 @@ def main():
7975
print("A subprocess has returned an error code")
8076
sys.exit(1)
8177

82-
83-
8478
# =============================================================================
8579

86-
8780
if __name__ == "__main__":
8881
main()
8982

example-problems/general-ssh/config-sshhost.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22
# Configure a box for the general ssh example challenge.
33
################################################################################
44

5-
65
import sys
7-
import os
86
import subprocess
9-
import re
10-
import zlib
11-
import json
12-
13-
147

158
def main():
169

@@ -27,15 +20,14 @@ def main():
2720

2821
# =====================================================================
2922

30-
3123
# Make new dirs =======================================================
32-
subprocess.run(
33-
["/bin/sh", "-c", "mkdir /home/ctf-player"], check=True
34-
)
24+
#subprocess.run(
25+
# ["/bin/sh", "-c", "mkdir /home/ctf-player"], check=True
26+
#)
3527

36-
subprocess.run(
37-
["/bin/sh", "-c", "mkdir /home/ctf-player/drop-in"], check=True
38-
)
28+
#subprocess.run(
29+
# ["/bin/sh", "-c", "mkdir /home/ctf-player/drop-in"], check=True
30+
#)
3931

4032
# =====================================================================
4133

@@ -86,4 +78,3 @@ def main():
8678

8779
if __name__ == "__main__":
8880
main()
89-

0 commit comments

Comments
 (0)