-
-
Notifications
You must be signed in to change notification settings - Fork 744
ascanrulesBeta: Add Example Alerts to InsecureHttpMethodScanRule #6789
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
Open
Brandosp
wants to merge
1
commit into
zaproxy:main
Choose a base branch
from
Brandosp:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 |
---|---|---|
|
@@ -113,6 +113,24 @@ public class InsecureHttpMethodScanRule extends AbstractAppPlugin | |
ALERT_TAGS = Collections.unmodifiableMap(alertTags); | ||
} | ||
|
||
private enum VulnType { | ||
DELETE_METHOD_ENABLED(1), | ||
OTHER_INSECURE_HTTP_METHOD(2), | ||
TRACE_TRACK_REFLECTS_COOKIES(3), | ||
OPEN_PROXY_THIRD_PARTY_CONNECT(4), | ||
INSECURE_WEBDAV_METHOD(5); | ||
|
||
private final int ref; | ||
|
||
private VulnType(int ref) { | ||
this.ref = ref; | ||
} | ||
|
||
public int getRef() { | ||
return this.ref; | ||
} | ||
} | ||
|
||
@Override | ||
public int getId() { | ||
return 90028; | ||
|
@@ -196,23 +214,13 @@ public void scan() { | |
enabledMethodsSet.remove( | ||
HttpRequestHeader | ||
.DELETE); // We don't actually want to make a DELETE request | ||
newAlert() | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", | ||
HttpRequestHeader.DELETE)) | ||
.setDescription( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.desc", | ||
HttpRequestHeader.DELETE)) | ||
.setOtherInfo( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.extrainfo", allowedmethods)) | ||
.setSolution( | ||
Constant.messages.getString("ascanbeta.insecurehttpmethod.soln")) | ||
.setEvidence(HttpRequestHeader.DELETE) | ||
.setMessage(optionsmsg) | ||
buildAlert( | ||
HttpRequestHeader.DELETE, | ||
HttpRequestHeader.DELETE, | ||
allowedmethods, | ||
HttpRequestHeader.DELETE, | ||
optionsmsg, | ||
VulnType.DELETE_METHOD_ENABLED) | ||
.raise(); | ||
} | ||
|
||
|
@@ -307,20 +315,14 @@ public void scan() { | |
if (raiseAlert) { | ||
LOGGER.debug("Raising alert for Insecure HTTP Method"); | ||
|
||
newAlert() | ||
buildAlert( | ||
insecureMethod, | ||
description, | ||
extraInfo, | ||
evidence, | ||
alertMessage, | ||
VulnType.OTHER_INSECURE_HTTP_METHOD) | ||
.setRisk(riskLevel) | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", | ||
insecureMethod)) | ||
.setDescription(description) | ||
.setOtherInfo(extraInfo) | ||
.setSolution( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.soln")) | ||
.setEvidence(evidence) | ||
.setMessage(alertMessage) | ||
.raise(); | ||
} | ||
} | ||
|
@@ -376,22 +378,14 @@ private void testTraceOrTrack(String method) throws Exception { | |
|
||
// if the response *body* from the TRACE request contains the cookie,we're in business :) | ||
if (msg.getResponseBody().toString().contains(randomcookievalue)) { | ||
newAlert() | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", method)) | ||
.setDescription( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.trace.exploitable.desc", method)) | ||
buildAlert( | ||
method, | ||
method, | ||
randomcookievalue, | ||
randomcookievalue, | ||
msg, | ||
VulnType.TRACE_TRACK_REFLECTS_COOKIES) | ||
.setUri(msg.getRequestHeader().getURI().toString()) | ||
.setOtherInfo( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.trace.exploitable.extrainfo", | ||
randomcookievalue)) | ||
.setSolution(Constant.messages.getString("ascanbeta.insecurehttpmethod.soln")) | ||
.setEvidence(randomcookievalue) | ||
.setMessage(msg) | ||
.raise(); | ||
} | ||
} | ||
|
@@ -495,25 +489,13 @@ private void handleConnectResponse( | |
Matcher m = thirdPartyContentPattern.matcher(response); | ||
if (m.matches()) { | ||
LOGGER.debug("Response matches expected third party pattern!"); | ||
newAlert() | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", | ||
HttpRequestHeader.CONNECT)) | ||
.setDescription( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.connect.exploitable.desc", | ||
HttpRequestHeader.CONNECT)) | ||
.setOtherInfo( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.connect.exploitable.extrainfo", | ||
thirdpartyHost)) | ||
.setSolution( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.soln")) | ||
.setEvidence(response) | ||
.setMessage(this.getBaseMsg()) | ||
buildAlert( | ||
HttpRequestHeader.CONNECT, | ||
HttpRequestHeader.CONNECT, | ||
thirdpartyHost, | ||
response, | ||
this.getBaseMsg(), | ||
VulnType.OPEN_PROXY_THIRD_PARTY_CONNECT) | ||
.raise(); | ||
} else { | ||
LOGGER.debug("Response does *not* match expected third party pattern"); | ||
|
@@ -624,16 +606,14 @@ private void testHttpMethod(String httpMethod) throws Exception { | |
} | ||
try { | ||
|
||
newAlert() | ||
buildAlert( | ||
httpMethod, | ||
exploitableDesc, | ||
exploitableExtraInfo, | ||
evidence, | ||
msg, | ||
VulnType.INSECURE_WEBDAV_METHOD) | ||
.setRisk(riskLevel) | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", httpMethod)) | ||
.setDescription(exploitableDesc) | ||
.setOtherInfo(exploitableExtraInfo) | ||
.setEvidence(evidence) | ||
.setMessage(msg) | ||
.raise(); | ||
} catch (Exception e) { | ||
} | ||
|
@@ -642,4 +622,80 @@ private void testHttpMethod(String httpMethod) throws Exception { | |
private static String randomAlphanumeric(int count) { | ||
return RandomStringUtils.secure().nextAlphanumeric(count); | ||
} | ||
|
||
private AlertBuilder buildAlert( | ||
String vulnName, | ||
String vulnDesc, | ||
String extraInfo, | ||
String evidence, | ||
HttpMessage msg, | ||
VulnType currentVT) { | ||
return newAlert() | ||
.setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
.setName( | ||
Constant.messages.getString( | ||
"ascanbeta.insecurehttpmethod.detailed.name", vulnName)) | ||
.setDescription(vulnDesc) | ||
.setOtherInfo(extraInfo) | ||
.setSolution(Constant.messages.getString("ascanbeta.insecurehttpmethod.soln")) | ||
.setEvidence(evidence) | ||
.setMessage(msg) | ||
.setCweId(getCweId()) | ||
.setWascId(getWascId()) | ||
.setAlertRef(getId() + "-" + currentVT.getRef()); | ||
} | ||
|
||
@Override | ||
public List<Alert> getExampleAlerts() { | ||
List<Alert> alerts = new ArrayList<>(); | ||
|
||
for (VulnType vulnType : VulnType.values()) { | ||
String name = ""; | ||
String description = ""; | ||
String extraInfo = ""; | ||
String evidence = ""; | ||
|
||
switch (vulnType) { | ||
case DELETE_METHOD_ENABLED: | ||
name = "DELETE Method Enabled"; | ||
description = "The server allows the DELETE HTTP method which can be unsafe."; | ||
extraInfo = "DELETE requests could remove resources if exploited."; | ||
evidence = "DELETE"; | ||
Comment on lines
+660
to
+663
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 values should be the actual values used in the alerts, though you may need to provide the details or specifics like "DELETE". You could also include these int he enum members as that likely simplifies things. It also ensure that they're translated etc. |
||
break; | ||
|
||
case OTHER_INSECURE_HTTP_METHOD: | ||
name = "Other Insecure HTTP Method Enabled"; | ||
description = "An insecure HTTP method (like PUT or PATCH) is enabled."; | ||
extraInfo = "These methods may allow resource modification."; | ||
evidence = "PUT/PATCH/etc."; | ||
break; | ||
|
||
case TRACE_TRACK_REFLECTS_COOKIES: | ||
name = "TRACE/TRACK Reflects Cookies"; | ||
description = "The server reflects cookies in TRACE/TRACK responses."; | ||
extraInfo = "Sensitive cookies may be exposed to attackers."; | ||
evidence = "Sample cookie value"; | ||
break; | ||
|
||
case OPEN_PROXY_THIRD_PARTY_CONNECT: | ||
name = "Open Proxy via CONNECT"; | ||
description = "The server allows CONNECT to a third-party host."; | ||
extraInfo = "The server could be abused as an open proxy."; | ||
evidence = "CONNECT to www.example.com"; | ||
break; | ||
|
||
case INSECURE_WEBDAV_METHOD: | ||
name = "Insecure WebDAV Method Enabled"; | ||
description = "A WebDAV method like COPY, LOCK, or MKCOL is enabled."; | ||
extraInfo = "These methods may allow unauthorized resource manipulation."; | ||
evidence = "MKCOL"; | ||
break; | ||
} | ||
|
||
// Build and add the example alert | ||
alerts.add(buildAlert(name, description, extraInfo, evidence, null, vulnType).build()); | ||
} | ||
|
||
return alerts; | ||
} | ||
} |
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
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.
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.
The builder should be usable by the existing code. Ex: Where alerts are currently raised it should be able to call the builder method(s) (there can be multiple if necessary) then just raise, like:
buildAlert(....).raise();