The Burp Suite User Forum was discontinued on the 1st November 2024.

Burp Suite User Forum

For support requests, go to the Support Center. To discuss with other Burp users, head to our Discord page.

SUPPORT CENTER DISCORD

Montoya API: Update HttpHeader in Repeater Tab

Manuel | Last updated: Mar 07, 2024 09:11AM UTC

Is it possible to change a HttpHeader on the HttpRequestResponse selected via a ContextMenuEvent in a Reapeater tab?

Hannah, PortSwigger Agent | Last updated: Mar 07, 2024 05:26PM UTC

Yes, it's possible to modify the contents of a message editor.

In the example below, I used "withAddedHeader()", but you could substitute this out for a different method.

import burp.api.montoya.BurpExtension;
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.ui.contextmenu.ContextMenuEvent;
import burp.api.montoya.ui.contextmenu.ContextMenuItemsProvider;
import burp.api.montoya.ui.contextmenu.MessageEditorHttpRequestResponse;

import javax.swing.*;
import java.awt.*;
import java.util.List;

import static burp.api.montoya.core.ToolType.REPEATER;
import static java.util.Collections.emptyList;

public class Extension implements BurpExtension
{
    @Override
    public void initialize(MontoyaApi api)
    {
        api.extension().setName("Add header in Repeater");
        
        api.userInterface().registerContextMenuItemsProvider(new ContextMenuItemsProvider()
        {
            @Override
            public List<Component> provideMenuItems(ContextMenuEvent event)
            {
                if (event.isFromTool(REPEATER))
                {
                    if (event.messageEditorRequestResponse().isPresent())
                    {
                        JMenuItem menuItem = new JMenuItem("Add header");
                        menuItem.addActionListener(l -> {
                            MessageEditorHttpRequestResponse messageEditorHttpRequestResponse = event.messageEditorRequestResponse().get();
                            messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withAddedHeader("Foo", "bar"));
                        });

                        return List.of(menuItem);
                    }
                }

                return emptyList();
            }
        });
    }
}

Manuel | Last updated: Mar 07, 2024 11:55PM UTC

Thanks for the reply. I wrongly used the immutable HttpRequestRespons instead of MessageEditorHttpRequestResponse, and using that solved my problem.

Hannah, PortSwigger Agent | Last updated: Mar 08, 2024 09:14AM UTC