id: privesc-expect

info:
  name: expect - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    expect is a Unix scripting and testing utility that automates interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, and more. It uses scripts to control interactive applications, making it useful for automating tasks that involve user input.
  reference:
    - https://gtfobins.github.io/gtfobins/expect/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,expect,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      expect -c 'spawn whoami;interact'

  - engine:
      - sh
      - bash
    source: |
      sudo expect -c 'spawn whoami;interact'

    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: 4a0a004730450221009f2596492cad6fcd37c1bda2fc8a14a9af44ec2f0177d5df7eac23a322c04bc7022001fdc068baee73c38fcdc9f126f2b9ad1b5c84b76d7b3fbaa2863802a31aa7a8:922c64590222798bb761d5b6d8e72950