id: motd-configured-properly-check

info:
  name: Ensure Message of the Day is Configured Properly
  author: Th3l0newolf
  severity: low
  description: |
    This template checks whether the Message of the Day (MOTD) is configured
    without exposing system information.
  remediation: |
    Edit `/etc/motd` and remove any operating system, kernel, architecture,
    or version information that could disclose system details.
  reference:
    - https://www.cisecurity.org/benchmark/ubuntu_linux
  tags: cis,linux,ubuntu,motd,banner,audit
  metadata:
    verified: true

self-contained: true

code:
  - engine:
      - bash
    args:
      - "-c"
      - |
        os_id=$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed 's/"//g')

        if grep -E -i "(\\\v|\\\r|\\\m|\\\s|$os_id)" /etc/motd >/dev/null 2>&1; then
          echo "[motd-configured-properly-check:Policy-Fail] [/etc/motd contains system information] [CIS_FAIL] [low]"
        else
          echo "[motd-configured-properly-check:Policy-Pass] [/etc/motd is properly configured] [CIS_PASS] [low]"
        fi

    matchers:
      - type: word
        name: policy-pass
        words:
          - "Policy-Pass"

      - type: word
        name: policy-fail
        words:
          - "Policy-Fail"
# digest: 4a0a0047304502205a5f2adda2516b58a427743cc99efc6ebbb0ecde6a4c1675c8b74c47b485913d022100c0fc56c0137edea5823b5e5f0594b7f64e062c607da5c940a903cd81e6fb2dd4:922c64590222798bb761d5b6d8e72950