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.

5.1 KB
Raw Blame
package opensuite.clickjack;

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

import javax.swing.*;
import java.awt.*;

/**
 * The Clickjacking PoC engagement tool: takes a target URL, builds a framing
 * page with {@link ClickjackPoc}, and lets the tester adjust the overlay and
 * save, copy or open it. The point is to show whether the target can be framed
 * at all; a site with the right framing defences stays blank inside the frame.
 */
public class ClickjackWindow extends JFrame {

    private final SuiteContext ctx;
    private final JTextField urlField = Ui.field("");
    private final JSpinner opacity = new JSpinner(new SpinnerNumberModel(50, ClickjackPoc.MIN_OPACITY, ClickjackPoc.MAX_OPACITY, 5));
    private final JSpinner offsetX = new JSpinner(new SpinnerNumberModel(0, -2000, 2000, 10));
    private final JSpinner offsetY = new JSpinner(new SpinnerNumberModel(0, -2000, 2000, 10));
    private final JTextField decoy = Ui.field("Click here");
    private final JTextArea output = new JTextArea();

    public ClickjackWindow(SuiteContext ctx, HttpService svc, HttpMessage req) {
        super("Clickjacking proof of concept");
        this.ctx = ctx;
        String url = svc == null ? "" : svc.url() + (req == null || req.path() == null || req.path().isEmpty() ? "/" : req.path());
        urlField.setText(url);
        output.setFont(Ui.MONO);
        output.setEditable(false);

        JButton gen = Ui.primaryButton("generate", "Build the clickjacking proof of concept");
        JButton save = Ui.button("save...");
        JButton copy = Ui.button("copy");
        JButton open = Ui.button("open in browser", "Write to a temporary file and open it");
        gen.addActionListener(e -> generate());
        save.addActionListener(e -> save());
        copy.addActionListener(e -> copy());
        open.addActionListener(e -> openInBrowser());
        javax.swing.event.ChangeListener live = e -> generate();
        opacity.addChangeListener(live);
        offsetX.addChangeListener(live);
        offsetY.addChangeListener(live);

        JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 6));
        controls.add(gen); controls.add(save); controls.add(copy); controls.add(open);

        JPanel form = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 6));
        form.add(Ui.label("target URL")); form.add(urlField);
        form.add(Ui.label("overlay opacity %")); form.add(opacity);
        form.add(Ui.label("offset x")); form.add(offsetX);
        form.add(Ui.label("offset y")); form.add(offsetY);
        form.add(Ui.label("decoy text")); form.add(decoy);
        urlField.setColumns(28);
        decoy.setColumns(14);

        JPanel north = new JPanel(new BorderLayout());
        north.add(controls, BorderLayout.NORTH);
        north.add(form, BorderLayout.CENTER);

        JPanel outPanel = new JPanel(new BorderLayout());
        outPanel.add(Ui.bold(" clickjacking proof of concept"), BorderLayout.NORTH);
        outPanel.add(Ui.scroll(output), BorderLayout.CENTER);

        setLayout(new BorderLayout());
        add(north, BorderLayout.NORTH);
        add(outPanel, BorderLayout.CENTER);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setSize(820, 560);
        setLocationRelativeTo(ctx.frame());
        generate();
    }

    private void generate() {
        output.setText(ClickjackPoc.generate(urlField.getText(),
                (Integer) opacity.getValue(), (Integer) offsetX.getValue(), (Integer) offsetY.getValue(), decoy.getText()));
        output.setCaretPosition(0);
    }

    private void save() {
        JFileChooser fc = new opensuite.ui.FileChooser();
        fc.setSelectedFile(new java.io.File("clickjack-poc.html"));
        if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return;
        try (java.io.PrintWriter w = new java.io.PrintWriter(fc.getSelectedFile(), java.nio.charset.StandardCharsets.UTF_8)) {
            w.print(output.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Save failed: " + ex.getMessage());
        }
    }

    private void copy() {
        Toolkit.getDefaultToolkit().getSystemClipboard()
                .setContents(new java.awt.datatransfer.StringSelection(output.getText()), null);
        ctx.alert("clickjacking PoC", "copied to clipboard");
    }

    private void openInBrowser() {
        try {
            java.io.File f = java.io.File.createTempFile("opensuite-clickjack", ".html");
            f.deleteOnExit();
            try (java.io.PrintWriter w = new java.io.PrintWriter(f, java.nio.charset.StandardCharsets.UTF_8)) { w.print(output.getText()); }
            if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                Desktop.getDesktop().browse(f.toURI());
            } else {
                ctx.alert("clickjacking PoC", "saved to " + f.getAbsolutePath() + " (open it manually)");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Could not open: " + ex.getMessage());
        }
    }
}