Skip to content

Commit 81642ad

Browse files
author
Robert Haimerl
committed
Merge branch 'main' into fix-command-injection
2 parents ffc1c62 + 2e0248a commit 81642ad

File tree

14 files changed

+88
-291
lines changed

14 files changed

+88
-291
lines changed

.github/workflows/docker.yml

-41
This file was deleted.

.github/workflows/local-analysis.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "Codacy Local Analysis"
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
analyze:
10+
name: analyze
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-java@v4
15+
with:
16+
distribution: temurin
17+
java-version: 17
18+
- uses: gradle/actions/setup-gradle@v3
19+
with:
20+
gradle-version: 8.9
21+
- name: build
22+
run: gradle build
23+
- name: generate coverage report
24+
run: gradle jacocoTestReport
25+
- name: uploade coverage data
26+
uses: codacy/[email protected]
27+
with:
28+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
29+
coverage-reports: reports/coverage.xml
30+
- name: generate and upload local analysis data
31+
uses: codacy/[email protected]
32+
with:
33+
tool: spotbugs
34+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
35+
upload: true

.github/workflows/release.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Release and Attest"
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
create-release:
10+
name: create-release
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
attestations: write
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: insert newrelic key
19+
run: sed -i "s|<LICENSE_KEY>|${{ secrets.NEWRELIC_LICENSE_KEY }}|g" newrelic.yml
20+
- name: Login to Docker Hub
21+
uses: docker/login-action@v3
22+
with:
23+
username: codingdepot
24+
password: ${{ secrets.DOCKERHUB_TOKEN }}
25+
- name: Extract metadata (tags, labels) for Docker
26+
id: meta
27+
uses: docker/metadata-action@v5
28+
with:
29+
tags: type=semver,pattern={{version}}
30+
flavor: latest=false
31+
images: codingdepot/idp-target-registry
32+
- name: Build and push
33+
id: push
34+
uses: docker/build-push-action@v6
35+
with:
36+
push: true
37+
tags: ${{ steps.meta.outputs.tags }}
38+
labels: ${{ steps.meta.outputs.labels }}
39+
- name: Generate artifact attestation
40+
uses: actions/attest-build-provenance@v1
41+
with:
42+
subject-name: docker.io/codingdepot/idp-target-registry
43+
subject-digest: ${{ steps.push.outputs.digest }}
44+
push-to-registry: true

Dockerfile

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ WORKDIR /home/gradle/src
44
RUN gradle downloadNewrelic && gradle unzipNewrelic
55
RUN gradle bootJar --no-daemon
66

7-
8-
FROM eclipse-temurin:17
9-
LABEL org.opencontainers.image.source="https://github.com/DataDog/vulnerable-java-application/"
7+
FROM amazoncorretto:17-alpine
108
EXPOSE 8000
119
RUN mkdir /app
1210
WORKDIR /app
1311
COPY --from=builder /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar
1412
COPY --from=builder /home/gradle/src/newrelic/* /app/newrelic/
1513
COPY --from=builder /home/gradle/src/newrelic.yml /app/newrelic/newrelic.yml
16-
RUN apt-get update && \
17-
apt-get install -y --no-install-recommends iputils-ping=3:20190709-3 && \
18-
apt-get clean && \
19-
rm -rf /var/lib/apt/lists/*
2014

2115
CMD ["java", "-javaagent:/app/newrelic/newrelic.jar", "-jar", "/app/spring-boot-application.jar"]

Makefile

-9
This file was deleted.

README.md

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
# Vulnerable Java application
22

3-
This repository contains a sample application, the "Websites Tester Service", that's vulnerable to a [Command Injection](https://owasp.org/www-community/attacks/Command_Injection) and [Server-Side Request Forgery (SSRF)](https://owasp.org/Top10/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/) vulnerability.
3+
This repository contains a sample application, the "Websites Tester Service", that's vulnerable to a [Command Injection](https://owasp.org/www-community/attacks/Command_Injection) vulnerability.
44

55
> **Warning!**
66
> This application is purposely vulnerable and can trivially be hacked. Don't expose it to the Internet, and don't run it in a production environment.
77
> Instead, you can run it locally on your machine, or in a cloud environment on a private VPC.
88
99
## Running locally
1010

11-
1. Build the image locally, or use `ghcr.io/datadog/vulnerable-java-application`:
11+
1. Build the image locally:
12+
```
13+
docker build -t vulnerable-java-application:latest .
14+
```
1215
2. Run:
1316
```
14-
docker run --rm -p 8000:8000 ghcr.io/datadog/vulnerable-java-application
17+
docker run --rm -p 8000:8000 vulnerable-java-application:latest
1518
```
1619
3. You can then access the web application at <http://127.0.0.1:8000>
1720
18-
## Running on Kubernetes
19-
20-
```
21-
kubectl run vulnerable-application --port=8000 --expose=true --image ghcr.io/datadog/vulnerable-java-application
22-
kubectl port-forward pod/vulnerable-application 8000
23-
```
24-
25-
You can then access the web application at <http://127.0.0.1:8000>
26-
2721
## Exploitation
2822
29-
### Server-side request vulnerability
30-
31-
1. Browse to <http://127.0.0.1:8000/website.html>
32-
2. Note how the input allows you to specify arbitrary URLs such as `http://google.com`, but also any internal IP such as `http://169.254.169.254/latest/meta-data/`
33-
3. When the applications is running in AWS, Azure or GCP, this can often be exploited to retrieve instance metadata credentials
34-
35-
### Command injection vulnerability
36-
3723
1. Browse to <http://127.0.0.1:8000/index.html>
3824
2. Note how the input allows you to specify domain names such as `google.com` and ping them
3925
3. Note that there is some level of input validation - entering `$(whoami)` returns `Invalid domain name: $(whoami) - don't try to hack us!`

build.gradle

+1-33
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ plugins {
22
id 'org.springframework.boot' version '2.7.3'
33
id 'io.spring.dependency-management' version '1.1.5'
44
id 'java'
5-
6-
//id 'com.github.spotbugs' version '6.0.11'
75
id 'jacoco'
8-
//id 'org.sonarqube' version '5.0.0.4638'
96
id "de.undercouch.download" version "5.3.0"
107
}
118

12-
group = 'com.datadoghq.workshops'
13-
version = '0.0.1-SNAPSHOT'
9+
version = '1.0.0'
1410
sourceCompatibility = '17'
1511

1612
repositories {
@@ -25,26 +21,8 @@ dependencies {
2521
compileOnly 'org.projectlombok:lombok:1.18.24'
2622
annotationProcessor 'org.projectlombok:lombok:1.18.24'
2723
testImplementation 'org.springframework.boot:spring-boot-starter-test'
28-
29-
// Added for testing
30-
//spotbugs 'com.github.spotbugs:spotbugs:4.8.4'
31-
//spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0'
3224
}
3325

34-
/*
35-
tasks.spotbugsMain {
36-
ignoreFailures = true
37-
reports.create("sarif") {
38-
required = true
39-
outputLocation = file("$rootDir/reports/spotbugs.sarif")
40-
}
41-
reports.create("html") {
42-
required = true
43-
outputLocation = file("$rootDir/reports/spotbugs.html")
44-
}
45-
}
46-
*/
47-
4826
tasks.named('test') {
4927
useJUnitPlatform()
5028
finalizedBy jacocoTestReport
@@ -68,13 +46,3 @@ task unzipNewrelic(type: Copy) {
6846
from zipTree(file('newrelic/newrelic-java.zip'))
6947
into rootDir
7048
}
71-
72-
/*
73-
sonar {
74-
properties {
75-
property("sonar.projectKey", "Vulnerable-Java-App")
76-
property("sonar.projectName", "Vulnerable Java App")
77-
// add host URL and TOKEN in command line
78-
}
79-
}
80-
*/

gradle/wrapper/gradle-wrapper.jar

-59.3 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.datadoghq.workshops.samplevulnerablejavaapp;
22

33
import com.datadoghq.workshops.samplevulnerablejavaapp.exception.InvalidDomainException;
4-
import com.datadoghq.workshops.samplevulnerablejavaapp.exception.UnableToTestDomainException;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,9 +16,6 @@ public class MainController {
1716
@Autowired
1817
private DomainTestService domainTestService;
1918

20-
@Autowired
21-
private WebsiteTestService websiteTestService;
22-
2319
@RequestMapping(method=RequestMethod.POST, value="/test-domain", consumes="application/json")
2420
public ResponseEntity<String> testDomain(@RequestBody DomainTestRequest request) {
2521
log.info("Testing domain " + request.domainName);
@@ -28,18 +24,8 @@ public ResponseEntity<String> testDomain(@RequestBody DomainTestRequest request)
2824
return new ResponseEntity<>(result, HttpStatus.OK);
2925
} catch(InvalidDomainException e) {
3026
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
31-
} catch (UnableToTestDomainException e) {
32-
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
33-
} catch(Exception e) {
27+
} catch (Exception e) {
3428
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
3529
}
3630
}
37-
38-
@RequestMapping(method=RequestMethod.POST, value="/test-website", consumes="application/json")
39-
public ResponseEntity<String> testWebsite(@RequestBody WebsiteTestRequest request) {
40-
log.info("Testing website " + request.url);
41-
String result = websiteTestService.testWebsite(request);
42-
return new ResponseEntity<>(result, HttpStatus.OK);
43-
}
44-
4531
}

src/main/java/com/datadoghq/workshops/samplevulnerablejavaapp/WebsiteTestRequest.java

-10
This file was deleted.

src/main/java/com/datadoghq/workshops/samplevulnerablejavaapp/WebsiteTestService.java

-31
This file was deleted.

src/main/resources/static/js/website.js

-41
This file was deleted.

0 commit comments

Comments
 (0)