Skip to content

Commit

Permalink
Merge pull request #5651 from kingthorin/td-tweaks
Browse files Browse the repository at this point in the history
tech detection: Maintenance tweaks
  • Loading branch information
psiinon authored Aug 23, 2024
2 parents caee177 + 44fa8f8 commit b2ae188
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 96 deletions.
2 changes: 2 additions & 0 deletions addOns/wappalyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Quick > Return on first match; which may mean missing version information, but should be slightly more performant. (This is the default.)
- Exhaustive > Keep matching and don't return early; likely slightly less performant.
- The add-on now also has the ability to optionally raise Alerts for each technology identified. The default setting is enabled. (Issue 8361)
- Maintenance changes.
- This may be a breaking change for anyone that has code using the Automation Framework's Tech Detection (Wappalyzer) data.

## [21.39.0] - 2024-07-04
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.List;

public interface WappalyzerApplicationHolder {
public interface ApplicationHolder {

void addApplicationsToSite(String site, ApplicationMatch applicationMatch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.zaproxy.zap.view.SiteMapTreeCellRenderer;

public class ExtensionWappalyzer extends ExtensionAdaptor
implements SessionChangedListener, SiteMapListener, WappalyzerApplicationHolder {
implements SessionChangedListener, SiteMapListener, ApplicationHolder {

public static final String NAME = "ExtensionWappalyzer";

Expand All @@ -77,16 +77,16 @@ public class ExtensionWappalyzer extends ExtensionAdaptor

private Map<String, TechTableModel> siteTechMap;
private boolean enabled;
private WappalyzerParam wappalyzerParam;
private TechDetectParam techDetectParam;

private static final Logger LOGGER = LogManager.getLogger(ExtensionWappalyzer.class);

/** The dependencies of the extension. */
private static final List<Class<? extends Extension>> EXTENSION_DEPENDENCIES =
List.of(ExtensionPassiveScan.class);

private WappalyzerPassiveScanner passiveScanner;
private WappalyzerAPI api;
private TechPassiveScanner passiveScanner;
private TechApi api;

public enum Mode {
QUICK(Constant.messages.getString("wappalyzer.mode.quick")),
Expand Down Expand Up @@ -144,15 +144,14 @@ public void init() {
LOGGER.error("Failed to enumerate Tech Detection technologies:", e);
}

WappalyzerData result =
new WappalyzerJsonParser()
.parse(CATEGORIES_PATH, technologyFiles, View.isInitialised());
TechData result =
new TechsJsonParser().parse(CATEGORIES_PATH, technologyFiles, View.isInitialised());
this.applications = result.getApplications();
this.categories = result.getCategories();

enabled = true;
wappalyzerParam = new WappalyzerParam();
passiveScanner = new WappalyzerPassiveScanner(this);
techDetectParam = new TechDetectParam();
passiveScanner = new TechPassiveScanner(this);
}

private static boolean isTechnology(ZipEntry entry) {
Expand All @@ -165,7 +164,7 @@ private static String techToResourcePath(ZipEntry entry) {
return name.substring(name.lastIndexOf(TECHNOLOGIES_PATH));
}

WappalyzerPassiveScanner getPassiveScanner() {
TechPassiveScanner getPassiveScanner() {
return passiveScanner;
}

Expand All @@ -184,9 +183,9 @@ public void hook(ExtensionHook extensionHook) {
extensionHook.getHookView().addOptionPanel(new TechOptionsPanel());
}

this.api = new WappalyzerAPI(this);
this.api = new TechApi(this);
extensionHook.addApiImplementor(this.api);
extensionHook.addOptionsParamSet(wappalyzerParam);
extensionHook.addOptionsParamSet(techDetectParam);

ExtensionPassiveScan extPScan =
Control.getSingleton()
Expand All @@ -200,9 +199,9 @@ public void hook(ExtensionHook extensionHook) {
public void optionsLoaded() {
super.optionsLoaded();

setWappalyzer(wappalyzerParam.isEnabled());
passiveScanner.setMode(wappalyzerParam.getMode());
passiveScanner.setRaiseAlerts(wappalyzerParam.isRaiseAlerts());
setWappalyzer(techDetectParam.isEnabled());
passiveScanner.setMode(techDetectParam.getMode());
passiveScanner.setRaiseAlerts(techDetectParam.isRaiseAlerts());
}

void setWappalyzer(boolean enabled) {
Expand All @@ -211,7 +210,7 @@ void setWappalyzer(boolean enabled) {
}
this.enabled = enabled;

wappalyzerParam.setEnabled(enabled);
techDetectParam.setEnabled(enabled);
getPassiveScanner().setEnabled(enabled);

if (hasView()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.zaproxy.zap.extension.api.ApiResponseSet;
import org.zaproxy.zap.extension.api.ApiView;

public class WappalyzerAPI extends ApiImplementor {
public class TechApi extends ApiImplementor {

public static final String PREFIX = "wappalyzer";

Expand All @@ -44,11 +44,11 @@ public class WappalyzerAPI extends ApiImplementor {
private ExtensionWappalyzer extension = null;

/** Provided only for API client generator usage. */
public WappalyzerAPI() {
public TechApi() {
this(null);
}

public WappalyzerAPI(ExtensionWappalyzer ext) {
public TechApi(ExtensionWappalyzer ext) {
this.extension = ext;
this.addApiView(new ApiView(VIEW_LIST_SITES));
this.addApiView(new ApiView(VIEW_LIST_ALL));
Expand Down Expand Up @@ -104,7 +104,7 @@ private ApiResponseList getAppListForSite(String site) {
return resultList;
}

private ApiResponseList sitesToList(String name, Set<String> sites) {
private static ApiResponseList sitesToList(String name, Set<String> sites) {
ApiResponseList resultList = new ApiResponseList(name);
sites.forEach(site -> resultList.addItem(new ApiResponseElement("site", site)));
return resultList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.List;
import java.util.Map;

public class WappalyzerData {
public class TechData {

private Map<String, String> categories = new HashMap<>();
private List<Application> applications = Collections.synchronizedList(new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.zaproxy.zap.common.VersionedAbstractParam;
import org.zaproxy.zap.extension.wappalyzer.ExtensionWappalyzer.Mode;

public class WappalyzerParam extends VersionedAbstractParam {
public class TechDetectParam extends VersionedAbstractParam {

/**
* The version of the configurations. Used to keep track of configurations changes between
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private JCheckBox getRaiseAlertsCheckBox() {
@Override
public void initParam(Object obj) {
OptionsParam options = (OptionsParam) obj;
WappalyzerParam param = options.getParamSet(WappalyzerParam.class);
TechDetectParam param = options.getParamSet(TechDetectParam.class);

modeComboBox.setSelectedItem(param.getMode());
raiseAlertsCheckBox.setSelected(param.isRaiseAlerts());
Expand All @@ -104,7 +104,7 @@ public void initParam(Object obj) {
@Override
public void saveParam(Object obj) throws Exception {
OptionsParam options = (OptionsParam) obj;
WappalyzerParam param = options.getParamSet(WappalyzerParam.class);
TechDetectParam param = options.getParamSet(TechDetectParam.class);

param.setMode((Mode) modeComboBox.getSelectedItem());
param.setRaiseAlerts(raiseAlertsCheckBox.isSelected());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
import org.zaproxy.zap.extension.wappalyzer.AppPattern.Result;
import org.zaproxy.zap.extension.wappalyzer.ExtensionWappalyzer.Mode;

public class WappalyzerPassiveScanner implements PassiveScanner, OptionsChangedListener {
public class TechPassiveScanner implements PassiveScanner, OptionsChangedListener {

private static final Logger LOGGER = LogManager.getLogger(WappalyzerPassiveScanner.class);
private static final Logger LOGGER = LogManager.getLogger(TechPassiveScanner.class);
private static final int PLUGIN_ID = 10004;

private WappalyzerApplicationHolder applicationHolder;
private ApplicationHolder applicationHolder;
private Map<String, Set<String>> tracker;
private Set<String> visitedSiteIdentifiers;
private volatile boolean enabled = true;
Expand All @@ -75,20 +75,20 @@ ApplicationMatch process(

private List<CustomProcessor> messageHeaderProcessors =
List.of(
WappalyzerPassiveScanner.this::checkUrlMatches,
WappalyzerPassiveScanner.this::checkHeadersMatches,
WappalyzerPassiveScanner.this::checkCookieMatches);
TechPassiveScanner.this::checkUrlMatches,
TechPassiveScanner.this::checkHeadersMatches,
TechPassiveScanner.this::checkCookieMatches);

private List<CustomProcessor> messageBodyProcessors =
List.of(
WappalyzerPassiveScanner.this::checkBodyMatches,
WappalyzerPassiveScanner.this::checkSimpleDomMatches,
WappalyzerPassiveScanner.this::checkDomElementMatches,
WappalyzerPassiveScanner.this::checkMetaElementsMatches,
WappalyzerPassiveScanner.this::checkScriptElementsMatches,
WappalyzerPassiveScanner.this::checkCssElementsMatches);

public WappalyzerPassiveScanner(WappalyzerApplicationHolder applicationHolder) {
TechPassiveScanner.this::checkBodyMatches,
TechPassiveScanner.this::checkSimpleDomMatches,
TechPassiveScanner.this::checkDomElementMatches,
TechPassiveScanner.this::checkMetaElementsMatches,
TechPassiveScanner.this::checkScriptElementsMatches,
TechPassiveScanner.this::checkCssElementsMatches);

public TechPassiveScanner(ApplicationHolder applicationHolder) {
super();
this.applicationHolder = applicationHolder;
this.reset();
Expand Down Expand Up @@ -503,7 +503,7 @@ public boolean appliesToHistoryType(int historyType) {

@Override
public void optionsChanged(OptionsParam optionsParam) {
WappalyzerParam param = optionsParam.getParamSet(WappalyzerParam.class);
TechDetectParam param = optionsParam.getParamSet(TechDetectParam.class);
mode = param.getMode();
raiseAlerts = param.isRaiseAlerts();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getImpliesString(Application app) {
return listToString(app.getImplies());
}

private String categoriesToString(List<String> list) {
private static String categoriesToString(List<String> list) {
if (list == null) {
return null;
}
Expand All @@ -125,7 +125,7 @@ private String categoriesToString(List<String> list) {
return sb.toString();
}

private String listToString(List<String> list) {
private static String listToString(List<String> list) {
if (list == null) {
return null;
}
Expand Down
Loading

0 comments on commit b2ae188

Please sign in to comment.