-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathOfferHostnameOverride.java
54 lines (46 loc) · 2.33 KB
/
OfferHostnameOverride.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package burp;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.requests.HttpRequest;
import burp.api.montoya.ui.contextmenu.ContextMenuEvent;
import burp.api.montoya.ui.contextmenu.ContextMenuItemsProvider;
import javax.swing.*;
import java.awt.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
public class OfferHostnameOverride implements ContextMenuItemsProvider {
public List<Component> provideMenuItems(ContextMenuEvent event)
{
List<Component> menuItemList = new ArrayList<>();
HttpRequestResponse requestResponse = event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0);
if (requestResponse == null || requestResponse.httpService() == null) {
return menuItemList;
}
String serviceHost = requestResponse.httpService().host();
String hostHeader = requestResponse.request().headerValue("host");
if (!serviceHost.equals(hostHeader)) {
JMenuItem retrieveRequestItem = new JMenuItem("Route requests to "+hostHeader + " via "+serviceHost);
retrieveRequestItem.addActionListener(l -> overrideHostname(serviceHost, hostHeader));
menuItemList.add(retrieveRequestItem);
}
return menuItemList;
}
// fixme nukes existing hostname overrides QQ
private static void overrideHostname(String serviceHost, String hostHeader) {
String ipAddress;
try {
ipAddress = InetAddress.getByName(serviceHost).getHostAddress();
} catch (UnknownHostException e) {
return;
}
String json = "{\"enabled\":true,\"hostname\":\""+hostHeader+"\",\"ip_address\":\""+ipAddress+"\"}"; // {"project_options":{"connections":{"hostname_resolution":[ ]}}}
String currentSettings = Utilities.montoyaApi.burpSuite().exportProjectOptionsAsJson("project_options.dns.hostname_resolution");
if (currentSettings.contains("ip_address")) {
json = currentSettings.replace("]", ","+json+"]");
} else {
json = currentSettings.replace("]", json+"]");
}
Utilities.montoyaApi.burpSuite().importProjectOptionsFromJson(json);
}
}