Skip to content

Commit b08198f

Browse files
authored
pscanrules: add example alerts to DirectoryBrowsingScanRule (#4537)
Add example alerts to DirectoryBrowsingScanRule. Signed-off-by: giothysham <[email protected]>
1 parent 40f779c commit b08198f

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

addOns/pscanrules/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
77
### Added
8+
- Added alert examples to Directory Browsing (Issue 6119).
89
- Added Trusted Domains in Cross-Domain JavaScript Source File Inclusion (Issue 7775).
910

1011
### Changed

addOns/pscanrules/src/main/java/org/zaproxy/zap/extension/pscanrules/DirectoryBrowsingScanRule.java

+25-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Iterator;
2323
import java.util.LinkedHashMap;
24+
import java.util.List;
2425
import java.util.Map;
2526
import java.util.regex.Matcher;
2627
import java.util.regex.Pattern;
@@ -105,21 +106,32 @@ public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {
105106
}
106107
if (evidence != null && evidence.length() > 0) {
107108
// we found something
108-
newAlert()
109-
.setName(getName() + " - " + server)
110-
.setRisk(Alert.RISK_MEDIUM)
111-
.setConfidence(Alert.CONFIDENCE_MEDIUM)
112-
.setDescription(getDescription() + " - " + server)
113-
.setOtherInfo(getExtraInfo(msg, evidence))
114-
.setSolution(getSolution())
115-
.setReference(getReference())
116-
.setEvidence(evidence)
117-
.setCweId(548) // Information Exposure Through Directory Listing
118-
.setWascId(16) // Directory Indexing
119-
.raise();
109+
buildAlert(server, evidence).raise();
120110
}
121111
}
122112

113+
private AlertBuilder buildAlert(String server, String evidence) {
114+
return newAlert()
115+
.setName(getName() + " - " + server)
116+
.setRisk(Alert.RISK_MEDIUM)
117+
.setConfidence(Alert.CONFIDENCE_MEDIUM)
118+
.setDescription(getDescription() + " - " + server)
119+
.setOtherInfo(getExtraInfo(evidence))
120+
.setSolution(getSolution())
121+
.setReference(getReference())
122+
.setEvidence(evidence)
123+
.setCweId(548) // Information Exposure Through Directory Listing
124+
.setWascId(16); // Directory Indexing
125+
}
126+
127+
@Override
128+
public List<Alert> getExampleAlerts() {
129+
return List.of(
130+
buildAlert("Apache 2", "<html><title>Index of /htdocs</title></html>").build(),
131+
buildAlert("Microsoft IIS", "<pre><A HREF=\"/\">[To Parent Directory]</A><br><br>")
132+
.build());
133+
}
134+
123135
/**
124136
* get the id of the scanner
125137
*
@@ -160,11 +172,10 @@ private String getReference() {
160172
/**
161173
* gets extra information associated with the alert
162174
*
163-
* @param msg
164175
* @param arg0
165176
* @return
166177
*/
167-
private String getExtraInfo(HttpMessage msg, String arg0) {
178+
private String getExtraInfo(String arg0) {
168179
return Constant.messages.getString(MESSAGE_PREFIX + "extrainfo", arg0);
169180
}
170181

addOns/pscanrules/src/test/java/org/zaproxy/zap/extension/pscanrules/DirectoryBrowsingScanRuleUnitTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import static org.hamcrest.Matchers.equalTo;
2424
import static org.hamcrest.Matchers.is;
2525

26+
import java.util.List;
2627
import java.util.Map;
2728
import org.apache.commons.httpclient.URI;
2829
import org.apache.commons.httpclient.URIException;
2930
import org.junit.jupiter.api.Test;
31+
import org.parosproxy.paros.core.scanner.Alert;
3032
import org.parosproxy.paros.network.HttpMessage;
3133
import org.parosproxy.paros.network.HttpRequestHeader;
3234
import org.parosproxy.paros.network.HttpResponseHeader;
@@ -114,4 +116,26 @@ void shouldReturnExpectedMappings() {
114116
tags.get(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getTag()),
115117
is(equalTo(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getValue())));
116118
}
119+
120+
@Test
121+
void shouldReturnExpectedExampleAlert() {
122+
// Given / When
123+
List<Alert> alerts = rule.getExampleAlerts();
124+
// Then
125+
assertThat(alerts.size(), is(equalTo(2)));
126+
Alert alertApache = alerts.get(0);
127+
assertThat(alertApache.getRisk(), is(equalTo(Alert.RISK_MEDIUM)));
128+
assertThat(alertApache.getConfidence(), is(equalTo(Alert.CONFIDENCE_MEDIUM)));
129+
assertThat(alertApache.getName(), is(equalTo("Directory Browsing - Apache 2")));
130+
assertThat(
131+
alertApache.getEvidence(),
132+
is(equalTo("<html><title>Index of /htdocs</title></html>")));
133+
Alert alertMicrosoft = alerts.get(1);
134+
assertThat(alertMicrosoft.getRisk(), is(equalTo(Alert.RISK_MEDIUM)));
135+
assertThat(alertMicrosoft.getConfidence(), is(equalTo(Alert.CONFIDENCE_MEDIUM)));
136+
assertThat(
137+
alertMicrosoft.getEvidence(),
138+
is(equalTo("<pre><A HREF=\"/\">[To Parent Directory]</A><br><br>")));
139+
assertThat(alertMicrosoft.getName(), is(equalTo("Directory Browsing - Microsoft IIS")));
140+
}
117141
}

0 commit comments

Comments
 (0)