id: privesc-nsenter

info:
  name: Nsenter - Privilege Escalation
  author: daffainfo
  severity: high
  description: |
    nsenter is a command-line utility in Linux that allows a user to enter into an existing namespace. It is commonly used for troubleshooting and managing namespaces in containerized environments. By using nsenter, users can enter into a specific namespace and execute commands within that namespace, which can be helpful for various system administration tasks.
  reference:
    - https://gtfobins.github.io/gtfobins/nsenter/
  metadata:
    verified: true
    max-request: 3
  tags: code,linux,nsenter,privesc,local

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

  - engine:
      - sh
      - bash
    source: |
      nsenter whoami

  - engine:
      - sh
      - bash
    source: |
      sudo nsenter 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: 4b0a004830460221008bd4125fd80c48fa98d3c5ccb0b0a5ed44c771a6b53ff6b496c9e15836ba48c5022100a2aa9667f4688e889be09561ede2e6bfe414b25f107aee2f3370d5e34abfd1e4:922c64590222798bb761d5b6d8e72950