id: privesc-nawk

info:
  name: nawk - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    nawk is an implementation of the AWK programming language. It is a text-processing language that is commonly used for pattern scanning and processing of text files. nawk provides powerful features for data extraction, reporting, and manipulation, making it a valuable tool for text processing tasks in shell scripts and command-line environments.
  reference:
    - https://gtfobins.github.io/gtfobins/nawk/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,nawk,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      nawk 'BEGIN {system("whoami")}'

  - engine:
      - sh
      - bash
    source: |
      sudo nawk 'BEGIN {system("whoami")}'

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

      - type: dsl
        dsl:
          - 'contains(code_2_response, "root")'
          - 'contains(code_3_response, "root")'
        condition: or
# digest: 4b0a00483046022100afce61790c5027e0b4a81e0506e18ad07ac5e8c2c8218f625514bb20d62be2d3022100f2f585eaa88f7f5ae2eb2cd635445b7f5c59889f47a6107636cf1a0b60c3d149:922c64590222798bb761d5b6d8e72950