Burp Suite User Forum

Create new post

Temporarily deregister and reregister a Registration?

Nadia | Last updated: Jan 11, 2023 04:12PM UTC

Hi all, I'm developing an extension utilizing the new Montoya API. I'm registering an HTTP handler as is done in the API examples: Registration headerHandler = api.proxy().registerRequestHandler(new MyHTTPHandlerExample(api)); I then want to use a checkbox in my extension's tab to turn on and off this handler. So far, the only way I have found to do this is to deregister the headerHandler Registration when the checkbox is deselected (headerHandler.deregister()). However, this then leaves no way of reregistering ("turning back on") the HTTP handler when the checkbox is selected again. Is there an alternate way of temporarily pausing and restarting a handler (analogous to what is done when the Proxy is turned on and off)? Thanks!

Nadia | Last updated: Jan 11, 2023 04:16PM UTC

Note: I realize I could just register a new handler every time the box is checked, I just wondered if there was a more elegant way to work with a single Registration.

Hannah, PortSwigger Agent | Last updated: Jan 12, 2023 09:48AM UTC

Hi You could deregister your handler and create a new one when the checkbox is toggled. Alternatively, you could have your checkbox toggle a Boolean value inside your Handler that determines whether the behavior in the Handler is carried out or not.

Nadia | Last updated: Jan 12, 2023 06:56PM UTC

Hi Hannah, Thanks for your reply! How would I access the Boolean you're mentioning? It seems to me that after registering a handler, all I have access to is its Registration, not the actual attributes of the class implementing ProxyRequestHandler that is inside the registered handler.

Hannah, PortSwigger Agent | Last updated: Jan 16, 2023 11:38AM UTC

Hi

There are a few different ways that you can go about this.

A simple example can be found here:
public class Foo implements BurpExtension
{
    boolean myBoolean = false;

    @Override
    public void initialize(MontoyaApi api)
    {
        api.http().registerHttpHandler(new MyHttpHandler());
    }

    class MyHttpHandler implements HttpHandler {

        @Override
        public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent requestToBeSent)
        {
            if (myBoolean) {
                System.out.println("Boolean set");
            } else {
                System.out.println("Boolean not set");
            }
            return continueWith(requestToBeSent);
        }

        @Override
        public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived responseReceived)
        {
            return continueWith(responseReceived);
        }
    }
}

You must be an existing, logged-in customer to reply to a thread. Please email us for additional support.