From 892e1e3c87bb4f004a3831db42df266c9f79d6f3 Mon Sep 17 00:00:00 2001 From: Nils Hanke Date: Wed, 23 Mar 2022 13:12:56 -0700 Subject: [PATCH] Use bodyTextLen instead of readLen for FailHTTPToHTTPS logic respContentLength can be -1 in certain cases, in which case readLen will be maxReadLen for the current scan. This will, however, then cause the FailHTTPToHTTPS if-condition to fail as the readLen is > 1024, even though the body content length can be in this range. So let us use the actual body length for the check to avoid this issue. --- modules/http/scanner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/http/scanner.go b/modules/http/scanner.go index 6992b7ee..6e299de5 100644 --- a/modules/http/scanner.go +++ b/modules/http/scanner.go @@ -549,7 +549,8 @@ func (scan *scan) Grab() *zgrab2.ScanError { } // Application-specific logic for retrying HTTP as HTTPS; if condition matches, return protocol error - if scan.scanner.config.FailHTTPToHTTPS && scan.results.Response.StatusCode == 400 && readLen < 1024 && readLen > 24 { + bodyTextLen := int64(len(bodyText)) + if scan.scanner.config.FailHTTPToHTTPS && scan.results.Response.StatusCode == 400 && bodyTextLen < 1024 && bodyTextLen > 24 { // Apache: "You're speaking plain HTTP to an SSL-enabled server port" // NGINX: "The plain HTTP request was sent to HTTPS port" var sliceLen int64 = 128 @@ -557,7 +558,6 @@ func (scan *scan) Grab() *zgrab2.ScanError { sliceLen = readLen } - bodyTextLen := int64(len(bodyText)) if bodyTextLen < sliceLen { sliceLen = bodyTextLen }