Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

3.1 KB
Raw Blame
package opensuite.engagement;

import opensuite.core.LogEntry;
import opensuite.core.Param;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * The Analyse target engagement tool's arithmetic: how many distinct URLs a
 * part of the site has, which take parameters (dynamic) and which do not
 * (static), and every parameter with the URLs it appears on. It is a measure
 * of how much attack surface there is to test.
 */
public final class TargetAnalysis {

    /** One distinct URL (method, host and path) with the parameters seen on it. */
    public static final class Url {
        public final String method;
        public final String url;
        public final Set<String> parameters = new LinkedHashSet<>();
        Url(String method, String url) { this.method = method; this.url = url; }
        public boolean dynamic() { return !parameters.isEmpty(); }
    }

    /** One distinct parameter name with every URL it was seen on. */
    public static final class Parameter {
        public final String name;
        public final Set<String> types = new LinkedHashSet<>();
        public final Set<String> urls = new LinkedHashSet<>();
        Parameter(String name) { this.name = name; }
    }

    private final Map<String, Url> urls = new LinkedHashMap<>();
    private final Map<String, Parameter> parameters = new LinkedHashMap<>();

    public static TargetAnalysis of(List<LogEntry> entries) {
        TargetAnalysis a = new TargetAnalysis();
        for (LogEntry e : entries) a.add(e);
        return a;
    }

    private void add(LogEntry e) {
        if (e == null || e.request() == null) return;
        String path = e.request().path();
        String url = e.service().url() + (path == null || path.isEmpty() ? "/" : path);
        String method = e.request().method();
        Url u = urls.computeIfAbsent(method + " " + url, k -> new Url(method, url));
        for (Param p : e.request().parameters()) {
            // Cookies ride on every request to a site, so counting them would
            // make every URL look dynamic.
            if (p.type() == Param.Type.COOKIE || p.type() == Param.Type.HEADER) continue;
            u.parameters.add(p.name());
            Parameter par = parameters.computeIfAbsent(p.name(), Parameter::new);
            par.types.add(p.typeLabel());
            par.urls.add(url);
        }
    }

    public List<Url> dynamicUrls() {
        List<Url> out = new ArrayList<>();
        for (Url u : urls.values()) if (u.dynamic()) out.add(u);
        return out;
    }

    public List<Url> staticUrls() {
        List<Url> out = new ArrayList<>();
        for (Url u : urls.values()) if (!u.dynamic()) out.add(u);
        return out;
    }

    public List<Parameter> parameters() { return new ArrayList<>(parameters.values()); }

    public int urlCount() { return urls.size(); }

    /** The total number of parameters across the dynamic URLs. */
    public int parameterInstances() {
        int n = 0;
        for (Url u : urls.values()) n += u.parameters.size();
        return n;
    }
}