Skip to content

Commit

Permalink
move whole protocol to msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
dnet committed Nov 23, 2016
1 parent ecff304 commit 53fbd7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<zipgroupfileset dir="lib" includes="msgpack-core-*.jar"/>
<fileset dir="build">
<include name="burp/BurpExtender.class"/>
<include name="burp/ClientHandler.class"/>
<include name="burp/ClientHandler*.class"/>
</fileset>
</zip>
</target>
Expand Down
46 changes: 16 additions & 30 deletions src/burp/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.*;

import org.msgpack.core.*;
import org.msgpack.value.*;

public class ClientHandler extends Thread {
private final Socket s;
Expand All @@ -21,19 +22,22 @@ public ClientHandler(Socket s, IBurpCollaboratorClientContext ccc,
@Override
public void run() {
try {
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
while (true) {
int cmd = is.read();
System.err.println("cmd = " + cmd);
switch (cmd) {
case 0:
sendPayload(os);
final MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(s.getInputStream());
while (unpacker.hasNext()) {
final Value v = unpacker.unpackValue();
final MessagePacker mbp = MessagePack.newDefaultPacker(os);
switch (v.getValueType()) {
case INTEGER:
switch (v.asIntegerValue().toInt()) {
case 0: mbp.packString(ccc.generatePayload(false)); break;
case 1: mbp.packString(ccc.generatePayload(true)); break;
case 2: mbp.packString(ccc.getCollaboratorServerLocation()); break;
}
mbp.close();
break;
case -1:
return;
default:
handleQuery(os, recvPayload(is, cmd));
case STRING:
handleQuery(mbp, v.asStringValue().asString());
break;
}
}
Expand All @@ -42,16 +46,9 @@ public void run() {
}
}

private void sendPayload(OutputStream os) throws IOException {
String s = ccc.generatePayload(true);
os.write(s.length());
os.write(s.getBytes());
}

private void handleQuery(OutputStream os, String payload) throws IOException {
private void handleQuery(MessagePacker mbp, String payload) throws IOException {
final List<IBurpCollaboratorInteraction> bci =
ccc.fetchCollaboratorInteractionsFor(payload);
final MessagePacker mbp = MessagePack.newDefaultPacker(os);
mbp.packArrayHeader(bci.size());
for (IBurpCollaboratorInteraction interaction : bci) {
final Map<String, String> props = interaction.getProperties();
Expand All @@ -76,15 +73,4 @@ private void handleQuery(OutputStream os, String payload) throws IOException {
}
mbp.close();
}

private String recvPayload(InputStream is, int length) throws IOException {
byte[] buf = new byte[length];
int pos = 0;
do {
int res = is.read(buf, pos, length - pos);
if (res == -1) return null;
pos += res;
} while (pos < length);
return new String(buf);
}
}

0 comments on commit 53fbd7f

Please sign in to comment.