id: disable-root-login

info:
  name: Disable SSH Root Login
  author: pussycat0x
  severity: high
  description: |
    Disabling direct root login can help prevent unauthorized users from gaining full control over your system.
  remediation: |
    Set PermitRootLogin no in /etc/ssh/sshd_config to disable root login and restart the SSH service.
  reference:
    - https://vishalraj82.medium.com/hardening-openssh-security-37f5d634015f
    - https://www.tecmint.com/disable-or-enable-ssh-root-login-and-limit-ssh-access-in-linux/
  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('PermitRootLogin yes')) {
      result += "Disable SSH Root Login; ";
      }
      else{
      exit();
      }
      result

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

    matchers:
      - type: dsl
        dsl:
          - "success == true"
    extractors:
      - type: dsl
        dsl:
          - response
# digest: 4a0a00473045022100aa61482bf6e32c32117c1183f432c3d4b7df59f098114ccc7569ff25f568e42502206f613044bce918573618fd6ace79bf634f30823e8d9e6e959d3e2199e15e53cb:922c64590222798bb761d5b6d8e72950