@@ -132,7 +132,7 @@ func (flags *Flags) Help() string {
132
132
}
133
133
134
134
// Protocol returns the protocol identifer for the scanner.
135
- func (s * Scanner ) Protocol () string {
135
+ func (scanner * Scanner ) Protocol () string {
136
136
return "http"
137
137
}
138
138
@@ -143,13 +143,13 @@ func (scanner *Scanner) Init(flags zgrab2.ScanFlags) error {
143
143
144
144
if fl .ComputeDecodedBodyHashAlgorithm == "sha1" {
145
145
scanner .decodedHashFn = func (body []byte ) string {
146
- raw_hash := sha1 .Sum (body )
147
- return fmt .Sprintf ("sha1:%s" , hex .EncodeToString (raw_hash [:]))
146
+ rawHash := sha1 .Sum (body )
147
+ return fmt .Sprintf ("sha1:%s" , hex .EncodeToString (rawHash [:]))
148
148
}
149
149
} else if fl .ComputeDecodedBodyHashAlgorithm == "sha256" {
150
150
scanner .decodedHashFn = func (body []byte ) string {
151
- raw_hash := sha256 .Sum256 (body )
152
- return fmt .Sprintf ("sha256:%s" , hex .EncodeToString (raw_hash [:]))
151
+ rawHash := sha256 .Sum256 (body )
152
+ return fmt .Sprintf ("sha256:%s" , hex .EncodeToString (rawHash [:]))
153
153
}
154
154
} else if fl .ComputeDecodedBodyHashAlgorithm != "" {
155
155
log .Panicf ("Invalid ComputeDecodedBodyHashAlgorithm choice made it through zflags: %s" , scanner .config .ComputeDecodedBodyHashAlgorithm )
@@ -239,18 +239,35 @@ func (scan *scan) dialContext(ctx context.Context, network string, addr string)
239
239
240
240
// getTLSDialer returns a Dial function that connects using the
241
241
// zgrab2.GetTLSConnection()
242
- func (scan * scan ) getTLSDialer (t * zgrab2.ScanTarget ) func (net , addr string ) (net.Conn , error ) {
243
- return func (net , addr string ) (net.Conn , error ) {
244
- outer , err := scan .dialContext (context .Background (), net , addr )
242
+ func (scan * scan ) getTLSDialer (t * zgrab2.ScanTarget ) func (network , addr string ) (net.Conn , error ) {
243
+ return func (network , addr string ) (net.Conn , error ) {
244
+ outer , err := scan .dialContext (context .Background (), network , addr )
245
245
if err != nil {
246
246
return nil , err
247
247
}
248
-
249
248
cfg , err := scan .scanner .config .TLSFlags .GetTLSConfigForTarget (t )
250
249
if err != nil {
251
250
return nil , err
252
251
}
253
252
253
+ // Set SNI server name on redirects unless --server-name was used (issue #300)
254
+ // - t.Domain is always set to the *original* Host so it's not useful for setting SNI
255
+ // - host is the current target of the request in this context; this is true for the
256
+ // initial request as well as subsequent requests caused by redirects
257
+ // - scan.scanner.config.ServerName is the value from --server-name if one was specified
258
+
259
+ // If SNI is enabled and --server-name is not set, use the target host for the SNI server name
260
+ if ! scan .scanner .config .NoSNI && scan .scanner .config .ServerName == "" {
261
+ host , _ , err := net .SplitHostPort (addr )
262
+ if err != nil {
263
+ log .Errorf ("getTLSDialer(): Something went wrong splitting host/port '%s': %s" , addr , err )
264
+ }
265
+ // RFC4366: Literal IPv4 and IPv6 addresses are not permitted in "HostName"
266
+ if i := net .ParseIP (host ); i == nil {
267
+ cfg .ServerName = host
268
+ }
269
+ }
270
+
254
271
if scan .scanner .config .OverrideSH {
255
272
cfg .SignatureAndHashes = []tls.SigAndHash {
256
273
{0x01 , 0x04 }, // rsa, sha256
@@ -262,7 +279,6 @@ func (scan *scan) getTLSDialer(t *zgrab2.ScanTarget) func(net, addr string) (net
262
279
{0x01 , 0x06 }, // rsa, sha512
263
280
}
264
281
}
265
-
266
282
tlsConn := scan .scanner .config .TLSFlags .GetWrappedConnection (outer , cfg )
267
283
268
284
// lib/http/transport.go fills in the TLSLog in the http.Request instance(s)
@@ -437,6 +453,16 @@ func (scan *scan) Grab() *zgrab2.ScanError {
437
453
encoder , _ , _ := charset .DetermineEncoding (buf .Bytes (), resp .Header .Get ("content_type" ))
438
454
decoder := encoder .NewDecoder ()
439
455
456
+ //"windows-1252" is the default value and will likely not decode correctly
457
+ if certain || encoding != "windows-1252" {
458
+ decoded , decErr := decoder .Bytes (buf .Bytes ())
459
+
460
+ if decErr == nil {
461
+ bodyText = string (decoded )
462
+ decodedSuccessfully = true
463
+ }
464
+ }
465
+
440
466
decoded , decErr := decoder .String (bufAsString )
441
467
442
468
// if the decoder errors out just use the buffer as a string
0 commit comments