id: rw-sudoers

info:
  name: /etc/sudoers writable or readable - Privilege Escalation
  author: daffainfo
  severity: high
  reference:
    - https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html?highlight=%2Fetc%2Fsudoers#etcsudoers-etcsudoersd
  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: 4a0a0047304502204b486f9634aee66597295d7afdc3039538318a8c75cc91e4995945afc621e91f022100bd4700f836ab41d9fa788d3608ec37a8b4df3acd1984170a14b15438eaa1ef60:922c64590222798bb761d5b6d8e72950