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

import opensuite.ui.Ui;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Changes one character of a value at a time, raising its code by one. Run it
 * over a token to see which characters the application actually checks: those
 * whose change makes no difference to the response are not significant.
 */
class CharacterFrobberGenerator extends AbstractGenerator {

    private final JRadioButton fromPosition = Ui.radio("base value of payload position", true);
    private final JRadioButton fromString = Ui.radio("specific string:", false);
    private final JTextField literal = Ui.field("", 24);
    private final JPanel panel;

    CharacterFrobberGenerator() {
        ButtonGroup g = new ButtonGroup();
        g.add(fromPosition); g.add(fromString);
        fromPosition.addActionListener(e -> fire());
        fromString.addActionListener(e -> fire());
        literal.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
            public void insertUpdate(javax.swing.event.DocumentEvent e)  { fire(); }
            public void removeUpdate(javax.swing.event.DocumentEvent e)  { fire(); }
            public void changedUpdate(javax.swing.event.DocumentEvent e) { fire(); }
        });
        panel = Ui.vbox(Ui.label("operate on:"), fromPosition, Ui.row(fromString, literal));
    }

    private List<String> sources() {
        return fromString.isSelected() ? List.of(literal.getText()) : base;
    }

    @Override public String label() { return " character frobber"; }
    @Override public JComponent config() { return panel; }

    @Override public int count() {
        long n = 0;
        for (String s : sources()) n += s.length();
        return (int) Math.min(n, CAP);
    }

    @Override public List<String> generate() {
        List<String> out = new ArrayList<>();
        for (String s : sources()) {
            for (String f : frob(s)) {
                if (out.size() >= CAP) return out;
                out.add(f);
            }
        }
        return out;
    }

    /** One variant per character, that character's code raised by one. */
    static List<String> frob(String value) {
        List<String> out = new ArrayList<>();
        for (int i = 0; i < value.length(); i++) {
            char[] c = value.toCharArray();
            c[i] = (char) ((c[i] + 1) & 0xff);
            out.add(new String(c));
        }
        return out;
    }
}