Skip to content
Draft
Show file tree
Hide file tree
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 Feb 19, 2025
aed7370
Added TOTP scan rule to check for blank passcode vulnerability
AliceMilshtein Mar 7, 2025
d608e64
Add TOTP scan rule to check for replay vulnerabilities
AliceMilshtein Mar 7, 2025
aef7ddc
Add TOTP rule to check if captcha/lockout mechanism is present & add…
AliceMilshtein Mar 7, 2025
13a9d1c
Add TOTp scan rule to check for lockout/captcha mechanism
AliceMilshtein Mar 26, 2025
074f98b
Add test web server for authentication with totp and server for authe…
AliceMilshtein Mar 27, 2025
cbe5dc7
Merge branch 'main' into TOTP-feature
AliceMilshtein Mar 27, 2025
2a53113
Fix browser based authentication message storage in client handler to…
AliceMilshtein Mar 27, 2025
471dcb8
Add test web server with totp authentication that locks account after…
AliceMilshtein Mar 28, 2025
88b5266
Add test web server with Totp Authentication that contains a captcha
AliceMilshtein Mar 28, 2025
0d68e14
Add spotlessApply to scan rules
AliceMilshtein Apr 7, 2025
df45cf7
Add spotless Apply to scan rules
AliceMilshtein Apr 7, 2025
ea71f84
Update all strings in active scan rules to be i18ned
AliceMilshtein Apr 7, 2025
e74ebb0
Update ClientSideHandler to store HTTP Message Numbers instead of ent…
AliceMilshtein Apr 7, 2025
ae985f3
Extract common TOTP scan context logic into helper class
AliceMilshtein Apr 8, 2025
61784d4
Add support for overriding TOTP value in AuthenticationStep
AliceMilshtein Apr 8, 2025
0f3ad88
Update test web server's to not allow unathenticated user access to h…
AliceMilshtein May 6, 2025
6beef13
Updated BlankTotpActiveScanRule to use wasAuthTestSucessful() from Br…
AliceMilshtein May 6, 2025
d695aba
Updated totp Active scan rules to correct false positive issue
AliceMilshtein May 7, 2025
20af733
Fixxed HTTpMessageHandler not recording messages properly
AliceMilshtein May 7, 2025
b2a7a13
Added support for use of custom field or TOTP step in authentication …
AliceMilshtein May 7, 2025
bddcb68
fixed headers
AliceMilshtein May 7, 2025
45ead48
Added support for return & updated test servers to implement totp gen…
AliceMilshtein May 27, 2025
ac3fae4
Added support for return and totp generation
AliceMilshtein May 27, 2025
a871046
Fixed override of totp value in scan rule issue
AliceMilshtein Jun 4, 2025
dc189a0
Addes test server with replay vulnerability + fixed replay issues
AliceMilshtein Jun 6, 2025
73f886e
replay cont
AliceMilshtein Jun 6, 2025
b12f85e
Added commonCode vulnerability test server
AliceMilshtein Jun 6, 2025
dc46b1b
styling
AliceMilshtein Jun 6, 2025
e27d61f
Merge branch 'main' into TOTP-feature + resolve conflicts
AliceMilshtein Jun 6, 2025
69876c9
styling
AliceMilshtein Jun 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions addOns/ascanrulesAlpha/ascanrulesAlpha.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ zapAddOn {
register("commonlib") {
version.set(">= 1.32.0 & < 2.0.0")
}
register("authhelper") {
version.set("0.26.0")
}
}
}
}
}

tasks.named("compileJava") {
dependsOn(":addOns:authhelper:enhance")
mustRunAfter(parent!!.childProjects.get("oast")!!.tasks.named("enhance"))
}

dependencies {
zapAddOn("commonlib")
zapAddOn("authhelper")

testImplementation(project(":testutils"))
}
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;
Copy link
Member

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 😁

Copy link
Member

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.


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",
Copy link
Member

Choose a reason for hiding this comment

The 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 Constant.messages.getString(MESSAGE_PREFIX + "soln");

"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);
}
}
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);
}
}
Loading