Dropping Kali in your test space
k8s testing with kali linux
Setting up docker
Add User to Docker Group
After installing Docker, add your user to the Docker group to run Docker commands without sudo
.
Add User to Docker Group:
sudo usermod -aG docker $USER
Refresh Group Membership:
newgrp docker
Verify Group Membership:
groups $USER
docker ps
This command lists running containers. We have nothing running as it's a new environment
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
docker run hello-world
The docker run hello-world
command is a simple way to verify that Docker is installed and functioning correctly on your system.
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
start minikube
Download minikube for your architechture
Minikube is an open-source tool that enables you to run a single-node Kubernetes cluster locally on your machine. Minikube runs a Kubernetes cluster in a virtual machine (VM) on your computer, which allows developers to create and manage Kubernetes environments without needing a full-blown, multi-node cluster.
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ minikube start
😄 minikube v1.33.1 on Debian kali-rolling (arm64)
✨ Using the docker driver based on existing profile
👍 Starting "minikube" primary control-plane node in "minikube" cluster
🚜 Pulling base image v0.0.44 ...
🏃 Updating the running docker "minikube" container ...
🐳 Preparing Kubernetes v1.30.0 on Docker 26.1.1 ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
❗ /usr/bin/kubectl is version 1.20.2, which may have incompatibilities with Kubernetes 1.30.0.
▪ Want kubectl v1.30.0? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
get nodes
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 25m v1.30.0
describe node
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl describe node minikube
Name: minikube
Roles: control-plane
Labels: beta.kubernetes.io/arch=arm64
<snip>
Lets create a deployment file and service file for nginx
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Apply the configurations...
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
Verify the deployment and service...
kubectl get deployments
kubectl get services
Getting deployments and services
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 17s
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP **.**.*.* <none> 443/TCP 9m15s
nginx-service LoadBalancer **.***.***.*** <pending> 80:32406/TCP 20s
Now lets get pods
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-77d8468669-s4t8z 1/1 Running 0 41s
nginx-deployment-77d8468669-tm2lr 1/1 Running 0 41s
Creating a kali dockerfile and pushing to docker hub
Here's what we're going to do to get kali pushed to our repo and then deployed
Create the kali dockerfile
Build the docker image
Push that image to Docker Hub
Deploy image to K8s
Apply the deployment to K8s
Create the docker file
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ vim Dockerfile
# Kali Linux latest with useful tools
FROM kalilinux/kali-rolling
# Set working directory to /root
WORKDIR /root
# Change the repository mirror to a known stable one
RUN sed -i 's/http.kali.org/kali.download/g' /etc/apt/sources.list
# Update and install CA certificates
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y ca-certificates
# Install common and useful tools with retries
RUN apt-get update --fix-missing && apt install -y --no-install-recommends \
curl \
wget \
vim \
git \
net-tools \
whois \
netcat-traditional \
pciutils \
python3-pip \
golang \
npm \
kali-tools-top10 \
exploitdb \
man-db \
dirb \
nikto \
wpscan \
uniscan \
lsof \
apktool \
dex2jar \
&& apt-get clean
# Set the default command to run when starting the container
ENTRYPOINT ["/bin/bash"]
Build the docker image
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ docker build -t sx0tt/kali-linux-tools .
Sending build context to Docker daemon 4.608kB
Step 1/6 : FROM kalilinux/kali-rolling
---> 004a2a193e66
Step 2/6 : WORKDIR /root
---> Using cache
---> 3a22277f9680
Step 3/6 : RUN sed -i 's/http.kali.org/kali.download/g' /etc/apt/sources.list
---> Using cache
---> a948ed5547d9
Step 4/6 : RUN apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates
---> Using cache
---> b7b4262177b9
Step 5/6 : RUN apt-get update --fix-missing && apt install -y --no-install-recommends curl wget vim git net-tools whois netcat-traditional pciutils python3-pip golang npm kali-tools-top10 exploitdb man-db dirb nikto wpscan uniscan lsof apktool dex2jar && apt-get clean
---> Running in 78d365f66f35
<...SNIP...>
Removing intermediate container 78d365f66f35
---> 5b031adcec12
Step 6/6 : ENTRYPOINT ["/bin/bash"]
---> Running in b3fd56581133
Removing intermediate container b3fd56581133
---> eaafa11a4876
Successfully built eaafa11a4876
Successfully tagged sx0tt/kali-linux-tools:latest
make sure to substitute your docker hub username and image name
docker build -t <your-docker-username>/<your-image-name> .
Now lets push this to our docker hub repo (this could take a while)
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ docker push sx0tt/kali-linux-tools
Using default tag: latest
The push refers to repository [docker.io/sx0tt/kali-linux-tools]
e9dd2133186b: Pushed
40eb6d0c6f6b: Layer already exists
677de27523b6: Layer already exists
e9ce6db5dc43: Layer already exists
latest: digest: sha256:57af414480fef47f32d1f03cf618b3144e7d0ac1fdbcd07cca1fd44d32d5be1a size: 1162
Once the push is finished lets create a deployment yaml for our image
apiVersion: apps/v1
kind: Deployment
metadata:
name: kali-linux-tools-deployment
spec:
replicas: 1
selector:
matchLabels:
app: kali-linux-tools
template:
metadata:
labels:
app: kali-linux-tools
spec:
containers:
- name: kali-linux-tools
image: your_dockerhub_username/kali-linux-tools:latest
ports:
- containerPort: 80
Deploy the image to k8s
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl apply -f kali-deployment.yaml
deployment.apps/kali-linux-tools-deployment created
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl get pods
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl describe pod <pod-name>
┌──(sx0tt㉿kali-linux)-[~/kube-test]
└─$ kubectl exec -it <pod-name> -c <container-name> -- /bin/bash
Last updated