0

I'm developing a Burp Suite extension.

I have a class BurpExtender, it has public static field.

public class BurpExtender implements IBurpExtender, IContextMenuFactory{

    private IBurpExtenderCallbacks callbacks;
    public static PrintWriter stdout;
    public static IExtensionHelpers helpers;
    ...
    @Override
        public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {

            this.callbacks = callbacks;
            this.helpers = callbacks.getHelpers();
            PrintWriter stdout = new PrintWriter(callbacks.getStdout(), true);

            callbacks.setExtensionName("REQUESTSENDER");
            callbacks.registerContextMenuFactory(BurpExtender.this);
            stdout.println("Registered");

        }

    public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
        List<JMenuItem> menuItemList = new ArrayList<JMenuItem>();
        JMenuItem item = new JMenuItem(new MyAction());
        menuItemList.add(item);
        return menuItemList;
    }

and in this file i have another class MyAction:

private class MyAction extends AbstractAction{
    public MyAction(){
        super("Name");
    }


    public void actionPerformed(ActionEvent e) {
        //Here i want to use BurpExtender.helpers, but i cant figure out, how to.
        //BurpExtender.stdout doesnt work here. Dunno why, NullPoinerException.
    }
}

I had another solution, when i tryed to do smth like JMenuItem item = new JMenuItem(new AbstractAction("123") {...} result it the same

Ivan Salosin
  • 183
  • 1
  • 1
  • 7
  • U need to initialise the static variable – Athul Dec 30 '16 at 08:58
  • You don't know but did you search what was that NullPointerException? This is THE exception you will encounter the most. – AxelH Dec 30 '16 at 09:00
  • Ofcourse i init helpers and stdout in BurpExtender – Ivan Salosin Dec 30 '16 at 09:02
  • **1** I don't see any initialisation, so if you do it in a Constructor, you need to be sure you build one instance before the action is used. **2** a NPE tell you that you have a `null` in stdout – AxelH Dec 30 '16 at 09:04
  • Simple, is there `"Registered"` in your output ? If not, then you never initialise it. Since this is done in a registerXXX method, this might not be done. Always check the value of a static instance if you initialise with an instance method (since this might never happen) – AxelH Dec 30 '16 at 09:08
  • Oh, I am an idiot. i init stdout as local var in registerExtenderCallbacks. Lost 2 hours, lol – Ivan Salosin Dec 30 '16 at 09:35

1 Answers1

1

You will need need to initialize the helper and stdout objects in your BurpExtender class.

Since these are static fields, an appropriate place would be to initialize them when declaring them or inside a static block in your class.

For Example:

  1. While declaring them:
public static PrintWriter stdout = System.out;
public static IExtensionHelpers helpers = new ExtensionHelperImpl();// something like this.
  1. Or inside a static block
public static PrintWriter stdout;
public static IExtensionHelpers helpers;

static {
    stdout = System.out;
    helpers = new ExtensionHelperImpl();// something like this.
}

Without this initialization, the stdout and helpers references will be pointing to null. This causes a NullPointerException when you try to use BurpExtender.stdout or BurpExtender.helpers in your other classes.

Update

In your MyAction class declare a reference to hold the IContextMenuInvocation invocation object. Some thing like this:

private class MyAction extends AbstractAction{
    private IContextMenuInvocation invocation;

    public MyAction(IContextMenuInvocation invocation){
        super("Name");
        this.invocation = invocation;
    }


    public void actionPerformed(ActionEvent e) {
        //Here you can use BurpExtender.helpers and IContextMenuInvocation invocation also.
        BurpExtender.helpers.doSomething();
        invocation.invoke();// for example..
    }
}

Then inside your outer class, change the createMenuItems method like this:

public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
    List<JMenuItem> menuItemList = new ArrayList<JMenuItem>();
    JMenuItem item = new JMenuItem(new MyAction(invocation));// this is the change
    menuItemList.add(item);
    return menuItemList;
}

Hope this helps!

anacron
  • 5,733
  • 2
  • 21
  • 31
  • If a wont make it static, is there a way to use private/public fields from BurpExtension class in another? If i make MyAction inner? – Ivan Salosin Dec 30 '16 at 09:13
  • Yes, _non-static_ inner classes *WILL* have access to the _non-static_ private and public fields declared in the outer class. – anacron Dec 30 '16 at 09:16
  • In (actionPerformed) i need to use (IContextMenuInvocation invocation). Is it possible to use it and BurpExtender.helpers? – Ivan Salosin Dec 30 '16 at 09:28