Example code for module 5
Below are several code examples designed to support the concepts in Module 5: Building Your Own Ethical Hacking Lab – A Step-by-Step Guide. These examples help automate common lab setup tasks and testing within your controlled, isolated environment. Always use these examples on systems you own or on lab networks where you have explicit permission.
Example 1: Vagrantfile for Setting Up Your Ethical Hacking Lab
This Vagrantfile sets up a simple lab with two virtual machines on a private network: one for your penetration testing platform (using Kali Linux) and one as a vulnerable target (using Ubuntu). You can use VirtualBox (or another provider) to run these VMs.
Usage:
Run vagrant up
in the directory containing this Vagrantfile. This will download the necessary images, create the VMs, and configure them on a private network so that they can communicate with one another.
Example 2: Bash Script to Update and Configure Your Kali Linux VM
This shell script automates the process of updating the Kali Linux system and installing a set of additional penetration testing tools. You can run it on your Kali VM to ensure your lab environment is current.
Usage:
Save the script as update_kali.sh
, make it executable with chmod +x update_kali.sh
, then run it using ./update_kali.sh
.
Example 3: Bash Script to Take a Snapshot of a VirtualBox VM
Before performing major tests or experiments, it’s good practice to take a snapshot of your VM. This script uses VirtualBox’s command-line tool (VBoxManage
) to create a snapshot of a specified VM.
Usage:
Save the script as snapshot_lab.sh
, give it executable permissions (chmod +x snapshot_lab.sh
), and run it from the command line.
Example 4: Python Script to Test Connectivity Between Lab Machines
This Python script checks connectivity between your lab VMs by pinging their IP addresses. It’s a simple way to ensure that your network configuration is correct.
Usage:
Run the script with python3 connectivity_check.py
to see the ping results from each host.
Final Notes
These code examples provide practical steps to help you build and manage your own ethical hacking lab:
Vagrantfile: Quickly sets up a multi-VM lab environment.
Bash Scripts: Automate system updates, tool installations, and snapshot management.
Python Script: Verifies network connectivity within your lab.
By following these examples and tailoring them to your specific needs, you’ll create a safe, controlled environment to practice penetration testing and further develop your ethical hacking skills. Remember to always work within authorized, legal, and isolated environments.
Happy lab building, and keep learning!