From 6d7a347aff08e921eeb6e8846ccca3815716bf89 Mon Sep 17 00:00:00 2001 From: Espen Date: Fri, 19 Nov 2021 10:22:53 +0100 Subject: [PATCH 1/3] Moved ssh alg. from init() to Init(). Fix issue 191 --- modules/ssh.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/ssh.go b/modules/ssh.go index 5248c38c..bdbc8507 100644 --- a/modules/ssh.go +++ b/modules/ssh.go @@ -33,14 +33,10 @@ type SSHScanner struct { func init() { var sshModule SSHModule - cmd, err := zgrab2.AddCommand("ssh", "SSH Banner Grab", sshModule.Description(), 22, &sshModule) + _, err := zgrab2.AddCommand("ssh", "SSH Banner Grab", sshModule.Description(), 22, &sshModule) if err != nil { log.Fatal(err) } - s := ssh.MakeSSHConfig() //dummy variable to get default for host key, kex algorithm, ciphers - cmd.FindOptionByLongName("host-key-algorithms").Default = []string{strings.Join(s.HostKeyAlgorithms, ",")} - cmd.FindOptionByLongName("kex-algorithms").Default = []string{strings.Join(s.KeyExchanges, ",")} - cmd.FindOptionByLongName("ciphers").Default = []string{strings.Join(s.Ciphers, ",")} } func (m *SSHModule) NewFlags() interface{} { @@ -71,6 +67,18 @@ func (s *SSHScanner) Init(flags zgrab2.ScanFlags) error { } func (s *SSHScanner) InitPerSender(senderID int) error { + sc := ssh.MakeSSHConfig() //dummy variable to get default for host key, kex algorithm, ciphers + f, _ := flags.(*SSHFlags) + s.config = f + if len(s.config.Ciphers) == 0 { + s.config.Ciphers = string(strings.Join(sc.Ciphers, ",")) + } + if len(s.config.KexAlgorithms) == 0 { + s.config.KexAlgorithms = string(strings.Join(sc.KeyExchanges, ",")) + } + if len(s.config.HostKeyAlgorithms) == 0 { + s.config.HostKeyAlgorithms = string(strings.Join(sc.HostKeyAlgorithms, ",")) + } return nil } From 324cfc74dfe8de4ec4bd1d8b353b68179a3bd4e7 Mon Sep 17 00:00:00 2001 From: Espen Date: Fri, 19 Nov 2021 10:36:06 +0100 Subject: [PATCH 2/3] Fixed error. Moved ssh key init to Init() --- modules/ssh.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/ssh.go b/modules/ssh.go index bdbc8507..ed13b647 100644 --- a/modules/ssh.go +++ b/modules/ssh.go @@ -61,12 +61,6 @@ func (f *SSHFlags) Help() string { } func (s *SSHScanner) Init(flags zgrab2.ScanFlags) error { - f, _ := flags.(*SSHFlags) - s.config = f - return nil -} - -func (s *SSHScanner) InitPerSender(senderID int) error { sc := ssh.MakeSSHConfig() //dummy variable to get default for host key, kex algorithm, ciphers f, _ := flags.(*SSHFlags) s.config = f @@ -79,6 +73,11 @@ func (s *SSHScanner) InitPerSender(senderID int) error { if len(s.config.HostKeyAlgorithms) == 0 { s.config.HostKeyAlgorithms = string(strings.Join(sc.HostKeyAlgorithms, ",")) } + f, _ := flags.(*SSHFlags) + return nil +} + +func (s *SSHScanner) InitPerSender(senderID int) error { return nil } From 05dd5507f7dc940a22462c9e82140665e561e75b Mon Sep 17 00:00:00 2001 From: Espen Date: Fri, 19 Nov 2021 10:39:04 +0100 Subject: [PATCH 3/3] Fixed error. Removed extra f, _ := flags.(*SSHFlags) --- modules/ssh.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ssh.go b/modules/ssh.go index ed13b647..3d065c35 100644 --- a/modules/ssh.go +++ b/modules/ssh.go @@ -73,7 +73,6 @@ func (s *SSHScanner) Init(flags zgrab2.ScanFlags) error { if len(s.config.HostKeyAlgorithms) == 0 { s.config.HostKeyAlgorithms = string(strings.Join(sc.HostKeyAlgorithms, ",")) } - f, _ := flags.(*SSHFlags) return nil }