Skip to content

Commit

Permalink
Fix for setting encoding on requests based on the default encoding in…
Browse files Browse the repository at this point in the history
… Settings
  • Loading branch information
ddwightx committed Jan 30, 2022
1 parent 7f7180e commit 6356290
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 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.6.0'
version '1.6.1'

targetCompatibility = '15'
sourceCompatibility = '15'
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/synfron/reshaper/burp/core/messages/ContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<ContentType> contentTypes = getValues().stream()
.filter(contentType -> contentType.hasFlags(flags))
Expand Down Expand Up @@ -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<ContentType> getValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -38,6 +40,7 @@ public void setEncoding(String encoding) {
} else {
charset = Charset.forName(encoding);
}
this.autoSet = autoSet;
}

public static List<String> getEncodings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6356290

Please sign in to comment.