-
-
Notifications
You must be signed in to change notification settings - Fork 253
Added corsair scan #208
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
Added corsair scan #208
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """ | ||
| This is an adaptation of Corsair Scan (https://github.com/Santandersecurityresearch/corsair_scan) as a ZAP active scan script. | ||
| This script will resend requests to all the sites being scanned in ZAP, injecting different origins. Then, it will read the value of Access-Control-Allow-Origin and based on that, it | ||
| will assess if CORS is properly configured. | ||
| """ | ||
| import urlparse | ||
| alertTitle = 'Corsair - CORS Misconfigured' | ||
| alertDescription = "Cross Origin Resource Sharing (CORS) is misconfigured. \n" | ||
| alertRisk = 2 | ||
| alertConfidence = 3 | ||
| alertSolution = "Configure CORS in a more restrictive way, to give access only the sites allowed to access your domain." | ||
| alertInfo = "Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any other origins (domain, scheme, or port) than its own from which a browser should permit loading of resources." | ||
| cweID = 942 | ||
| wascID = 14 | ||
|
|
||
| SM_ORIGIN = 'https://example.com' | ||
| SM_ORIGIN_NO_PROTOCOL = 'example.com' | ||
| SM_ORIGIN_DOMAIN = 'example' | ||
|
|
||
| """ | ||
| In this method, we read the request performed and create a new request with a fake origin. Also, if the request already contains an origin header, we perform two extra requests: | ||
| 1 - Fake subdomain. It is, we set as origin a fake subdomain to validate if CORS is configured at domain level, or if it has granularity at subdomain level. | ||
| 2 - Fake postdomain. Here, we set a request using the existing origin as a subdomain for a fake domain. We do it to validate if CORS is misconfigured and it only checks if the expected value exists in the origin header. | ||
| Then, we call cors_scan, which will send that request and validate the response. | ||
| """ | ||
| def scanNode(sas, msg): | ||
| origMsg = msg | ||
| msg = origMsg.cloneRequest() | ||
| msg.getRequestHeader().setHeader("Origin", SM_ORIGIN) | ||
| cors_scan(sas,msg, "fake origin") | ||
| if origMsg.getRequestHeader().getHeader('Origin'): | ||
| parsed_url = urlparse.urlparse(origMsg.getRequestHeader().getHeader('Origin')) | ||
| subdomain= parsed_url.scheme + '://' + SM_ORIGIN_DOMAIN + '.' + parsed_url.netloc | ||
| postdomain = origMsg.getRequestHeader().getHeader('Origin') + '.' + SM_ORIGIN_NO_PROTOCOL | ||
| msg.getRequestHeader().setHeader("Origin", subdomain) | ||
| cors_scan(sas,msg, "fake subdomain") | ||
| msg.getRequestHeader().setHeader("Origin", postdomain) | ||
| cors_scan(sas,msg, "fake postdomain") | ||
|
|
||
| """ | ||
| cors_scan sends the request crafted by scanNode and reads the value of the Access-Control-Allow-Origin header. | ||
| If it is the origin reflected, * or NULL, we consider that CORS is misconfigured and raise an alert. | ||
| """ | ||
| def cors_scan(sas,msg, test_type): | ||
| sas.sendAndReceive(msg, True, False); | ||
| header = str(msg.getResponseHeader().getHeader("Access-Control-Allow-Origin")) | ||
| if (header in ['null', '*', msg.getRequestHeader().getHeader('Origin')]): | ||
| alertParam = "Test performed: Injecting a "+test_type | ||
| sas.raiseAlert(alertRisk, alertConfidence, alertTitle, alertDescription + alertParam, msg.getRequestHeader().getURI().toString(), "Origin", | ||
| msg.getRequestHeader().getHeader('Origin'), alertInfo, alertSolution, msg.getRequestHeader().getHeader('Origin'), cweID, wascID, msg); | ||
|
|
||
| def scan(sas, msg, param, value): | ||
| pass | ||
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.