Skip to content

Commit

Permalink
解决合并存在注释的分块内容失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ny1 committed Aug 5, 2021
1 parent 9168c1c commit 1c02b04
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/main/java/burp/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* 编码解码类,负责对目标请求进行编码解码
*/
public class Transfer {
public static final byte http_0 = 48;
public static final byte http_r = 13; // \r
public static final byte http_n = 10; // \n
/**
* 对请求包进行chunked编码
* @param requestResponse 要处理的请求响应对象
Expand Down Expand Up @@ -110,7 +113,7 @@ public static byte[] splitReqBody(byte[] reqBody,int minChunkedLen,int maxChunke
byte_encoding_body = joinByteArray(byte_encoding_body,b);
byte_encoding_body = joinByteArray(byte_encoding_body,"\r\n".getBytes());
}
byte_encoding_body = joinByteArray(byte_encoding_body,"0\n\n".getBytes());
byte_encoding_body = joinByteArray(byte_encoding_body,"0\r\n\r\n".getBytes());
return byte_encoding_body;
}

Expand All @@ -134,7 +137,14 @@ public static byte[] mergeReqBody(byte[] chunkedReqBody){
byte[] chunkedLen = new byte[length];
System.arraycopy(chunkedReqBody, j, chunkedLen, 0, length);
j = i + 2;
int cLen = Util.hexToDecimal(new String(chunkedLen));
int cLen;
String strChunkedLen = new String(chunkedLen);
if(strChunkedLen.contains(";")){// 如果存在注释
cLen = Util.hexToDecimal(strChunkedLen.substring(0,strChunkedLen.indexOf(";")));
}else{
cLen = Util.hexToDecimal(strChunkedLen);
}

// 根据分块长度获取分块内容
byte[] chunked = new byte[cLen];
System.arraycopy(chunkedReqBody, j, chunked, 0, cLen);
Expand All @@ -145,9 +155,11 @@ public static byte[] mergeReqBody(byte[] chunkedReqBody){
}

// 处理结尾0\n\n
if(chunkedReqBody[i] == "0".getBytes()[0]
&& chunkedReqBody[i+1] == "\n".getBytes()[0]
&& chunkedReqBody[i+2] == "\n".getBytes()[0]){
if(chunkedReqBody[i] == http_0
&& chunkedReqBody[i+1] == http_r
&& chunkedReqBody[i+2] == http_n
&& chunkedReqBody[i+2] == http_r
&& chunkedReqBody[i+3] == http_n){
break;
}
}
Expand Down
64 changes: 62 additions & 2 deletions src/main/test/TransferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,69 @@ public static void TestSplitReqBody(){

}

public static void TestOk(){
String body = "3;IWFbM4mTXBxSq7cjU2ZOrdg\r\n" +
"ser\r\n" +
"1;XcM0dC2gATfT2cMaX\r\n" +
"v\r\n" +
"1;HL3RZyqc2kk5E2ZRu0djQOu\r\n" +
"i\r\n" +
"3;AwPNeJDu\r\n" +
"ce=\r\n" +
"1;kvFfaa9\r\n" +
"h\r\n" +
"1;VwZXqUfdKcL\r\n" +
"t\r\n" +
"3;g0IdgC\r\n" +
"tps\r\n" +
"2;EHIqC5t\r\n" +
"%3\r\n" +
"3;6P49NW26kLv\r\n" +
"A%2\r\n" +
"1;Mg1IZGijv5keoWV3Pex\r\n" +
"F\r\n" +
"2;gYn0nPRoS5xfLEvE\r\n" +
"%2\r\n" +
"1;XqBYhlH0KbqUD1TKk\r\n" +
"F\r\n" +
"1;ToE8BVCsBm5VKj0C\r\n" +
"y\r\n" +
"2;2FLXZwRSXUAQ6ilT5pggbHUE\r\n" +
"un\r\n" +
"1;BZoEH3S3GqHU4Gqj0QxKj3\r\n" +
".\r\n" +
"1;F5ddaFsfKx1MTjMEedJh\r\n" +
"s\r\n" +
"2;eqijFldn5Cga4tLA\r\n" +
"cn\r\n" +
"3;Vcb0BzTALRJKv6ji9duogGfwO\r\n" +
"yw.\r\n" +
"2;BVGq0Efdg\r\n" +
"co\r\n" +
"2;fvCiZ\r\n" +
"m%\r\n" +
"3;12ViYBzk3q67b\r\n" +
"2Fp\r\n" +
"1;Lb1uT4\r\n" +
"o\r\n" +
"1;brgH3py6bSqWI1qK\r\n" +
"r\r\n" +
"3;pNtzewGd2XM3lAH\r\n" +
"tal\r\n" +
"3;5NAfSvlZmv0D\r\n" +
"%2F\r\n" +
"0\n" +
"\n";

byte[] newBody = Transfer.mergeReqBody(body.getBytes());
System.out.println(new String(newBody));

}

public static void main(String[] args) {
TestMergeReqBody();
TestSplitReqBody();
// TestMergeReqBody();
// TestSplitReqBody();
TestOk();
}
}

Expand Down

0 comments on commit 1c02b04

Please sign in to comment.