diff --git a/cmd/integration-test/javascript.go b/cmd/integration-test/javascript.go index 6e99b7f84..3fb7e1baa 100644 --- a/cmd/integration-test/javascript.go +++ b/cmd/integration-test/javascript.go @@ -17,15 +17,17 @@ var jsTestcases = []TestCaseInfo{ {Path: "protocols/javascript/net-https.yaml", TestCase: &javascriptNetHttps{}}, {Path: "protocols/javascript/oracle-auth-test.yaml", TestCase: &javascriptOracleAuthTest{}, DisableOn: func() bool { return osutils.IsWindows() || osutils.IsOSX() }}, {Path: "protocols/javascript/vnc-pass-brute.yaml", TestCase: &javascriptVncPassBrute{}}, + {Path: "protocols/javascript/multi-ports.yaml", TestCase: &javascriptMultiPortsSSH{}}, } var ( - redisResource *dockertest.Resource - sshResource *dockertest.Resource - oracleResource *dockertest.Resource - vncResource *dockertest.Resource - pool *dockertest.Pool - defaultRetry = 3 + redisResource *dockertest.Resource + sshResource *dockertest.Resource + oracleResource *dockertest.Resource + vncResource *dockertest.Resource + multiPortsSShResource *dockertest.Resource + pool *dockertest.Pool + defaultRetry = 3 ) type javascriptNetHttps struct{} @@ -167,6 +169,36 @@ func (j *javascriptVncPassBrute) Execute(filePath string) error { return multierr.Combine(errs...) } +type javascriptMultiPortsSSH struct{} + +func (j *javascriptMultiPortsSSH) Execute(filePath string) error { + if sshResource == nil || pool == nil { + // skip test as redis is not running + return nil + } + finalURL := "scanme.sh" + errs := []error{} + for i := 0; i < defaultRetry; i++ { + results := []string{} + var err error + _ = pool.Retry(func() error { + //let ssh server start + time.Sleep(3 * time.Second) + results, err = testutils.RunNucleiTemplateAndGetResults(filePath, finalURL, debug) + return nil + }) + if err != nil { + return err + } + if err := expectResultsCount(results, 1); err == nil { + return nil + } else { + errs = append(errs, err) + } + } + return multierr.Combine(errs...) +} + // purge any given resource if it is not nil func purge(resource *dockertest.Resource) { if resource != nil && pool != nil { diff --git a/cmd/nuclei/ssh.yaml b/cmd/nuclei/ssh.yaml deleted file mode 100644 index afc5115d8..000000000 --- a/cmd/nuclei/ssh.yaml +++ /dev/null @@ -1,31 +0,0 @@ -id: ssh-auth-methods - -info: - name: SSH Auth Methods - Detection - author: Ice3man543 - severity: info - description: | - SSH (Secure Shell) authentication modes are methods used to verify the identity of users and ensure secure access to remote systems. Common SSH authentication modes include password-based authentication, which relies on a secret passphrase, and public key authentication, which uses cryptographic keys for a more secure and convenient login process. Additionally, multi-factor authentication (MFA) can be employed to enhance security by requiring users to provide multiple forms of authentication, such as a password and a one-time code. - reference: - - https://nmap.org/nsedoc/scripts/ssh-auth-methods.html - metadata: - max-request: 1 - shodan-query: product:"OpenSSH" - tags: js,detect,ssh,enum,network - -javascript: - - pre-condition: | - isPortOpen(Host,Port); - code: | - var m = require("nuclei/ssh"); - var c = m.SSHClient(); - var response = c.ConnectSSHInfoMode(Host, Port); - Export(response); - args: - Host: "{{Host}}" - Port: "222,22" - - extractors: - - type: json - json: - - '.UserAuth' \ No newline at end of file diff --git a/pkg/protocols/javascript/js.go b/pkg/protocols/javascript/js.go index 5bfd660c9..2d927555f 100644 --- a/pkg/protocols/javascript/js.go +++ b/pkg/protocols/javascript/js.go @@ -778,7 +778,14 @@ func (request *Request) Type() templateTypes.ProtocolType { func (request *Request) getPorts() []string { for k, v := range request.Args { if strings.EqualFold(k, "Port") { - ports := types.ToStringSlice(strings.Split(types.ToString(v), ",")) + portStr := types.ToString(v) + ports := []string{} + for _, p := range strings.Split(portStr, ",") { + trimmed := strings.TrimSpace(p) + if trimmed != "" { + ports = append(ports, trimmed) + } + } return sliceutil.Dedupe(ports) } }