Skip to content

Commit f270fe0

Browse files
authored
Merge pull request #452 from ricekot/passive-scripts-metadata
2 parents 5be5721 + 6851ba7 commit f270fe0

File tree

6 files changed

+160
-141
lines changed

6 files changed

+160
-141
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515

1616
### Changed
1717
- Use Prettier to format all JavaScript scripts.
18-
- Update the following scripts to implement the `getMetadata()` function:
18+
- Update the following scripts to implement the `getMetadata()` function with revised metadata:
1919
- active/Cross Site WebSocket Hijacking.js
2020
- active/cve-2019-5418.js
2121
- active/gof_lite.js
@@ -36,6 +36,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3636
- passive/find_reflected_params.py
3737
- passive/HUNT.py
3838
- passive/Mutliple Security Header Check.js
39+
- passive/google_api_keys_finder.js
40+
- passive/JavaDisclosure.js
41+
- passive/Report non static sites.js
42+
- passive/RPO.js
43+
- passive/s3.js
3944

4045
## [18] - 2024-01-29
4146
### Added

passive/JavaDisclosure.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
//Passive scan for Java error messages containing sensitive information (CWE-209)
22

3-
function scan(ps, msg, src) {
4-
var alertRisk = 2;
5-
var alertConfidence = 3;
6-
var alertTitle = "Java stack trace disclosure";
7-
var alertDesc = "Java stack trace disclosure (or similar) was found";
8-
var alertSolution =
9-
"Investigate Java stack trace disclosures found in the response, remove or mask as required";
10-
var cweId = 209;
11-
var wascId = 0;
3+
var ScanRuleMetadata = Java.type(
4+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
5+
);
126

7+
function getMetadata() {
8+
return ScanRuleMetadata.fromYaml(`
9+
id: 100035
10+
name: Information Disclosure - Java Stack Trace
11+
description: A Java stack trace was found in the HTTP response body.
12+
solution: >
13+
Catch and handle exceptions properly, avoiding the exposure of stack traces to users.
14+
Configure the web server or application framework to log stack traces instead of displaying them.
15+
risk: medium
16+
confidence: high
17+
cweId: 209 # CWE-209: Generation of Error Message Containing Sensitive Information
18+
wascId: 13 # WASC-13: Information Leakage
19+
status: alpha
20+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/JavaDisclosure.js
21+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
22+
`);
23+
}
24+
25+
function scan(helper, msg, src) {
1326
var re = /springframework|\.java|rootBeanClass/i;
1427

1528
var contentType = msg.getResponseHeader().getHeader("Content-Type");
@@ -27,21 +40,13 @@ function scan(ps, msg, src) {
2740

2841
var body = msg.getResponseBody().toString();
2942
if (re.test(body)) {
30-
let url = msg.getRequestHeader().getURI().toString();
31-
ps.raiseAlert(
32-
alertRisk,
33-
alertConfidence,
34-
alertTitle,
35-
alertDesc,
36-
url,
37-
"",
38-
"",
39-
body,
40-
alertSolution,
41-
body,
42-
cweId,
43-
wascId,
44-
msg
45-
);
43+
re.lastIndex = 0;
44+
var match = re.exec(body)[0];
45+
helper
46+
.newAlert()
47+
.setEvidence(match)
48+
.setOtherInfo(body)
49+
.setMessage(msg)
50+
.raise();
4651
}
4752
}

passive/RPO.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@
33
// for more info see http://www.thespanner.co.uk/2014/03/21/rpo/
44
// *WARNING* this is a Beta version of this detection and may give many false positives!
55

6-
function scan(ps, msg, src) {
7-
var url = msg.getRequestHeader().getURI().toString();
8-
var alertRisk = 2;
9-
var alertConfidence = 2;
10-
var alertTitle = "Potential Relative Path Overwrite - RPO(beta script)";
11-
var alertDesc = "Potential RPO (Relative Path Overwrite) found ";
12-
var alertSolution =
13-
"Make sure all style sheets are refered by full paths rather than relative paths.";
6+
var ScanRuleMetadata = Java.type(
7+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
8+
);
149

15-
var cweId = 0;
16-
var wascId = 0;
10+
function getMetadata() {
11+
return ScanRuleMetadata.fromYaml(`
12+
id: 100018
13+
name: Relative Path Overwrite
14+
description: >
15+
Potential RPO (Relative Path Overwrite) found.
16+
RPO allows attackers to manipulate URLs to include unintended paths,
17+
potentially leading to the execution of malicious scripts or the disclosure of sensitive information.
18+
solution: >
19+
Use absolute paths in URLs and resources to prevent manipulation.
20+
Validate and sanitize all user inputs that are used to construct URLs.
21+
risk: medium
22+
confidence: medium
23+
cweId: 20 # CWE-20: Improper Input Validation
24+
wascId: 13 # WASC-13: Information Leakage
25+
status: alpha
26+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/RPO.js
27+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
28+
`);
29+
}
30+
31+
function scan(helper, msg, src) {
1732
// regex must appear within /( and )/g
1833
var re = /(href\=\"((?!\/|http|www)).*\.css\")/g;
1934

@@ -41,21 +56,12 @@ function scan(ps, msg, src) {
4156
while ((comm = re.exec(body))) {
4257
foundRPO.push(comm[0]);
4358
}
44-
ps.raiseAlert(
45-
alertRisk,
46-
alertConfidence,
47-
alertTitle,
48-
alertDesc,
49-
url,
50-
"",
51-
"",
52-
foundRPO.toString(),
53-
alertSolution,
54-
"",
55-
cweId,
56-
wascId,
57-
msg
58-
);
59+
helper
60+
.newAlert()
61+
.setEvidence(foundRPO[0])
62+
.setOtherInfo(`Other instances: ${foundRPO.slice(1).toString()}`)
63+
.setMessage(msg)
64+
.raise();
5965
}
6066
}
6167
}

passive/Report non static sites.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,61 @@
44
// Note that new passive scripts will initially be disabled
55
// Right click the script in the Scripts tree and select "enable"
66

7+
var ScanRuleMetadata = Java.type(
8+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
9+
);
10+
11+
function getMetadata() {
12+
return ScanRuleMetadata.fromYaml(`
13+
id: 100017
14+
name: Non Static Site Detected
15+
description: >
16+
A query string or form has been detected in the HTTP response body.
17+
This indicates that this may not be a static site.
18+
solution: >
19+
If this is not a static site then ignore or disable this rule.
20+
risk: info
21+
confidence: medium
22+
status: alpha
23+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/Report%20non%20static%20sites.js
24+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
25+
`);
26+
}
27+
728
/**
829
* Passively scans an HTTP message. The scan function will be called for
930
* request/response made via ZAP, actual messages depend on the function
1031
* "appliesToHistoryType", defined below.
1132
*
12-
* @param ps - the PassiveScan parent object that will do all the core interface tasks
33+
* @param helper - the PassiveScan parent object that will do all the core interface tasks
1334
* (i.e.: providing access to Threshold settings, raising alerts, etc.).
1435
* This is an ScriptsPassiveScanner object.
1536
* @param msg - the HTTP Message being scanned. This is an HttpMessage object.
1637
* @param src - the Jericho Source representation of the message being scanned.
1738
*/
18-
function scan(ps, msg, src) {
19-
// Test the request and/or response here
39+
function scan(helper, msg, src) {
2040
if (msg.getRequestHeader().getURI().getEscapedQuery() != null) {
21-
// raiseAlert(risk, int confidence, String name, String description, String uri,
22-
// String param, String attack, String otherInfo, String solution, String evidence,
23-
// int cweId, int wascId, HttpMessage msg)
24-
// risk: 0: info, 1: low, 2: medium, 3: high
25-
// confidence: 0: falsePositive, 1: low, 2: medium, 3: high, 4: confirmed
26-
ps.raiseAlert(
27-
3,
28-
2,
29-
"Non static site (query present)",
30-
"A query string has been detected in one of the sites URLs. This indicates that this might well not be a static site",
31-
msg.getRequestHeader().getURI().toString(),
32-
"",
33-
"",
34-
"",
35-
"If this is not a static site then ignore or disable this script",
36-
msg.getRequestHeader().getURI().getEscapedQuery(),
37-
0,
38-
0,
39-
msg
40-
);
41+
helper
42+
.newAlert()
43+
.setName("Non Static Site Detected (query present)")
44+
.setDescription(
45+
"A query string has been detected in the HTTP response body. This indicates that this may not be a static site."
46+
)
47+
.setEvidence(msg.getRequestHeader().getURI().getEscapedQuery())
48+
.setMessage(msg)
49+
.raise();
4150
}
4251
if (src != null && !src.getFormFields().isEmpty()) {
4352
// There are form fields
44-
ps.raiseAlert(
45-
3,
46-
2,
47-
"Non static site (form present)",
48-
"One or more forms have been detected in the response. This indicates that this might well not be a static site",
49-
msg.getRequestHeader().getURI().toString(),
50-
"",
51-
"",
52-
"",
53-
"If this is not a static site then ignore or disable this script",
54-
src.getFormFields().toString(),
55-
0,
56-
0,
57-
msg
58-
);
53+
helper
54+
.newAlert()
55+
.setName("Non Static Site Detected (form present)")
56+
.setDescription(
57+
"One or more forms have been detected in the response. This indicates that this may not be a static site."
58+
)
59+
.setEvidence(src.getFormFields().toString())
60+
.setMessage(msg)
61+
.raise();
5962
}
6063
}
6164

passive/google_api_keys_finder.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@
44
* @SkypLabs
55
*/
66

7-
function scan(ps, msg, src) {
8-
var alertRisk = 0; // Informational
9-
var alertConfidence = 3; // High
10-
var alertTitle = "Information Disclosure - Google API Keys Found";
11-
var alertDesc = "Google API keys have been found.";
12-
var alertSolution = "Make sure the API key is not overly permissive.";
13-
var cweId = 200; // "Exposure of Sensitive Information to an Unauthorized Actor"
14-
var wascId = 13; // "Information Leakage"
7+
var ScanRuleMetadata = Java.type(
8+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
9+
);
1510

11+
function getMetadata() {
12+
return ScanRuleMetadata.fromYaml(`
13+
id: 100034
14+
name: Information Disclosure - Google API Key
15+
description: A Google API Key was found in the HTTP response body.
16+
solution: Ensure the API key is not overly permissive.
17+
risk: info
18+
confidence: high
19+
cweId: 200 # CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
20+
wascId: 13 # WASC-13: Information Leakage
21+
status: alpha
22+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/google_api_keys_finder.js
23+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
24+
`);
25+
}
26+
27+
function scan(helper, msg, src) {
1628
// Regex targeting Google API keys.
1729
// Taken from Table III of "How Bad Can It Git? Characterizing Secret Leakage in Public GitHub Repositories".
1830
// https://www.ndss-symposium.org/ndss-paper/how-bad-can-it-git-characterizing-secret-leakage-in-public-github-repositories/
@@ -45,21 +57,11 @@ function scan(ps, msg, src) {
4557
foundKeys.push(key[0]);
4658
}
4759

48-
ps.raiseAlert(
49-
alertRisk,
50-
alertConfidence,
51-
alertTitle,
52-
alertDesc,
53-
url,
54-
"",
55-
"",
56-
"The following Google API keys have been found in the page: " +
57-
foundKeys.join(", "), // Other info
58-
alertSolution,
59-
foundKeys[0].toString(), // Evidence
60-
cweId,
61-
wascId,
62-
msg
63-
);
60+
helper
61+
.newAlert()
62+
.setEvidence(foundKeys[0])
63+
.setOtherInfo(`Other instances: ${foundKeys.slice(1).toString()}`)
64+
.setMessage(msg)
65+
.raise();
6466
}
6567
}

passive/s3.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
// S3 bucket finder by alishasinghania09@gmail.com
22

3-
function scan(ps, msg, src) {
4-
// populate some parameters which will be needed if s3 bucket url is present
5-
var alertRisk = 1;
6-
var alertConfidence = 3;
7-
var alertTitle = "s3 Bucket URL";
8-
var alertDesc = "s3 Bucket URL found in response.";
9-
var alertSolution =
10-
"Remove s3 Buckets name from response or make sure the permissions in bucket are configured properly.";
11-
var cweId = 200;
12-
var wascId = 13;
3+
var ScanRuleMetadata = Java.type(
4+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
5+
);
136

7+
function getMetadata() {
8+
return ScanRuleMetadata.fromYaml(`
9+
id: 100036
10+
name: Information Disclosure - Amazon S3 Bucket URL
11+
description: An Amazon S3 bucket URL was found in the HTTP response body.
12+
solution: Remove S3 Bucket names from the response or ensure that the permissions in bucket are configured properly.
13+
risk: low
14+
confidence: high
15+
cweId: 200 # CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
16+
wascId: 13 # WASC-13: Information Leakage
17+
status: alpha
18+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/s3.js
19+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
20+
`);
21+
}
22+
23+
function scan(helper, msg, src) {
1424
// the regex for s3 bucket url and it must appear within /( and )/g
1525
var re = /((s3:\\[a-zA-Z0-9-\.\\_]+)|((s3-|s3\.)?(.*)\.amazonaws\.com))/g;
1626

17-
// we need to set the url variable to the request or we cant track the alert later
18-
var url = msg.getRequestHeader().getURI().toString();
19-
2027
// If the file type is image jpeg/png , then the scan will be skipped
2128
var contenttype = msg.getResponseHeader().getHeader("Content-Type");
2229
var unwantedfiletypes = [
@@ -39,21 +46,12 @@ function scan(ps, msg, src) {
3946
founds3bucket.push(buckets[0]);
4047
}
4148
//raise the alert
42-
ps.raiseAlert(
43-
alertRisk,
44-
alertConfidence,
45-
alertTitle,
46-
alertDesc,
47-
url,
48-
"",
49-
"",
50-
founds3bucket.toString(),
51-
alertSolution,
52-
"",
53-
cweId,
54-
wascId,
55-
msg
56-
);
49+
helper
50+
.newAlert()
51+
.setEvidence(founds3bucket[0])
52+
.setOtherInfo(`Other instances: ${founds3bucket.slice(1).toString()}`)
53+
.setMessage(msg)
54+
.raise();
5755
}
5856
}
5957
}

0 commit comments

Comments
 (0)