Skip to content

Commit

Permalink
ascanrules: Add policy alert tags
Browse files Browse the repository at this point in the history
- CHANGELOG > Add note and fix note.
- Scan rules > Add PolicyTag values.
- Unit tests > Assert the new tags.
- Build file > Update the required version of commonlib.

Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
  • Loading branch information
kingthorin committed Nov 26, 2024
1 parent e56eaab commit a0367b6
Show file tree
Hide file tree
Showing 86 changed files with 1,067 additions and 261 deletions.
4 changes: 4 additions & 0 deletions addOns/ascanrules/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Updated help with specific Category identifiers for use with the Custom Payloads add-on for rules:
- Hidden File Finder
- User Agent Fuzzer
- Now depends on minimum Common Library version 1.29.0.

### Added
- Standardized Scan Policy related alert tags on the rule.

## [69] - 2024-10-23
### Changed
Expand Down
2 changes: 1 addition & 1 deletion addOns/ascanrules/ascanrules.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ zapAddOn {
dependencies {
addOns {
register("commonlib") {
version.set(">= 1.21.0 & < 2.0.0")
version.set(">= 1.29.0 & < 2.0.0")
}
register("network") {
version.set(">= 0.3.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.URIException;
Expand All @@ -36,6 +38,7 @@
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.network.HttpResponseHeader;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.zap.model.Tech;
import org.zaproxy.zap.model.TechSet;

Expand All @@ -45,10 +48,18 @@ public class BufferOverflowScanRule extends AbstractAppParamPlugin
/** Prefix for internationalised messages used by this rule */
private static final String MESSAGE_PREFIX = "ascanrules.bufferoverflow.";

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION));
alertTags.put(PolicyTag.API.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

private static final String CONNECTION_CLOSED = "Connection: close";

private static final int PLUGIN_ID = 30001;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
Expand All @@ -31,6 +32,7 @@
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;

/**
* Attempts to retrieve cloud metadata by forging the host header and requesting a specific URL. See
Expand All @@ -48,10 +50,18 @@ public class CloudMetadataScanRule extends AbstractHostPlugin implements CommonA
"169.254.169.254", "aws.zaproxy.org", "100.100.100.200", "alibaba.zaproxy.org");

private static final Logger LOGGER = LogManager.getLogger(CloudMetadataScanRule.class);
private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG));
alertTags.put(PolicyTag.API.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

@Override
public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand All @@ -32,6 +34,7 @@
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.zap.model.Tech;
import org.zaproxy.zap.model.TechSet;

Expand All @@ -47,11 +50,22 @@ public class CodeInjectionScanRule extends AbstractAppParamPlugin
/** Prefix for internationalised messages used by this rule */
private static final String MESSAGE_PREFIX = "ascanrules.codeinjection.";

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_11_CODE_INJ);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_11_CODE_INJ));
alertTags.put(PolicyTag.API.getTag(), "");
alertTags.put(PolicyTag.DEV_FULL.getTag(), "");
alertTags.put(PolicyTag.QA_STD.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
alertTags.put(PolicyTag.SEQUENCE.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

// PHP control Token used to verify the vulnerability
private static final String PHP_CONTROL_TOKEN = "zap_token";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.IOException;
import java.net.SocketException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand All @@ -42,6 +44,7 @@
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.addon.commonlib.timing.TimingUtils;
import org.zaproxy.addon.commonlib.vulnerabilities.Vulnerabilities;
import org.zaproxy.addon.commonlib.vulnerabilities.Vulnerability;
Expand Down Expand Up @@ -87,11 +90,24 @@ public class CommandInjectionScanRule extends AbstractAppParamPlugin
private static final Map<String, Pattern> WIN_OS_PAYLOADS = new LinkedHashMap<>();
private static final Map<String, Pattern> PS_PAYLOADS = new LinkedHashMap<>();

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_12_COMMAND_INJ);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_12_COMMAND_INJ));
alertTags.put(PolicyTag.API.getTag(), "");
alertTags.put(PolicyTag.DEV_CICD.getTag(), "");
alertTags.put(PolicyTag.DEV_STD.getTag(), "");
alertTags.put(PolicyTag.DEV_FULL.getTag(), "");
alertTags.put(PolicyTag.QA_STD.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
alertTags.put(PolicyTag.SEQUENCE.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

static {
// No quote payloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// ZAP: 2020/07/24 Normalise scan rule class names.
package org.zaproxy.zap.extension.ascanrules;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -41,18 +43,29 @@
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;

public class CrlfInjectionScanRule extends AbstractAppParamPlugin
implements CommonActiveScanRuleInfo {

/** Prefix for internationalised messages used by this rule */
private static final String MESSAGE_PREFIX = "ascanrules.crlfinjection.";

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_15_HTTP_SPLITTING);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A01_INJECTION,
CommonAlertTag.WSTG_V42_INPV_15_HTTP_SPLITTING));
alertTags.put(PolicyTag.API.getTag(), "");
alertTags.put(PolicyTag.DEV_FULL.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
alertTags.put(PolicyTag.SEQUENCE.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

private String randomString = "Tamper=" + UUID.randomUUID().toString();
private String cookieTamper1 = "Set-cookie: " + randomString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.URIException;
Expand All @@ -38,6 +40,7 @@
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.network.HttpRequestHeader;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.addon.commonlib.http.HttpFieldsNames;
import org.zaproxy.addon.commonlib.vulnerabilities.Vulnerabilities;
import org.zaproxy.addon.commonlib.vulnerabilities.Vulnerability;
Expand All @@ -50,11 +53,23 @@ public class CrossSiteScriptingScanRule extends AbstractAppParamPlugin
/** Prefix for internationalised messages used by this rule */
private static final String MESSAGE_PREFIX = "ascanrules.crosssitescripting.";

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A07_XSS,
CommonAlertTag.WSTG_V42_INPV_01_REFLECTED_XSS);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A03_INJECTION,
CommonAlertTag.OWASP_2017_A07_XSS,
CommonAlertTag.WSTG_V42_INPV_01_REFLECTED_XSS));
alertTags.put(PolicyTag.DEV_CICD.getTag(), "");
alertTags.put(PolicyTag.DEV_STD.getTag(), "");
alertTags.put(PolicyTag.DEV_FULL.getTag(), "");
alertTags.put(PolicyTag.QA_STD.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
alertTags.put(PolicyTag.SEQUENCE.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

protected static final String GENERIC_SCRIPT_ALERT = "<scrIpt>alert(1);</scRipt>";
protected static final String GENERIC_ONERROR_ALERT = "<img src=x onerror=prompt()>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
package org.zaproxy.zap.extension.ascanrules;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand All @@ -40,6 +42,7 @@
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.zap.model.Tech;

public class DirectoryBrowsingScanRule extends AbstractAppPlugin
Expand All @@ -48,10 +51,19 @@ public class DirectoryBrowsingScanRule extends AbstractAppPlugin
/** Prefix for internationalised messages used by this rule */
private static final String MESSAGE_PREFIX = "ascanrules.directorybrowsing.";

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A01_BROKEN_AC,
CommonAlertTag.OWASP_2017_A05_BROKEN_AC);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A01_BROKEN_AC,
CommonAlertTag.OWASP_2017_A05_BROKEN_AC));
alertTags.put(PolicyTag.API.getTag(), "");
alertTags.put(PolicyTag.QA_STD.getTag(), "");
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

private static final Pattern patternIIS = Pattern.compile("Parent Directory", PATTERN_PARAM);
private static final Pattern patternApache =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
*/
package org.zaproxy.zap.extension.ascanrules;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.AbstractHostFilePlugin;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.zap.model.Tech;
import org.zaproxy.zap.model.TechSet;

Expand All @@ -35,11 +38,18 @@ public class ElmahScanRule extends AbstractHostFilePlugin implements CommonActiv
private static final String MESSAGE_PREFIX = "ascanrules.elmah.";
private static final int PLUGIN_ID = 40028;

private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG,
CommonAlertTag.WSTG_V42_CONF_05_ENUMERATE_INFRASTRUCTURE);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG,
CommonAlertTag.WSTG_V42_CONF_05_ENUMERATE_INFRASTRUCTURE));
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

public ElmahScanRule() {
super("/elmah.axd", MESSAGE_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
*/
package org.zaproxy.zap.extension.ascanrules;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.AbstractAppFilePlugin;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.zaproxy.addon.commonlib.PolicyTag;

public class EnvFileScanRule extends AbstractAppFilePlugin implements CommonActiveScanRuleInfo {

Expand All @@ -35,11 +38,18 @@ public class EnvFileScanRule extends AbstractAppFilePlugin implements CommonActi
private static final Pattern COMMENT_PATTERN =
Pattern.compile("^#\\s{0,10}\\w+", Pattern.MULTILINE);
private static final Pattern KEYVAL_PATTERN = Pattern.compile("^\\w+=\\w+", Pattern.MULTILINE);
private static final Map<String, String> ALERT_TAGS =
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG,
CommonAlertTag.WSTG_V42_CONF_05_ENUMERATE_INFRASTRUCTURE);
private static final Map<String, String> ALERT_TAGS;

static {
Map<String, String> alertTags =
new HashMap<>(
CommonAlertTag.toMap(
CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG,
CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG,
CommonAlertTag.WSTG_V42_CONF_05_ENUMERATE_INFRASTRUCTURE));
alertTags.put(PolicyTag.QA_FULL.getTag(), "");
ALERT_TAGS = Collections.unmodifiableMap(alertTags);
}

public EnvFileScanRule() {
super(".env", MESSAGE_PREFIX);
Expand Down
Loading

0 comments on commit a0367b6

Please sign in to comment.