forked from zaproxy/community-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAlert on HTTP Response Code Errors.js
More file actions
118 lines (112 loc) · 3.7 KB
/
Copy pathAlert on HTTP Response Code Errors.js
File metadata and controls
118 lines (112 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// A script which will raise alerts based on HTTP Response codes
// By default it will raise 'Info' level alerts for Client Errors (4xx) (apart from 404s) and 'Low' Level alerts for Server Errors (5xx)
// But it can be easily changed.
const Integer = Java.type("java.lang.Integer");
const Pattern = Java.type("java.util.regex.Pattern");
const Alert = Java.type("org.parosproxy.paros.core.scanner.Alert");
const ExtensionAlert = Java.type(
"org.zaproxy.zap.extension.alert.ExtensionAlert"
);
const HistoryReference = Java.type(
"org.parosproxy.paros.model.HistoryReference"
);
pluginid = 100000; // https://github.com/zaproxy/zaproxy/blob/main/docs/scanners.md
function sendingRequest(msg, initiator, helper) {
// Nothing to do
}
function responseReceived(msg, initiator, helper) {
if (isGloballyExcluded(msg)) {
// Not of interest.
return;
}
var extensionAlert = control
.getExtensionLoader()
.getExtension(ExtensionAlert.NAME);
if (extensionAlert != null) {
var code = msg.getResponseHeader().getStatusCode();
if (code < 400 || code >= 600 || code == 404) {
// Do nothing
} else {
var risk = 0; // Info
var title = "A Client Error response code was returned by the server";
if (code >= 500) {
// Server error
risk = 1; // Low
title = "A Server Error response code was returned by the server";
}
// CONFIDENCE_HIGH = 3 (we can be pretty sure we're right)
var alert = new Alert(pluginid, risk, 3, title);
var ref = msg.getHistoryRef();
if (
ref != null &&
HistoryReference.getTemporaryTypes().contains(
Integer.valueOf(ref.getHistoryType())
)
) {
// Dont use temporary types as they will get deleted
ref = null;
}
if (ref == null) {
// map the initiator
var type;
switch (initiator) {
case 1: // PROXY_INITIATOR
type = 1; // Proxied
break;
case 2: // ACTIVE_SCANNER_INITIATOR
type = 3; // Scanner
break;
case 3: // SPIDER_INITIATOR
type = 2; // Spider
break;
case 4: // FUZZER_INITIATOR
type = 8; // Fuzzer
break;
case 5: // AUTHENTICATION_INITIATOR
type = 15; // User
break;
case 6: // MANUAL_REQUEST_INITIATOR
type = 15; // User
break;
case 8: // BEAN_SHELL_INITIATOR
type = 15; // User
break;
case 9: // ACCESS_CONTROL_SCANNER_INITIATOR
type = 13; // Access control
break;
default:
type = 15; // User - fallback
break;
}
ref = new HistoryReference(model.getSession(), type, msg);
}
alert.setMessage(msg);
alert.setUri(msg.getRequestHeader().getURI().toString());
alert.setDescription(
"A response code of " +
code +
" was returned by the server.\n" +
"This may indicate that the application is failing to handle unexpected input correctly.\n" +
"Raised by the 'Alert on HTTP Response Code Error' script"
);
alert.setEvidence(code.toString());
alert.setCweId(388); // CWE CATEGORY: Error Handling
alert.setWascId(20); // WASC Improper Input Handling
extensionAlert.alertFound(alert, ref);
}
}
}
function isGloballyExcluded(msg) {
var url = msg.getRequestHeader().getURI().toString();
var regexes = model.getSession().getGlobalExcludeURLRegexs();
for (var i in regexes) {
if (
Pattern.compile(regexes[i], Pattern.CASE_INSENSITIVE)
.matcher(url)
.matches()
) {
return true;
}
}
return false;
}