id: privesc-dc

info:
  name: dc - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    dc is a command-line calculator in Unix and Unix-like operating systems. It uses reverse Polish notation (RPN) and provides a simple and efficient way to perform arithmetic operations from the command line. It can be used for basic and advanced mathematical calculations, making it a handy tool for scripting and quick calculations in the terminal.
  reference:
    - https://gtfobins.github.io/gtfobins/dc/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,dc,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      dc -e '!whoami'

  - engine:
      - sh
      - bash
    source: |
      sudo dc -e '!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: 4a0a0047304502201acdf1dadca97a95fb57db52fcdf888e35702ff28eb21f4f835d123a3771d5b7022100c92ab141e6e080b7d64def2785e6c81d163d4f1bbd235e8f38e1d77d625882f4:922c64590222798bb761d5b6d8e72950