From 282fd569928a9cbfe90ed3698af164fb909af056 Mon Sep 17 00:00:00 2001 From: Sergey Batalov Date: Wed, 25 Sep 2024 10:53:30 +0500 Subject: [PATCH 1/3] Make banner read options configurable via CLI --- modules/banner/scanner.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/banner/scanner.go b/modules/banner/scanner.go index 1b268e066..bc6afe651 100644 --- a/modules/banner/scanner.go +++ b/modules/banner/scanner.go @@ -17,6 +17,7 @@ import ( "net" "regexp" "strconv" + "time" "github.com/zmap/zgrab2" ) @@ -24,6 +25,9 @@ import ( // Flags give the command-line flags for the banner module. type Flags struct { zgrab2.BaseFlags + ReadTimeout int `long:"read-timeout" default:"10" description:"Read timeout in milliseconds"` + BufferSize int `long:"buffer-size" default:"8209" description:"Read buffer size in bytes"` + MaxReadSize int `long:"max-read-size" default:"512" description:"Maximum amount of data to read in KiB (1024 bytes)"` Probe string `long:"probe" default:"\\n" description:"Probe to send to the server. Use triple slashes to escape, for example \\\\\\n is literal \\n. Mutually exclusive with --probe-file."` ProbeFile string `long:"probe-file" description:"Read probe from file as byte array (hex). Mutually exclusive with --probe."` Pattern string `long:"pattern" description:"Pattern to match, must be valid regexp."` @@ -177,7 +181,11 @@ func (s *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{} for try := 0; try < s.config.MaxTries; try++ { _, err = conn.Write(s.probe) - data, readErr = zgrab2.ReadAvailable(conn) + data, readErr = zgrab2.ReadAvailableWithOptions(conn, + s.config.BufferSize, + time.Duration(s.config.ReadTimeout)*time.Millisecond, + 0, + s.config.MaxReadSize*1024) if err != nil { continue } From deba94c4f099eb35a96b92c12acc18f618669330 Mon Sep 17 00:00:00 2001 From: Sergey Batalov Date: Wed, 25 Sep 2024 11:52:17 +0500 Subject: [PATCH 2/3] Run gofmt on modules/banner/scanner.go --- modules/banner/scanner.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/banner/scanner.go b/modules/banner/scanner.go index bc6afe651..f3767518e 100644 --- a/modules/banner/scanner.go +++ b/modules/banner/scanner.go @@ -25,19 +25,19 @@ import ( // Flags give the command-line flags for the banner module. type Flags struct { zgrab2.BaseFlags - ReadTimeout int `long:"read-timeout" default:"10" description:"Read timeout in milliseconds"` - BufferSize int `long:"buffer-size" default:"8209" description:"Read buffer size in bytes"` - MaxReadSize int `long:"max-read-size" default:"512" description:"Maximum amount of data to read in KiB (1024 bytes)"` - Probe string `long:"probe" default:"\\n" description:"Probe to send to the server. Use triple slashes to escape, for example \\\\\\n is literal \\n. Mutually exclusive with --probe-file."` - ProbeFile string `long:"probe-file" description:"Read probe from file as byte array (hex). Mutually exclusive with --probe."` - Pattern string `long:"pattern" description:"Pattern to match, must be valid regexp."` - UseTLS bool `long:"tls" description:"Sends probe with TLS connection. Loads TLS module command options."` - MaxTries int `long:"max-tries" default:"1" description:"Number of tries for timeouts and connection errors before giving up. Includes making TLS connection if enabled."` - Hex bool `long:"hex" description:"Store banner value in hex. Mutually exclusive with --base64."` - Base64 bool `long:"base64" description:"Store banner value in base64. Mutually exclusive with --hex."` - MD5 bool `long:"md5" description:"Calculate MD5 hash of banner value."` - SHA1 bool `long:"sha1" description:"Calculate SHA1 hash of banner value."` - SHA256 bool `long:"sha256" description:"Calculate SHA256 hash of banner value."` + ReadTimeout int `long:"read-timeout" default:"10" description:"Read timeout in milliseconds"` + BufferSize int `long:"buffer-size" default:"8209" description:"Read buffer size in bytes"` + MaxReadSize int `long:"max-read-size" default:"512" description:"Maximum amount of data to read in KiB (1024 bytes)"` + Probe string `long:"probe" default:"\\n" description:"Probe to send to the server. Use triple slashes to escape, for example \\\\\\n is literal \\n. Mutually exclusive with --probe-file."` + ProbeFile string `long:"probe-file" description:"Read probe from file as byte array (hex). Mutually exclusive with --probe."` + Pattern string `long:"pattern" description:"Pattern to match, must be valid regexp."` + UseTLS bool `long:"tls" description:"Sends probe with TLS connection. Loads TLS module command options."` + MaxTries int `long:"max-tries" default:"1" description:"Number of tries for timeouts and connection errors before giving up. Includes making TLS connection if enabled."` + Hex bool `long:"hex" description:"Store banner value in hex. Mutually exclusive with --base64."` + Base64 bool `long:"base64" description:"Store banner value in base64. Mutually exclusive with --hex."` + MD5 bool `long:"md5" description:"Calculate MD5 hash of banner value."` + SHA1 bool `long:"sha1" description:"Calculate SHA1 hash of banner value."` + SHA256 bool `long:"sha256" description:"Calculate SHA256 hash of banner value."` zgrab2.TLSFlags } From a94f4d73d6097040cb8da1ad8fd0f27f976a5e3d Mon Sep 17 00:00:00 2001 From: phillip-stephens Date: Mon, 27 Jan 2025 10:00:30 -0800 Subject: [PATCH 3/3] go lint --- modules/banner/scanner.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/banner/scanner.go b/modules/banner/scanner.go index a70755b03..5689d7edb 100644 --- a/modules/banner/scanner.go +++ b/modules/banner/scanner.go @@ -30,16 +30,16 @@ type Flags struct { ReadTimeout int `long:"read-timeout" default:"10" description:"Read timeout in milliseconds"` BufferSize int `long:"buffer-size" default:"8209" description:"Read buffer size in bytes"` MaxReadSize int `long:"max-read-size" default:"512" description:"Maximum amount of data to read in KiB (1024 bytes)"` - Probe string `long:"probe" default:"\\n" description:"Probe to send to the server. Use triple slashes to escape, for example \\\\\\n is literal \\n. Mutually exclusive with --probe-file."` - ProbeFile string `long:"probe-file" description:"Read probe from file as byte array (hex). Mutually exclusive with --probe."` - Pattern string `long:"pattern" description:"Pattern to match, must be valid regexp."` - UseTLS bool `long:"tls" description:"Sends probe with TLS connection. Loads TLS module command options."` - MaxTries int `long:"max-tries" default:"1" description:"Number of tries for timeouts and connection errors before giving up. Includes making TLS connection if enabled."` - Hex bool `long:"hex" description:"Store banner value in hex. Mutually exclusive with --base64."` - Base64 bool `long:"base64" description:"Store banner value in base64. Mutually exclusive with --hex."` - MD5 bool `long:"md5" description:"Calculate MD5 hash of banner value."` - SHA1 bool `long:"sha1" description:"Calculate SHA1 hash of banner value."` - SHA256 bool `long:"sha256" description:"Calculate SHA256 hash of banner value."` + Probe string `long:"probe" default:"\\n" description:"Probe to send to the server. Use triple slashes to escape, for example \\\\\\n is literal \\n. Mutually exclusive with --probe-file."` + ProbeFile string `long:"probe-file" description:"Read probe from file as byte array (hex). Mutually exclusive with --probe."` + Pattern string `long:"pattern" description:"Pattern to match, must be valid regexp."` + UseTLS bool `long:"tls" description:"Sends probe with TLS connection. Loads TLS module command options."` + MaxTries int `long:"max-tries" default:"1" description:"Number of tries for timeouts and connection errors before giving up. Includes making TLS connection if enabled."` + Hex bool `long:"hex" description:"Store banner value in hex. Mutually exclusive with --base64."` + Base64 bool `long:"base64" description:"Store banner value in base64. Mutually exclusive with --hex."` + MD5 bool `long:"md5" description:"Calculate MD5 hash of banner value."` + SHA1 bool `long:"sha1" description:"Calculate SHA1 hash of banner value."` + SHA256 bool `long:"sha256" description:"Calculate SHA256 hash of banner value."` } // Module is the implementation of the zgrab2.Module interface.