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.
Java application-securityappsecbug-bountyburp-alternativeburp-suitedasthttp-proxyinfosecintercepting-proxyjavaowaspowasp-zappenetration-testingpentestingsecuritysecurity-toolsvulnerability-scannerweb-application-securityweb-security
package opensuite.ui;
import opensuite.core.ResourcePool;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
/**
* The resource pool chooser every task uses: pick an existing pool from the
* table, or describe a new one (concurrency, pacing, automatic throttling).
* One component, three homes: the Intruder side panel, the New scan wizard
* and the live task dialog. {@link #selected()} returns the pool the task
* should use, creating and registering a new one when that was chosen.
*/
public final class ResourcePoolPanel extends JPanel {
private final JRadioButton useExisting = Ui.radio("Use existing resource pool", true);
private final JRadioButton createNew = Ui.radio("Create new resource pool", false);
private final PoolModel model = new PoolModel();
private final JTable table = new JTable(model);
private final JTextField name = Ui.field("");
private final JCheckBox limitConcurrent = Ui.check("Maximum concurrent requests:", false);
private final JTextField concurrent = number("");
private final JCheckBox delayOn = Ui.check("Delay between requests:", false);
private final JTextField delayMs = number("");
private final JRadioButton fixed = Ui.radio("Fixed", true);
private final JRadioButton random = Ui.radio("With random variations", false);
private final JRadioButton increment = Ui.radio("Increase delay in increments of", false);
private final JTextField incrementMs = number("");
private final JCheckBox throttleOn = Ui.check("Automatic throttling", false);
private final JCheckBox t429 = Ui.check("429", true);
private final JCheckBox t503 = Ui.check("503", false);
private final JCheckBox tOther = Ui.check("Other", false);
private final JTextField tOtherCodes = Ui.field("");
public ResourcePoolPanel() { this("task"); }
/** @param what the thing that will run in the pool, as the opening line names it: a task, or an attack */
public ResourcePoolPanel(String what) {
super(new BorderLayout());
setBackground(Theme.BG);
ButtonGroup mode = new ButtonGroup();
mode.add(useExisting); mode.add(createNew);
ButtonGroup delay = new ButtonGroup();
delay.add(fixed); delay.add(random); delay.add(increment);
Ui.styleTable(table);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// The columns keep their own widths and the table scrolls sideways, as the reference's does.
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
int[] widths = { 58, 136, 116, 84, 92, 104, 96 };
for (int k = 0; k < widths.length; k++) {
table.getColumnModel().getColumn(k).setPreferredWidth(Ui.em(widths[k])); // in proportion to the font
table.getColumnModel().getColumn(k).setMinWidth(24);
}
table.getColumnModel().getColumn(0).setCellRenderer(new SelectedRenderer());
// The radio says which pool is chosen; the row itself is not tinted.
table.setSelectionBackground(Theme.CONTENT);
table.getSelectionModel().addListSelectionListener(e -> table.repaint());
if (model.getRowCount() > 0) table.setRowSelectionInterval(0, 0);
JScrollPane sp = new JScrollPane(table);
sp.setBorder(BorderFactory.createLineBorder(Ui.GRID));
sp.getViewport().setBackground(table.getBackground());
table.setFillsViewportHeight(true);
sp.setPreferredSize(new Dimension(200, 254 + 40 * Ui.fontGrowth())); // measured: 334 at the usual 13px
ResourcePool.addListener(() -> SwingUtilities.invokeLater(() -> {
int sel = table.getSelectedRow();
model.fireTableDataChanged();
if (sel >= 0 && sel < model.getRowCount()) table.setRowSelectionInterval(sel, sel);
else if (model.getRowCount() > 0) table.setRowSelectionInterval(0, 0);
}));
JPanel nameRow = new JPanel(new BorderLayout(5, 0));
nameRow.setOpaque(false);
nameRow.add(Ui.label("Name:"), BorderLayout.WEST);
nameRow.add(name, BorderLayout.CENTER);
Ui.sized(nameRow, 100);
JLabel csv = Ui.label("CSV format (e.g. 504,505)");
csv.setBorder(Ui.pad(0, 34, 0, 0));
Ui.sized(tOtherCodes, 214);
JPanel csvField = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
csvField.setOpaque(false);
csvField.setBorder(Ui.pad(0, 32, 0, 0));
csvField.add(tOtherCodes);
for (AbstractButton b : new AbstractButton[] { useExisting, createNew, fixed, random, throttleOn, t429, t503, tOther,
limitConcurrent, delayOn, increment }) {
b.setBorder(Ui.pad(0, 2, 0, 0));
b.setPreferredSize(new Dimension(b.getPreferredSize().width + 2, Ui.tall(20)));
}
tOtherCodes.setColumns(0);
JPanel col = Sections.column(0,
Sections.text("Specify the resource pool in which the " + what + " will be run. Resource pools are used to "
+ "manage the usage of system resources across multiple tasks."),
Sections.gap(15),
useExisting, Sections.gap(10),
Sections.fill(sp), Sections.gap(10),
createNew, Sections.gap(10),
Sections.fill(nameRow), Sections.gap(5),
lead(limitConcurrent, 0, concurrent, null), Sections.gap(5),
lead(delayOn, 0, delayMs, "milliseconds"), Sections.gap(5),
indent(fixed), Sections.gap(5),
indent(random), Sections.gap(5),
lead(increment, 16, incrementMs, "milliseconds"), Sections.gap(5),
throttleOn, Sections.gap(10),
indent(t429), Sections.gap(10),
indent(t503), Sections.gap(9),
indent(tOther),
csv, Sections.gap(2),
csvField);
col.setBorder(Ui.pad(15, 10, 5, 10));
col.setOpaque(true);
col.setBackground(Theme.BG);
JScrollPane page = Ui.scrollColumn(col);
page.getViewport().setBackground(Theme.BG);
add(page, BorderLayout.CENTER);
Runnable sync = () -> {
// The new pool's controls stay live whichever choice is made, as the
// reference leaves them; each still follows the tick box above it.
{
concurrent.setEnabled(limitConcurrent.isSelected());
boolean d = delayOn.isSelected();
delayMs.setEnabled(d); fixed.setEnabled(d); random.setEnabled(d); increment.setEnabled(d);
incrementMs.setEnabled(d && increment.isSelected());
boolean t = throttleOn.isSelected();
t429.setEnabled(t); t503.setEnabled(t); tOther.setEnabled(t);
tOtherCodes.setEnabled(t && tOther.isSelected());
}
};
for (AbstractButton b : new AbstractButton[]{useExisting, createNew, limitConcurrent, delayOn, fixed, random,
increment, throttleOn, tOther}) b.addItemListener(e -> sync.run());
sync.run();
java.awt.event.FocusAdapter pick = new java.awt.event.FocusAdapter() {
@Override public void focusGained(java.awt.event.FocusEvent e) { createNew.setSelected(true); }
};
for (JComponent c : new JComponent[] { name, concurrent, delayMs, incrementMs, tOtherCodes }) c.addFocusListener(pick);
for (AbstractButton b : new AbstractButton[] { limitConcurrent, delayOn, throttleOn }) {
b.addActionListener(e -> createNew.setSelected(true));
}
}
/** A 64px field for a count or a number of milliseconds. */
private static JTextField number(String value) {
JTextField f = Ui.field(value);
f.setColumns(0);
Ui.sized(f, 64);
return f;
}
private static int value(JTextField f, int fallback) {
try { return Math.max(0, Integer.parseInt(f.getText().strip())); } catch (NumberFormatException e) { return fallback; }
}
/** A tick box or radio, then its field 204px into the column whatever the label's length, then a unit. */
private static JPanel lead(AbstractButton lead, int indent, JTextField field, String unit) {
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
p.setOpaque(false);
p.setBorder(Ui.pad(0, Math.max(0, indent - 2), 0, 0));
lead.setPreferredSize(new Dimension(204 + Math.round(10.5f * Ui.fontGrowth()) - Math.max(0, indent - 2), Ui.tall(22)));
p.add(lead);
p.add(field);
if (unit != null) {
p.add(Box.createHorizontalStrut(10));
JLabel u = new JLabel(unit);
u.setFont(Ui.PLAIN);
u.setForeground(Theme.TEXT);
p.add(u);
}
return p;
}
private static JPanel indent(JComponent c) {
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
p.setOpaque(false);
p.setBorder(Ui.pad(0, 14, 0, 0));
p.add(c);
return p;
}
/** The Selected column: a radio mark, filled on the chosen pool's row. */
private static final class SelectedRenderer extends JRadioButton implements javax.swing.table.TableCellRenderer {
SelectedRenderer() { setHorizontalAlignment(SwingConstants.CENTER); setOpaque(true); setBorder(null); }
@Override public Component getTableCellRendererComponent(JTable t, Object v, boolean sel, boolean focus, int row, int col) {
setSelected(Boolean.TRUE.equals(v));
setBackground(t.getBackground());
return this;
}
}
/** The pool to use. Creating a new one registers it so other tasks can reuse it. */
public ResourcePool selected() {
if (useExisting.isSelected()) {
int r = table.getSelectedRow();
java.util.List<ResourcePool> all = ResourcePool.all();
return r >= 0 && r < all.size() ? all.get(r) : ResourcePool.byName(ResourcePool.DEFAULT_NAME);
}
ResourcePool p = new ResourcePool(name.getText().strip());
p.setLimitConcurrent(limitConcurrent.isSelected());
p.setConcurrent(Math.max(1, value(concurrent, 10)));
p.setDelayOn(delayOn.isSelected());
p.setDelayMs(value(delayMs, 0));
p.setDelayMode(random.isSelected() ? ResourcePool.DelayMode.RANDOM
: increment.isSelected() ? ResourcePool.DelayMode.INCREMENT : ResourcePool.DelayMode.FIXED);
p.setIncrementMs(value(incrementMs, 0));
p.setThrottleOn(throttleOn.isSelected());
p.setThrottle429(t429.isSelected());
p.setThrottle503(t503.isSelected());
p.setThrottleOther(tOther.isSelected() ? tOtherCodes.getText().strip() : "");
ResourcePool.add(p);
// After creating it, the panel shows it as the chosen existing pool.
useExisting.setSelected(true);
int idx = ResourcePool.all().indexOf(p);
if (idx >= 0) table.setRowSelectionInterval(idx, idx);
return p;
}
/** The concurrency the chosen pool allows, for engines that take a thread count. */
public int concurrency() {
if (useExisting.isSelected()) {
int r = table.getSelectedRow();
java.util.List<ResourcePool> all = ResourcePool.all();
return (r >= 0 && r < all.size() ? all.get(r) : all.get(0)).effectiveConcurrent();
}
return limitConcurrent.isSelected() ? Math.max(1, value(concurrent, 10)) : 50;
}
/** Preselect a pool by name (a task being edited shows the pool it uses). */
public void select(String poolName) {
java.util.List<ResourcePool> all = ResourcePool.all();
for (int i = 0; i < all.size(); i++) if (all.get(i).name().equals(poolName)) {
useExisting.setSelected(true);
table.setRowSelectionInterval(i, i);
return;
}
}
private final class PoolModel extends AbstractTableModel {
private final String[] cols = {"Selected", "Resource pool", "Concurrent requests", "Request delay",
"Random delay", "Delay increment", "Auto throttle"};
@Override public int getRowCount() { return ResourcePool.all().size(); }
@Override public int getColumnCount() { return cols.length; }
@Override public String getColumnName(int c) { return cols[c]; }
@Override public Object getValueAt(int r, int c) {
ResourcePool p = ResourcePool.all().get(r);
return switch (c) {
case 0 -> table.getSelectedRow() == r;
case 1 -> p.name();
case 2 -> p.limitConcurrent() ? String.valueOf(p.concurrent()) : "Unlimited";
case 3 -> p.requestDelayText();
case 4 -> p.randomDelayText();
case 5 -> p.delayIncrementText();
default -> p.autoThrottleText();
};
}
}
}