id: change-default-port

info:
  name: Change SSH Default Port
  author: pussycat0x
  severity: info
  description: |
    Reduces Automated Attacks: Changing the default port can help avoid most automated attacks that target port 22.
  remediation: |
    Set Port 2222 in /etc/ssh/sshd_config to change the default SSH port and restart the SSH service.
  reference:
    - https://vishalraj82.medium.com/hardening-openssh-security-37f5d634015f
    - https://gcore.com/learning/how-to-change-ssh-port/
  metadata:
    verified: true
  tags: audit,config,ssh,auth

javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      var m = require("nuclei/ssh");
      var c = m.SSHClient();
      c.Connect(Host,Port,User,Pass);
      const sshConfig = c.Run('cat /etc/ssh/sshd_config')
      sshConfig
      let result = "";
      if (sshConfig.includes('#Port 22') && !sshConfig.includes('Port  ')) {
      result += "Default SSH Port Detected; ";
       }
      else{
      exit();
      }
      result

    args:
      Host: "{{Host}}"
      Port: "22"
      User: "{{usernames}}"
      Pass: "{{passwords}}"

    matchers:
      - type: dsl
        dsl:
          - "success == true"

    extractors:
      - type: dsl
        dsl:
          - response
# digest: 4a0a00473045022100b8bb63087a69512d1c645d43a523120deacae3ae090c2bf1980a4fc7b582affb0220784836e7371a3dcab75a9b1998013603031386aa936a345b42a3581a8e336e9d:922c64590222798bb761d5b6d8e72950