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.

2.6 KB
Raw Blame
package opensuite.intruder;

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

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

/**
 * The attack target as a single row under the attack type, as in the reference:
 * the target URL and whether the request's Host header should be rewritten to
 * match it. The URL is filled in automatically when a request is sent to
 * Intruder.
 */
public class TargetPanel extends JPanel {

    private final JTextField url = Ui.field("http://localhost:80");
    private final JCheckBox updateHost = Ui.check("Update Host header to match target", true);

    public TargetPanel() {
        super(new BorderLayout(10, 0));
        setOpaque(false);
        url.setToolTipText("URL of the target server for the attack");
        url.putClientProperty("JTextField.placeholderText", "https://host");
        updateHost.setToolTipText("Update the request's Host header to match the target URL");
        // As in the reference: a plain label, the field across the row, the tick at its end.
        add(Ui.label("Target"), BorderLayout.WEST);
        add(url, BorderLayout.CENTER);
        updateHost.setBorder(Ui.pad(0, 2, 0, 2));
        updateHost.setIconTextGap(9);
        add(updateHost, BorderLayout.EAST);
    }

    /** Show the target without letting it be changed, as an attack's own record of it does. */
    public void lock() { url.setEditable(false); url.setBackground(opensuite.ui.Theme.BG); updateHost.setEnabled(false); }

    /** The target as typed, for saving with the project. */
    public String text() { return url.getText(); }

    /** Restore a saved target. */
    public void setText(String s) { url.setText(s == null ? "" : s); }

    public void setUpdateHostHeader(boolean on) { updateHost.setSelected(on); }

    public void set(HttpService svc) {
        if (svc == null) return;
        url.setText(svc.url());
    }

    /** Whether the Host header should be rewritten to match the target. */
    public boolean updateHostHeader() { return updateHost.isSelected(); }

    public HttpService service() {
        String s = url.getText().trim();
        boolean secure = s.toLowerCase().startsWith("https://");
        String rest = s.replaceFirst("(?i)^https?://", "");
        int slash = rest.indexOf('/');
        if (slash >= 0) rest = rest.substring(0, slash);
        int port = secure ? 443 : 80;
        int colon = rest.lastIndexOf(':');
        if (colon > 0) {
            try { port = Integer.parseInt(rest.substring(colon + 1)); } catch (NumberFormatException ignored) {}
            rest = rest.substring(0, colon);
        }
        return new HttpService(rest, port, secure);
    }
}