Skip to content

Commit c657f83

Browse files
Fixes to the fix verification feature to make it work for multiple testcases.
1 parent 9623bcc commit c657f83

File tree

5 files changed

+131
-60
lines changed

5 files changed

+131
-60
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* OWASP Benchmark Project
3+
*
4+
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project For
5+
* details, please see <a
6+
* href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7+
*
8+
* <p>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+
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13+
* PURPOSE. See the GNU General Public License for more details.
14+
*
15+
* @author David Anderson
16+
* @created 2024
17+
*/
18+
package org.owasp.benchmarkutils.entities;
19+
20+
import javax.xml.bind.annotation.XmlRootElement;
21+
22+
@XmlRootElement
23+
public class VerifyFixOutput {
24+
private String testCaseName;
25+
private ResponseInfo unfixedSafeResponseInfo;
26+
private ResponseInfo unfixedAttackResponseInfo;
27+
private ResponseInfo fixedSafeResponseInfo;
28+
private ResponseInfo fixedAttackResponseInfo;
29+
private boolean wasNotVerifiable;
30+
private boolean wasExploited;
31+
private boolean wasBroken;
32+
33+
public String getTestCaseName() {
34+
return testCaseName;
35+
}
36+
37+
public void setTestCaseName(String testCaseName) {
38+
this.testCaseName = testCaseName;
39+
}
40+
41+
public ResponseInfo getUnfixedSafeResponseInfo() {
42+
return unfixedSafeResponseInfo;
43+
}
44+
45+
public void setUnfixedSafeResponseInfo(ResponseInfo unfixedSafeResponseInfo) {
46+
this.unfixedSafeResponseInfo = unfixedSafeResponseInfo;
47+
}
48+
49+
public ResponseInfo getUnfixedAttackResponseInfo() {
50+
return unfixedAttackResponseInfo;
51+
}
52+
53+
public void setUnfixedAttackResponseInfo(ResponseInfo unfixedAttackResponseInfo) {
54+
this.unfixedAttackResponseInfo = unfixedAttackResponseInfo;
55+
}
56+
57+
public ResponseInfo getFixedSafeResponseInfo() {
58+
return fixedSafeResponseInfo;
59+
}
60+
61+
public void setFixedSafeResponseInfo(ResponseInfo fixedSafeResponseInfo) {
62+
this.fixedSafeResponseInfo = fixedSafeResponseInfo;
63+
}
64+
65+
public ResponseInfo getFixedAttackResponseInfo() {
66+
return fixedAttackResponseInfo;
67+
}
68+
69+
public void setFixedAttackResponseInfo(ResponseInfo fixedAttackResponseInfo) {
70+
this.fixedAttackResponseInfo = fixedAttackResponseInfo;
71+
}
72+
73+
public boolean isWasNotVerifiable() {
74+
return wasNotVerifiable;
75+
}
76+
77+
public void setWasNotVerifiable(boolean wasNotVerifiable) {
78+
this.wasNotVerifiable = wasNotVerifiable;
79+
}
80+
81+
public boolean isWasExploited() {
82+
return wasExploited;
83+
}
84+
85+
public void setWasExploited(boolean wasExploited) {
86+
this.wasExploited = wasExploited;
87+
}
88+
89+
public boolean isWasBroken() {
90+
return wasBroken;
91+
}
92+
93+
public void setWasBroken(boolean wasBroken) {
94+
this.wasBroken = wasBroken;
95+
}
96+
}

plugin/src/main/java/org/owasp/benchmarkutils/helpers/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
import org.eclipse.persistence.oxm.MediaType;
6262
import org.owasp.benchmarkutils.entities.ResponseInfo;
6363
import org.owasp.benchmarkutils.entities.TestSuite;
64+
import org.owasp.benchmarkutils.entities.VerifyFixOutput;
6465
import org.owasp.benchmarkutils.tools.TestCaseRequestFileParseException;
6566
import org.owasp.benchmarkutils.tools.TestCaseVerificationResults;
6667
import org.owasp.benchmarkutils.tools.TestCaseVerificationResultsCollection;
67-
import org.owasp.benchmarkutils.tools.VerifyFixOutput;
6868
import org.xml.sax.InputSource;
6969
import org.xml.sax.SAXException;
7070

plugin/src/main/java/org/owasp/benchmarkutils/tools/BenchmarkCrawler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void load() {
139139
new Categories(categoriesFileStream);
140140

141141
this.testSuite = Utils.parseHttpFile(this.theCrawlerFile);
142-
System.out.println("Test suite: " + this.testSuite);
142+
// System.out.println("Test suite: " + this.testSuite);
143143
Collections.sort(
144144
this.testSuite.getTestCases(),
145145
TestCase.getNameComparator()); // Probably not necessary

plugin/src/main/java/org/owasp/benchmarkutils/tools/BenchmarkCrawlerVerification.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.owasp.benchmarkutils.entities.TestCaseSetup;
5757
import org.owasp.benchmarkutils.entities.TestCaseSetupException;
5858
import org.owasp.benchmarkutils.entities.TestSuite;
59+
import org.owasp.benchmarkutils.entities.VerifyFixOutput;
5960
import org.owasp.benchmarkutils.helpers.Utils;
6061
import org.xml.sax.SAXException;
6162

@@ -115,6 +116,10 @@ public class BenchmarkCrawlerVerification extends BenchmarkCrawler {
115116
private Map<String, TestCaseVerificationResults> testCaseNameToTestCaseVerificationResultsMap =
116117
new HashMap<>();
117118

119+
private List<VerifyFixOutput> exploitedFixedTestcases = new ArrayList<>();
120+
private List<VerifyFixOutput> brokenFixedTestcases = new ArrayList<>();
121+
private List<VerifyFixOutput> notVerifiableFixedTestcases = new ArrayList<>();
122+
118123
BenchmarkCrawlerVerification() {
119124
// A default constructor required to support Maven plugin API.
120125
// The theCrawlerFile has to be instantiated before a crawl can be done.
@@ -133,6 +138,7 @@ protected void crawl(TestSuite testSuite) throws Exception {
133138
List<TestCaseVerificationResults> results =
134139
new ArrayList<TestCaseVerificationResults>();
135140

141+
Files.createDirectories(Paths.get(getOutputDirectory()));
136142
final File FILE_NON_DISCRIMINATORY_LOG =
137143
new File(getOutputDirectory(), FILENAME_NON_DISCRIMINATORY_LOG);
138144
final File FILE_ERRORS_LOG = new File(getOutputDirectory(), FILENAME_ERRORS_LOG);
@@ -391,6 +397,7 @@ protected void crawl(TestSuite testSuite) throws Exception {
391397
System.out.printf("Test case time measurements written to: %s%n", FILE_TIMES_LOG);
392398

393399
RegressionTesting.printCrawlSummary(results);
400+
printFixVerificationSummary();
394401
System.out.println();
395402
System.out.println(completionMessage);
396403
}
@@ -399,6 +406,15 @@ protected void crawl(TestSuite testSuite) throws Exception {
399406
// cleanupSetups(setups);
400407
}
401408

409+
private void printFixVerificationSummary() {
410+
System.out.println("Fix verification summary:");
411+
System.out.println();
412+
System.out.println("\tExploited fixed test cases:\t" + exploitedFixedTestcases.size());
413+
System.out.println("\tBroken fixed test cases:\t" + brokenFixedTestcases.size());
414+
System.out.println(
415+
"\tNot verifiable fixed test cases:\t" + notVerifiableFixedTestcases.size());
416+
}
417+
402418
/**
403419
* @param testSuite
404420
* @throws Exception
@@ -599,7 +615,7 @@ private boolean verifyFix(
599615
TestCaseVerificationResults beforeFixResults,
600616
TestCaseVerificationResults afterFixResults) {
601617

602-
boolean wasNotVerfiable =
618+
boolean wasNotVerifiable =
603619
afterFixResults.getTestCase().isVulnerability()
604620
&& afterFixResults.getTestCase().isUnverifiable()
605621
&& afterFixResults.isPassed();
@@ -612,22 +628,32 @@ private boolean verifyFix(
612628
.getResponseToSafeValue()
613629
.getResponseString()
614630
.equals(afterFixResults.getResponseToSafeValue().getResponseString());
615-
if (wasNotVerfiable) {
631+
632+
VerifyFixOutput verifyFixOutput = new VerifyFixOutput();
633+
verifyFixOutput.setTestCaseName(afterFixResults.getTestCase().getName());
634+
verifyFixOutput.setUnfixedSafeResponseInfo(beforeFixResults.getResponseToSafeValue());
635+
verifyFixOutput.setUnfixedAttackResponseInfo(beforeFixResults.getResponseToAttackValue());
636+
verifyFixOutput.setFixedSafeResponseInfo(afterFixResults.getResponseToSafeValue());
637+
verifyFixOutput.setFixedAttackResponseInfo(afterFixResults.getResponseToAttackValue());
638+
verifyFixOutput.setWasNotVerifiable(wasNotVerifiable);
639+
verifyFixOutput.setWasExploited(wasExploited);
640+
verifyFixOutput.setWasBroken(wasBroken);
641+
642+
if (wasNotVerifiable) {
616643
System.out.println("NOT FIXED: Vulnerability could not be verified");
644+
notVerifiableFixedTestcases.add(verifyFixOutput);
617645
}
618646
if (wasExploited) {
619647
System.out.println("NOT FIXED: Vulnerability was exploited");
648+
exploitedFixedTestcases.add(verifyFixOutput);
620649
}
621650
if (wasBroken) {
622651
System.out.println("NOT FIXED: Functionality was broken");
652+
brokenFixedTestcases.add(verifyFixOutput);
623653
}
624654

625655
File verifyFixResultFile = new File(getOutputDirectory(), FILENAME_VERIFY_FIX_RESULT);
626656
try (BufferedWriter writer = new BufferedWriter(new FileWriter(verifyFixResultFile))) {
627-
VerifyFixOutput verifyFixOutput = new VerifyFixOutput();
628-
verifyFixOutput.setWasNotVerfiable(wasNotVerfiable);
629-
verifyFixOutput.setWasExploited(wasExploited);
630-
verifyFixOutput.setWasBroken(wasBroken);
631657
String output = Utils.objectToJson(verifyFixOutput);
632658
// System.out.println(output);
633659
writer.write(output);
@@ -640,7 +666,7 @@ private boolean verifyFix(
640666
e.printStackTrace();
641667
}
642668

643-
return !wasNotVerfiable && !wasExploited && !wasBroken;
669+
return !wasNotVerifiable && !wasExploited && !wasBroken;
644670
}
645671

646672
private boolean verifyFixes(

plugin/src/main/java/org/owasp/benchmarkutils/tools/VerifyFixOutput.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)