id: idle-timeout-interval

info:
  name: Set SSH Idle Timeout Interval
  author: pussycat0x
  severity: low
  description: |
    Missing an SSH idle timeout interval can lead to security risks by allowing unattended sessions to remain open, increasing the chance of unauthorized access or session hijacking.
  remediation: |
    Set ClientAliveInterval 300 and ClientAliveCountMax 0 in /etc/ssh/sshd_config to enforce an idle timeout and restart the SSH service.
  reference:
    - https://vishalraj82.medium.com/hardening-openssh-security-37f5d634015f
    - https://support.forcepoint.com/s/article/000015900
  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('#ClientAliveInterval') && sshConfig.includes('#ClientAliveCountMax') && !sshConfig.includes('ClientAliveInterval  ') && !sshConfig.includes('ClientAliveCountMax  ')){
      result += "Set SSH Idle Timeout Interval";
      }
      else{
      exit();
      }
      result

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

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

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