Skip to content

Commit

Permalink
Adds --hex option to banner module (#325)
Browse files Browse the repository at this point in the history
Conversion of binary responses to UTF8 occasionally yields U+FFFD [replacement characters](https://en.wikipedia.org/wiki/Specials_(Unicode_block))
(see #197, #263). As a result it is not possible to restore the original response.

This introduces the `--hex` option to the `banner` module. When enabled,
the `banner` value will contain server response in hex.

Refs #197, #263

#325
  • Loading branch information
svbatalov authored Aug 29, 2021
1 parent a70b933 commit 1161167
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/banner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net"
"regexp"
"strconv"
"encoding/hex"

"github.com/zmap/zgrab2"
)
Expand All @@ -24,6 +25,7 @@ type Flags struct {
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. "`
zgrab2.TLSFlags
}

Expand Down Expand Up @@ -179,7 +181,12 @@ func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, inter
if readerr != io.EOF && readerr != nil {
return zgrab2.TryGetScanStatus(readerr), nil, readerr
}
results := Results{Banner: string(ret), Length: len(ret)}
var results Results
if scanner.config.Hex {
results = Results{Banner: hex.EncodeToString(ret), Length: len(ret)}
} else {
results = Results{Banner: string(ret), Length: len(ret)}
}
if scanner.regex.Match(ret) {
return zgrab2.SCAN_SUCCESS, &results, nil
}
Expand Down

0 comments on commit 1161167

Please sign in to comment.