Skip to content

Commit

Permalink
Add collaborator server info to contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyD97 committed Nov 11, 2019
1 parent 26e3541 commit da9ee3c
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
public abstract class CollaboratorEventAdapter implements CollaboratorEventListener {

@Override
public void onPollingRequestSent(String biid, boolean isFirstPoll) {}
public void onPollingRequestSent(String collaboratorServer, String contextIdentifier, boolean isFirstPoll) {}

@Override
public void onPollingResponseReceived(String biid, ArrayList<Interaction> interactions) {}
public void onPollingResponseReceived(String collaboratorServer, String contextIdentifier, ArrayList<Interaction> interactions) {}

@Override
public void onPollingFailure(String error) {}
public void onPollingFailure(String collaboratorServer, String contextIdentifier, String error) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.ArrayList;

public interface CollaboratorEventListener {
void onPollingRequestSent(String biid, boolean isFirstPoll);
void onPollingResponseReceived(String biid, ArrayList<Interaction> interactions);
void onPollingFailure(String error);
void onPollingRequestSent(String collaboratorServer, String contextIdentifier, boolean isFirstPoll);
void onPollingResponseReceived(String collaboratorServer, String contextIdentifier, ArrayList<Interaction> interactions);
void onPollingFailure(String collaboratorServer, String contextIdentifier, String error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import burp.IExtensionStateListener;
import com.coreyd97.BurpExtenderUtilities.DefaultGsonProvider;
import com.coreyd97.BurpExtenderUtilities.Preferences;
import com.nccgroup.collaboratorplusplus.extension.context.CollaboratorContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.ContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.Interaction;
import com.nccgroup.collaboratorplusplus.extension.ui.ExtensionUI;
import com.nccgroup.collaboratorplusplus.utilities.LogManager;
Expand All @@ -27,7 +27,7 @@ public class CollaboratorPlusPlus implements IBurpExtender, IExtensionStateListe
public static IBurpExtenderCallbacks callbacks;
public static LogManager logManager;
private ProxyService proxyService;
private CollaboratorContextManager collaboratorContextManager;
private ContextManager contextManager;
private Preferences preferences;
private ArrayList<IProxyServiceListener> proxyServiceListeners;

Expand Down Expand Up @@ -58,7 +58,7 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
//Setup preferences
DefaultGsonProvider gsonProvider = new DefaultGsonProvider();
this.preferences = new CollaboratorPreferenceFactory(gsonProvider, callbacks).buildPreferences();
this.collaboratorContextManager = new CollaboratorContextManager(this);
this.contextManager = new ContextManager(this);
logManager.setLogLevel(this.preferences.getSetting(PREF_LOG_LEVEL));

//Clean up proxy service on startup failure and color tab when running/stopped
Expand All @@ -82,14 +82,14 @@ public void onShutdown() {
});

//Color tab orange if errors, green if working correctly.
this.collaboratorContextManager.addEventListener(new CollaboratorEventAdapter() {
this.contextManager.addEventListener(new CollaboratorEventAdapter() {
@Override
public void onPollingResponseReceived(String biid, ArrayList<Interaction> interactions) {
public void onPollingResponseReceived(String collaboratorServer, String contextIdentifier, ArrayList<Interaction> interactions) {
burpTabController.setTabColor(Color.GREEN);
}

@Override
public void onPollingFailure(String error) {
public void onPollingFailure(String collaboratorServer, String contextIdentifier, String error) {
burpTabController.setTabColor(Color.ORANGE);
}
});
Expand Down Expand Up @@ -163,7 +163,7 @@ public void startCollaboratorProxy() throws URISyntaxException {
callbacks.loadConfigFromJson(Utilities.buildPollingRedirectionConfig(preferences, listenPort));

//Build the proxy service with the required values.
proxyService = new ProxyService(collaboratorContextManager, proxyServiceListeners,
proxyService = new ProxyService(contextManager, proxyServiceListeners,
collaboratorAddress, listenPort, pollingAddress,
useAuthentication, secret, ignoreCertificateErrors, verifyHostname, proxy);

Expand Down Expand Up @@ -257,7 +257,7 @@ public LogManager getLogController() {
return logManager;
}

public CollaboratorContextManager getContextManager() {
return this.collaboratorContextManager;
public ContextManager getContextManager() {
return this.contextManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.nccgroup.collaboratorplusplus.extension.context.CollaboratorContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.ContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.Interaction;
import com.nccgroup.collaboratorplusplus.extension.exception.*;
import com.nccgroup.collaboratorplusplus.utilities.Encryption;
Expand Down Expand Up @@ -43,7 +43,7 @@

public class ProxyService implements HttpRequestHandler {

private final CollaboratorContextManager contextManager;
private final ContextManager contextManager;
private final String collaboratorAddress;
private final int listenPort;
private final boolean useAuthentication;
Expand All @@ -56,12 +56,12 @@ public class ProxyService implements HttpRequestHandler {
private HttpServer server;
private URI forwardingURI;

ProxyService(CollaboratorContextManager collaboratorContextManager, ArrayList<IProxyServiceListener> listeners,
ProxyService(ContextManager contextManager, ArrayList<IProxyServiceListener> listeners,
String collaboratorAddress, Integer listenPort, URI forwardingURI, boolean useAuthentication,
String secret, boolean ignoreCertificateErrors, boolean hostnameVerification,
HttpHost proxyAddress){
this.serviceListeners = listeners;
this.contextManager = collaboratorContextManager;
this.contextManager = contextManager;
this.collaboratorAddress = collaboratorAddress;
this.listenPort = listenPort;
this.ignoreCertificateErrors = ignoreCertificateErrors;
Expand Down Expand Up @@ -161,7 +161,7 @@ public ArrayList<Interaction> requestInteractionsForContext(String contextIdenti
try {
return requestInteractionsForContext(client, contextIdentifier).getInteractions();
}catch (CollaboratorPollingException e){
this.contextManager.pollingFailure(e.getMessage());
this.contextManager.pollingFailure(collaboratorAddress, contextIdentifier, e.getMessage());
throw e;
} finally {
if (client != null) {
Expand Down Expand Up @@ -277,16 +277,17 @@ private CollaboratorServerResponse requestInteractionsForContext(CloseableHttpCl
}

@Override
public void handle(HttpRequest request, HttpResponse forwardedResponse, HttpContext context) throws IOException {
public void handle(HttpRequest request, HttpResponse forwardedResponse, HttpContext context) {

String responseString = "";
String contextIdentifier = "";
try {
CloseableHttpClient httpClient = buildHttpClient();
String contextId = URLDecoder.decode(request.getRequestLine().getUri().substring("/burpresults?biid=".length()), "UTF-8");
contextIdentifier = URLDecoder.decode(request.getRequestLine().getUri().substring("/burpresults?biid=".length()), "UTF-8");

CollaboratorServerResponse collaboratorResponse;
try {
collaboratorResponse = requestInteractionsForContext(httpClient, contextId);
collaboratorResponse = requestInteractionsForContext(httpClient, contextIdentifier);
}finally {
if (httpClient != null) {
try {
Expand Down Expand Up @@ -316,7 +317,7 @@ public void handle(HttpRequest request, HttpResponse forwardedResponse, HttpCont
responseString = e.getMessage();
}

this.contextManager.pollingFailure(responseString);
this.contextManager.pollingFailure(collaboratorAddress, contextIdentifier, responseString);

forwardedResponse.setStatusCode(500);
logManager.logInfo("Could not retrieve interactions: " + responseString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,76 @@
package com.nccgroup.collaboratorplusplus.extension.context;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.nccgroup.collaboratorplusplus.extension.CollaboratorEventListener;
import com.nccgroup.collaboratorplusplus.extension.CollaboratorPlusPlus;
import com.nccgroup.collaboratorplusplus.extension.Globals;
import com.nccgroup.collaboratorplusplus.extension.Utilities;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;

import java.awt.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

public class CollaboratorContextManager {
public class ContextManager {

private final CollaboratorPlusPlus extension;
private ArrayList<String> identifiers;
private HashMap<String, ContextInfo> collaboratorHistory;
private final ArrayList<CollaboratorEventListener> eventListeners;

public CollaboratorContextManager(CollaboratorPlusPlus extension){
public ContextManager(CollaboratorPlusPlus extension){
this.extension = extension;
this.identifiers = new ArrayList<>();
this.eventListeners = new ArrayList<>();
loadCollaboratorContextHistory();
}

public void pollingRequestSent(String collaboratorAddress, String identifier){
boolean isFirstPoll = !this.collaboratorHistory.containsKey(identifier);
public void pollingRequestSent(String collaboratorAddress, String contextIdentifier){
String completeIdentifier = getCompleteIdentifier(collaboratorAddress, contextIdentifier);

boolean isFirstPoll = !this.collaboratorHistory.containsKey(completeIdentifier);
if(isFirstPoll){
this.collaboratorHistory.put(identifier, new ContextInfo(collaboratorAddress, identifier));
this.identifiers.add(identifier);
this.collaboratorHistory.put(completeIdentifier, new ContextInfo(collaboratorAddress, contextIdentifier));
this.identifiers.add(completeIdentifier);
}else{
this.collaboratorHistory.get(identifier).lastPolled = new Date();
this.collaboratorHistory.get(completeIdentifier).lastPolled = new Date();
}

saveState();

for (CollaboratorEventListener eventListener : eventListeners) {
try {
eventListener.onPollingRequestSent(identifier, isFirstPoll);
eventListener.onPollingRequestSent(collaboratorAddress, contextIdentifier, isFirstPoll);
}catch (Exception ignored){
ignored.printStackTrace();
}
}
}

public void addInteractions(String collaboratorAddress, String identifier, ArrayList<Interaction> interactions){
if(!this.collaboratorHistory.containsKey(identifier)){
this.collaboratorHistory.put(identifier, new ContextInfo(collaboratorAddress, identifier));
this.identifiers.add(identifier);
String completeIdentifier = getCompleteIdentifier(collaboratorAddress, identifier);
if(!this.collaboratorHistory.containsKey(completeIdentifier)){
this.collaboratorHistory.put(completeIdentifier, new ContextInfo(collaboratorAddress, identifier));
this.identifiers.add(completeIdentifier);
}

//Parse our interactions
ContextInfo contextInfo = this.collaboratorHistory.get(identifier);
ContextInfo contextInfo = this.collaboratorHistory.get(completeIdentifier);
contextInfo.addInteractions(interactions);

saveState();

for (CollaboratorEventListener eventListener : eventListeners) {
try {
eventListener.onPollingResponseReceived(identifier, interactions);
eventListener.onPollingResponseReceived(collaboratorAddress, identifier, interactions);
}catch (Exception ignored){
ignored.printStackTrace();
}
}
}

public void pollingFailure(String message){
public void pollingFailure(String collaboratorAddress, String identifier, String message){
for (CollaboratorEventListener eventListener : eventListeners) {
try {
eventListener.onPollingFailure(message);
eventListener.onPollingFailure(collaboratorAddress, identifier, message);
}catch (Exception ignored){
ignored.printStackTrace();
}
Expand Down Expand Up @@ -126,4 +122,8 @@ public void setHighlight(ContextInfo contextInfo, Color color){
saveState();
}

private static String getCompleteIdentifier(String collaboratorAddress, String identifier){
return String.format("%s.%s", identifier, collaboratorAddress);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
import com.coreyd97.BurpExtenderUtilities.Preferences;
import com.nccgroup.collaboratorplusplus.extension.CollaboratorEventAdapter;
import com.nccgroup.collaboratorplusplus.extension.context.CollaboratorContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.ContextManager;
import com.nccgroup.collaboratorplusplus.extension.context.ContextInfo;
import com.nccgroup.collaboratorplusplus.extension.context.Interaction;
import com.nccgroup.collaboratorplusplus.utilities.SelectableLabel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class ContextInformationPanel extends JPanel {

private final CollaboratorContextManager contextManager;
private final ContextManager contextManager;
private final Preferences preferences;

ContextInfo selectedContext;
Expand All @@ -28,7 +26,7 @@ class ContextInformationPanel extends JPanel {

InteractionsTable interactionsTable;

ContextInformationPanel(CollaboratorContextManager contextManager, Preferences preferences){
ContextInformationPanel(ContextManager contextManager, Preferences preferences){
super(new BorderLayout());
this.contextManager = contextManager;
this.preferences = preferences;
Expand Down Expand Up @@ -63,22 +61,18 @@ private JComponent buildIDInfoPane(){
}
});

try{
JLabel idTitle = new JLabel("ID: ");
JLabel lpTitle = new JLabel("Last Polled: ");
idTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 30));
lpTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 30));
return panelBuilder.build(new JComponent[][]{
new JComponent[] {idTitle, identifierLabel, pollNowButton},
new JComponent[] {lpTitle, lastPolledLabel, pollNowButton},
}, new int[][]{
new int[]{0, 1, 0},
new int[]{0, 1, 0},
new int[]{0, 100, 0}
}, Alignment.CENTER, 1.0, 1.0);
}catch (Exception e){
return new JLabel("Could not build Context Information panel! :(");
}
JLabel idTitle = new JLabel("ID: ");
JLabel lpTitle = new JLabel("Last Polled: ");
idTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 30));
lpTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 30));
return panelBuilder.build(new JComponent[][]{
new JComponent[] {idTitle, identifierLabel, pollNowButton},
new JComponent[] {lpTitle, lastPolledLabel, pollNowButton},
}, new int[][]{
new int[]{0, 1, 0},
new int[]{0, 1, 0},
new int[]{0, 100, 0}
}, Alignment.CENTER, 1.0, 1.0);
}

void displayContext(ContextInfo contextInfo){
Expand All @@ -89,7 +83,7 @@ void displayContext(ContextInfo contextInfo){
this.lastPolledLabel.setText(contextInfo.getLastPolled().toString());
}else{
this.selectedContext = null;
this.interactionsTable.setContext(contextInfo);
this.interactionsTable.setContext(null);
this.identifierLabel.setText("N/A");
this.lastPolledLabel.setText("N/A");
}
Expand All @@ -105,10 +99,13 @@ private void registerListeners(){
interactionInformationPanel.setActiveInteraction(selectedInteraction);
});

//Update last polled text when poll request sent
this.contextManager.addEventListener(new CollaboratorEventAdapter() {
@Override
public void onPollingRequestSent(String biid, boolean isFirstPoll) {
if(selectedContext != null && biid.equalsIgnoreCase(selectedContext.getIdentifier())){
public void onPollingRequestSent(String collaboratorServer, String contextIdentifier, boolean isFirstPoll) {
if(selectedContext != null
&& collaboratorServer.equalsIgnoreCase(selectedContext.getCollaboratorAddress())
&& contextIdentifier.equalsIgnoreCase(selectedContext.getIdentifier())){
lastPolledLabel.setText(selectedContext.getLastPolled().toString());
lastPolledLabel.setForeground(Color.ORANGE);

Expand Down
Loading

0 comments on commit da9ee3c

Please sign in to comment.