Skip to content

Commit

Permalink
Added Site Map and Decode as new Then Send To target. Require URL for…
Browse files Browse the repository at this point in the history
… When In Scope constraints used under WebSocket Rules. Added new Then: Read File. Then Run Process: Fixed issue with running commands on UNIX-like systems. Auto-refresh export data lists. Add select all and unselect all functionality to export data lists. Remember last export and import folder location.
  • Loading branch information
ddwightx committed Oct 28, 2023
1 parent 1f3e2fa commit 7df7b9e
Show file tree
Hide file tree
Showing 35 changed files with 937 additions and 229 deletions.
2 changes: 1 addition & 1 deletion extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

group 'com.synfron.reshaper.burp'
archivesBaseName = 'reshaper-for-burp'
version '2.2.0'
version '2.3.0'

targetCompatibility = '17'
sourceCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public ProxyRequestToBeSentAction handleRequestToBeSent(InterceptedRequest inter
@Override
public ProxyResponseReceivedAction handleResponseReceived(InterceptedResponse interceptedResponse) {
if (BurpExtender.getGeneralSettings().isCapture(BurpTool.Proxy)) {
HttpEventInfo eventInfo = asEventInfo(false, BurpTool.Proxy, getMessageId(BurpTool.Proxy, interceptedResponse.messageId()), interceptedResponse.initiatingRequest(), interceptedResponse, interceptedResponse.annotations());
HttpEventInfo eventInfo = asEventInfo(false, BurpTool.Proxy, getMessageId(BurpTool.Proxy, interceptedResponse.messageId()), interceptedResponse.initiatingRequest(), interceptedResponse, interceptedResponse.annotations(), interceptedResponse.listenerInterface(), null);
return processEvent(false, eventInfo, true).asProxyResponseAction();
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package synfron.reshaper.burp.core.messages;

import lombok.Getter;

public enum HighlightColor {
None(null, burp.api.montoya.core.HighlightColor.NONE),
Red("red", burp.api.montoya.core.HighlightColor.RED),
Orange("orange", burp.api.montoya.core.HighlightColor.ORANGE),
Yellow("yellow", burp.api.montoya.core.HighlightColor.YELLOW),
Green("green", burp.api.montoya.core.HighlightColor.GREEN),
Cyan("cyan", burp.api.montoya.core.HighlightColor.CYAN),
Blue("blue", burp.api.montoya.core.HighlightColor.BLUE),
Pink("pink", burp.api.montoya.core.HighlightColor.PINK),
Magenta("magenta", burp.api.montoya.core.HighlightColor.MAGENTA),
Gray("gray", burp.api.montoya.core.HighlightColor.GRAY);

private final String value;

@Getter
private final burp.api.montoya.core.HighlightColor highlightColor;

HighlightColor(String value, burp.api.montoya.core.HighlightColor highlightColor) {
this.value = value;
this.highlightColor = highlightColor;
}

public String getValue() {
return this.value;
}

@Override
public String toString() {
return this.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public HttpEventInfo(EventInfo sourceRequestEventInfo) {
this.dataDirection = HttpDataDirection.Request;
this.initialDataDirection = HttpDataDirection.Request;
this.initialHttpResponse = null;
this.httpResponseMessage = new HttpResponseMessage((byte[]) null, encoder);
this.sourceAddress = "burp::";
this.proxyName = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,8 @@ private HttpRequest getAdjustedRequest(byte[] request) {
public String getText() {
return encoder.decode(getValue());
}

public boolean isSet() {
return request.length > 0 || isChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@ private HttpResponse getAdjustedResponse(byte[] response) {
public String getText() {
return encoder.decode(getValue());
}

public boolean isSet() {
return response.length > 0 || isChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IDiagnostics {

void logValue(When<?> when, boolean result, Object... values);

void logProperties(When<?> when, boolean hasError, List<? extends Pair<String, ? extends Serializable>> properties);
void logProperties(When<?> when, boolean result, List<? extends Pair<String, ? extends Serializable>> properties);

void logValue(Then<?> then, boolean hasError, Object... values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
@JsonSubTypes.Type(value = ThenParseHttpMessage.class),
@JsonSubTypes.Type(value = ThenSendRequest.class),
@JsonSubTypes.Type(value = ThenSendMessage.class),
@JsonSubTypes.Type(value = ThenRepeat.class)
@JsonSubTypes.Type(value = ThenRepeat.class),
@JsonSubTypes.Type(value = ThenReadFile.class)
})
public abstract class Then<T extends Then<T>> implements IRuleOperation<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import lombok.Setter;
import synfron.reshaper.burp.core.messages.EventInfo;
import synfron.reshaper.burp.core.messages.HighlightColor;
import synfron.reshaper.burp.core.rules.IHttpRuleOperation;
import synfron.reshaper.burp.core.rules.IWebSocketRuleOperation;
import synfron.reshaper.burp.core.rules.RuleOperationType;
Expand All @@ -18,7 +19,7 @@ public RuleResponse perform(EventInfo eventInfo) {
boolean hasError = true;
try {
if (eventInfo.getAnnotations() != null) {
eventInfo.getAnnotations().setHighlightColor(color.highlightColor);
eventInfo.getAnnotations().setHighlightColor(color.getHighlightColor());
hasError = false;
}
} finally {
Expand All @@ -32,33 +33,4 @@ public RuleOperationType<ThenHighlight> getType() {
return ThenType.Highlight;
}

public enum HighlightColor {
None(null, burp.api.montoya.core.HighlightColor.NONE),
Red("red", burp.api.montoya.core.HighlightColor.RED),
Orange("orange", burp.api.montoya.core.HighlightColor.ORANGE),
Yellow("yellow", burp.api.montoya.core.HighlightColor.YELLOW),
Green("green", burp.api.montoya.core.HighlightColor.GREEN),
Cyan("cyan", burp.api.montoya.core.HighlightColor.CYAN),
Blue("blue", burp.api.montoya.core.HighlightColor.BLUE),
Pink("pink", burp.api.montoya.core.HighlightColor.PINK),
Magenta("magenta", burp.api.montoya.core.HighlightColor.MAGENTA),
Gray("gray", burp.api.montoya.core.HighlightColor.GRAY);

private final String value;
private final burp.api.montoya.core.HighlightColor highlightColor;

HighlightColor(String value, burp.api.montoya.core.HighlightColor highlightColor) {
this.value = value;
this.highlightColor = highlightColor;
}

public String getValue() {
return this.value;
}

@Override
public String toString() {
return this.name();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package synfron.reshaper.burp.core.rules.thens;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import synfron.reshaper.burp.core.exceptions.WrappedException;
import synfron.reshaper.burp.core.messages.Encoder;
import synfron.reshaper.burp.core.messages.EventInfo;
import synfron.reshaper.burp.core.rules.IHttpRuleOperation;
import synfron.reshaper.burp.core.rules.IWebSocketRuleOperation;
import synfron.reshaper.burp.core.rules.RuleOperationType;
import synfron.reshaper.burp.core.rules.RuleResponse;
import synfron.reshaper.burp.core.rules.thens.entities.savefile.FileExistsAction;
import synfron.reshaper.burp.core.vars.SetListItemPlacement;
import synfron.reshaper.burp.core.vars.VariableSource;
import synfron.reshaper.burp.core.vars.VariableString;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class ThenReadFile extends Then<ThenReadFile> implements IHttpRuleOperation, IWebSocketRuleOperation {

@Getter @Setter
private VariableString filePath;
@Getter @Setter
private VariableString encoding;
@Getter @Setter
private boolean breakAfterFailure = true;
@Getter @Setter
private boolean captureAfterFailure;
@Getter @Setter
private VariableSource captureVariableSource = VariableSource.Global;
@Getter @Setter
private VariableString captureVariableName;
@Getter @Setter
private SetListItemPlacement itemPlacement = SetListItemPlacement.Index;
@Getter @Setter
private VariableString delimiter;
@Getter @Setter
private VariableString index;

@Override
public RuleResponse perform(EventInfo eventInfo) {
boolean hasError = false;
boolean failed = true;
String captureVariableName = null;
String filePathValue = null;
String fileText = "";
String encodingValue = null;
try {
captureVariableName = getVariableName(eventInfo);
filePathValue = filePath.getText(eventInfo);
try {
Path path = Paths.get(filePathValue);
if (Files.isRegularFile(path) && Files.isReadable(path)) {
encodingValue = VariableString.getTextOrDefault(eventInfo, encoding, Charset.defaultCharset().name());
Encoder encoder = new Encoder(encodingValue);
fileText = encoder.decode(FileUtils.readFileToByteArray(path.toFile()));
failed = false;
}
} catch (Exception ignored) {
} finally {
if (!failed || captureAfterFailure) {
setVariable(
captureVariableSource,
eventInfo,
captureVariableName,
itemPlacement,
VariableString.getTextOrDefault(eventInfo, delimiter, "\n"),
VariableString.getIntOrDefault(eventInfo, index, 0),
fileText
);
}
}
} catch (Exception e) {
hasError = true;
throw e;
} finally {
if (eventInfo.getDiagnostics().isEnabled()) eventInfo.getDiagnostics().logProperties(this, hasError, List.of(
Pair.of("filePath", filePathValue),
Pair.of("text", fileText),
Pair.of("encoding", encodingValue),
Pair.of("captureVariableSource", captureVariableSource),
Pair.of("captureVariableName", captureVariableName),
Pair.of("itemPlacement", captureVariableSource.isList() ? itemPlacement : null),
Pair.of("delimiter", captureVariableSource.isList() && itemPlacement.isHasDelimiterSetter() ? VariableString.getTextOrDefault(eventInfo, delimiter, null) : null),
Pair.of("index", captureVariableSource.isList() && itemPlacement.isHasIndexSetter() ? VariableString.getTextOrDefault(eventInfo, index, null) : null),
Pair.of("failed", failed)
));
}
return failed && breakAfterFailure ? RuleResponse.BreakRules : RuleResponse.Continue;
}

private String getVariableName(EventInfo eventInfo) {
String captureVariableName;
if (StringUtils.isEmpty(captureVariableName = this.captureVariableName.getText(eventInfo))) {
throw new IllegalArgumentException("Invalid variable name");
}
return captureVariableName;
}

@Override
public RuleOperationType<ThenReadFile> getType() {
return ThenType.ReadFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import synfron.reshaper.burp.core.exceptions.WrappedException;
import synfron.reshaper.burp.core.messages.EventInfo;
Expand Down Expand Up @@ -69,7 +70,12 @@ public RuleResponse perform(EventInfo eventInfo) {
input = VariableString.getTextOrDefault(eventInfo, this.input, "");
captureVariableName = getVariableName(eventInfo);
ExecutorService executor = Executors.newSingleThreadExecutor();
Process process = Runtime.getRuntime().exec(command.getText(eventInfo));
Process process;
if (SystemUtils.IS_OS_WINDOWS) {
process = Runtime.getRuntime().exec(command.getText(eventInfo));
} else {
process = Runtime.getRuntime().exec(new String[]{ "sh", "-c", command.getText(eventInfo) });
}
if (StringUtils.isNotEmpty(input)) {
IOUtils.write(input, process.getOutputStream(), Charset.defaultCharset());
process.getOutputStream().close();
Expand Down
Loading

0 comments on commit 7df7b9e

Please sign in to comment.