id: rw-sudoers

info:
  name: /etc/sudoers writable or readable - Privilege Escalation
  author: daffainfo
  severity: high
  reference:
    - https://book.hacktricks.xyz/linux-hardening/privilege-escalation#etc-sudoers-etc-sudoers.d
  metadata:
    verified: true
    max-request: 2
  tags: code,linux,privesc,local

self-contained: true
code:
  - engine:
      - sh
      - bash
    source: |
        whoami

  - engine:
      - sh
      - bash
    source: |
        [ -r "/etc/sudoers" ] || [ -w "/etc/sudoers" ] && echo "Either readable or writable" || echo "Not readable and not writable"

    matchers:
      - type: word
        part: code_1_response
        words:
          - "root"
        negative: true

      - type: word
        part: code_2_response
        words:
          - "Either readable or writable"

      - type: word
        part: code_2_response
        words:
          - "Not readable and not writable"
        negative: true
# digest: 490a004630440220058488f0abb109eeda0bb09699d34242875b4af49c51688db2197fd166f508e0022048ed2cfffb8b7b256a3eb1710ebf6a77dc391cc0d20314008b321708803f4881:922c64590222798bb761d5b6d8e72950