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.proxy;
import opensuite.core.*;
import opensuite.ui.*;
import opensuite.ui.settings.SettingsPage;
import javax.swing.*;
import javax.swing.table.TableRowSorter;
import java.awt.*;
import java.nio.file.Path;
import java.util.List;
/** The proxy tool: intercept, HTTP history, and options. */
public class ProxyTool implements ToolModule {
private ProxyServer server;
private SuiteContext ctx;
private InterceptPanel interceptPanel;
private HistoryPanel historyPanel;
public ProxyTool() {}
public ProxyServer server() { return server; }
@Override public String name() { return "proxy"; }
@Override public boolean alwaysTabbed() { return true; }
@Override public void init(SuiteContext ctx) {
this.ctx = ctx;
try {
Path home = Path.of(System.getProperty("user.home"), ".opensuite");
this.server = new ProxyServer(ctx, home.resolve("ca"));
} catch (Exception e) {
ctx.alert("proxy", "failed to initialise proxy: " + e.getMessage());
return;
}
server.unpackGzip = ctx.settings().getBool("http.unpackGzip", true);
// Out-of-scope logging is a project setting, so the banner, the settings
// pane and a restored project all drive the one flag on the server.
// The flag is a preference as well, so it can arrive from an earlier
// session; with no scope defined it has nothing to apply to, and would
// otherwise read as "record nothing", so it is cleared.
if (ctx.scope().isEmpty() && !ProjectOptions.logOutOfScope(ctx.settings())) {
ctx.settings().setBool(ProjectOptions.LOG_OUT_OF_SCOPE, true);
}
server.logOutOfScope = ProjectOptions.logOutOfScope(ctx.settings());
ctx.settings().addListener(key -> {
if (ProjectOptions.LOG_OUT_OF_SCOPE.equals(key)) server.logOutOfScope = ProjectOptions.logOutOfScope(ctx.settings());
});
lastIncludeCount = ctx.scope().include().size();
ctx.addScopeListener(this::scopeEdited);
server.startAll();
// Publish routing info for the browser crawler.
try {
for (ProxyListener l : server.listeners()) if (l.running) { ctx.setProxyPort(l.port); break; }
ctx.setCaSpki(server.ca().spkiFingerprint());
ctx.setBrowserBinary(opensuite.proxy.EmbeddedBrowser.findBinary());
} catch (Exception e) { Debug.log("could not publish proxy routing info: " + e); }
}
@Override public void shutdown() { server.stopAll(); }
private volatile int lastIncludeCount;
/**
* When an item is added to the scope while out-of-scope traffic is still
* being recorded, offer to stop recording it, as the reference does. The
* answer can be remembered ("always take the same action in future"), and
* is then applied without asking; the choice lives under Settings >
* Project. A scope arriving from an opened project never asks.
*/
private void scopeEdited() {
int now = ctx.scope().include().size();
boolean grew = now > lastIncludeCount;
lastIncludeCount = now;
// The last include rule gone: there is no scope to restrict logging to.
if (now == 0 && !ProjectOptions.logOutOfScope(ctx.settings())) {
ctx.settings().setBool(ProjectOptions.LOG_OUT_OF_SCOPE, true);
}
if (!grew || ctx.restoring() || server == null || !server.logOutOfScope) return;
String choice = ProjectOptions.outOfScopeChoice(ctx.settings());
if ("keep".equals(choice)) return;
if ("stop".equals(choice)) { ctx.settings().setBool(ProjectOptions.LOG_OUT_OF_SCOPE, false); return; }
SwingUtilities.invokeLater(this::askOutOfScope);
}
private void askOutOfScope() {
if (!server.logOutOfScope) return;
JTextArea text = Ui.note(
"You have added an item to the target scope. Do you want the Proxy to stop sending "
+ "out-of-scope items to the history and the other tools?\n\n"
+ "Answering \"yes\" avoids accumulating project data for out-of-scope items.");
Ui.sizeNote(text, 440);
JCheckBox always = Ui.check("Always take the same action in future", false);
JPanel body = new JPanel(new BorderLayout(0, 10));
body.add(text, BorderLayout.CENTER);
body.add(always, BorderLayout.SOUTH);
int r = JOptionPane.showOptionDialog(ctx.frame(), body, "Proxy history logging",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
new Object[]{"Yes", "No"}, "Yes");
if (r == JOptionPane.CLOSED_OPTION) return;
boolean stop = r == JOptionPane.YES_OPTION;
if (always.isSelected()) ctx.settings().set(ProjectOptions.OUT_OF_SCOPE_CHOICE, stop ? "stop" : "keep");
if (stop) {
ctx.settings().setBool(ProjectOptions.LOG_OUT_OF_SCOPE, false);
ctx.alert("proxy", "no longer recording out-of-scope traffic");
}
}
/** The history filter travels with the project. */
@Override public java.io.Serializable saveState() {
return historyPanel == null ? null : historyPanel.filter.copy();
}
@Override public void restoreState(java.io.Serializable state) {
if (historyPanel == null || !(state instanceof HistoryFilter f)) return;
f.scope = ctx.scope();
historyPanel.filter.copyFrom(f);
SwingUtilities.invokeLater(historyPanel::applyFilter);
}
@Override public Tab[] tabs() {
if (server == null) {
try {
Path home = Path.of(System.getProperty("user.home"), ".opensuite");
server = new ProxyServer(ctx, home.resolve("ca"));
} catch (Exception e) {
// init() already reported this once and left the proxy for a
// retry; if it still fails, degrade to an explanatory tab
// rather than killing the whole suite at startup.
ctx.alert("proxy", "failed to initialise proxy: " + e.getMessage());
final String why = "The proxy could not start: " + e.getMessage()
+ ". Resolve the problem and restart Open Suite.";
// Its settings page says so too, in place of an empty page.
SettingsDialog.register("Proxy", () -> {
JPanel p = new JPanel(new BorderLayout());
p.setOpaque(false);
p.add(Ui.note(why), BorderLayout.NORTH);
return p;
});
return new Tab[] { new Tab("proxy", Ui.note(why)) };
}
}
interceptPanel = new InterceptPanel(ctx, server);
historyPanel = new HistoryPanel(ctx, server);
// The proxy and browser settings live in the suite Settings dialog, so
// each setting has one home; the tab here opens the dialog at Proxy.
OptionsPanel options = new OptionsPanel(ctx, server);
SettingsDialog.register("Proxy", () -> options);
SettingsDialog.register("Browser", () -> new BrowserSettingsPanel(ctx));
return new Tab[]{
new Tab("Intercept", interceptPanel),
new Tab("HTTP history", historyPanel),
new Tab("WebSockets history", new opensuite.websocket.WebSocketsPanel(ctx)),
new Tab("Match and replace", new MatchReplacePanel(server)),
new Tab("Proxy settings", SettingsDialog.launcher(ctx, "Proxy", "Proxy settings",
"Listeners, interception, response modification and the upstream proxy "
+ "are configured under Settings > Proxy. The testing browser is configured under "
+ "Settings > Browser."))
};
}
/** Hug a settings page to the top of its tab instead of stretching it to fill. */
private static JComponent topAligned(JComponent page) {
JPanel holder = new JPanel(new BorderLayout());
holder.add(page, BorderLayout.NORTH);
return Ui.scroll(holder);
}
// ---------------- intercept tab ----------------
/**
* The Intercept tab, laid out like the reference: a toolbar with the
* intercept toggle, Forward, Drop and Action on the left and Open browser on
* the right; below it either a centred idle card (intercept state, what it
* does, the listener status and an Open browser button) or, while a message
* is held, the message editor.
*/
/**
* Shown over the Intercept tab while no proxy listener is running, which is
* usually because another program already has the port: a pale band that
* says so, with a button that starts the listeners again.
*/
static final class NoListenersBanner extends JPanel {
private final JLabel text = Ui.label("No proxy listeners are currently running");
private final JButton enable = Ui.button("Enable", "Start the proxy listeners");
private static final Color BAND = Theme.dark ? new Color(0x2F, 0x3A, 0x45) : new Color(0xEB, 0xF1, 0xF6);
NoListenersBanner(SuiteContext ctx, ProxyServer server) {
super(null);
setBackground(Theme.BG);
enable.setBorder(BorderFactory.createEmptyBorder());
enable.addActionListener(e -> {
for (ProxyListener l : new java.util.ArrayList<>(server.listeners())) server.start(l);
// Still nothing listening: the port is taken, so show where it is chosen.
if (!server.anyRunning()) opensuite.ui.SettingsDialog.open(SwingUtilities.getWindowAncestor(this), ctx, "Tools > Proxy");
});
add(text);
add(enable);
Runnable show = () -> { setVisible(!server.anyRunning()); revalidate(); };
server.onListenersChanged(show);
show.run();
}
@Override public Dimension getPreferredSize() { return new Dimension(10, 31); }
@Override public void doLayout() {
int c = getWidth() / 2;
Dimension t = text.getPreferredSize();
text.setBounds(c - 173, 4 + (26 - t.height) / 2, t.width, t.height);
enable.setBounds(c + 86, 6, 86, 24);
}
@Override protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setColor(BAND);
g2.fillRect(10, 5, getWidth() - 21, 26);
// Our own information mark: a ring with a lower-case i, 19px.
int x = getWidth() / 2 - 213, y = 8;
g2.setColor(Theme.TEXT);
g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.draw(new java.awt.geom.Ellipse2D.Double(x + 0.75, y + 0.75, 17.5, 17.5));
g2.draw(new java.awt.geom.Line2D.Double(x + 9.5, y + 8.7, x + 9.5, y + 13.4));
g2.fill(new java.awt.geom.Ellipse2D.Double(x + 8.5, y + 4.8, 2, 2));
g2.dispose();
}
}
static class InterceptPanel extends JPanel implements InterceptQueue.Presenter {
/** The idle card's illustration: our own signal head with its lower lamp lit, 109 by 77. */
private static Icon trafficLights() {
int w = 109, h = 77;
java.awt.image.BufferedImage img = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Soft grey strokes around the head.
g.setColor(new Color(0xE2, 0xE2, 0xE2));
g.setStroke(new BasicStroke(3.4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.drawLine(2, 6, 24, 22); g.drawLine(84, 6, 107, 22); g.drawLine(2, 62, 24, 50); g.drawLine(84, 62, 107, 50);
// Pole.
g.setColor(new Color(0xCF, 0xCF, 0xCF));
g.fillRoundRect(52, 56, 5, 20, 4, 4);
// Body: a control-blue slab with a lighter face, tilted a little.
g.rotate(Math.toRadians(-8), 54, 34);
g.setColor(Theme.CONTROL);
g.fillRoundRect(37, 2, 34, 60, 12, 12);
g.setColor(Theme.ACCENT_LIGHT);
g.fillRoundRect(42, 6, 25, 52, 9, 9);
g.setColor(new Color(0x9F, 0xB4, 0xCC)); g.fillOval(47, 12, 15, 15);
g.setColor(new Color(0x3F, 0xB0, 0x4E)); g.fillOval(47, 36, 15, 15);
g.dispose();
return new ImageIcon(img);
}
/** The mark on the intercept button: a small switch, its knob left when off and right when on. */
private static Icon switchIcon(boolean on) {
java.awt.image.BufferedImage img = new java.awt.image.BufferedImage(16, 12, java.awt.image.BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g.setColor(Theme.TEXT);
g.setStroke(new BasicStroke(1.3f));
g.draw(new java.awt.geom.RoundRectangle2D.Double(1, 1.5, 14, 9, 9, 9));
g.draw(new java.awt.geom.Ellipse2D.Double(on ? 8.6 : 3.4, 3.9, 4.2, 4.2));
g.dispose();
return new ImageIcon(img);
}
private static Icon globeIcon() {
java.awt.image.BufferedImage img = new java.awt.image.BufferedImage(16, 16, java.awt.image.BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Theme.ICON);
g.setStroke(new BasicStroke(1.3f));
g.drawOval(1, 1, 13, 13); g.drawOval(5, 1, 5, 13); g.drawLine(1, 8, 14, 8);
g.dispose();
return new ImageIcon(img);
}
/** A button and its dropdown chevron drawn as one control. */
/**
* The Forward / Drop pair: one rounded shape carrying a label and a
* chevron, sized and coloured from the reference frames.
*
* <p>The reference draws two styles: Forward as a flat grey slab, and
* Drop as white with a hairline and a divider before its chevron. The
* style is fixed per button rather than following enablement. The
* whole shape is
* painted here rather than assembled from bordered panels, so there is
* no second box around the chevron.
*/
private static JComponent splitButton(JButton main, JButton menu, int width, boolean filled) {
JPanel p = new JPanel(new BorderLayout(0, 0)) {
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth(), h = getHeight(), arc = Theme.RADIUS;
g2.setColor(filled ? Theme.BORDER : Theme.CARD);
g2.fillRoundRect(0, 0, w - 1, h - 1, arc, arc);
if (!filled) {
g2.setColor(Theme.BORDER);
g2.drawRoundRect(0, 0, w - 1, h - 1, arc, arc);
int x = w - menu.getPreferredSize().width;
g2.drawLine(x, 3, x, h - 4);
}
g2.dispose();
}
};
p.setOpaque(false);
for (JButton b : new JButton[]{main, menu}) {
b.setContentAreaFilled(false);
b.setBorderPainted(false);
b.setOpaque(false);
b.setFocusPainted(false);
}
p.add(main, BorderLayout.CENTER);
p.add(menu, BorderLayout.EAST);
p.setPreferredSize(new Dimension(width, BUTTON_HEIGHT));
p.setMaximumSize(p.getPreferredSize());
return p;
}
/** Toolbar button height, measured from the reference frames. */
private static final int BUTTON_HEIGHT = Ui.tall(22);
/** The three left-hand buttons: 158 wide at the smallest font, 181 at the usual 13px. */
private static final int BUTTON_WIDTH = 158 + Math.round(11.5f * Ui.fontGrowth());
private final ProxyServer server;
private final MessageEditor editor;
private final JToggleButton toggle;
private final JButton forward, drop, action;
private final JLabel status = Ui.label(" ");
private final CardLayout cards = new CardLayout();
private final JPanel body = new JPanel(cards);
private InterceptQueue.Pending current;
InterceptPanel(SuiteContext ctx, ProxyServer server) {
super(new BorderLayout());
this.server = server;
this.editor = new MessageEditor(ctx, MessageEditor.REQUEST | MessageEditor.RESPONSE, true);
Runnable launchBrowser = () -> BrowserSetup.open(this, ctx, server);
// Toolbar.
toggle = new JToggleButton("Intercept off", false);
toggle.setFont(Ui.BOLD);
toggle.setIcon(switchIcon(false));
toggle.setSelectedIcon(switchIcon(true));
final boolean usual = Ui.fontGrowth() > 0;
toggle.setIconTextGap(usual ? 10 : 8);
// At the usual 13px the switch and its words stand 5px left of centre.
if (usual) toggle.setBorder(Ui.pad(3, 16, 3, 26));
toggle.setToolTipText("Toggle message interception");
toggle.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
forward = Ui.button("Forward", "Forward the displayed message");
forward.setFont(Ui.BOLD);
forward.setIcon(opensuite.ui.Glyphs.arrow(14, Theme.ICON, 0));
forward.setIconTextGap(usual ? 12 : 8);
drop = Ui.button("Drop", "Drop the displayed message");
drop.setFont(Ui.BOLD);
action = Ui.button("Action", "Perform additional actions");
forward.setEnabled(false); drop.setEnabled(false); action.setEnabled(false);
status.setForeground(Theme.MUTED);
JButton forwardMenu = opensuite.ui.Glyphs.button(usual ? opensuite.ui.Glyphs.fold(Theme.MUTED, false, 1.1f) : opensuite.ui.Glyphs.chevron(14, Theme.MUTED, 1, 1.2f), "Forward options", null);
forwardMenu.addActionListener(ev -> {
JPopupMenu m = new JPopupMenu();
JMenuItem all = new JMenuItem("Forward all");
all.setFont(Ui.PLAIN);
all.addActionListener(x -> server.interceptQueue().releaseAll());
m.add(all);
m.show(forwardMenu, 0, forwardMenu.getHeight());
});
JButton dropMenu = opensuite.ui.Glyphs.button(usual ? opensuite.ui.Glyphs.fold(Theme.MUTED, false, 1.1f) : opensuite.ui.Glyphs.chevron(14, Theme.MUTED, 1, 1.2f), "Drop options", null);
dropMenu.addActionListener(ev -> {
JPopupMenu m = new JPopupMenu();
JMenuItem all = new JMenuItem("Drop all");
all.setFont(Ui.PLAIN);
all.addActionListener(x -> { if (current != null) resolve(InterceptQueue.Action.DROP); });
m.add(all);
m.show(dropMenu, 0, dropMenu.getHeight());
});
forwardMenu.setPreferredSize(new Dimension(usual ? 30 : 28, BUTTON_HEIGHT));
dropMenu.setPreferredSize(new Dimension(usual ? 30 : 28, BUTTON_HEIGHT));
JPanel left = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
left.setOpaque(false);
left.add(toggle);
left.add(Box.createHorizontalStrut(10));
left.add(splitButton(forward, forwardMenu, BUTTON_WIDTH + (usual ? 1 : 0), true));
left.add(Box.createHorizontalStrut(usual ? 9 : 10));
left.add(splitButton(drop, dropMenu, BUTTON_WIDTH, false));
left.add(Box.createHorizontalStrut(10));
left.add(status);
JButton openBrowser = Ui.button("Open browser",
"Launch a browser routed through the proxy, with the CA already trusted");
openBrowser.setFont(Ui.BOLD);
openBrowser.setIcon(globeIcon());
openBrowser.setIconTextGap(8);
openBrowser.setBorder(Ui.pad(3, 11, 3, 21)); // the globe sits nearer the edge than a plain label would
openBrowser.setPreferredSize(new Dimension(Ui.column(134, openBrowser.getFont(), "Open browser"), BUTTON_HEIGHT));
openBrowser.addActionListener(ev -> launchBrowser.run());
JButton help = opensuite.ui.Glyphs.button(opensuite.ui.Glyphs.help(20, Theme.TEXT), "About interception", () -> JOptionPane.showMessageDialog(this,
"When interception is on, each request and response from the browser is held here until it is forwarded or dropped.\n"
+ "The rules under Settings > Tools > Proxy determine which messages are held.", "Intercept", JOptionPane.INFORMATION_MESSAGE));
help.setPreferredSize(new Dimension(20, BUTTON_HEIGHT));
JButton more = opensuite.ui.Glyphs.menuButton("More", () -> {
JPopupMenu m = current == null ? new JPopupMenu() : editor.buildMenu();
if (m.getComponentCount() > 0) m.addSeparator();
JMenuItem settings = new JMenuItem("Proxy settings");
settings.setFont(Ui.PLAIN);
settings.addActionListener(ev -> SettingsDialog.open(SwingUtilities.getWindowAncestor(this), ctx, "Proxy"));
m.add(settings);
return m;
});
more.setPreferredSize(new Dimension(18, BUTTON_HEIGHT));
JPanel right = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
right.setOpaque(false);
right.add(openBrowser);
right.add(Box.createHorizontalStrut(19));
right.add(help);
right.add(Box.createHorizontalStrut(10));
right.add(more);
JPanel bar = new JPanel(new BorderLayout());
bar.setOpaque(false);
bar.setBorder(Ui.pad(20, 20, 14, 20));
bar.add(left, BorderLayout.WEST);
bar.add(right, BorderLayout.EAST);
// Idle cards, one for each state of the switch.
for (boolean on : new boolean[] { false, true }) {
JButton idleBrowser = Ui.primaryButton("Open browser",
"Launch a browser routed through the proxy, with the CA already trusted");
idleBrowser.addActionListener(ev -> launchBrowser.run());
body.add(opensuite.ui.EmptyState.of(trafficLights(), 34, on ? "Intercept is on" : "Intercept is off",
on ? "Waiting for a message. Requests and responses passing through the proxy "
+ "are held here for you to review, edit, forward or drop."
: "If you turn Intercept on, messages between Open Suite's browser and your target servers are held "
+ "here. This enables you to analyze and modify these messages, before you forward them.",
520, Theme.BG, opensuite.ui.EmptyState.learnMore(), idleBrowser), on ? "idleOn" : "idleOff");
}
body.setOpaque(false);
body.add(editor, "message");
add(Ui.vbox(new NoListenersBanner(ctx, server), new OutOfScopeBanner(ctx), bar), BorderLayout.NORTH);
add(body, BorderLayout.CENTER);
// "Default Proxy interception state": on from the start when the setting says so.
if (interceptAtStartup(ctx.settings())) SwingUtilities.invokeLater(() -> { if (!toggle.isSelected()) toggle.doClick(); });
forward.addActionListener(e -> resolve(InterceptQueue.Action.FORWARD));
drop.addActionListener(e -> resolve(InterceptQueue.Action.DROP));
toggle.addActionListener(e -> {
boolean on = toggle.isSelected();
toggle.setText(on ? "Intercept on" : "Intercept off");
server.interceptingEnabled = on;
ctx.settings().setBool(INTERCEPT_LAST, on);
if (!on) server.interceptQueue().releaseAll();
if (!on || current == null) showIdle();
});
action.addActionListener(e -> {
JPopupMenu m = editor.buildMenu();
if (current != null && current.isRequest) {
m.addSeparator();
JMenu dont = new JMenu("Don't intercept requests");
dont.setFont(Ui.PLAIN);
for (InterceptExclusion.Kind k : InterceptExclusion.Kind.values()) {
if (!InterceptExclusion.applies(k, current.message)) continue;
JMenuItem mi = new JMenuItem(
InterceptExclusion.label(k, current.service, current.message));
mi.setFont(Ui.PLAIN);
mi.addActionListener(x -> {
if (InterceptExclusion.add(server.requestRules, k, current.service, current.message)) {
ctx.alert("proxy", "added an interception rule: "
+ InterceptExclusion.label(k, current.service, current.message));
}
resolve(InterceptQueue.Action.FORWARD);
});
dont.add(mi);
}
m.add(dont);
}
m.show(action, 0, action.getHeight());
});
server.interceptQueue().setPresenter(this);
server.setObserver(new ProxyServer.Observer() {
public void exchangeLogged(LogEntry entry) {}
public void statusChanged(String text) {}
});
// Keep the port on screen: refresh the idle card whenever a listener
// starts or stops, unless an intercepted message is being shown.
server.onListenersChanged(() -> { if (current == null) showIdle(); });
showIdle();
}
private void showIdle() {
SwingUtilities.invokeLater(() -> {
current = null;
boolean on = toggle.isSelected();
status.setText(" ");
editor.setMessage(null, new HttpMessage(new byte[0]));
forward.setEnabled(false); drop.setEnabled(false); action.setEnabled(false);
cards.show(body, on ? "idleOn" : "idleOff");
});
}
@Override public void present(InterceptQueue.Pending p) {
SwingUtilities.invokeLater(() -> {
current = p;
status.setText((p.isRequest ? "Request to " : "Response from ") + p.service.url());
editor.setMessage(p.service, p.message, p.relatedRequest);
forward.setEnabled(true); drop.setEnabled(true); action.setEnabled(true);
cards.show(body, "message");
});
}
@Override public void cleared(InterceptQueue.Pending p) {
showIdle();
}
private void resolve(InterceptQueue.Action a) {
InterceptQueue.Pending p = current;
if (p == null) return;
byte[] edited = a == InterceptQueue.Action.FORWARD ? editor.bytes() : null;
// Release this message. completed() pumps the next queued item (if any)
// and drives the button state via cleared()/present(); do not force idle
// here or it would wipe the next request that was just presented.
p.resolve(a, edited);
server.interceptQueue().completed(p);
}
}
// ---------------- history tab ----------------
static class HistoryPanel extends JPanel {
private final SuiteContext ctx;
private final HistoryModel model;
private final JTable table;
private final MessageEditor reqView, respView;
private opensuite.ui.MessagePair pair;
final HistoryFilter filter = HistoryFilter.proxyDefaults();
private final JButton filterButton = Ui.filterButton();
HistoryPanel(SuiteContext ctx, ProxyServer server) {
super(new BorderLayout());
this.ctx = ctx;
this.model = new HistoryModel("proxy");
this.filter.scope = ctx.scope();
this.table = new JTable(model);
this.reqView = new MessageEditor(ctx, MessageEditor.REQUEST, false);
this.respView = new MessageEditor(ctx, MessageEditor.RESPONSE, false);
Ui.styleTable(table);
// Shown in the reference's order: cookies before the time, the listener port before the timer.
table.moveColumn(15, 14);
table.moveColumn(17, 16);
// #, host, method, URL, params, edited, status, length, MIME, ext, title, notes, TLS, IP, cookies, time, port, timer
Ui.exactWidths(table, 40, 172, 54, 206, 54, 54, 82, 56, 68, 68, 137, 103, 40, 109, 109, 82, 82, 82);
if (Ui.fontGrowth() > 0) {
// As measured at the usual 13px on a 1920px screen; other widths keep these proportions.
int[] at13 = { 49, 204, 66, 246, 66, 68, 98, 66, 82, 82, 164, 122, 49, 131, 131, 98, 98, 100 };
for (int i = 0; i < at13.length; i++) table.getColumnModel().getColumn(i).setPreferredWidth(at13[i]);
}
Ui.centerCells(table);
TableRowSorter<HistoryModel> sorter = new opensuite.ui.NumberSorter<>(model);
table.setRowSorter(sorter);
// Newest first, so the latest request is on the top row without scrolling; a click on
// the # header reverses it.
sorter.setSortKeys(java.util.List.of(new RowSorter.SortKey(0, SortOrder.DESCENDING)));
JPanel top = new JPanel(new BorderLayout());
top.add(new OutOfScopeBanner(ctx), BorderLayout.NORTH);
top.add(buildFilterBar(), BorderLayout.CENTER);
add(top, BorderLayout.NORTH);
opensuite.ui.MessagePair detail = new opensuite.ui.MessagePair(reqView, respView);
this.pair = detail;
JScrollPane tableScroll = Ui.scrollPlain(table);
tableScroll.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Theme.BORDER));
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, detail);
split.setDividerSize(1);
Ui.balance(split, Ui.fontGrowth() > 0 ? 0.3146 : 0.3125);
add(split, BorderLayout.CENTER);
opensuite.ui.RowSelection.watch(table, model::at, this::showSelected);
new HistoryContextMenu(ctx, table, model).install();
server.setObserver(new ProxyServer.Observer() {
public void exchangeLogged(LogEntry entry) {
SwingUtilities.invokeLater(() -> model.add(entry));
}
public void statusChanged(String text) {}
});
// A restored project replaces the history wholesale: reload the
// table once from the store rather than leaving it empty.
ctx.store().addListener(new MessageStore.Listener() {
@Override public void entryAdded(LogEntry e) {}
@Override public void entryUpdated(LogEntry e) {}
@Override public void reloaded(java.util.List<LogEntry> all) {
SwingUtilities.invokeLater(() -> model.reload(all));
}
});
ctx.addScopeListener(() -> { filter.scope = ctx.scope(); applyFilter(); });
applyFilter();
}
private JPanel buildFilterBar() {
// A clickable filter bar that opens the full filter popup, with the
// fast URL search beside it, both at one uniform height.
filterButton.setText("Filter settings: " + filter.summary());
filterButton.addActionListener(e -> openFilter());
JTextField urlSearch = Ui.searchField(22);
urlSearch.setToolTipText("Quick search of the URL only");
urlSearch.getDocument().addDocumentListener(new SimpleDoc(() -> {
filter.urlSearch = urlSearch.getText(); applyFilter();
}));
JCheckBox filterOn = Ui.switchBox("Filter on", true);
filterOn.setToolTipText("Apply the filter settings to the history");
final HistoryFilter saved = filter;
filterOn.addActionListener(e -> {
if (filterOn.isSelected()) { model.setFilter(saved::test); }
else model.setFilter(null);
filterButton.setText("Filter settings: " + (filterOn.isSelected() ? filter.summary() : "Showing all items"));
});
JButton help = opensuite.ui.Glyphs.button(opensuite.ui.Glyphs.help(), "About the history", () -> JOptionPane.showMessageDialog(this,
"All requests that have passed through the proxy, newest first.\nClick the filter bar to configure which items are shown.",
"HTTP history", JOptionPane.INFORMATION_MESSAGE));
JButton kebab = opensuite.ui.Glyphs.menuButton("Table layout and custom columns", () -> opensuite.ui.TableLayoutMenu.build(table));
if (Ui.fontGrowth() > 0) {
// At the usual 13px the bar is as tall as its search field and no taller.
int h = urlSearch.getPreferredSize().height;
for (JComponent c : new JComponent[]{ filterOn, help, kebab }) {
c.setPreferredSize(new Dimension(c.getPreferredSize().width, Math.min(h, c.getPreferredSize().height)));
}
}
return Ui.filterBar(filterButton, urlSearch, filterOn, help, kebab);
}
private void openFilter() {
Window owner = SwingUtilities.getWindowAncestor(this);
new FilterDialog(owner, "HTTP history filter", filter, false, this::applyFilter).setVisible(true);
}
void applyFilter() {
model.setFilter(filter::test);
filterButton.setText("Filter settings: " + filter.summary());
}
private void showSelected() {
int row = table.getSelectedRow();
pair.show(row < 0 ? null : model.at(table.convertRowIndexToModel(row)));
}
}
// ---------------- options tab ----------------
static class OptionsPanel extends JPanel {
/** A tick box kept in the settings under {@code key} and applied to the proxy now and on every change. */
private static JCheckBox option(opensuite.core.Settings s, String key, boolean def, String text, java.util.function.Consumer<Boolean> apply) {
JCheckBox box = SettingsPage.check(s, "proxy.opt." + key, def, text);
apply.accept(box.isSelected());
box.addItemListener(e -> apply.accept(box.isSelected()));
return box;
}
/** The reference leaves 5px more under a block that ends in tick boxes below a table. */
private static JComponent tail() {
JPanel p = new JPanel(null);
p.setOpaque(false);
p.setPreferredSize(new Dimension(1, 0));
return p;
}
OptionsPanel(SuiteContext ctx, ProxyServer server) {
super(new BorderLayout());
opensuite.core.Settings s = ctx.settings();
SettingsPage page = new SettingsPage();
page.setMinWidth(969);
page.block("Proxy listeners", SettingsPage.Kind.PROJECT,
"Open Suite uses listeners to receive incoming HTTP requests from your browser. You will need to configure your browser "
+ "to use one of the listeners as its proxy server.",
null, new ListenersPanel(ctx, server));
// The two chains, each with its own switch, as the reference
// separates them. The chain itself is evaluated by ProxyRule.
JCheckBox interceptReq = option(s, "interceptRequests", true, "Intercept requests based on the following rules:", v -> server.interceptRequests = v);
page.block("Request interception rules", SettingsPage.Kind.PROJECT,
"Use these settings to control which requests are stalled for viewing and editing in the Intercept tab.",
null,
new InterceptRulesPanel(server, false, interceptReq),
Sections.gap(5),
option(s, "fixNewlines", false, "Automatically fix missing or superfluous new lines at end of request", v -> server.fixRequestNewlines = v),
option(s, "clRequests", true, "Automatically update Content-Length header when the request is edited", v -> server.updateContentLengthRequests = v),
tail());
JCheckBox interceptResp = option(s, "interceptResponses", false, "Intercept responses based on the following rules:", v -> server.interceptResponses = v);
page.block("Response interception rules", SettingsPage.Kind.PROJECT,
"Use these settings to control which responses are stalled for viewing and editing in the Intercept tab.",
null,
new InterceptRulesPanel(server, true, interceptResp),
Sections.gap(5),
option(s, "clResponses", true, "Automatically update Content-Length header when the response is edited", v -> server.updateContentLengthResponses = v),
tail());
WebSocketConnection.inScope = host -> {
for (boolean secure : new boolean[]{ true, false })
if (ctx.scope().isInScope(new opensuite.core.HttpService(host, secure ? 443 : 80, secure), "/")) return true;
return false;
};
page.block("WebSocket interception rules", SettingsPage.Kind.PROJECT,
"Use these settings to control which WebSocket messages are stalled for viewing and editing in the Intercept tab.",
null,
option(s, "wsClientToServer", true, "Intercept client-to-server messages", v -> WebSocketConnection.interceptClientToServer = v),
option(s, "wsServerToClient", true, "Intercept server-to-client messages", v -> WebSocketConnection.interceptServerToClient = v),
option(s, "wsInScopeOnly", false, "Only intercept in-scope messages", v -> WebSocketConnection.interceptInScopeOnly = v));
JCheckBox highlight = option(s, "highlightUnhidden", false, "Prominently highlight unhidden fields", v -> server.highlightUnhidden = v);
JCheckBox unhide = option(s, "unhide", false, "Unhide hidden form fields", v -> { server.unhideHiddenFields = v; highlight.setEnabled(v); });
highlight.setEnabled(unhide.isSelected());
JCheckBox stripSec = option(s, "stripSecurityHeaders", false, "Strip response security headers (CSP, X-Frame-Options) for a proof of concept",
v -> server.stripSecurityHeaders = v);
stripSec.addActionListener(e -> ctx.alert("proxy", stripSec.isSelected()
? "stripping response security headers for the browser; the scanner still audits the server's original response"
: "no longer stripping response security headers"));
page.block("Response modification rules", SettingsPage.Kind.PROJECT,
"Use these settings to control how Open Suite automatically modifies responses.",
null,
unhide,
OptionsPage.indent(highlight, 19),
option(s, "enableDisabled", false, "Enable disabled form fields", v -> server.enableDisabledFields = v),
option(s, "removeLimits", false, "Remove input field length limits", v -> server.removeLengthLimits = v),
option(s, "removeJsValidation", false, "Remove JavaScript form validation", v -> server.removeJsValidation = v),
option(s, "removeAllJs", false, "Remove all JavaScript", v -> server.removeAllJavaScript = v),
option(s, "removeObjects", false, "Remove <object> tags", v -> server.removeObjectTags = v),
option(s, "httpsToHttp", false, "Convert HTTPS links to HTTP", v -> server.httpsLinksToHttp = v),
option(s, "removeSecure", false, "Remove secure flag from cookies", v -> server.removeSecureFlag = v),
stripSec,
Sections.text("Stripping security headers allows an injected payload to execute in the browser, so that you can build and demonstrate a working "
+ "proof of concept. Only the response delivered to the browser is affected; the scanner always audits the server's original response."));
page.block("HTTP match and replace rules", SettingsPage.Kind.PROJECT,
"Use these settings to automatically replace parts of HTTP requests and responses passing through the Proxy.",
null, MatchReplacePanel.block(server, false));
page.block("WebSocket match and replace rules", SettingsPage.Kind.PROJECT,
"Use these settings to automatically replace parts of WebSocket messages passing through the Proxy.",
null, MatchReplacePanel.block(server, true));
page.block("TLS pass through", SettingsPage.Kind.PROJECT,
"Use these settings to specify destination web servers for which Open Suite will directly pass through TLS connections. No details "
+ "about requests or responses made via these connections will be available in the Proxy intercept view or history.",
null, new TlsPassThroughPanel(ctx));
// What happens to out-of-scope history when something is added to the target scope.
JRadioButton[] onScope = SettingsPage.radios(s, ProjectOptions.OUT_OF_SCOPE_CHOICE, "ask", new String[]{ "stop", "ask", "keep" },
"Stop logging out-of-scope items", "Ask the user what to do", "Do nothing");
page.block("Proxy history logging", SettingsPage.Kind.PROJECT,
"Use this setting to choose whether Open Suite automatically stops sending out-of-scope items to the history and other tools "
+ "when you add a target to the scope.",
() -> { s.set(ProjectOptions.OUT_OF_SCOPE_CHOICE, "ask"); onScope[1].setSelected(true); },
onScope[0], onScope[1], onScope[2]);
JRadioButton[] startup = SettingsPage.radios(s, INTERCEPT_STARTUP, "never", new String[]{ "always", "never", "restore" },
"Always enable", "Always disable", "Restore setting from when Open Suite was last closed");
page.block("Default Proxy interception state", SettingsPage.Kind.USER,
"Use this setting to choose whether interception is enabled by default when you start Open Suite.",
() -> { s.set(INTERCEPT_STARTUP, "never"); startup[1].setSelected(true); },
Sections.caption("Enable interception at startup:"),
startup[0], startup[1], startup[2]);
// "Don't send items ... if out of scope" is the one switch the scope prompt also sets.
JCheckBox notOutOfScope = Ui.check("Don't send items to Proxy history or live tasks, if out of scope", !ProjectOptions.logOutOfScope(s));
notOutOfScope.addActionListener(e -> s.setBool(ProjectOptions.LOG_OUT_OF_SCOPE, !notOutOfScope.isSelected()));
s.addListener(key -> {
if (ProjectOptions.LOG_OUT_OF_SCOPE.equals(key))
SwingUtilities.invokeLater(() -> notOutOfScope.setSelected(!ProjectOptions.logOutOfScope(s)));
});
JCheckBox unpack = SettingsPage.check(s, "http.unpackGzip", true, "Unpack gzip / deflate in responses");
page.block("Miscellaneous", SettingsPage.Kind.PROJECT,
"Use these settings to change details of how Open Suite Proxy behaves.",
null,
option(s, "http10", false, "Use HTTP/1.0 in requests to server", v -> server.http10 = v),
option(s, "http10Responses", false, "Use HTTP/1.0 in responses to client", v -> server.http10Responses = v),
option(s, "closeResponses", false, "Set response header \"Connection: close\"", v -> server.closeResponses = v),
option(s, "closeRequests", false, "Set \"Connection: close\" on incoming requests", v -> server.closeRequests = v),
option(s, "stripProxyHeaders", true, "Strip Proxy-* headers in incoming requests", v -> server.stripProxyHeaders = v),
option(s, "removeEncodings", true, "Remove unsupported encodings from Accept-Encoding headers in incoming requests", v -> server.removeUnsupportedEncodings = v),
option(s, "stripWsExtensions", true, "Strip Sec-WebSocket-Extensions headers in incoming requests", v -> server.stripWsExtensions = v),
option(s, "unpackRequests", false, "Unpack gzip / deflate in requests", v -> server.unpackRequests = v),
unpack,
option(s, "disableWebInterface", false, "Disable web interface at http://opensuite", v -> server.disableWebInterface = v),
option(s, "suppressErrors", false, "Suppress Open Suite error messages in browser", v -> server.suppressErrors = v),
option(s, "dontLog", false, "Don't send items to Proxy history or live tasks", v -> server.dontLog = v),
notOutOfScope);
add(page, BorderLayout.CENTER);
}
}
/** Settings > Tools > Proxy > Default Proxy interception state. */
static final String INTERCEPT_STARTUP = "proxy.intercept.startup", INTERCEPT_LAST = "proxy.intercept.last";
/** Whether interception starts switched on, by that setting. */
static boolean interceptAtStartup(opensuite.core.Settings s) {
return switch (s.get(INTERCEPT_STARTUP, "never")) {
case "always" -> true;
case "restore" -> s.getBool(INTERCEPT_LAST, false);
default -> false;
};
}
@Override public JMenu[] menus() { return null; }
// small helper
static class SimpleDoc implements javax.swing.event.DocumentListener {
private final Runnable r;
SimpleDoc(Runnable r) { this.r = r; }
public void insertUpdate(javax.swing.event.DocumentEvent e) { r.run(); }
public void removeUpdate(javax.swing.event.DocumentEvent e) { r.run(); }
public void changedUpdate(javax.swing.event.DocumentEvent e) { r.run(); }
}
}