-
-
Notifications
You must be signed in to change notification settings - Fork 245
Add extender/ScanMonitor script #468
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// This script monitors the active scanner and ends the scan if certain conditions are met. | ||
// By default it just ends the scan for high: | ||
// * Connection failures | ||
// * Authentication failures | ||
// * Response times | ||
// You can easily chane the script to end the scan for other conditions, such as high 4xx / 5xx response codes, | ||
// but these tend to be application specific so they are not enabled by default. | ||
|
||
var SessionStructure = Java.type("org.zaproxy.zap.model.SessionStructure"); | ||
var Timer = Java.type("java.util.Timer"); | ||
var TimerTask = Java.type("java.util.TimerTask"); | ||
var URI = Java.type("org.apache.commons.httpclient.URI"); | ||
|
||
var extAscan = control.getExtensionLoader().getExtension("ExtensionActiveScan"); | ||
var inMemoryStats = control | ||
.getExtensionLoader() | ||
.getExtension("ExtensionStats") | ||
.getInMemoryStats(); | ||
|
||
var timer = new Timer(); | ||
var timerSecs = 10 * 1000; // Check every 10 secs | ||
|
||
// Set to true to see the stats reported live | ||
var log = false; | ||
|
||
function install(helper) { | ||
timer.scheduleAtFixedRate( | ||
new TimerTask() { | ||
run: function () { | ||
runchecks(); | ||
}, | ||
}, | ||
0, | ||
timerSecs | ||
); | ||
} | ||
|
||
function getStat(site, stat) { | ||
var val = | ||
site == null | ||
? inMemoryStats.getStat(stat) | ||
: inMemoryStats.getStat(site, stat); | ||
return val == null ? 0 : val; | ||
} | ||
|
||
// Response times are recorded in logarithmic millisec time slices | ||
function getLongRespStats(site) { | ||
return ( | ||
getStat(site, "stats.responseTime.16384") + | ||
kingthorin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getStat(site, "stats.responseTime.32768") + | ||
getStat(site, "stats.responseTime.65536") | ||
); | ||
} | ||
|
||
function runchecks() { | ||
if (log) print("Running checks.."); | ||
ascans = extAscan.getActiveScans(); | ||
ascans.forEach((as, i) => { | ||
// For the full set of stats that can be monitored see https://www.zaproxy.org/docs/internal-statistics/ | ||
var site = SessionStructure.getHostName(new URI(as.getDisplayName(), true)); | ||
if (log) print("Site: " + site); | ||
// Connection failures are global rather than site specific | ||
var connFails = getStat(null, "stats.network.send.failure"); | ||
// All HTTP response codes are recorded, so you can add checks for 401, 403 etc etc | ||
var stats401 = getStat(site, "stats.code.401"); | ||
var stats500 = getStat(site, "stats.code.500"); | ||
// Auth fails are only relevant for authenticated scans | ||
var authFails = getStat(site, "stats.auth.failure"); | ||
var longResp = getLongRespStats(site); | ||
|
||
if (log) { | ||
print(" 401 resps:\t" + stats401); | ||
kingthorin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(" 500 resps:\t" + stats500); | ||
print(" conn fails:\t" + connFails); | ||
print(" auth fails:\t" + authFails); | ||
print(" long resps:\t" + longResp); | ||
} | ||
// Change this test to meet your requirements as needed. | ||
if (connFails > 1000 || authFails > 1000 || longResp > 1000) { | ||
if (log) print("Stopping ascan " + site); | ||
as.stopScan(); | ||
} | ||
}); | ||
} | ||
|
||
function uninstall(helper) { | ||
timer.cancel(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ All notable changes to the 'other' section of this repository will be documented | |
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | ||
|
||
### 2024-08-30 | ||
- Added af-plans/ApiScanExample.yaml | ||
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. Looks like I should have included this in a prev PR :/ 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 thought it was :) |
||
|
||
### 2024-02-06 | ||
- Added af-plans/FullScanBrokenCrystals.yaml | ||
- Added af-plans/ScriptEnvVarAccess.yaml | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.