Skip to content

Commit

Permalink
Testing for smaller encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Static-Flow authored and test1212121212121212 committed Mar 4, 2020
1 parent 40fa487 commit 08f5ce6
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 19 deletions.
37 changes: 33 additions & 4 deletions src/teamextension/BurpTeamPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,24 @@ public void popupMenuCanceled(PopupMenuEvent e) {
JMenuItem getLinkItem = new JMenuItem("Get Link");
getLinkItem.addActionListener(e -> {
HttpRequestResponse burpMessage = ((SharedLinksModel) j.getModel()).getBurpMessageAtIndex(j.getSelectedRow());

// try {
// this.sharedValues.getCallbacks().printOutput("Port: "+burpMessage.getHttpService().getPort());
// this.sharedValues.getCallbacks().printOutput("Body:" + new String(stripBurpMessage(burpMessage)));
// } catch (IOException ex) {
// ex.printStackTrace();
// }
StringSelection stringSelection = null;
try {
String jsonString =
this.sharedValues.getGson().toJson(burpMessage);
this.sharedValues.getCallbacks().printOutput(jsonString);
// stringSelection = new StringSelection(
// "burptcmessage/" +
// Base64.getEncoder().encodeToString(compress(stripBurpMessage(burpMessage))));
stringSelection = new StringSelection(
"burptcmessage/" +
Base64.getEncoder().encodeToString(compress(this.sharedValues.getGson().toJson(burpMessage))));
Base64.getEncoder().encodeToString(compress(jsonString.getBytes())));
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -695,6 +708,22 @@ public void ancestorMoved(AncestorEvent event) {

}

byte[] stripBurpMessage(HttpRequestResponse burpMessage) throws IOException {
ByteArrayOutputStream my_stream = new ByteArrayOutputStream();
byte[] divider = "\nBURPTCDELIM".getBytes();
my_stream.write(burpMessage.getRequest());
my_stream.write(divider);
my_stream.write(burpMessage.getResponse());
my_stream.write(divider);
my_stream.write(burpMessage.getHttpService().getHost().getBytes());
my_stream.write(divider);
my_stream.write(Integer.toString(burpMessage.getHttpService().getPort()).getBytes());
my_stream.write(divider);
my_stream.write(burpMessage.getHttpService().getProtocol().getBytes());

return my_stream.toByteArray();
}

void swapServerAndRoomLists(boolean toRoom) {
new SwingWorker<Boolean, Void>() {
@Override
Expand All @@ -719,10 +748,10 @@ public void done() {
}.execute();
}

private static byte[] compress(String data) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length());
private static byte[] compress(byte[] data) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
GZIPOutputStream gzip = new GZIPOutputStream(bos);
gzip.write(data.getBytes());
gzip.write(data);
gzip.close();
byte[] compressed = bos.toByteArray();
bos.close();
Expand Down
79 changes: 64 additions & 15 deletions src/teamextension/CustomURLServer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package teamextension;

import com.google.gson.JsonObject;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.StringTokenizer;
Expand Down Expand Up @@ -78,26 +81,68 @@ private void handleConnection(Socket connection) {
}


private static String decompress(byte[] compressed) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis);
BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while((line = br.readLine()) != null) {
sb.append(line);
private ArrayList fromBytesToString(byte[] data) {
ArrayList<Integer> values = new ArrayList<>();
for(byte b : data){
values.add((int) b);
}
return values;
}

private String decompress(byte[] compressed) throws IOException {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis);
BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line+"\n");
}
br.close();
gis.close();
bis.close();
String strippedJson = sb.toString();
/*
{"request":[],"httpService":{"host":"detectportal.firefox.com","port":80,"protocol":"http"}}
*/
this.sharedValues.getCallbacks().printOutput(
"StrippedJson: " + strippedJson);
String[] strippedJsonByDelimiter = strippedJson.split("BURPTCDELIM");
for (String jsonPiece : strippedJsonByDelimiter) {
this.sharedValues.getCallbacks().printOutput(jsonPiece);
}
JsonObject httpService = new JsonObject();
httpService.addProperty("host",strippedJsonByDelimiter[2].trim());
httpService.addProperty("port",strippedJsonByDelimiter[3].trim());
httpService.addProperty("protocol",strippedJsonByDelimiter[4].trim());
JsonObject mainJson = new JsonObject();
mainJson.add("request",
this.sharedValues.getGson().newBuilder().create().toJsonTree(fromBytesToString(strippedJsonByDelimiter[0].getBytes())));
mainJson.add("response",
this.sharedValues.getGson().newBuilder().create().toJsonTree(fromBytesToString(strippedJsonByDelimiter[1].getBytes())));
mainJson.add("httpService",httpService);

return mainJson.toString();

} catch (NumberFormatException e){
sharedValues.getCallbacks().printError("Decompress: " +
e.getMessage());
return "";
}
br.close();
gis.close();
bis.close();
return sb.toString();

}


private void parseCustomMessage(String httpQueryString) {
try {
HttpRequestResponse httpRequestResponse = this.sharedValues.getGson().fromJson(
decompress(Base64.getDecoder().decode(httpQueryString.substring(1))),
byte[] Base64Decoded =
Base64.getDecoder().decode(httpQueryString.substring(1));
String decompressedJson =
decompress(Base64Decoded);
this.sharedValues.getCallbacks().printOutput(
"Decompressed: " + decompressedJson);
HttpRequestResponse httpRequestResponse = this.sharedValues.getGson().fromJson(decompressedJson,
HttpRequestResponse.class);
this.sharedValues.getCallbacks().sendToRepeater(
httpRequestResponse.getHttpService().getHost(),
Expand All @@ -107,7 +152,11 @@ private void parseCustomMessage(String httpQueryString) {
httpRequestResponse.getRequest(),
"BurpTC Link Payload");
} catch (Exception e) {
sharedValues.getCallbacks().printError(e.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sharedValues.getCallbacks().printError("ParseCustomMessage: " +
sw);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/teamextension/HttpRequestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public HttpRequestResponse(IHttpRequestResponse copy) {

@Override
public byte[] getRequest() {
// if(request == null) {
// return new byte[]{};
// }
return request;
}

Expand All @@ -41,6 +44,9 @@ public void setRequest(byte[] message) {

@Override
public byte[] getResponse() {
if(response == null) {
return new byte[]{};
}
return response;
}

Expand Down
6 changes: 6 additions & 0 deletions src/teamextension/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public HttpService() {

@Override
public String getHost() {
if(host == null){
return "";
}
return host;
}

Expand All @@ -32,6 +35,9 @@ public int getPort() {

@Override
public String getProtocol() {
if(protocol == null){
return "";
}
return protocol;
}
}

0 comments on commit 08f5ce6

Please sign in to comment.