-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
110 lines (84 loc) · 3.18 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# MIT License
# Copyright (c) 2022 Saket Upadhyay
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
FROM ubuntu:18.04
# you can also use ubuntu:latest ; 18.04 also works well.
LABEL maintainer="saketupadhyay"
# Update Ubuntu and Install important packages/tools
RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y update && apt-get install -y \
autoconf \
bison \
flex \
gcc \
g++ \
git \
vim \
python2.7 \
netcat \
net-tools \
socat \
libprotobuf-dev \
libnl-route-3-dev \
libtool \
make \
pkg-config \
protobuf-compiler \
openssh-server \
&& rm -rf /var/lib/apt/lists/*
# Setting up SSH
RUN rm -f /etc/service/sshd/down
RUN export LC_ALL=C
RUN export DEBIAN_FRONTEND=noninteractive
RUN dpkg-reconfigure openssh-server
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
# Adding CTF users / low priv. users
RUN groupadd ctf && \
useradd -g ctf ctf -m -s /bin/bash && \
password=$(openssl passwd -1 -salt 'abcdefg' 'aefei7UR') && \
sed -i 's/^ctf:!/ctf:'$password'/g' /etc/shadow
RUN useradd challenger
# Building NS Jail
COPY ./bin/nsjail/ /nsjail
RUN cd /nsjail && make && mv /nsjail/nsjail /bin/pwnjail
RUN rm -rf /nsjail
# Setting up directories
RUN mkdir /home/packages && chown ctf:ctf /home/packages
WORKDIR /home/ctf/challenge
# Setting up challenge binary
COPY ./chal /home/ctf/challenge
# Adding chllenge file and flag
# This will give any binary you import a general name- "challengebin"
RUN mv /home/ctf/challenge/* /home/ctf/challenge/challengebin
RUN chown -R root:ctf /home/ctf/challenge
RUN chmod -R 775 /home/ctf/challenge
WORKDIR /home/ctf
COPY ./flag /home/ctf/flag
RUN chmod 644 /home/ctf/flag && chown root:root /home/ctf
# Copying some essential scripts
ADD ./bin/rerun.sh /
RUN chmod 755 /rerun.sh
ADD ./bin/pwnjailexec.sh /
RUN chmod +x /pwnjailexec.sh
ADD ./bin/start.sh /etc/my_init.d/
RUN chmod u+x /etc/my_init.d/start.sh
# Adding pwnjail configuration from ./bin/pwnjail.cfg
ADD ./bin/pwnjail.cfg /etc/
RUN chmod 644 /etc/pwnjail.cfg
# Exposing port 1337 for communication; change this if needed
EXPOSE 1337