Skip to content

Commit dcb094b

Browse files
committed
integrating with SonarQube to show vulnerabilities metrics
1 parent e70c936 commit dcb094b

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
<version>0.0.1-SNAPSHOT</version>
88
<name>JavaVulnerableLab Maven Webapp</name>
99
<url>http://maven.apache.org</url>
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<jetty-version>9.4.0.v20161208</jetty-version>
13+
<spring.version>4.0.2.RELEASE</spring.version>
14+
<tomcat.version>8.0.28</tomcat.version>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
</properties>
1018
<dependencies>
1119
<dependency>
1220
<groupId>junit</groupId>
1321
<artifactId>junit</artifactId>
14-
<version>3.8.1</version>
22+
<version>4.12</version>
1523
<scope>test</scope>
1624
</dependency>
1725
<dependency>

sonar-project.properties

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sonar.projectKey=org.cysecurity:JavaVulnerableLab
2+
sonar.projectName=pJavaVulnerableLab
3+
sonar.projectVersion=0.0.1-SNAPSHOT
4+
sonar.sources=src/main/java
5+
sonar.sourceEncoding=UTF-8
6+
sonar.binaries=target/classes
7+
sonar.java.binaries=target/classes
8+
sonar.tests=src/test/java
9+
sonar.scm.provider=git
10+
11+
#Java report only
12+
sonar.language=java
13+
14+
sonar.zaproxy.reportPath=${WORKSPACE}/zaproxy-report.xml

sonarqube/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
FROM sonarqube:lts
3+
USER root
4+
RUN apt-get update && apt-get install -y wget
5+
6+
USER sonarqube
7+
RUN wget https://github.com/Coveros/zap-sonar-plugin/releases/download/sonar-zap-plugin-1.2.0/sonar-zap-plugin-1.2.0.jar -O /opt/sonarqube/extensions/plugins/sonar-zap-plugin-1.2.0.jar
8+
9+
ENTRYPOINT ["./bin/run.sh"]
10+
479 KB
Loading

sonarqube/run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ "${1:0:1}" != '-' ]; then
6+
exec "$@"
7+
fi
8+
9+
#chown -R sonarqube:sonarqube $SONARQUBE_HOME
10+
exec
11+
java -jar lib/sonar-application-$SONAR_VERSION.jar \
12+
-Dsonar.log.console=true \
13+
-Dsonar.jdbc.username="$SONARQUBE_JDBC_USERNAME" \
14+
-Dsonar.jdbc.password="$SONARQUBE_JDBC_PASSWORD" \
15+
-Dsonar.jdbc.url="$SONARQUBE_JDBC_URL" \
16+
-Dsonar.security.realm="$SONARQUBE_SECURITY_REALM" \
17+
-Dsonar.security.savePassword="$SONARQUBE_SECURITY_SAVEPASSWORD" \
18+
-Dldap.bindDn="$SONARQUBE_LDAP_BINDDN" \
19+
-Dldap.bindPassword="$SONARQUBE_LDAP_BINDPASSWORD" \
20+
-Dldap.url="$SONARQUBE_LDAP_URL" \
21+
-Dldap.user.baseDn="$SONARQUBE_LDAP_USER_BASEDN" \
22+
-Dldap.user.request="$SONARQUBE_LDAP_USER_REQUEST" \
23+
-Dldap.user.realNameAttribute="$SONARQUBE_LDAP_USER_REALNAMEATTRIBUTE" \
24+
-Dldap.group.baseDn="$SONARQUBE_LDAP_GROUP_BASEDN" \
25+
-Dldap.group.request="$SONARQUBE_LDAP_GROUP_REQUEST" \
26+
-Dldap.group.idAttribute="$SONARQUBE_LDAP_GROUP_IDATTRIBUTE" \
27+
-Dsonar.ce.javaOpts="$SONARQUBE_CE_JVM_OPTS" \
28+
-Dsonar.web.javaOpts="$SONARQUBE_WEB_JVM_OPTS" \
29+
-Dsonar.web.javaAdditionalOpts="-Djava.security.egd=file:/dev/./urandom" \
30+
"$@"

sonarqube/sonarqube.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
## Add configuration
3+
4+
We need to add sonar configuration for the project to let mvn scan it.
5+
6+
```sh
7+
echo "
8+
sonar.projectKey=org.cysecurity:JavaVulnerableLab
9+
sonar.projectName=pJavaVulnerableLab
10+
sonar.projectVersion=0.0.1-SNAPSHOT
11+
sonar.sources=src/main/java
12+
sonar.sourceEncoding=UTF-8
13+
sonar.binaries=target/classes
14+
sonar.java.binaries=target/classes
15+
sonar.tests=src/test/java
16+
sonar.scm.provider=git
17+
18+
#Java report only
19+
sonar.language=java
20+
21+
sonar.zaproxy.reportPath=${WORKSPACE}/zaproxy-report.xml
22+
" > ./sonar-project.properties
23+
```
24+
25+
The line below indicates to the Maven Sonar plugin to use the ZAP-Proxy plugin when do a scan in the project codebase :
26+
27+
```
28+
sonar.zaproxy.reportPath=${WORKSPACE}/zaproxy-report.xml
29+
```
30+
31+
## ZAP Sonar plugin
32+
33+
We can use a plugin that has been developed by Gene Gotimer ([zap-sonar-plugin](https://github.com/Coveros/zap-sonar-plugin)). And for information, as per the time this is being tested, that plugin requires SonarQube 7.9.
34+
35+
## SonarQube instance
36+
37+
In order to be able to scan the code for vulnerabilities as well as for code qualimetry (coverage, duplication...), we need a running instance of SonarQube. Here we are using Docker to provide that instance, and by the way we do have to create a Dockerfile adding the Zap-Proxy plugin jar on top of SonarQube docker image `sonarqube:lts`. The Current LTS version is 7.9.
38+
39+
## Run a scan
40+
41+
Run this command to analyse the codebase :
42+
43+
```sh
44+
mvn sonar:sonar
45+
```
46+
47+
It connected to the SonarQube server to retrieve informations, such as rules and plugins to apply while scanning the code.
48+
49+
## Quality Metrics
50+
51+
Once this is done, we can see the metrics on SonarQube [Dashboard](http://127.0.0.1:9000/project/issues?id=org.cysecurity%3AJavaVulnerableLab&resolved=false&sonarsourceSecurity=sql-injection&types=SECURITY_HOTSPOT)
52+
53+
![Alt Text](./Java-SonarQube-OWASP-Vulnerabilities.png)

0 commit comments

Comments
 (0)