Skip to content

Commit a25516a

Browse files
authored
Added static IPs, Challenge 2 and Challenge 4 (#10)
* testing branches * added base challenge structure * adding readme and gitignore * delete .vs * delete .vs and add .gitignore * Challenge 2 ready for testing * forgot to add the role. * Adding sudo to installed packages. * It's cat, not ls... also changed password. * Added documentation and made it more thematic * fixed sudoers * Updated to static IPs * Challenge 4 ready to test * Trying to fix path issue
1 parent 5d3db8c commit a25516a

File tree

13 files changed

+207
-3
lines changed

13 files changed

+207
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vs

.vs/FITS-CTFs/v16/.suo

-11.5 KB
Binary file not shown.

.vs/slnx.sqlite

-88 KB
Binary file not shown.

hosts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[challengeservers]
2-
192.168.1.130
2+
192.168.10.11
33

44
[devservers]
5-
192.168.1.30
5+
192.168.10.12

main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
become: yes
77
roles:
88
- common
9-
- challenge1
9+
- challenge1
10+
- challenge2
11+
- challenge4

readme.md

+57
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
11
# FITS CTF
2+
3+
## Creating a new challenge
4+
5+
- Create a branch called "challenge#" where # is one above the highest challenge number
6+
- This number will determine the port number if dockerizing the challenge. 6000 + # = the exposed port
7+
8+
- Switch to your branch in the editor and add the following:
9+
- Add a directory called roles/challenge# - this is where all the challenge files go
10+
- Inside of challenge# add:
11+
- A folder called `docker` (if applicable)
12+
- A folder called `tasks`
13+
- A file called <span>`readme.md`</span> which will have the details of the challenge
14+
- A file in `tasks` called `main.yml`
15+
- A file in docker called `Dockerfile` (if applicable, case-sensitive)
16+
- a folder called `resouces` if you need things like config files and webpages copied to the challenge vm/container
17+
18+
### Dockerfiles
19+
20+
If your challenge is using docker, you will need a Dockerfile. It should contain most of what you need in the container for the challenge. Use challenge1's dockerfile as an example.
21+
22+
The dockerfile will handle setup such as:
23+
24+
- What operating system you want the container to run
25+
- What packages you need installed
26+
- Removing unncessary packages
27+
- Creating files, echoing into files (like flags), permissions of files
28+
- Copying files from the host machine to the container (config files, webpages, databases, etc) NOTE: Please see [Ansible Variables](#ansible-variables) for details on how to refer to these files.
29+
30+
As things come up I will make this overview more thorough.
31+
32+
### Creating tasks in tasks/main.yml
33+
34+
The main ansible tasks.yml file has 2 roles:
35+
36+
#### When used with docker:
37+
- Get the dockerfile and necessary resources from orchestrator to the CTF-Challenges VM
38+
- Kickoff docker build to build the image
39+
- Start the container
40+
41+
#### When used with a standalone VM:
42+
TODO as this has not happened yet, but presumably ansible is now responsible for 100% of setup and you will not have a dockerfile at all.
43+
44+
45+
### Ansible Variables
46+
47+
Because prod and dev are pulling from 2 different branches for deployment, variables are used when referring to a file location on orchestrator. For example, in challenge1's `tasks/main.yml` there's this command to copy a dockerfile:
48+
49+
- name: Copy dockerfile
50+
copy:
51+
src: "{{ repo_path }}/roles/challenge1/docker/Dockerfile"
52+
dest: /tmp/docker-challenge1/Dockerfile
53+
mode: '0744'
54+
force: yes
55+
56+
The `src` field has the variable `{{repo_path}}` because depending on the machine it's being deployed to (prod vs dev) the path might be `/home/rundeck/FITS-CTF/` (for prod) or it might be `/home/rundeck/FITS-CTF-DEV/` (for dev).
57+
58+
These variables are defined in `group_vars` and `vars` folders in the root of the project.

roles/challenge2/docker/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update && apt-get install -y openssh-server sudo
4+
RUN mkdir /var/run/sshd
5+
RUN useradd -m -d /home/giant giant
6+
RUN echo 'giant:b0nes2br3ad' | chpasswd
7+
RUN usermod -s /bin/bash giant
8+
9+
# SSH login fix. Otherwise user is kicked off after login
10+
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
11+
ENV NOTVISIBLE "in users profile"
12+
RUN echo "export VISIBLE=now" >> /etc/profile
13+
14+
EXPOSE 22
15+
CMD ["/usr/sbin/sshd", "-D"]
16+
17+
RUN touch /home/giant/catme.txt
18+
RUN echo "flag{Gogmagog}" >> /home/giant/catme.txt
19+
RUN chown root:root /home/giant/catme.txt
20+
RUN chmod 400 /home/giant/catme.txt
21+
RUN echo 'giant ALL=NOPASSWD: /bin/cat, /usr/bin/whoami' >> /etc/sudoers

roles/challenge2/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Challenge 2 - Sudo (NO PASSWD)
2+
3+
## Overview
4+
5+
Challenge is to ssh onto a box and grab the flag in `catme.txt` which is in the user's home directory, BUT the file is owned by root and permissions are 600, so sudo must be used.
6+
7+
SSH is running on port 6002 in an ubuntu 18.04 docker container
8+
9+
## Creds
10+
11+
giant:b0nes2br3ad
12+
13+
## Flag
14+
15+
flag{Gogmagog}

roles/challenge2/tasks/main.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
- name: Create a directory if it does not exist
2+
file:
3+
path: /tmp/docker-challenge2
4+
state: directory
5+
mode: '0755'
6+
7+
- name: Copy dockerfile
8+
copy:
9+
src: "{{ repo_path }}/roles/challenge2/docker/Dockerfile"
10+
dest: /tmp/docker-challenge2/Dockerfile
11+
mode: '0744'
12+
force: yes
13+
14+
- name: Build image
15+
docker_image:
16+
name: challenge2-image
17+
build:
18+
path: /tmp/docker-challenge2/
19+
source: build
20+
state: present
21+
force_source: yes
22+
repository: challenge2-image:latest
23+
force_tag: yes
24+
25+
- name: Run the container
26+
docker_container:
27+
name: challenge2-ssh
28+
image: challenge2-image
29+
state: started
30+
restart: yes
31+
expose: 22
32+
detach: yes
33+
published_ports: '6002:22'

roles/challenge4/docker/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update && apt-get install -y openssh-server sudo
4+
RUN mkdir /var/run/sshd
5+
RUN useradd -m -d /home/sysadmin sysadmin
6+
RUN echo 'sysadmin:ikn0wwh4timd0ing' | chpasswd
7+
RUN usermod -s /bin/bash sysadmin
8+
9+
# SSH login fix. Otherwise user is kicked off after login
10+
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
11+
ENV NOTVISIBLE "in users profile"
12+
RUN echo "export VISIBLE=now" >> /etc/profile
13+
14+
EXPOSE 22
15+
CMD ["/usr/sbin/sshd", "-D"]
16+
17+
COPY --chown=sysadmin:sysadmin super_secret_program /home/sysadmin/super_secret_program
18+
RUN chmod 644 /home/sysadmin/super_secret_program

roles/challenge4/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Challenge 4 - chmod
2+
3+
## Overview
4+
5+
Challenge is to ssh onto a box and execute an obsfuscated program which has the flag in it. Permissions will be 644 owned by the user and they need to chmod +x or chmod 744 to run it.
6+
7+
SSH is running on port 6004 in an ubuntu 18.04 docker container
8+
9+
## Creds
10+
11+
sysadmin:ikn0wwh4timd0ing
12+
13+
## Flag
14+
15+
flag{bad_permissions_are_a_bad_day}

roles/challenge4/resources/super_secret_program

+2
Large diffs are not rendered by default.

roles/challenge4/tasks/main.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- name: Create a directory if it does not exist
2+
file:
3+
path: /tmp/docker-challenge4
4+
state: directory
5+
mode: '0755'
6+
7+
- name: Copy dockerfile
8+
copy:
9+
src: "{{ repo_path }}/roles/challenge4/docker/Dockerfile"
10+
dest: /tmp/docker-challenge4/Dockerfile
11+
mode: '0744'
12+
force: yes
13+
14+
- name: Copy program with the flag
15+
copy:
16+
src: "{{ repo_path }}/roles/challenge4/resources/super_secret_program"
17+
dest: /tmp/docker-challenge4/super_secret_program
18+
mode: '0744'
19+
force: yes
20+
21+
- name: Build image
22+
docker_image:
23+
name: challenge4-image
24+
build:
25+
path: /tmp/docker-challenge4/
26+
source: build
27+
state: present
28+
force_source: yes
29+
repository: challenge4-image:latest
30+
force_tag: yes
31+
32+
- name: Run the container
33+
docker_container:
34+
name: challenge4-ssh
35+
image: challenge4-image
36+
state: started
37+
restart: yes
38+
expose: 22
39+
detach: yes
40+
published_ports: '6004:22'

0 commit comments

Comments
 (0)