Skip to content

Commit 06a84b6

Browse files
authored
Merge pull request #34 from gdgd009xcd/JOHANNES240325
## [v0.8.9] - 2024-03-28
2 parents 9ca1ffe + 7ec667b commit 06a84b6

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

addOns/customactivescan/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this add-on will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5+
6+
## [v0.8.9] - 2024-03-28
7+
### Changed
8+
- bugfix: Changed to correctly encode and decode the HttpRequest body based on Content-Encoding.
9+
510
## [v0.8.8] - 2024-03-12
611
### Added
712
- new feature: Supported URLEncoded(%XX) value within pattern for embeding binary data on the request. see [this](https://github.com/gdgd009xcd/CustomActiveScanForZAP/wiki/2.0.-CustomActiveScan-Main-Panel/#5-decode-urlencodedxx-value-check-box)

addOns/customactivescan/customactivescan.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.zaproxy.gradle.addon.AddOnStatus
22

33

4-
version = "0.8.8"
4+
version = "0.8.9"
55
description = "a Active Scanner with custmizable rules"
66

77
val jar by tasks.getting(Jar::class) {

addOns/customactivescan/src/main/java/org/zaproxy/zap/extension/customactivescan/CustomSQLInjectionScanRule.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ private void setPatternToHttpMessage(
16611661
UUID uuid = UUIDGenerator.getUUID();
16621662
String embedDummy = "X___" + uuid.toString() + "~~~Y";
16631663
setParameter(msg2, paramName, embedDummy);
1664-
byte[] bodyBytes = msg2.getRequestBody().getBytes();
1664+
byte[] bodyBytes = msg2.getRequestBody().getContent();
16651665
String charsetName = msg2.getRequestBody().getCharset();
16661666
Charset charset = Charset.forName(charsetName);
16671667
LOGGER4J.debug("embed charset:" + charset);
@@ -1687,7 +1687,7 @@ private void setPatternToHttpMessage(
16871687
keyString.getBytes(StandardCharsets.UTF_8),
16881688
binBytes.getBytes());
16891689
byte[] outputBodyBytes = replaceByteSequence.action(0);
1690-
httpMessage.setRequestBody(outputBodyBytes);
1690+
httpMessage.getRequestBody().setContent(outputBodyBytes);
16911691
}
16921692
break;
16931693
case NameValuePair.TYPE_GRAPHQL_INLINE:// inline arguments in GRAPH QL
@@ -1719,6 +1719,7 @@ private void setPatternToHttpMessage(
17191719
String charsetName = msg2.getRequestBody().getCharset();
17201720
Charset charset = Charset.forName(charsetName);
17211721
LOGGER4J.debug("embed charset:" + charset);
1722+
17221723
boolean isURLEncoded = false;
17231724
org.apache.commons.httpclient.URI uri = msg2.getRequestHeader().getURI();
17241725
try {
@@ -1785,7 +1786,7 @@ private void setPatternToHttpMessage(
17851786
if (isURLEncoded) {
17861787
setEscapedParameter(httpMessage, paramName, paramValueEncoded);
17871788
} else {
1788-
byte[] bodyBytes = msg2.getRequestBody().getBytes();
1789+
byte[] bodyBytes = msg2.getRequestBody().getContent();//this decode request body with using Content-Encoding method and return it.
17891790
ParmGenBinUtil replaceBytes = new ParmGenBinUtil(originalValue.getBytes(charset));
17901791
if (isConvertURLDecodedValue) {
17911792
PartialURLDecodeISO8859_1ToBytes partialURLDecodeISO88591ToBytes =
@@ -1802,7 +1803,8 @@ private void setPatternToHttpMessage(
18021803
embedDummy.getBytes(StandardCharsets.UTF_8),
18031804
replaceBytes.getBytes());
18041805
byte[] outputBodyBytes = replaceByteSequence.action(0);
1805-
httpMessage.setRequestBody(outputBodyBytes);
1806+
1807+
httpMessage.getRequestBody().setContent(outputBodyBytes);// This encode specified binary with using the Content-Encoding method and set it to request body.
18061808
}
18071809
}
18081810
}
@@ -1832,7 +1834,7 @@ private void embedParamValueToRequestBodyAsBytes(
18321834
UUID uuid = UUIDGenerator.getUUID();
18331835
String embedDummy = "X___" + uuid.toString() + "~~~Y";
18341836
setParameter(msg2, paramName, embedDummy);
1835-
byte[] bodyBytes = msg2.getRequestBody().getBytes();
1837+
byte[] bodyBytes = msg2.getRequestBody().getContent();
18361838
String charsetName = msg2.getRequestBody().getCharset();
18371839
Charset charset = Charset.forName(charsetName);
18381840
LOGGER4J.debug("embed charset:" + charset);
@@ -1850,7 +1852,7 @@ private void embedParamValueToRequestBodyAsBytes(
18501852
embedDummy.getBytes(StandardCharsets.UTF_8),
18511853
binBuffer.getBytes());
18521854
byte[] outputBodyBytes = replaceByteSequence.action(0);
1853-
httpMessage.setRequestBody(outputBodyBytes);
1855+
httpMessage.getRequestBody().setContent(outputBodyBytes);
18541856
}
18551857

18561858
private String getEscapedParamValueUTF8(String originalValue, String patternValue) {

addOns/customactivescan/src/main/java/org/zaproxy/zap/extension/customactivescan/HttpMessageWithLCSResponse.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,26 @@ private String getWholeMessageString(HttpMessage httpMessage) {
307307
return originalMessageString;
308308
}
309309

310-
310+
/**
311+
* update request body with bodyBytes and update Content-Length with bodyBytes.length
312+
* this method may not need because plugin's SendAndReceive method always update Content-Length by calling updateRequestContentLength.
313+
*
314+
* @param message
315+
* @param bodyBytes
316+
*/
317+
public static void updateRequestContent(HttpMessage message, byte[] bodyBytes) {
318+
message.getRequestBody().setContent(bodyBytes);
319+
int bodyLength = message.getRequestBody().length();
320+
String method = message.getRequestHeader().getMethod();
321+
if (bodyLength == 0
322+
&& (HttpRequestHeader.GET.equalsIgnoreCase(method)
323+
|| HttpRequestHeader.CONNECT.equalsIgnoreCase(method)
324+
|| HttpRequestHeader.DELETE.equalsIgnoreCase(method)
325+
|| HttpRequestHeader.HEAD.equalsIgnoreCase(method)
326+
|| HttpRequestHeader.TRACE.equalsIgnoreCase(method))) {
327+
message.getRequestHeader().setHeader(HttpHeader.CONTENT_LENGTH, null);
328+
return;
329+
}
330+
message.getRequestHeader().setContentLength(bodyLength);
331+
}
311332
}

addOns/customactivescan/src/main/javahelp/help/contents/help.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <H2>About</H2>
1414

1515
<H2>Description</H2>
1616
<UL>
17-
<B>These below links go to the page under https://github.com/gdgd009xcd/AutoMacroBuilderForZAP/wiki/</B><P></P>
17+
<B>These below links go to the page under https://github.com/gdgd009xcd/CustomActiveScanForZAP</B><P></P>
1818
<LI><A HREF="https://github.com/gdgd009xcd/CustomActiveScanForZAP#customactivescanforzap">Overview</A>
1919
<LI><A HREF="https://github.com/gdgd009xcd/CustomActiveScanForZAP/wiki/1.0.-Basic-Usage">Basic Usage</A>
2020
</UL>

0 commit comments

Comments
 (0)