-
-
Notifications
You must be signed in to change notification settings - Fork 255
Address potential classloader performance issues in JS scripts #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
|
|
||
| // This script needs Diff add-on | ||
|
|
||
| var DiffTool = Java.type("org.zaproxy.zap.extension.diff.diff_match_patch"); | ||
| const DiffTool = Java.type("org.zaproxy.zap.extension.diff.diff_match_patch"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert. |
||
|
|
||
| /* | ||
| * Declare parameters | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,21 @@ | |
| // 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. | ||
|
|
||
| var Pattern = Java.type("java.util.regex.Pattern"); | ||
| 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" | ||
| ); | ||
|
|
||
| const extensionAlert = control | ||
| .getExtensionLoader() | ||
| .getExtension(ExtensionAlert.NAME); | ||
|
|
||
| pluginid = 100000; // https://github.com/zaproxy/zaproxy/blob/main/docs/scanners.md | ||
|
|
||
| function sendingRequest(msg, initiator, helper) { | ||
|
|
@@ -14,12 +28,10 @@ function responseReceived(msg, initiator, helper) { | |
| // Not of interest. | ||
| return; | ||
| } | ||
| var extensionAlert = control | ||
| .getExtensionLoader() | ||
| .getExtension(org.zaproxy.zap.extension.alert.ExtensionAlert.NAME); | ||
|
|
||
| if (extensionAlert != null) { | ||
| var code = msg.getResponseHeader().getStatusCode(); | ||
| if (code < 400 || code >= 600 || code == 404) { | ||
| if (code < 400 || code >= 600) { | ||
| // Do nothing | ||
| } else { | ||
| var risk = 0; // Info | ||
|
|
@@ -30,17 +42,12 @@ function responseReceived(msg, initiator, helper) { | |
| 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 org.parosproxy.paros.core.scanner.Alert( | ||
| pluginid, | ||
| risk, | ||
| 3, | ||
| title | ||
| ); | ||
| var alert = new Alert(pluginid, risk, 3, title); | ||
| var ref = msg.getHistoryRef(); | ||
| if ( | ||
| ref != null && | ||
| org.parosproxy.paros.model.HistoryReference.getTemporaryTypes().contains( | ||
| java.lang.Integer.valueOf(ref.getHistoryType()) | ||
| HistoryReference.getTemporaryTypes().contains( | ||
| Integer.valueOf(ref.getHistoryType()) | ||
| ) | ||
| ) { | ||
| // Dont use temporary types as they will get deleted | ||
|
|
@@ -78,11 +85,7 @@ function responseReceived(msg, initiator, helper) { | |
| type = 15; // User - fallback | ||
| break; | ||
| } | ||
| ref = new org.parosproxy.paros.model.HistoryReference( | ||
| model.getSession(), | ||
| type, | ||
| msg | ||
| ); | ||
| ref = new HistoryReference(model.getSession(), type, msg); | ||
| } | ||
| alert.setMessage(msg); | ||
| alert.setUri(msg.getRequestHeader().getURI().toString()); | ||
|
|
@@ -93,9 +96,7 @@ function responseReceived(msg, initiator, helper) { | |
| "This may indicate that the application is failing to handle unexpected input correctly.\n" + | ||
| "Raised by the 'Alert on HTTP Response Code Error' script" | ||
| ); | ||
| // Use a regex to extract the evidence from the response header | ||
| var regex = new RegExp("^HTTP.*" + code); | ||
|
Comment on lines
-96
to
-97
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These unrelated changes should have their respective note in the changelog. |
||
| alert.setEvidence(msg.getResponseHeader().toString().match(regex)); | ||
| alert.setEvidence(code.toString()); | ||
| alert.setCweId(388); // CWE CATEGORY: Error Handling | ||
| alert.setWascId(20); // WASC Improper Input Handling | ||
| extensionAlert.alertFound(alert, ref); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ | |
| // Note that new passive scripts will initially be disabled | ||
| // Right click the script in the Scripts tree and select "enable" | ||
|
|
||
| const PluginPassiveScanner = Java.type( | ||
| "org.zaproxy.zap.extension.pscan.PluginPassiveScanner" | ||
| ); | ||
| var ScanRuleMetadata = Java.type( | ||
| "org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata" | ||
| ); | ||
|
|
@@ -73,7 +76,5 @@ function appliesToHistoryType(historyType) { | |
| // return historyType == org.parosproxy.paros.model.HistoryReference.TYPE_SPIDER; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be updated as well. |
||
|
|
||
| // Default behaviour scans default types. | ||
| return org.zaproxy.zap.extension.pscan.PluginPassiveScanner.getDefaultHistoryTypes().contains( | ||
| historyType | ||
| ); | ||
| return PluginPassiveScanner.getDefaultHistoryTypes().contains(historyType); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| // if they don't already have a tag that starts with TAG_PREFIX as defined below. | ||
| // Author: kingthorin | ||
| // 20160207: Initial release | ||
| // 20251212: Maintenance changes | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this add?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷♂️ was just trying to be consistent, happy to drop it (them?) |
||
| const ScriptVars = Java.type("org.zaproxy.zap.extension.script.ScriptVars"); | ||
|
|
||
| extHist = control | ||
| .getExtensionLoader() | ||
|
|
@@ -13,7 +15,7 @@ extHist = control | |
| TAG_PREFIX = "SRC_"; | ||
|
|
||
| if (extHist != null) { | ||
| i = org.zaproxy.zap.extension.script.ScriptVars.getGlobalVar("tagged_ref"); // Check for global reference | ||
| i = ScriptVars.getGlobalVar("tagged_ref"); // Check for global reference | ||
| if (i == null) { | ||
| i = 1; // Global reference was null so 1 | ||
| } | ||
|
|
@@ -48,8 +50,5 @@ if (extHist != null) { | |
| } | ||
| i++; | ||
| } | ||
| org.zaproxy.zap.extension.script.ScriptVars.setGlobalVar( | ||
| "tagged_ref", | ||
| lastRef + 1 | ||
| ); // Set global reference | ||
| ScriptVars.setGlobalVar("tagged_ref", lastRef + 1); // Set global reference | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| // Searches www.xssposed.org for known XSS vulnerabilities. | ||
| // This script just launches your default browser to perform the search. | ||
| const DesktopUtils = Java.type("org.zaproxy.zap.utils.DesktopUtils"); | ||
|
|
||
| function invokeWith(msg) { | ||
| var host = msg.getRequestHeader().getURI().getHost(); | ||
|
|
||
| org.zaproxy.zap.utils.DesktopUtils.openUrlInBrowser( | ||
| DesktopUtils.openUrlInBrowser( | ||
| "https://www.xssposed.org/search/?search=" + host + "&type=host" | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| * Contributed by Astra Security (https://www.getastra.com/) | ||
| * @author Prince Mendiratta <[email protected]> | ||
| */ | ||
| const Alert = Java.type("org.parosproxy.paros.core.scanner.Alert"); | ||
|
|
||
| var pluginid = 100024; | ||
|
|
||
|
|
@@ -151,12 +152,7 @@ function customAlert( | |
| .getExtension(ExtensionAlert.NAME); | ||
| var ref = new HistoryReference(session, HistoryReference.TYPE_ZAP_USER, msg); | ||
|
|
||
| var alert = new org.parosproxy.paros.core.scanner.Alert( | ||
| pluginid, | ||
| alertRisk, | ||
| alertConfidence, | ||
| alertName | ||
| ); | ||
| var alert = new Alert(pluginid, alertRisk, alertConfidence, alertName); | ||
| alert.setDescription(alertDesc); | ||
| alert.setAttack(alertAttack); | ||
| alert.setEvidence(alertEvidence); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,11 @@ | |
| // released under the Apache v2.0 license. | ||
| //You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| //Author : @haseebeqx | ||
| const CONTENT_TYPE = Java.type( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd have expected the Java.type on the HttpHeader (more common usage and avoids loading the class more than once like in the xml script). |
||
| "org.parosproxy.paros.network.HttpHeader.CONTENT_TYPE" | ||
| ); | ||
| const StringSelection = Java.type("java.awt.datatransfer.StringSelection"); | ||
| const Toolkit = java.type("java.awt.Toolkit"); | ||
|
|
||
| function invokeWith(msg) { | ||
| var string = "<!DOCTYPE html>\n"; | ||
|
|
@@ -32,9 +37,7 @@ function invokeWith(msg) { | |
| if (body.length() != 0) | ||
| if (!isJson(body)) { | ||
| if (ismultipart(msg.getRequestHeader())) { | ||
| var type = msg | ||
| .getRequestHeader() | ||
| .getHeader(org.parosproxy.paros.network.HttpHeader.CONTENT_TYPE); | ||
| var type = msg.getRequestHeader().getHeader(CONTENT_TYPE); | ||
| var delim = type.substring(type.search("=") + 1, type.length()); | ||
| var h = body.split("--" + delim); | ||
| var k = 0; | ||
|
|
@@ -98,8 +101,8 @@ function invokeWith(msg) { | |
| string += "\n</body></html>"; | ||
| print("\n\n\n"); | ||
| print(string); | ||
| var selected = new java.awt.datatransfer.StringSelection(string); | ||
| var clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
| var selected = new StringSelection(string); | ||
| var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
| clipboard.setContents(selected, null); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Java.type usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if it needed it. I should have commented asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not need it, but for consistency and good practices.