From 635629029166e8f0c8e6c2f706f14b9087bcedf9 Mon Sep 17 00:00:00 2001 From: ddwightx Date: Sat, 15 Jan 2022 12:03:48 -0500 Subject: [PATCH] Fix for setting encoding on requests based on the default encoding in Settings --- build.gradle | 2 +- .../reshaper/burp/core/messages/ContentType.java | 14 ++++---------- .../reshaper/burp/core/messages/Encoder.java | 7 +++++-- .../core/messages/entities/HttpRequestMessage.java | 6 +++--- .../messages/entities/HttpResponseMessage.java | 4 ++-- .../burp/core/rules/thens/ThenSetEncoding.java | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 0854b23..82f49c5 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'com.synfron.reshaper.burp' -version '1.6.0' +version '1.6.1' targetCompatibility = '15' sourceCompatibility = '15' diff --git a/src/main/java/synfron/reshaper/burp/core/messages/ContentType.java b/src/main/java/synfron/reshaper/burp/core/messages/ContentType.java index 8178ab4..3d7946f 100644 --- a/src/main/java/synfron/reshaper/burp/core/messages/ContentType.java +++ b/src/main/java/synfron/reshaper/burp/core/messages/ContentType.java @@ -9,11 +9,11 @@ @EqualsAndHashCode public class ContentType { - public static final ContentType Json = new ContentType("JSON", 4, 16); - public static final ContentType UrlEncoded = new ContentType("URL Encoded", 1, 2); - public static final ContentType Xml = new ContentType("XML", 3, 8); public static final ContentType None = new ContentType("None", 0, 1); + public static final ContentType UrlEncoded = new ContentType("URL Encoded", 1, 2); public static final ContentType MultiPart = new ContentType("Multi-Part", 2, 4); + public static final ContentType Xml = new ContentType("XML", 3, 8); + public static final ContentType Json = new ContentType("JSON", 4, 16); public static final ContentType Amf = new ContentType("AMF", 5, 32); public static final ContentType Unknown = new ContentType("Unknown", -1, 64); @@ -42,12 +42,6 @@ private ContentType(String name, int id, int flags) { this.flags = flags; } - private ContentType(String[] names, int[] ids, int flags) { - this.names = names; - this.ids = ids; - this.flags = flags; - } - private ContentType(int flags) { List contentTypes = getValues().stream() .filter(contentType -> contentType.hasFlags(flags)) @@ -81,7 +75,7 @@ public static ContentType get(int id) { } public boolean isTextBased() { - return flags < ContentType.None.flags; + return flags != 0 && (flags & ~(Json.flags | UrlEncoded.flags | Xml.flags)) == 0; } public static List getValues() { diff --git a/src/main/java/synfron/reshaper/burp/core/messages/Encoder.java b/src/main/java/synfron/reshaper/burp/core/messages/Encoder.java index f8e6be8..22c5cec 100644 --- a/src/main/java/synfron/reshaper/burp/core/messages/Encoder.java +++ b/src/main/java/synfron/reshaper/burp/core/messages/Encoder.java @@ -23,12 +23,14 @@ public class Encoder { private boolean useDefault; @Getter private boolean useAutoDetect; + @Getter + private boolean autoSet = true; public Encoder(String encoding) { - setEncoding(encoding); + setEncoding(encoding, true); } - public void setEncoding(String encoding) { + public void setEncoding(String encoding, boolean autoSet) { useDefault = false; useAutoDetect = false; if (encoding == null || defaultEncoderName.equalsIgnoreCase(encoding)) { @@ -38,6 +40,7 @@ public void setEncoding(String encoding) { } else { charset = Charset.forName(encoding); } + this.autoSet = autoSet; } public static List getEncodings() { diff --git a/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpRequestMessage.java b/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpRequestMessage.java index 86503e5..c9a1399 100644 --- a/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpRequestMessage.java +++ b/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpRequestMessage.java @@ -37,6 +37,9 @@ public boolean isChanged() { private IRequestInfo getRequestInfo() { if (requestInfo == null) { requestInfo = BurpExtender.getCallbacks().getHelpers().analyzeRequest(request); + if (!encoder.isUseDefault() && encoder.isAutoSet() && !getContentType().isTextBased()) { + encoder.setEncoding("default", true); + } } return requestInfo; } @@ -48,9 +51,6 @@ public ContentType getContentType() { public HttpRequestStatusLine getStatusLine() { if (statusLine == null) { statusLine = new HttpRequestStatusLine(getRequestInfo().getHeaders().stream().findFirst().orElse("")); - if (!encoder.isUseDefault() && !getContentType().isTextBased()) { - encoder.setEncoding("default"); - } } return statusLine; } diff --git a/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpResponseMessage.java b/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpResponseMessage.java index d79b546..a80ad01 100644 --- a/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpResponseMessage.java +++ b/src/main/java/synfron/reshaper/burp/core/messages/entities/HttpResponseMessage.java @@ -40,8 +40,8 @@ public boolean isChanged() { private IResponseInfo getResponseInfo() { if (responseInfo == null) { responseInfo = BurpExtender.getCallbacks().getHelpers().analyzeResponse(response); - if (!encoder.isUseDefault() && !getMimeType().isTextBased()) { - encoder.setEncoding("default"); + if (!encoder.isUseDefault() && encoder.isAutoSet() && !getMimeType().isTextBased()) { + encoder.setEncoding("default", true); } } return responseInfo; diff --git a/src/main/java/synfron/reshaper/burp/core/rules/thens/ThenSetEncoding.java b/src/main/java/synfron/reshaper/burp/core/rules/thens/ThenSetEncoding.java index 561088f..ca97698 100644 --- a/src/main/java/synfron/reshaper/burp/core/rules/thens/ThenSetEncoding.java +++ b/src/main/java/synfron/reshaper/burp/core/rules/thens/ThenSetEncoding.java @@ -18,7 +18,7 @@ public RuleResponse perform(IEventInfo eventInfo) { boolean hasError = false; String encodingValue = encoding.getText(eventInfo); try { - eventInfo.getEncoder().setEncoding(encodingValue); + eventInfo.getEncoder().setEncoding(encodingValue, false); } catch (Exception e) { hasError = true; throw e;