Skip to content

Instantly share code, notes, and snippets.

@pajswigger
Created January 10, 2018 09:54
Show Gist options
  • Save pajswigger/e8e25abfb12e81fdac0b058d7283b99c to your computer and use it in GitHub Desktop.
Save pajswigger/e8e25abfb12e81fdac0b058d7283b99c to your computer and use it in GitHub Desktop.
Enable/disable cookies in Repeater quickly
package burp;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONTokener;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;
public class BurpExtender implements IBurpExtender, IContextMenuFactory, ActionListener
{
IBurpExtenderCallbacks callbacks;
JCheckBoxMenuItem menuItem;
boolean useCookies = false;
@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks)
{
this.callbacks = callbacks;
callbacks.registerContextMenuFactory(this);
}
@Override
public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation)
{
menuItem = new JCheckBoxMenuItem("Use cookies in Repeater", useCookies);
menuItem.addActionListener(this);
return Collections.singletonList(menuItem);
}
@Override
public void actionPerformed(ActionEvent e)
{
try
{
useCookies = !useCookies;
String json = callbacks.saveConfigAsJson("project_options.sessions.session_handling_rules");
JSONObject root = new JSONObject(new JSONTokener(json));
JSONArray rules = root.getJSONObject("project_options")
.getJSONObject("sessions")
.getJSONObject("session_handling_rules")
.getJSONArray("rules");
for (int i = 0; i < rules.length(); i++)
{
JSONObject rule = rules.getJSONObject(i);
if (rule.getString("description").equals("Use cookies from Burp's cookie jar"))
{
JSONArray toolScope = rule.getJSONArray("tools_scope");
for (int j = 0; j < toolScope.length(); j++)
{
if (toolScope.getString(j).equals("Repeater"))
{
toolScope.remove(j);
break;
}
}
if (useCookies)
{
toolScope.put("Repeater");
}
}
}
callbacks.loadConfigFromJson(root.toString(4));
}
catch(Exception ex)
{
callbacks.printError(ex.toString());
ex.printStackTrace(new PrintWriter(callbacks.getStderr()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment