Skip to content

Commit

Permalink
Outscoping options added
Browse files Browse the repository at this point in the history
  • Loading branch information
hvqzao committed May 21, 2019
2 parents c31a207 + 4ea4ad6 commit 44392f3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/hvqzao/wildcard/OutscopePane.form
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</Group>
</Group>
</Group>
<EmptySpace min="0" pref="393" max="32767" attributes="0"/>
<EmptySpace min="0" pref="66" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -98,7 +98,7 @@
</Component>
<Component class="javax.swing.JLabel" name="description">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Scope control features.&lt;/html&gt;"/>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Scope control features.Works only when &quot;Use advanced scope control&quot; is ticked in Target / Scope tab.&lt;/html&gt;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="title">
Expand Down
4 changes: 2 additions & 2 deletions src/hvqzao/wildcard/OutscopePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void initComponents() {
defaultsButton.setMinimumSize(new java.awt.Dimension(24, 24));
defaultsButton.setPreferredSize(new java.awt.Dimension(24, 24));

description.setText("<html>Scope control features.</html>");
description.setText("<html>Scope control features.Works only when \"Use advanced scope control\" is ticked in Target / Scope tab.</html>");

title.setText("<html><b style='color:#ff6633;font-size:10px'>Scope</b></html>");

Expand All @@ -77,7 +77,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(description, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(excludeButton))))
.addGap(0, 393, Short.MAX_VALUE))
.addGap(0, 66, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down
33 changes: 23 additions & 10 deletions src/hvqzao/wildcard/WildcardExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class WildcardExtension implements IBurpExtender {
private static Dimension iconDimension;
private static PrintWriter stderr;
private JSeparator separator;

private JPanel optionsPane;
private SpringLayout optionsLayout;
private JPanel previousPane;

@Override
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) {

Expand All @@ -52,21 +55,24 @@ public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) {
// options tab
extensionTabbedPane = new DnDTabbedPane();
callbacks.customizeUiComponent(extensionTabbedPane);
JPanel optionsPane = new JPanel();
optionsPane = new JPanel();
optionsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
SpringLayout optionsLayout = new SpringLayout();
optionsLayout = new SpringLayout();
optionsPane.setLayout(optionsLayout);
// wildcard options pane
wildcardOptionsPane = new WildcardOptionsPane(extensionTabbedPane);
optionsPane.add(wildcardOptionsPane);
optionsLayout.putConstraint(SpringLayout.NORTH, wildcardOptionsPane, 0, SpringLayout.NORTH, optionsPane);
// --
addSeparator(optionsPane, optionsLayout, wildcardOptionsPane);
previousPane = wildcardOptionsPane;
// outscope pane
addSeparator();
OutscopePane outscopePane = new OutscopePane();
optionsPane.add(outscopePane);
optionsLayout.putConstraint(SpringLayout.NORTH, outscopePane, 20, SpringLayout.SOUTH, wildcardOptionsPane);
//optionsPane.add(Box.createVerticalGlue());
// [...]
// next pane
//addPane(new NextPane());
// wrap in scrollPane and add as "Options" tab
JScrollPane optionsTab = new JScrollPane(optionsPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
callbacks.customizeUiComponent(optionsTab);
Expand Down Expand Up @@ -96,11 +102,18 @@ public static Dimension getIconDimension() {
return iconDimension;
}

private void addSeparator(JPanel pane, SpringLayout paneLayout, WildcardOptionsPane previousPane) {
private void addSeparator() {
separator = new JSeparator();
pane.add(separator);
paneLayout.putConstraint(SpringLayout.NORTH, separator, 10, SpringLayout.SOUTH, previousPane);
paneLayout.putConstraint(SpringLayout.WEST, separator, 0, SpringLayout.WEST, pane);
paneLayout.putConstraint(SpringLayout.EAST, separator, 0, SpringLayout.EAST, pane);
optionsPane.add(separator);
optionsLayout.putConstraint(SpringLayout.NORTH, separator, 10, SpringLayout.SOUTH, previousPane);
optionsLayout.putConstraint(SpringLayout.WEST, separator, 0, SpringLayout.WEST, optionsPane);
optionsLayout.putConstraint(SpringLayout.EAST, separator, 0, SpringLayout.EAST, optionsPane);
}

private void addPane(JPanel nextPane) {
addSeparator();
optionsPane.add(nextPane);
optionsLayout.putConstraint(SpringLayout.NORTH, nextPane, 20, SpringLayout.SOUTH, wildcardOptionsPane);
}

}
7 changes: 7 additions & 0 deletions src/hvqzao/wildcard/WildcardOptionsPane.form
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</Group>
<Component id="settingsShortenTab" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="settingsHijack" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="excludeCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
Expand Down Expand Up @@ -72,6 +73,7 @@
<Component id="settingsDefaults" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="excludeCheckbox" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -139,5 +141,10 @@
<Property name="text" type="java.lang.String" value="Hijack tabs belonging to other extensions"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="excludeCheckbox">
<Properties>
<Property name="text" type="java.lang.String" value="Exclude common static files"/>
</Properties>
</Component>
</SubComponents>
</Form>
77 changes: 70 additions & 7 deletions src/hvqzao/wildcard/WildcardOptionsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
Expand Down Expand Up @@ -66,6 +67,7 @@ private void initialize() {
settingsUnsupported.setSelected(false);
settingsPersistency.setSelected(false);
optionsSettingsUnsupportedChange();
removeExclude();
});
// unsupported
settingsUnsupported.addActionListener((e) -> {
Expand All @@ -90,12 +92,67 @@ private void initialize() {
}
optionsSettingsHijackUpdate();
});
// exclude
excludeCheckbox.setSelected(isExcluded());
excludeCheckbox.addActionListener((e) -> {
if (excludeCheckbox.isSelected() == false) {
removeExclude();
} else {
addExclude();
}
});
}

private boolean isExcluded() {
// without Json-aware library
String config = callbacks.saveConfigAsJson("target.scope.exclude");
return config.contains("\"file\":\"^/.*\\\\.(js|css|gif|png|jpg|jpeg|ico|svg|woff|woff2|eot|ttf)(;|\\\\?|$)\",\n");
}

private void addExclude() {
// without Json-aware library
String config = callbacks.saveConfigAsJson("target.scope.exclude");
int startIndex = config.indexOf("[");
int closeIndex = config.lastIndexOf("]");
StringBuilder configBuilder = new StringBuilder(config.substring(0, closeIndex));
if (startIndex + 1 != closeIndex) {
configBuilder.append(",\n");
}
configBuilder.append("{\n"
+ "\"enabled\":true,\n"
+ "\"file\":\"^/.*\\\\.(js|css|gif|png|jpg|jpeg|ico|svg|woff|woff2|eot|ttf)(;|\\\\?|$)\",\n"
+ "\"protocol\":\"any\"\n"
+ "}");
configBuilder.append(config.substring(closeIndex, config.length()));
callbacks.loadConfigFromJson(configBuilder.toString());
excludeCheckbox.setSelected(true);
}

private void removeExclude() {
// without Json-aware library
String config = callbacks.saveConfigAsJson("target.scope.exclude");
//callbacks.printOutput(config);
ArrayList<String> pieces = new ArrayList<>(Arrays.asList(config.split("}")));
pieces.add("");
ArrayList<Integer> found = new ArrayList<>();
for (int i = 0; i < pieces.size(); i++) {
String piece = pieces.get(i);
if (piece.contains("\"file\":\"^/.*\\\\.(js|css|gif|png|jpg|jpeg|ico|svg|woff|woff2|eot|ttf)(;|\\\\?|$)\",\n")) {
found.add(i);
}
}
found.forEach((Integer t) -> {
pieces.set(t, null);
});
pieces.removeAll(Collections.singleton(null));
try {
callbacks.loadConfigFromJson(String.join("}", pieces));
} catch (Exception ex) {
ex.printStackTrace(BurpExtender.getStderr());
}
excludeCheckbox.setSelected(false);
}

/**
* Activate functionalities
*
*/
public void start() {
callbacks.addSuiteTab(this);
burpTabbedPane = (JTabbedPane) extensionTabbedPane.getParent();
Expand Down Expand Up @@ -356,7 +413,7 @@ private void extensionTabHighlightOrange() {
extensionTabHighlightTimer = null;
});
//extensionTabLabel.setForeground(new Color(229, 137, 0));
extensionTabLabel.setForeground(new Color(255, 102, 51));
extensionTabLabel.setForeground(new Color(255, 102, 51)); // color:#ff6633
extensionTabHighlightTimer.setRepeats(false);
extensionTabHighlightTimer.start();
}
Expand All @@ -378,6 +435,7 @@ private void initComponents() {
settingsPersistency = new javax.swing.JCheckBox();
settingsShortenTab = new javax.swing.JCheckBox();
settingsHijack = new javax.swing.JCheckBox();
excludeCheckbox = new javax.swing.JCheckBox();

setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));

Expand All @@ -403,6 +461,8 @@ private void initComponents() {

settingsHijack.setText("Hijack tabs belonging to other extensions");

excludeCheckbox.setText("Exclude common static files");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -423,7 +483,8 @@ private void initComponents() {
.addGap(21, 21, 21)
.addComponent(settingsPersistency))
.addComponent(settingsShortenTab)
.addComponent(settingsHijack))))
.addComponent(settingsHijack)
.addComponent(excludeCheckbox))))
.addGap(0, 349, Short.MAX_VALUE))
);
layout.setVerticalGroup(
Expand All @@ -445,12 +506,14 @@ private void initComponents() {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(settingsHijack))
.addComponent(settingsDefaults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(excludeCheckbox))
);
}// </editor-fold>//GEN-END:initComponents


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox excludeCheckbox;
private javax.swing.JButton settingsDefaults;
private javax.swing.JLabel settingsDescription;
private javax.swing.JButton settingsHelp;
Expand Down

0 comments on commit 44392f3

Please sign in to comment.