Running Kali Linux in a Docker Container

Introduction:
Kali Linux is a popular penetration testing and ethical hacking distribution. With Docker, you can run Kali Linux in a containerized environment, making it easy to experiment and perform security assessments. In this guide, we’ll show you how to run Kali Linux as a Docker container and access it interactively.

Step 1: Install Docker
Before proceeding, make sure you have Docker installed on your system. If you haven’t installed Docker yet, follow the official Docker installation instructions for your operating system.

Step 2: Pull Kali Linux Docker Image
To run Kali Linux, pull the latest Kali Linux Docker image from Docker Hub using the following command:

docker pull kalilinux/kali-rolling

Step 3: Create and Start Kali Linux Container
Run the following command to create and start a Kali Linux container:

docker run -d --name=kalilinux -v kalilinux_data:/data --tty --interactive kalilinux/kali-rolling

Explanation of options used:

  • -d: Run the container in the background (detached mode).
  • --name=kalilinux: Assign the name “kalilinux” to the container for easy management.
  • -v kalilinux_data:/data: Create a Docker volume named “kalilinux_data” and mount it to the /data directory inside the container. This volume allows you to persist data and configuration between container restarts.
  • --tty: Allocate a pseudo-TTY, which enables interactive access to the container’s terminal.
  • --interactive: Keep STDIN open even if not attached. This allows you to interact with the container’s terminal.

Step 4: Access the Kali Linux Container
To access the Kali Linux container interactively, use the following command:

docker exec -it kalilinux bash

This command will attach your current terminal to the running Kali Linux container, providing you with an interactive shell inside the container.

Step 5: Clean Up
If you want to stop and remove the Kali Linux container and the associated volume, use the following commands:

docker stop kalilinux
docker rm kalilinux
docker volume rm kalilinux_data

Conclusion:
You’ve successfully run Kali Linux in a Docker container, allowing you to perform security assessments and penetration testing in an isolated environment. Docker enables easy management and deployment of Kali Linux, making it an excellent choice for testing and experimenting with various tools and configurations.

Happy hacking!




Automating Raspberry Pi Configuration with Ansible

Introduction:
Managing multiple Raspberry Pi devices can be time-consuming and error-prone if done manually. Fortunately, Ansible provides a powerful solution for automating configuration tasks across your Raspberry Pi fleet. In this guide, we’ll walk you through setting up Ansible, creating an inventory, and using playbooks to perform various tasks on your Raspberry Pi devices.

Prerequisites:
Before proceeding, make sure you have Python3 and pip installed on your Raspberry Pi. You can install pip using the following command:

sudo apt install python3-pip

Step 1: Install Ansible
First, let’s install Ansible using pip:

python3 -m pip install --user ansible-core==2.12.3

Step 2: Create Ansible Configuration
Now, create a directory for your Ansible project and add an ansible.cfg file inside it:

mkdir /ansible
vi /ansible/ansible.cfg

Paste the following configuration in the ansible.cfg file:

[defaults]
inventory = inventory
host_key_checking = False

Save the file and exit the editor.

Step 3: Create the Inventory
The inventory file contains information about the hosts (Raspberry Pi devices) you want to manage. Create an inventory file inside the /ansible directory:

vi /ansible/inventory

Add the following content to the inventory file:

[tower]
RPIT1 ansible_host=192.168.0.220
RPIT2 ansible_host=192.168.0.221
RPIT3 ansible_host=192.168.0.222
RPTT4 ansible_host=192.168.0.223

[test]
RPI2GB ansible_host=192.168.0.227

[docker]
RPIDOCKER ansible_host=192.168.0.224

[kali]
RPIKALI ansible_host=192.168.0.226

[zeros]
RPIZEROW ansible_host=192.168.0.228 
RPIZEROW2 ansible_host=192.168.0.225

[all:vars]
ansible_ssh_user=pi ansible_ssh_pass=xxxxxxxxx

This inventory defines groups of hosts (towers, test, docker, kali, and zeros) and sets the SSH username and password to access them.

Step 4: Test Host Reachability
Before proceeding with any configuration, make sure all defined hosts are reachable using Ansible’s ping module:

ansible all -m ping

Step 5: Check OS Information
Retrieve OS information on all clients using the shell module:

ansible all -m shell -a "lsb_release -a"

Step 6: Upgrade Servers
Use a playbook to upgrade all servers:

ansible-playbook -e "target_host=all" update_upgrade.yaml

Step 7: Install Neofetch and Temperature
Create a playbook to install Neofetch and display the system temperature:

ansible-playbook -e "target_host=all" install_neofetch.yaml

Step 8: Shutdown the Tower
Create a playbook to shut down the tower (remember Docker always on):

ansible-playbook -e "target_host=tower" shutdown_now.yaml

Conclusion:
You’ve successfully set up Ansible and used playbooks to automate tasks on your Raspberry Pi devices. Ansible simplifies managing multiple devices and allows you to perform configurations efficiently and consistently. With Ansible, you can now spend less time on repetitive tasks and focus more on your Raspberry Pi projects.

Happy automating!