Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
godfuzz3r committed Aug 28, 2023
0 parents commit b3bef37
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
.vscode
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## UnUnicode


A burpsuite extention mostly based on this repository: asd https://github.com/bit4woo/u2c

## Why

Plugin from repository above didn't work in my burp suite, so I decided to make a simple replacement that uses StringEscapeUtils.unescapeJava to convert unicode escape sequences to single-byte characters.

## Example

Below is an example of how a json with a unicode escape sequence can be viewed in a burp without converting it in python cli or smth.
You may notice that the double-byte unicode character (emoji at the end of the json) was not converted correctly, but this is enough for my routine tasks.

![default pretty print](img/1.png)

![decode unicode escape sequences](img/2.png)

This is works on any content type as well, but pretty print implemented to json only:

![simple text](img/3.png)

## Install

```bash
mvn clean install
# install target/ununicode-1.0-jar-with-dependencies.jar
# in your burp extentions
```

Much thanks to [bit4woo](https://github.com/bit4woo) and [u2u](https://github.com/bit4woo/u2c) project for code base.
Binary file added img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/origin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/u2cTab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.godfuzz3r.burp</groupId>
<artifactId>ununicode</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addDefaultImplementationEntries>
true<!--to get Version from pom.xml -->
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.portswigger.burp.extender/burp-extender-api -->
<dependency>
<groupId>net.portswigger.burp.extender</groupId>
<artifactId>burp-extender-api</artifactId>
<version>[2.3,)</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>[1.10.0,)</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>[2.10.1,)</version>
</dependency>
</dependencies>
</project>
139 changes: 139 additions & 0 deletions src/UnUnicode/UnUnicode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package UnUnicode;

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.apache.commons.text.StringEscapeUtils;

import burp.IBurpExtenderCallbacks;
import burp.IExtensionHelpers;
import burp.IMessageEditorController;
import burp.IMessageEditorTab;
import burp.IRequestInfo;
import burp.ITextEditor;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;


public class UnUnicode implements IMessageEditorTab{
private ITextEditor txtInput;
private JPanel panel = new JPanel(new BorderLayout(0, 0));

private static IExtensionHelpers helpers;

public byte[] getHeaders(byte[] data){
IRequestInfo analyze = helpers.analyzeRequest(data);
int bodyOffset = analyze.getBodyOffset();
byte[] headers = Arrays.copyOfRange(data, 0, bodyOffset);
return headers;
}

public byte[] getBody(byte[] data){
IRequestInfo analyze = helpers.analyzeRequest(data);
int bodyOffset = analyze.getBodyOffset();
byte[] body = Arrays.copyOfRange(data, bodyOffset, data.length);
return body;
}

public byte[] concatHttp(byte[] headers, byte[] content) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(headers);
outputStream.write(content);
return outputStream.toByteArray();
}


public static boolean isJson(String content) {
Gson gson = new Gson();
try {
gson.fromJson(content, Object.class);
Object jsonObjType = gson.fromJson(content, Object.class).getClass();
if(jsonObjType.equals(String.class)){
return false;
}
return true;
} catch (com.google.gson.JsonSyntaxException ex) {
return false;
}
}

public String prettifyJson(String json) {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().serializeNulls().create();
JsonElement je = JsonParser.parseString(json);
return gson.toJson(je);
}

public UnUnicode(IMessageEditorController controller, boolean editable, IExtensionHelpers helpers, IBurpExtenderCallbacks callbacks)
{
txtInput = callbacks.createTextEditor();

panel.setLayout(new BorderLayout(0, 0));
panel.setBorder(new EmptyBorder(0, 0, 0, 0));
panel.add(txtInput.getComponent(), BorderLayout.CENTER);
callbacks.customizeUiComponent(panel);
UnUnicode.helpers = helpers;
}

@Override
public String getTabCaption()
{
return "UnUnicode";
}

@Override
public Component getUiComponent()
{
return panel;
}

@Override
public boolean isEnabled(byte[] content, boolean isRequest)
{
return true;
}

@Override
public void setMessage(byte[] content, boolean isRequest)
{
byte[] headers = getHeaders(content);
byte[] body = getBody(content);

String unescaped = StringEscapeUtils.unescapeJava(new String(body));
if (isJson(unescaped)){
unescaped = prettifyJson(unescaped);
}
try{
byte[] out = concatHttp(headers, unescaped.getBytes());
txtInput.setText(out);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public byte[] getMessage()
{
return txtInput.getSelectedText();
}

@Override
public boolean isModified()
{
return txtInput.isTextModified();
}

@Override
public byte[] getSelectedData()
{
return txtInput.getSelectedText();
}
}
62 changes: 62 additions & 0 deletions src/burp/BurpExtender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package burp;

import java.io.PrintWriter;

import UnUnicode.UnUnicode;

public class BurpExtender implements IBurpExtender,IMessageEditorTabFactory
{
private static IBurpExtenderCallbacks callbacks;
private IExtensionHelpers helpers;

private static PrintWriter stdout;
private static PrintWriter stderr;
public static String ExtensionName = "UnUnicode";
public static String Author = "godfuzz3r";
public String github = "https://github.com/godfuzz3r/burp-ununicode";

@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks)
{
BurpExtender.callbacks = callbacks;
callbacks.printOutput(getFullExtensionName());
callbacks.printOutput(github);
helpers = callbacks.getHelpers();
callbacks.setExtensionName(getFullExtensionName());
callbacks.registerMessageEditorTabFactory(this);
}

@Override
public IMessageEditorTab createNewInstance(IMessageEditorController controller, boolean editable) {
return new UnUnicode(controller, false, helpers, callbacks);
}

private static void flushStd(){
try{
stdout = new PrintWriter(callbacks.getStdout(), true);
stderr = new PrintWriter(callbacks.getStderr(), true);
}catch (Exception e){
stdout = new PrintWriter(System.out, true);
stderr = new PrintWriter(System.out, true);
}
}

public static PrintWriter getStdout() {
flushStd();
return stdout;
}

public static PrintWriter getStderr() {
flushStd();
return stderr;
}

//name+version+author
public static String getFullExtensionName(){
return ExtensionName;
}

public static IBurpExtenderCallbacks getCallbacks() {
return callbacks;
}
}

0 comments on commit b3bef37

Please sign in to comment.