Skip to content

Commit

Permalink
Added function to set the Rule Response in scripts. Removed Then Brea…
Browse files Browse the repository at this point in the history
…k from being callable from scripts due to it not having effect in this context. Fix for using using lone variables tags in number based fields. Improved console.log/err printing in script.
  • Loading branch information
ddwightx committed Apr 19, 2022
1 parent 0a855fc commit e9f3e0f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 19 deletions.
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.synfron.reshaper.burp'
version '1.8.1'
version '1.8.2'

targetCompatibility = '15'
sourceCompatibility = '15'
Expand All @@ -16,26 +16,27 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:4.2.0'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'org.mozilla:rhino:1.7.13'
implementation 'org.mozilla:rhino:1.7.14'
implementation 'cat.inspiracio:rhino-js-engine:1.7.10'
implementation 'org.apache.commons:commons-text:1.9'
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'net.jodah:expiringmap:0.5.10'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'com.miglayout:miglayout-swing:11.0'
implementation 'org.jsoup:jsoup:1.14.3'
implementation 'com.jayway.jsonpath:json-path:2.6.0'
implementation 'com.jayway.jsonpath:json-path:2.7.0'
implementation 'net.portswigger.burp.extender:burp-extender-api:2.3'
implementation 'org.rypt:f8:1.1-RC1'
implementation 'org.apache.commons:commons-csv:1.8'
implementation 'org.apache.commons:commons-csv:1.9.0'
implementation files('libs/htmlchardet-1.0.2.1.jar')
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
}

jar {
from {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
18 changes: 12 additions & 6 deletions docs/ScriptingLibrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ value - The new value.

Get all [Message Value](MessageValues.html) keys.

#### setRuleResponse(ruleResponse)

Set whether further processing of Thens or Rules should continue after this script finishes executing. This provides the same functionality as Then Break.

Continue - Continue processing as normal.</br>
BreakThens - Skip running any further Thens of the current Rule.</br>
BreakRules - Skip running any further Thens and Rules for this event.

Parameters:

ruleResponse - "Continue" | "BreakThens" | "BreakRules"

#### runThen(thenType, thenData)

Run a Then action.
Expand All @@ -59,12 +71,6 @@ BuildHttpMessage
destinationVariableName: string
}
```
Break
```
{
breakType: "Continue" | "BreakThens" | "BreakRules"
}
```
Delete Value
```
{
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MINGW* )
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import synfron.reshaper.burp.core.rules.whens.When;
import synfron.reshaper.burp.core.utils.Log;

import java.util.List;

public class RulesEngine {

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ThenRunScript extends Then<ThenRunScript> {

public RuleResponse perform(IEventInfo eventInfo) {
boolean hasError = false;
RuleResponse ruleResponse = RuleResponse.Continue;
try {
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxExecutionSeconds(maxExecutionSeconds);
Expand All @@ -29,13 +30,15 @@ public RuleResponse perform(IEventInfo eventInfo) {
1,
null
));

ruleResponse = (RuleResponse)dispatcher.getDataBag().getOrDefault("ruleResponse", ruleResponse);
} catch (Exception e) {
hasError = true;
throw e;
} finally {
if (eventInfo.getDiagnostics().isEnabled()) eventInfo.getDiagnostics().logValue(this, hasError, script);
}
return RuleResponse.Continue;
return ruleResponse;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
package synfron.reshaper.burp.core.rules.thens.entities.script;

import org.mozilla.javascript.ScriptableObject;
import synfron.reshaper.burp.core.utils.Log;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ConsoleObj {
public void log(Object... args) {
Log.get().withMessage("Script Log").withPayload(args.length == 1 ? args[0] : args).log();
List<Object> values = getConsoleWritable(args);
Log.get().withMessage("Script Log").withPayload(values.size() == 1 ? values.get(0) : values).log();
}

public void error(Object... args) {
Log.get().withMessage("Script Log").withPayload(args.length == 1 ? args[0] : args).logErr();
List<Object> values = getConsoleWritable(args);
Log.get().withMessage("Script Log").withPayload(values.size() == 1 ? values.get(0) : values).logErr();
}

private List<Object> getConsoleWritable(Object[] values) {
return Arrays.stream(values)
.map(value -> value instanceof ScriptableObject ? Objects.toString(value) : value)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import synfron.reshaper.burp.core.messages.MessageValue;
import synfron.reshaper.burp.core.messages.MessageValueHandler;
import synfron.reshaper.burp.core.rules.RuleOperationType;
import synfron.reshaper.burp.core.rules.RuleResponse;
import synfron.reshaper.burp.core.rules.thens.Then;
import synfron.reshaper.burp.core.rules.thens.ThenType;
import synfron.reshaper.burp.core.utils.GetItemPlacement;
Expand Down Expand Up @@ -112,7 +113,6 @@ public String runThen(String thenType, NativeObject thenData) {
ThenType.DeleteValue,
ThenType.DeleteVariable,
ThenType.Drop,
ThenType.Break,
ThenType.Log,
ThenType.ParseHttpMessage,
ThenType.SendRequest,
Expand All @@ -138,5 +138,19 @@ public String runThen(String thenType, NativeObject thenData) {
Then<?> then = (Then<?>)Serializer.deserialize(thenDataJson, thenClass);
return then.perform((IEventInfo)Dispatcher.getCurrent().getDataBag().get("eventInfo")).toString();
}

public void setRuleResponse(String ruleResponse) {
switch (ruleResponse.toUpperCase()) {
case "CONTINUE":
Dispatcher.getCurrent().getDataBag().put("ruleResponse", RuleResponse.Continue);
break;
case "BREAKTHENS":
Dispatcher.getCurrent().getDataBag().put("ruleResponse", RuleResponse.BreakThens);
break;
case "BREAKRULES":
Dispatcher.getCurrent().getDataBag().put("ruleResponse", RuleResponse.BreakRules);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static boolean isPotentialInt(String formattedString) {
return false;
}
String strippedText = formattedString.replaceAll(String.format("\\{\\{(%s):(.+?)\\}\\}", String.join("|", VariableSource.getSupportedNames())), "");
return TextUtils.isInt(strippedText);
return TextUtils.isInt(strippedText) || strippedText.isEmpty();
}

public static boolean hasTag(String text) {
Expand Down

0 comments on commit e9f3e0f

Please sign in to comment.