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.

4.1 KB
Raw Blame
package opensuite.engagement;

import opensuite.core.HttpMessage;
import opensuite.core.HttpService;
import opensuite.core.LogEntry;
import opensuite.core.SuiteContext;
import opensuite.ui.Ui;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * The Analyse target engagement tool: a summary of how much there is to test
 * at or below the selected URL, with the dynamic URLs, the static URLs and the
 * parameters each listed on its own tab.
 */
public class AnalysisWindow extends JFrame {

    public AnalysisWindow(SuiteContext ctx, HttpService svc, HttpMessage req) {
        super("target analyser");
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        String path = req == null || req.path() == null || req.path().isEmpty() ? "/" : req.path();

        List<LogEntry> in = new ArrayList<>();
        for (LogEntry e : ctx.store().all()) {
            if (e.request() == null) continue;
            if (!e.service().host().equalsIgnoreCase(svc.host()) || e.service().port() != svc.port()) continue;
            if (FindWindow.under(e.request().path(), path)) in.add(e);
        }
        TargetAnalysis a = TargetAnalysis.of(in);

        JTabbedPane tabs = new JTabbedPane();
        tabs.setFont(Ui.PLAIN);
        tabs.addTab("Summary", summary(a, svc.url() + path));

        DefaultTableModel dyn = model("Method", "URL", "Parameters", "Names");
        for (TargetAnalysis.Url u : a.dynamicUrls()) {
            dyn.addRow(new Object[]{u.method, u.url, u.parameters.size(), String.join(", ", u.parameters)});
        }
        tabs.addTab("Dynamic URLs", table(dyn, 70, 420, 90, 320));

        DefaultTableModel stat = model("Method", "URL");
        for (TargetAnalysis.Url u : a.staticUrls()) stat.addRow(new Object[]{u.method, u.url});
        tabs.addTab("Static URLs", table(stat, 70, 830));

        DefaultTableModel par = model("Name", "Type", "URLs", "Seen on");
        for (TargetAnalysis.Parameter p : a.parameters()) {
            par.addRow(new Object[]{p.name, String.join(", ", p.types), p.urls.size(), String.join("  ", p.urls)});
        }
        tabs.addTab("Parameters", table(par, 160, 110, 70, 560));

        JPanel root = new JPanel(new BorderLayout());
        root.setBorder(Ui.pad(10, 10, 10, 10));
        root.add(tabs, BorderLayout.CENTER);
        setContentPane(root);
        setSize(960, 620);
        setLocationRelativeTo(ctx.frame());
    }

    private static DefaultTableModel model(String... cols) {
        return new DefaultTableModel(cols, 0) {
            @Override public boolean isCellEditable(int r, int c) { return false; }
            @Override public Class<?> getColumnClass(int c) {
                return getRowCount() > 0 && getValueAt(0, c) instanceof Integer ? Integer.class : String.class;
            }
        };
    }

    private static JComponent table(DefaultTableModel m, int... widths) {
        JTable t = new JTable(m);
        Ui.styleTable(t);
        Ui.distributeWidths(t, widths);
        t.setRowSorter(new opensuite.ui.NumberSorter<>(t.getModel()));
        return Ui.scroll(t);
    }

    private static JComponent summary(TargetAnalysis a, String scope) {
        JPanel form = Ui.form(
                "Analysed:", Ui.label(scope),
                "Number of dynamic URLs:", Ui.bold(String.valueOf(a.dynamicUrls().size())),
                "Number of static URLs:", Ui.bold(String.valueOf(a.staticUrls().size())),
                "Number of parameters:", Ui.bold(String.valueOf(a.parameterInstances())),
                "Number of unique parameter names:", Ui.bold(String.valueOf(a.parameters().size())));
        JPanel p = Ui.vbox(
                Ui.heading("Summary"),
                Ui.note("Dynamic URLs take parameters; static URLs do not. The number of "
                        + "parameters is an approximate indicator of the effort required to test "
                        + "this part of the application thoroughly."),
                form);
        JPanel wrap = new JPanel(new BorderLayout());
        wrap.setBorder(Ui.pad(12, 12, 12, 12));
        wrap.add(p, BorderLayout.NORTH);
        return wrap;
    }
}