-
-
Notifications
You must be signed in to change notification settings - Fork 747
[WIP] Totp Active Scan Rules #6255
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
Draft
AliceMilshtein
wants to merge
31
commits into
zaproxy:main
Choose a base branch
from
AliceMilshtein:TOTP-feature
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.
Draft
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
cd926fc
Add ZAP test app with TOTP authentication that has blank passcode vul…
AliceMilshtein aed7370
Added TOTP scan rule to check for blank passcode vulnerability
AliceMilshtein d608e64
Add TOTP scan rule to check for replay vulnerabilities
AliceMilshtein aef7ddc
Add TOTP rule to check if captcha/lockout mechanism is present & add…
AliceMilshtein 13a9d1c
Add TOTp scan rule to check for lockout/captcha mechanism
AliceMilshtein 074f98b
Add test web server for authentication with totp and server for authe…
AliceMilshtein cbe5dc7
Merge branch 'main' into TOTP-feature
AliceMilshtein 2a53113
Fix browser based authentication message storage in client handler to…
AliceMilshtein 471dcb8
Add test web server with totp authentication that locks account after…
AliceMilshtein 88b5266
Add test web server with Totp Authentication that contains a captcha
AliceMilshtein 0d68e14
Add spotlessApply to scan rules
AliceMilshtein df45cf7
Add spotless Apply to scan rules
AliceMilshtein ea71f84
Update all strings in active scan rules to be i18ned
AliceMilshtein e74ebb0
Update ClientSideHandler to store HTTP Message Numbers instead of ent…
AliceMilshtein ae985f3
Extract common TOTP scan context logic into helper class
AliceMilshtein 61784d4
Add support for overriding TOTP value in AuthenticationStep
AliceMilshtein 0f3ad88
Update test web server's to not allow unathenticated user access to h…
AliceMilshtein 6beef13
Updated BlankTotpActiveScanRule to use wasAuthTestSucessful() from Br…
AliceMilshtein d695aba
Updated totp Active scan rules to correct false positive issue
AliceMilshtein 20af733
Fixxed HTTpMessageHandler not recording messages properly
AliceMilshtein b2a7a13
Added support for use of custom field or TOTP step in authentication …
AliceMilshtein bddcb68
fixed headers
AliceMilshtein 45ead48
Added support for return & updated test servers to implement totp gen…
AliceMilshtein ac3fae4
Added support for return and totp generation
AliceMilshtein a871046
Fixed override of totp value in scan rule issue
AliceMilshtein dc189a0
Addes test server with replay vulnerability + fixed replay issues
AliceMilshtein 73f886e
replay cont
AliceMilshtein b12f85e
Added commonCode vulnerability test server
AliceMilshtein dc46b1b
styling
AliceMilshtein e27d61f
Merge branch 'main' into TOTP-feature + resolve conflicts
AliceMilshtein 69876c9
styling
AliceMilshtein 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
124 changes: 124 additions & 0 deletions
124
...lpha/src/main/java/org/zaproxy/zap/extension/ascanrulesAlpha/BlankTotpActiveScanRule.java
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,124 @@ | ||
| /* | ||
| * Zed Attack Proxy (ZAP) and its related class files. | ||
| * | ||
| * ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
| * | ||
| * Copyright 2025 The ZAP Development Team | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.zaproxy.zap.extension.ascanrulesAlpha; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.parosproxy.paros.Constant; | ||
| import org.parosproxy.paros.core.scanner.AbstractHostPlugin; | ||
| import org.parosproxy.paros.core.scanner.Alert; | ||
| import org.parosproxy.paros.core.scanner.Category; | ||
| import org.parosproxy.paros.network.HttpMessage; | ||
| import org.zaproxy.addon.authhelper.internal.AuthenticationStep; | ||
|
|
||
| public class BlankTotpActiveScanRule extends AbstractHostPlugin | ||
| implements CommonActiveScanRuleInfo { | ||
| private static final String MESSAGE_PREFIX = "ascanalpha.blanktotp."; | ||
| private static final Logger LOGGER = LogManager.getLogger(BlankTotpActiveScanRule.class); | ||
| private static final Map<String, String> ALERT_TAGS = new HashMap<>(); | ||
|
|
||
| @Override | ||
| public int getId() { | ||
| return 40048; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "name"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "desc"); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCategory() { | ||
| return Category.MISC; | ||
| } | ||
|
|
||
| @Override | ||
| public String getSolution() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "soln"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getReference() { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| @Override | ||
| public void scan() { | ||
| try { | ||
|
|
||
| // Get target URL from request | ||
| HttpMessage msg = getBaseMsg(); | ||
| TotpScanContext context = TotpScanContextHelper.resolve(msg); | ||
| if (context == null) { | ||
| return; | ||
| } | ||
|
|
||
| List<AuthenticationStep> mutableAuthSteps = new ArrayList<>(context.authSteps); | ||
|
|
||
| AuthenticationStep testStep = new AuthenticationStep(); | ||
| testStep.setType(AuthenticationStep.Type.CUSTOM_FIELD); | ||
| testStep.setXpath(context.totpStep.getXpath()); | ||
| testStep.setCssSelector(context.totpStep.getCssSelector()); | ||
| testStep.setValue(""); | ||
|
|
||
| for (int i = 0; i < mutableAuthSteps.size(); i++) { | ||
| AuthenticationStep step = mutableAuthSteps.get(i); | ||
| if (step.getType() == AuthenticationStep.Type.TOTP_FIELD) { | ||
| mutableAuthSteps.set(i, testStep); // Replace the TOTP step with the test step | ||
| break; | ||
| } | ||
| } | ||
| context.browserAuthMethod.setAuthenticationSteps(mutableAuthSteps); | ||
| context.browserAuthMethod.authenticate( | ||
| context.sessionManagementMethod, context.credentials, context.user); | ||
| boolean webSessionBlankCode = context.browserAuthMethod.wasAuthTestSucessful(); | ||
|
|
||
| if (webSessionBlankCode) { | ||
| buildAlert( | ||
| "Blank Passcode Vulnerability", | ||
|
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. All text shown to the user should be i18n'ed. Use code like |
||
| "The application allows authentication with a blank or empty passcode, which poses a significant security risk. Attackers can exploit this vulnerability to gain unauthorized access without providing valid credentials.", | ||
| "Enforce strict password policies that require non-empty, strong passcodes. Implement validation checks to prevent blank passcodes during authentication", | ||
| msg) | ||
| .raise(); | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.error("Error in TOTP Page Scan Rule: {}", e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| private AlertBuilder buildAlert( | ||
| String name, String description, String solution, HttpMessage msg) { | ||
| return newAlert() | ||
| .setConfidence(Alert.CONFIDENCE_HIGH) | ||
| .setName(name) | ||
| .setDescription(description) | ||
| .setSolution(solution) | ||
| .setMessage(msg); | ||
| } | ||
| } | ||
207 changes: 207 additions & 0 deletions
207
...ha/src/main/java/org/zaproxy/zap/extension/ascanrulesAlpha/CaptchaTotpActiveScanRule.java
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,207 @@ | ||
| /* | ||
| * Zed Attack Proxy (ZAP) and its related class files. | ||
| * | ||
| * ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
| * | ||
| * Copyright 2025 The ZAP Development Team | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.zaproxy.zap.extension.ascanrulesAlpha; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.parosproxy.paros.Constant; | ||
| import org.parosproxy.paros.core.scanner.AbstractHostPlugin; | ||
| import org.parosproxy.paros.core.scanner.Alert; | ||
| import org.parosproxy.paros.core.scanner.Category; | ||
| import org.parosproxy.paros.network.HttpMessage; | ||
| import org.zaproxy.addon.authhelper.BrowserBasedAuthenticationMethodType.BrowserBasedAuthenticationMethod; | ||
| import org.zaproxy.addon.authhelper.internal.AuthenticationStep; | ||
| import org.zaproxy.zap.authentication.UsernamePasswordAuthenticationCredentials; | ||
| import org.zaproxy.zap.session.SessionManagementMethod; | ||
| import org.zaproxy.zap.session.WebSession; | ||
| import org.zaproxy.zap.users.User; | ||
|
|
||
| public class CaptchaTotpActiveScanRule extends AbstractHostPlugin | ||
| implements CommonActiveScanRuleInfo { | ||
| private static final String MESSAGE_PREFIX = "ascanalpha.captchatotp."; | ||
| private static final Logger LOGGER = LogManager.getLogger(CaptchaTotpActiveScanRule.class); | ||
| private static final Map<String, String> ALERT_TAGS = new HashMap<>(); | ||
|
|
||
| @Override | ||
| public int getId() { | ||
| return 40051; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "name"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "desc"); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCategory() { | ||
| return Category.INFO_GATHER; | ||
| } | ||
|
|
||
| @Override | ||
| public String getSolution() { | ||
| return Constant.messages.getString(MESSAGE_PREFIX + "soln"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getReference() { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| @Override | ||
| public void scan() { | ||
| try { | ||
|
|
||
| // Get target URL from request | ||
| HttpMessage msg = getBaseMsg(); | ||
| TotpScanContext context = TotpScanContextHelper.resolve(msg); | ||
| if (context == null) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if lockout or captcha mechanism is detected | ||
| boolean captchaDetected = false; | ||
| boolean lockoutDetected = false; | ||
|
|
||
| // Run 10 incorrect authentications and store the responses | ||
| // Check responses for any changes or any common captcha technology | ||
|
|
||
| List<AuthenticationStep> authSteps = new ArrayList<>(context.authSteps); | ||
| AuthenticationStep totpStep = context.totpStep; | ||
| int totpIndex = authSteps.indexOf(totpStep); | ||
| List<AuthenticationStep> subset = | ||
| new ArrayList<>(authSteps.subList(totpIndex + 1, authSteps.size())); | ||
| for (int i = 0; i < 9; i++) { | ||
| for (AuthenticationStep step : subset) { | ||
| authSteps.add(step); | ||
| } | ||
| } | ||
| WebSession test = | ||
| testAuthenticatSession( | ||
| context.totpStep, | ||
| "111111", | ||
| authSteps, | ||
| context.browserAuthMethod, | ||
| context.sessionManagementMethod, | ||
| context.credentials, | ||
| context.user); | ||
|
|
||
| List<HttpMessage> messages = context.browserAuthMethod.getRecordedHttpMessages(); | ||
|
|
||
| // Check for key captcha words in the responses | ||
| String[] captchaKeywords = { | ||
| "captcha", | ||
| "g-recaptcha", | ||
| "hcaptcha", | ||
| "data-sitekey", | ||
| "verify you are human", | ||
| "challenge-response", | ||
| "bot detection", | ||
| "recaptcha/api.js", | ||
| "hcaptcha.com/1/api.js", | ||
| "please solve the captcha", | ||
| "captcha verification", | ||
| "input type=\"hidden\" name=\"g-recaptcha-response\"" | ||
| }; | ||
| for (String keyword : captchaKeywords) { | ||
| for (HttpMessage response : messages) { | ||
| String contentType = response.getResponseHeader().getHeader("Content-Type"); | ||
| if (contentType == null || !contentType.toLowerCase().contains("text")) { | ||
| continue; | ||
| } | ||
| if (response.getResponseBody().toString().toLowerCase().contains(keyword)) { | ||
| captchaDetected = true; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check for lockout words in the responses | ||
| String[] lockoutKeywords = { | ||
| "lockout", | ||
| "locked", | ||
| "too many failed attempts", | ||
| "too many login attempts", | ||
| "reset your password", | ||
| "account disabled", | ||
| "unlock" | ||
| }; | ||
| for (String keyword : lockoutKeywords) { | ||
| for (HttpMessage response : messages) { | ||
| String contentType = response.getResponseHeader().getHeader("Content-Type"); | ||
| if (contentType == null || !contentType.toLowerCase().contains("text")) { | ||
| continue; | ||
| } | ||
| if (response.getResponseBody().toString().toLowerCase().contains(keyword)) { | ||
| lockoutDetected = true; | ||
| return; | ||
| } else if (response.getResponseHeader().getStatusCode() == 403) { | ||
| lockoutDetected = true; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!captchaDetected && !lockoutDetected) { | ||
| buildAlert( | ||
| "No Lockout or Captcha Mechanism Detected", | ||
| "\"The application does not enforce CAPTCHA or account lockout mechanisms, making it vulnerable to brute-force attacks.", | ||
| "Implement CAPTCHA verification and/or account lockout policies after multiple failed login attempts.", | ||
| msg) | ||
| .raise(); | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.error("Error in TOTP Page Scan Rule: {}", e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| private WebSession testAuthenticatSession( | ||
| AuthenticationStep totpStep, | ||
| String newTotpValue, | ||
| List<AuthenticationStep> authSteps, | ||
| BrowserBasedAuthenticationMethod browserAuthMethod, | ||
| SessionManagementMethod sessionManagementMethod, | ||
| UsernamePasswordAuthenticationCredentials credentials, | ||
| User user) { | ||
| if (totpStep.getType() == AuthenticationStep.Type.TOTP_FIELD) | ||
| totpStep.setUserProvidedTotp(newTotpValue); | ||
| else totpStep.setValue(newTotpValue); | ||
| browserAuthMethod.setAuthenticationSteps(authSteps); | ||
| return browserAuthMethod.authenticate(sessionManagementMethod, credentials, user); | ||
| } | ||
|
|
||
| private AlertBuilder buildAlert( | ||
| String name, String description, String solution, HttpMessage msg) { | ||
| return newAlert() | ||
| .setConfidence(Alert.CONFIDENCE_MEDIUM) | ||
| .setName(name) | ||
| .setDescription(description) | ||
| .setSolution(solution) | ||
| .setMessage(msg); | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
All code should have the standard header - you can just rip it off from any other class, just remember to change the year to 2025 😁
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 spotlessApply task will add them with the proper year.