Skip to content

Commit f9ce850

Browse files
author
gal.benyair
committed
Added HCL IAST code
1 parent cb23399 commit f9ce850

5 files changed

Lines changed: 312 additions & 8 deletions

File tree

‎pom.xml‎

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<configuration>
115115
<target>
116116
<ant target="run" antfile="${basedir}/src/config/build.xml">
117-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
117+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
118118
</ant>
119119
</target>
120120
</configuration>
@@ -128,7 +128,7 @@
128128
<configuration>
129129
<target>
130130
<ant target="databaseServer" antfile="${basedir}/src/config/build.xml">
131-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
131+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
132132
</ant>
133133
</target>
134134
</configuration>
@@ -142,7 +142,7 @@
142142
<configuration>
143143
<target>
144144
<ant target="databaseInit" antfile="${basedir}/src/config/build.xml">
145-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
145+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
146146
</ant>
147147
</target>
148148
</configuration>
@@ -212,7 +212,7 @@
212212
<configuration>
213213
<target>
214214
<ant target="run" antfile="${basedir}/src/config/build.xml">
215-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
215+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
216216
</ant>
217217
</target>
218218
</configuration>
@@ -226,7 +226,7 @@
226226
<configuration>
227227
<target>
228228
<ant target="databaseServer" antfile="${basedir}/src/config/build.xml">
229-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
229+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
230230
</ant>
231231
</target>
232232
</configuration>
@@ -240,7 +240,7 @@
240240
<configuration>
241241
<target>
242242
<ant target="databaseInit" antfile="${basedir}/src/config/build.xml">
243-
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
243+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
244244
</ant>
245245
</target>
246246
</configuration>
@@ -300,6 +300,109 @@
300300
</plugins>
301301
</build>
302302
</profile>
303+
304+
<profile>
305+
<id>deploywhcl</id>
306+
<properties>
307+
<skipTests>true</skipTests>
308+
</properties>
309+
<build>
310+
<plugins>
311+
<plugin>
312+
<artifactId>maven-antrun-plugin</artifactId>
313+
<executions>
314+
<execution>
315+
<id>ldap-server</id>
316+
<phase>package</phase>
317+
<goals>
318+
<goal>run</goal>
319+
</goals>
320+
<configuration>
321+
<target>
322+
<ant target="run" antfile="${basedir}/src/config/build.xml">
323+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
324+
</ant>
325+
</target>
326+
</configuration>
327+
</execution>
328+
<execution>
329+
<id>database-server</id>
330+
<phase>package</phase>
331+
<goals>
332+
<goal>run</goal>
333+
</goals>
334+
<configuration>
335+
<target>
336+
<ant target="databaseServer" antfile="${basedir}/src/config/build.xml">
337+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
338+
</ant>
339+
</target>
340+
</configuration>
341+
</execution>
342+
<execution>
343+
<id>database-init</id>
344+
<phase>package</phase>
345+
<goals>
346+
<goal>run</goal>
347+
</goals>
348+
<configuration>
349+
<target>
350+
<ant target="databaseInit" antfile="${basedir}/src/config/build.xml">
351+
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath" />
352+
</ant>
353+
</target>
354+
</configuration>
355+
</execution>
356+
</executions>
357+
</plugin>
358+
<plugin>
359+
<groupId>org.codehaus.cargo</groupId>
360+
<artifactId>cargo-maven2-plugin</artifactId>
361+
<configuration>
362+
<container>
363+
<timeout>400000</timeout>
364+
<containerId>tomcat${tomcat.major.version}x</containerId>
365+
<zipUrlInstaller>
366+
<url>${tomcat.url}</url>
367+
</zipUrlInstaller>
368+
</container>
369+
<properties>
370+
<cargo.jvmargs>-XX:MaxPermSize=6G -Xms1G –Xmx8G</cargo.jvmargs>
371+
</properties>
372+
<configuration>
373+
<configfiles>
374+
<configfile>
375+
<file>${basedir}/src/config/local/server.xml</file>
376+
<todir>conf</todir>
377+
<overwrite>true</overwrite>
378+
</configfile>
379+
<configfile>
380+
<file>${basedir}/src/config/local/context.xml</file>
381+
<todir>conf</todir>
382+
<overwrite>true</overwrite>
383+
</configfile>
384+
</configfiles>
385+
<properties>
386+
<cargo.jvmargs>
387+
-Xmx8G
388+
-javaagent:${basedir}/tools/hcl/secagent.jar=agent_path=${basedir}/tools/hcl/secagent.jar
389+
-Dsecagent.log=${basedir}/tools/hcl/working/HCL-IAST.hcl
390+
</cargo.jvmargs>
391+
<cargo.servlet.port>8443</cargo.servlet.port>
392+
<cargo.protocol>https</cargo.protocol>
393+
<cargo.tomcat.connector.clientAuth>false</cargo.tomcat.connector.clientAuth>
394+
<cargo.tomcat.connector.sslProtocol>TLS</cargo.tomcat.connector.sslProtocol>
395+
<cargo.tomcat.connector.keystoreFile>../../../../.keystore</cargo.tomcat.connector.keystoreFile>
396+
<cargo.tomcat.connector.keystorePass>changeit</cargo.tomcat.connector.keystorePass>
397+
<cargo.tomcat.connector.keyAlias>tomcat</cargo.tomcat.connector.keyAlias>
398+
<cargo.tomcat.httpSecure>true</cargo.tomcat.httpSecure>
399+
</properties>
400+
</configuration>
401+
</configuration>
402+
</plugin>
403+
</plugins>
404+
</build>
405+
</profile>
303406

304407
<profile>
305408
<id>time</id>
@@ -587,7 +690,7 @@ But it might be needed for Java 10, because I get this error, that I don't get w
587690
<dependency>
588691
<groupId>org.owasp.esapi</groupId>
589692
<artifactId>esapi</artifactId>
590-
<version>2.1.0.1</version>
693+
<version>2.2.0.0</version>
591694
</dependency>
592695

593696
</dependencies>

‎src/main/java/org/owasp/benchmark/score/BenchmarkScore.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import org.owasp.benchmark.score.parsers.WebInspectReader;
8686
import org.owasp.benchmark.score.parsers.XanitizerReader;
8787
import org.owasp.benchmark.score.parsers.ZapReader;
88+
import org.owasp.benchmark.score.parsers.HCLReader;
8889
import org.owasp.benchmark.score.report.Report;
8990
import org.owasp.benchmark.score.report.ScatterHome;
9091
import org.owasp.benchmark.score.report.ScatterVulns;
@@ -831,7 +832,11 @@ else if ( filename.endsWith( ".fpr" ) ) {
831832
else if ( filename.endsWith( ".log" ) ) {
832833
tr = new ContrastReader().parse( fileToParse );
833834
}
834-
835+
836+
else if ( filename.endsWith( ".hcl" ) ) {
837+
tr = new HCLReader().parse( fileToParse );
838+
}
839+
835840
else if ( filename.endsWith( ".hlg" ) ) {
836841
tr = new HdivReader().parse( fileToParse );
837842
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* OWASP Benchmark Project
3+
*
4+
* This file is part of the Open Web Application Security Project (OWASP)
5+
* Benchmark Project For details, please see
6+
* <a href="https://www.owasp.org/index.php/Benchmark">https://www.owasp.org/index.php/Benchmark</a>.
7+
*
8+
* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9+
* of the GNU General Public License as published by the Free Software Foundation, version 2.
10+
*
11+
* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details
14+
*
15+
* @author Dave Wichers <a href="https://www.aspectsecurity.com">Aspect Security</a>
16+
* @created 2015
17+
*/
18+
19+
package org.owasp.benchmark.score.parsers;
20+
21+
import java.io.BufferedReader;
22+
import java.io.File;
23+
import java.io.FileReader;
24+
import java.text.SimpleDateFormat;
25+
import java.util.Date;
26+
27+
import org.json.JSONObject;
28+
29+
public class HCLReader extends Reader {
30+
31+
public static void main(String[] args) throws Exception {
32+
File f = new File("results/HCL-IAST.hcl");
33+
HCLReader cr = new HCLReader();
34+
cr.parse(f);
35+
}
36+
37+
38+
public TestResults parse(File f) throws Exception {
39+
TestResults tr = new TestResults("HCL IAST", true, TestResults.ToolType.IAST);
40+
41+
BufferedReader reader = new BufferedReader(new FileReader(f));
42+
String firstLine = null;
43+
String lastLine = "";
44+
String line = "";
45+
tr.setToolVersion("1.0");
46+
while (line != null) {
47+
try {
48+
line = reader.readLine();
49+
if (line != null) {
50+
if (line.contains("writeVulnerabilityToFile")) {
51+
parseFindings(tr, line);
52+
} else if (line.contains("Agent Version:")) {
53+
String version = line.substring(line.indexOf("Version:") + 8);
54+
tr.setToolVersion(version.trim());
55+
} else if (line.contains("[checking URL:") && line.contains("BenchmarkTest00001")) {
56+
firstLine = line;
57+
} else if (line.contains("[checking URL:")) {
58+
lastLine = line;
59+
}
60+
}
61+
} catch (Exception ex) {
62+
ex.printStackTrace();
63+
}
64+
}
65+
reader.close();
66+
tr.setTime(calculateTime(firstLine, lastLine));
67+
return tr;
68+
}
69+
70+
71+
private void parseFindings(TestResults tr, String json) throws Exception {
72+
TestCaseResult tcr = new TestCaseResult();
73+
74+
try {
75+
String splitJson = json.split("writeVulnerabilityToFile - ")[1];
76+
JSONObject obj = new JSONObject(splitJson);
77+
JSONObject result = obj.getJSONObject("result");
78+
79+
String ruleId = result.getString( "ruleId" );
80+
tcr.setCWE(cweLookup(ruleId));
81+
tcr.setCategory(ruleId);
82+
83+
JSONObject request = result.getJSONObject("request");
84+
String uri = request.getString("uri" );
85+
86+
if ( uri.contains( "BenchmarkTest" ) ) {
87+
String testNumber = uri.substring( uri.lastIndexOf('/') + "BenchmarkTest".length() + 1 );
88+
tcr.setNumber(Integer.parseInt(testNumber));
89+
if (tcr.getCWE() != 0) {
90+
// System.out.println( tcr.getNumber() + "\t" + tcr.getCWE() + "\t" + tcr.getCategory() );
91+
tr.put(tcr);
92+
}
93+
}
94+
} catch (Exception e) {
95+
// System.err.println("> Parse error: " + json);
96+
// e.printStackTrace();
97+
}
98+
}
99+
100+
101+
private static int cweLookup(String rule) {
102+
switch (rule) {
103+
case "SessionManagement.Cookies":
104+
return 614; // insecure cookie use
105+
case "Injection.SQL":
106+
return 89; // sql injection
107+
case "Injection.OS":
108+
return 78; // command injection
109+
case "Injection.LDAP":
110+
return 90; // ldap injection
111+
case "CrossSiteScripting.Reflected":
112+
return 79; // xss
113+
case "Injection.XPath":
114+
return 643; // xpath injection
115+
case "PathTraversal":
116+
return 22; // path traversal
117+
case "Cryptography.Mac":
118+
return 328; // weak hash
119+
case "Cryptography.PoorEntropy":
120+
return 330; // weak random
121+
case "Cryptography.Ciphers":
122+
return 327; // weak encryption
123+
case "Validation.Required":
124+
return 501; // trust boundary
125+
}
126+
return 0;
127+
}
128+
129+
private String calculateTime(String firstLine, String lastLine) {
130+
try {
131+
String start = firstLine.split(" ")[0];
132+
String stop = lastLine.split(" ")[0];
133+
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
134+
Date startTime = sdf.parse(start);
135+
Date stopTime = sdf.parse(stop);
136+
long startMillis = startTime.getTime();
137+
long stopMillis = stopTime.getTime();
138+
long seconds = (stopMillis - startMillis) / 1000;
139+
return seconds + " seconds";
140+
} catch (Exception e) {
141+
e.printStackTrace();
142+
}
143+
return null;
144+
}
145+
146+
}

‎tools/HCL/runBenchmark_wHCL.bat‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@ECHO OFF
2+
IF EXIST .\secagent.jar (
3+
IF EXIST .\working (
4+
DEL /F /Q .\working\*.*
5+
6+
RMDIR /S /Q .\working\cache
7+
8+
ECHO ""
9+
10+
ECHO Previous results have been removed
11+
12+
ECHO ""
13+
)
14+
15+
CD ..\..
16+
17+
CALL mvn clean package cargo:run -Pdeploywhcl
18+
19+
ECHO Copying reports to results directory
20+
21+
COPY tools\HCL\working\HCL-IAST.hcl results\HCL-IAST.hcl
22+
23+
CD tools\HCL
24+
25+
)

‎tools/HCL/runBenchmark_wHCL.sh‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
if [ -f ./secagent.jar ]; then
4+
5+
if [ -d ./working ]; then
6+
7+
rm -r ./working/HCL-IAST.hcl
8+
echo ""
9+
echo "Previous results in /working removed"
10+
echo ""
11+
12+
fi
13+
14+
cd ../..
15+
mvn clean package cargo:run -Pdeploywhcl
16+
17+
echo "Copying report to results directory"
18+
cp tools/HCL/working/HCL-IAST.hcl results/HCL-IAST.hcl
19+
cd tools/HCL
20+
21+
else
22+
23+
echo "secagent.jar is required to run this benchmark. Please contact HCL at https://www.hcl.com/."
24+
25+
fi

0 commit comments

Comments
 (0)