Skip to content

Commit 8fbe274

Browse files
authored
Merge pull request #448 from ricekot/passive-scripts-metadata
Implement `getMetadata` for some more Passive scripts
2 parents 1c1cd85 + f4ec405 commit 8fbe274

11 files changed

+257
-299
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2424
- passive/detect_csp_notif_and_reportonly.js
2525
- passive/detect_samesite_protection.js
2626
- passive/f5_bigip_cookie_internal_ip.js
27+
- passive/find base64 strings.js
28+
- passive/Find Credit Cards.js
29+
- passive/Find Emails.js
30+
- passive/Find Hashes.js
31+
- passive/Find HTML Comments.js
2732

2833
## [18] - 2024-01-29
2934
### Added

passive/CookieHTTPOnly.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ confidence: medium
1818
cweId: 0
1919
wascId: 13 # WASC-13: Information Leakage
2020
status: alpha
21+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/CookieHTTPOnly.js
22+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
2123
`);
2224
}
2325

passive/Find Credit Cards.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
// CreditCard Finder by freakyclown@gmail.com
22

3-
function scan(ps, msg, src) {
4-
// lets set up some stuff we are going to need for the alert later if we find a credit card
5-
var url = msg.getRequestHeader().getURI().toString();
3+
var ScanRuleMetadata = Java.type(
4+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
5+
);
6+
7+
function getMetadata() {
8+
return ScanRuleMetadata.fromYaml(`
9+
id: 100008
10+
name: Information Disclosure - Credit Card Number
11+
description: A credit card number was found in the HTTP response body.
12+
solution: >
13+
Encrypt credit card numbers during transmission, use tokenization,
14+
and adhere to PCI DSS standards for secure handling and storage.
15+
risk: high
16+
confidence: medium
17+
cweId: 311 # CWE-311: Missing Encryption of Sensitive Data
18+
wascId: 13 # WASC-13: Information Leakage
19+
status: alpha
20+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/Find%20Credit%20Cards.js
21+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
22+
`);
23+
}
24+
25+
function scan(helper, msg, src) {
626
var body = msg.getResponseBody().toString();
7-
var alertRisk = [0, 1, 2, 3]; //1=informational, 2=low, 3=medium, 4=high
8-
var alertConfidence = [0, 1, 2, 3, 4]; //0=fp,1=low,2=medium,3=high,4=confirmed
9-
var alertTitle = ["Credit Card Number(s) Disclosed (script)", ""];
10-
var alertDesc = ["Credit Card number(s) was discovered.", ""];
11-
var alertSolution = [
12-
"why are you showing Credit and debit card numbers?",
13-
"",
14-
];
15-
var cweId = [0, 1];
16-
var wascId = [0, 1];
1727

1828
// lets make some regular expressions for well known credit cards
1929
// regex must appear within /( and )/g
20-
2130
var re_visa = /([3-5][0-9]{3}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4})/g; //visa or mastercard
2231
var re_amex = /(3[47][0-9]{2}[ -]?[0-9]{6}[ -]?[0-9]{5})/g; //amex
2332
var re_disc = /(6011[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4})/g; //discovery
@@ -56,21 +65,12 @@ function scan(ps, msg, src) {
5665
}
5766
}
5867
if (foundCard.length != 0) {
59-
ps.raiseAlert(
60-
alertRisk[3],
61-
alertConfidence[2],
62-
alertTitle[0],
63-
alertDesc[0],
64-
url,
65-
"",
66-
"",
67-
foundCard.toString(),
68-
alertSolution[0],
69-
"",
70-
cweId[0],
71-
wascId[0],
72-
msg
73-
);
68+
helper
69+
.newAlert()
70+
.setEvidence(foundCard[0])
71+
.setOtherInfo(`Other instances: ${foundCard.slice(1).toString()}`)
72+
.setMessage(msg)
73+
.raise();
7474
}
7575
}
7676
}

passive/Find Emails.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,39 @@
55
// https://support.google.com/mail/answer/12096?hl=en
66
// https://regex101.com/r/sH4vC0/2
77
// 20181213 - Update by nil0x42+owaspzap@gmail.com to ignore false positives (such as '*@123' or '$@#!.')
8+
// 20240604 - Implement getMetadata() to expose the script as a scan rule.
89

9-
function scan(ps, msg, src) {
10-
// first lets set up some details incase we find an email, these will populate the alert later
11-
var alertRisk = 0;
12-
var alertConfidence = 3;
13-
var alertTitle = "Email addresses (script)";
14-
var alertDesc = "Email addresses were found";
15-
var alertSolution = "Remove emails that are not public";
16-
var cweId = 0;
17-
var wascId = 0;
10+
var ScanRuleMetadata = Java.type(
11+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
12+
);
1813

14+
function getMetadata() {
15+
return ScanRuleMetadata.fromYaml(`
16+
id: 100009
17+
name: Information Disclosure - Email Addresses
18+
description: >
19+
An email address was found in the HTTP response body.
20+
Exposure of email addresses in HTTP messages can lead to privacy violations
21+
and targeted phishing attacks.
22+
solution: >
23+
Mask email addresses during transmission and ensure proper access controls
24+
to protect user privacy and prevent unauthorized access.
25+
risk: low
26+
confidence: high
27+
cweId: 311 # CWE-311: Missing Encryption of Sensitive Data
28+
wascId: 13 # WASC-13: Information Leakage
29+
status: alpha
30+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/Find%20Emails.js
31+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
32+
`);
33+
}
34+
35+
function scan(helper, msg, src) {
1936
// lets build a regular expression that can find email addresses
2037
// the regex must appear within /( and )/g
2138
var re =
2239
/([a-zA-Z0-9_.+-]+@[a-zA-Z0-9]+[a-zA-Z0-9-]*\.[a-zA-Z0-9-.]*[a-zA-Z0-9]{2,})/g;
2340

24-
// we need to set the url variable to the request or we cant track the alert later
25-
var url = msg.getRequestHeader().getURI().toString();
26-
2741
// lets check its not one of the files types that are never likely to contain stuff, like pngs and jpegs
2842
var contenttype = msg.getResponseHeader().getHeader("Content-Type");
2943
var unwantedfiletypes = [
@@ -49,21 +63,12 @@ function scan(ps, msg, src) {
4963
foundEmail.push(comm[0]);
5064
}
5165
// woohoo we found an email lets make an alert for it
52-
ps.raiseAlert(
53-
alertRisk,
54-
alertConfidence,
55-
alertTitle,
56-
alertDesc,
57-
url,
58-
"",
59-
"",
60-
foundEmail.toString(),
61-
alertSolution,
62-
"",
63-
cweId,
64-
wascId,
65-
msg
66-
);
66+
helper
67+
.newAlert()
68+
.setEvidence(foundEmail[0])
69+
.setOtherInfo(`Other instances: ${foundEmail.slice(1).toString()}`)
70+
.setMessage(msg)
71+
.raise();
6772
}
6873
}
6974
}

passive/Find HTML Comments.js

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,37 @@
1818
// NOTE: This script will only find HTML comments in content which passes through ZAP.
1919
// Therefore if you browser is caching you may not see something you expect to.
2020

21-
function scan(ps, msg, src) {
21+
var ScanRuleMetadata = Java.type(
22+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
23+
);
24+
25+
function getMetadata() {
26+
return ScanRuleMetadata.fromYaml(`
27+
id: 100011
28+
name: Information Disclosure - HTML Comments
29+
description: >
30+
While adding general comments is very useful, some programmers tend to leave important data,
31+
such as: filenames related to the web application, old links or links which were not meant
32+
to be browsed by users, old code fragments, etc.
33+
solution: >
34+
Remove comments which have sensitive information about the design/implementation
35+
of the application. Some of the comments may be exposed to the user and affect
36+
the security posture of the application.
37+
risk: info
38+
confidence: medium
39+
cweId: 615 # CWE-615: Inclusion of Sensitive Information in Source Code Comments
40+
wascId: 13 # WASC-13: Information Leakage
41+
status: alpha
42+
codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/Find%20HTML%20Comments.js
43+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
44+
`);
45+
}
46+
47+
function scan(helper, msg, src) {
2248
// Both can be true, just know that you'll see duplication.
2349
var RESULT_PER_FINDING = new Boolean(0); // If you want to see results on a per comment basis (i.e.: A single URL may be listed more than once), set this to true (1)
2450
var RESULT_PER_URL = new Boolean(1); // If you want to see results on a per URL basis (i.e.: all comments for a single URL will be grouped together), set this to true (1)
2551

26-
// lets set up some details we will need for alerts later if we find some comments
27-
var alertRisk = 0;
28-
var alertConfidence = 2;
29-
var alertTitle = "Information Exposure Through HTML Comments (script)";
30-
var alertDesc =
31-
"While adding general comments is very useful, \
32-
some programmers tend to leave important data, such as: filenames related to the web application, old links \
33-
or links which were not meant to be browsed by users, old code fragments, etc.";
34-
var alertSolution =
35-
"Remove comments which have sensitive information about the design/implementation \
36-
of the application. Some of the comments may be exposed to the user and affect the security posture of the \
37-
application.";
38-
var cweId = 615;
39-
var wascId = 13;
40-
var url = msg.getRequestHeader().getURI().toString();
41-
4252
// this is a rough regular expression to find HTML comments
4353
// regex needs to be inside /( and )/g to work
4454
var re = /(\<![\s]*--[\-!@#$%^&*:;ºª.,"'(){}\w\s\/\\[\]]*--[\s]*\>)/g;
@@ -66,40 +76,22 @@ application.";
6676
if (RESULT_PER_FINDING == true) {
6777
counter = counter + 1;
6878
//fakeparam+counter gives us parameter differientiation per comment alert (RESULT_PER_FINDING)
69-
ps.raiseAlert(
70-
alertRisk,
71-
alertConfidence,
72-
alertTitle,
73-
alertDesc,
74-
url,
75-
"fakeparam" + counter,
76-
"",
77-
comm[0],
78-
alertSolution,
79-
"",
80-
cweId,
81-
wascId,
82-
msg
83-
);
79+
helper
80+
.newAlert()
81+
.setParam("fakeparam" + counter)
82+
.setEvidence(comm[0])
83+
.setMessage(msg)
84+
.raise();
8485
}
8586
foundComments.push(comm[0]);
8687
}
8788
if (RESULT_PER_URL == true) {
88-
ps.raiseAlert(
89-
alertRisk,
90-
alertConfidence,
91-
alertTitle,
92-
alertDesc,
93-
url,
94-
"",
95-
"",
96-
foundComments.toString(),
97-
alertSolution,
98-
"",
99-
cweId,
100-
wascId,
101-
msg
102-
);
89+
helper
90+
.newAlert()
91+
.setEvidence(foundComments[0])
92+
.setOtherInfo(`Other instances: ${foundComments.slice(1).toString()}`)
93+
.setMessage(msg)
94+
.raise();
10395
}
10496
}
10597
}

0 commit comments

Comments
 (0)