id: insecure-sudoers-permissions

info:
  name: macOS Insecure /etc/sudoers Permissions
  author: geeknik
  severity: high
  description: |
    Audits permissions on the /etc/sudoers file that defines which users can run commands with root privileges on macOS.
  impact: |
    Insecure permissions on /etc/sudoers could allow unauthorized users to modify the file and grant themselves root privileges.
  remediation: |
    Ensure that the /etc/sudoers file is owned by root with a system group (wheel, admin, etc.) and has permissions of 0440 or more restrictive.
  tags: macos,audit,local,security,sudo

self-contained: true

code:
  - engine:
      - sh
      - bash
    source: |
      ls -l /etc/sudoers 2>&1
    matchers-condition: and
    matchers:
      - type: status
        status:
          - 0
      - type: regex
        regex:
          - "^-r--r-----\\s+\\d+\\s+root\\s+\\w+"
        negative: true
# digest: 4b0a0048304602210097a287244d9ed09ffb331116f32802392d11aaa8fb0213fc39c35c24166d8beb022100bd0f5ae8e37b1081db8f56616615959457283c1558406ddcb720f041b2aaa582:922c64590222798bb761d5b6d8e72950