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.4 KB
Raw Blame
package opensuite.ui;

import opensuite.core.Issue;
import opensuite.core.SuiteContext;

import javax.swing.*;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.function.IntFunction;

/**
 * What can be done with chosen findings, the same wherever they are listed:
 * report them, mark them as false positives or as real again, delete them.
 */
public final class IssueMenu {
    private IssueMenu() {}

    /** Mark what a finding points at: the evidence in the response, the payload and parameter in the request. */
    public static void markEvidence(Issue i, MessageEditor request, MessageEditor response) {
        if (i == null) return;
        if (response != null) response.mark(i.evidence());
        if (request != null) request.mark(i.attack(), i.attack().isEmpty() ? i.evidence() : null);
    }

    /** Give a table of findings the menu; {@code at} turns a view row into its finding. */
    public static void install(JTable table, SuiteContext ctx, IntFunction<Issue> at) {
        table.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override public void mousePressed(java.awt.event.MouseEvent e) { pop(e); }
            @Override public void mouseReleased(java.awt.event.MouseEvent e) { pop(e); }
            private void pop(java.awt.event.MouseEvent e) {
                if (!e.isPopupTrigger()) return;
                int row = table.rowAtPoint(e.getPoint());
                if (row < 0) return;
                if (!table.isRowSelected(row)) table.setRowSelectionInterval(row, row);
                List<Issue> chosen = new ArrayList<>();
                for (int r : table.getSelectedRows()) {
                    Issue i = at.apply(r);
                    if (i != null && !chosen.contains(i)) chosen.add(i);
                }
                show(table, e.getX(), e.getY(), ctx, chosen);
            }
        });
    }

    public static void show(Component on, int x, int y, SuiteContext ctx, List<Issue> chosen) {
        if (chosen == null || chosen.isEmpty()) return;
        JPopupMenu m = new JPopupMenu();
        String many = chosen.size() == 1 ? "issue" : "issues";
        boolean allFalse = true;
        for (Issue i : chosen) allFalse &= i.falsePositive();
        add(m, "Report selected " + many, () -> opensuite.report.Export.reportDialog(ctx.frame(), chosen, "opensuite-report"));
        m.addSeparator();
        JMenu sev = new JMenu("Set severity");
        sev.setFont(Ui.PLAIN);
        JMenuItem fp = new JMenuItem("False positive");
        fp.setFont(Ui.PLAIN);
        fp.setEnabled(!allFalse);
        fp.addActionListener(e -> { for (Issue i : chosen) i.setFalsePositive(true); ctx.issuesChanged(); });
        JMenuItem real = new JMenuItem("As reported");
        real.setFont(Ui.PLAIN);
        boolean anyFalse = false;
        for (Issue i : chosen) anyFalse |= i.falsePositive();
        real.setEnabled(anyFalse);
        real.addActionListener(e -> { for (Issue i : chosen) i.setFalsePositive(false); ctx.issuesChanged(); });
        sev.add(fp);
        sev.add(real);
        m.add(sev);
        m.addSeparator();
        add(m, "Delete selected " + many, () -> ctx.removeIssuesWhere(chosen::contains));
        m.show(on, x, y);
    }

    private static void add(JPopupMenu m, String label, Runnable r) {
        JMenuItem mi = new JMenuItem(label);
        mi.setFont(Ui.PLAIN);
        mi.addActionListener(e -> r.run());
        m.add(mi);
    }
}