Skip to content

Commit

Permalink
Fix intercept proxy error handling, remove unused response interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeyax committed Feb 26, 2025
1 parent e9ea5dd commit bf45973
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/main/java/burp/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import burp.api.montoya.BurpExtension;
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.http.HttpService;
import burp.api.montoya.proxy.http.*;
import burp.api.montoya.proxy.http.InterceptedRequest;
import burp.api.montoya.proxy.http.ProxyRequestHandler;
import burp.api.montoya.proxy.http.ProxyRequestReceivedAction;
import burp.api.montoya.proxy.http.ProxyRequestToBeSentAction;
import com.google.gson.Gson;

import java.net.URL;
Expand Down Expand Up @@ -42,17 +45,6 @@ public ProxyRequestReceivedAction handleRequestReceived(InterceptedRequest inter
return ProxyRequestReceivedAction.continueWith(interceptedRequest);
}
});
api.proxy().registerResponseHandler(new ProxyResponseHandler() {
@Override
public ProxyResponseToBeSentAction handleResponseToBeSent(InterceptedResponse interceptedResponse) {
return processHttpResponse(interceptedResponse);
}

@Override
public ProxyResponseReceivedAction handleResponseReceived(InterceptedResponse interceptedResponse) {
return ProxyResponseReceivedAction.continueWith(interceptedResponse);
}
});

new Thread(() -> {
var err = ServerLibrary.INSTANCE.StartServer(settings.getSpoofProxyAddress());
Expand All @@ -70,6 +62,10 @@ private ProxyRequestToBeSentAction processHttpRequest(InterceptedRequest request
try {
var requestURL = new URL(request.url());

if (requestURL.getHost().equals("awesome-tls-error")) {
throw new Error(new String(request.body().getBytes(), StandardCharsets.UTF_8));
}

var headerOrder = new String[request.headers().size()];
for (var i = 0; i < request.headers().size(); i++) {
headerOrder[i] = request.headers().get(i).name();
Expand All @@ -91,12 +87,4 @@ private ProxyRequestToBeSentAction processHttpRequest(InterceptedRequest request
return null;
}
}

private ProxyResponseToBeSentAction processHttpResponse(InterceptedResponse proxyMessage) {
if (proxyMessage.request().httpService().host().equals("awesome-tls-error")) {
api.logging().logToError("Http response error: " + new String(proxyMessage.body().getBytes(), StandardCharsets.UTF_8));
}

return ProxyResponseToBeSentAction.continueWith(proxyMessage);
}
}

0 comments on commit bf45973

Please sign in to comment.