id: privesc-stdbuf

info:
  name: stdbuf - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    The stdbuf command is used to modify the buffering operations of another command. It can be used to adjust the input/output buffering of a command, which can be useful for controlling the flow of data and improving the performance of certain operations.
  reference:
    - https://gtfobins.github.io/gtfobins/stdbuf/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,stdbuf,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      stdbuf -i0 whoami

  - engine:
      - sh
      - bash
    source: |
      sudo stdbuf -i0 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: 4b0a0048304602210085cba2a30005f4f9c23a11929f87585140347123e6bec9a5819aa7c245f601f7022100a3b46722f3fa1c936780bd46b5b1ab2003171ee49e74bab5877174a53fad9fab:922c64590222798bb761d5b6d8e72950