# 1.2 Setting Up Your Cyber Lab
> Goal: by the end of this section you will have a working Linux VM, essential tools installed (Python, Git, Wireshark, text editor), and a snapshot you can revert to.
> NOTE: If you're on a school or work computer, use a personal machine or cloud VM you own. Don’t install VMs on devices you don’t control.
---
## Overview — which setup to choose?
- **VirtualBox + Ubuntu LTS (recommended for beginners)**
- Stable, easy to use, works on Windows/Mac/Linux.
- Ubuntu is beginner friendly and widely used in labs and tutorials.
- **Kali Linux (optional, for pentesting tools)**
- Kali comes preloaded with many security tools. Best used as a separate VM after you are comfortable with Ubuntu basics.
- If you prefer, you can use **Ubuntu for learning**, and later install individual pentesting tools, or run Kali alongside.
---
## A. Download required software
1. **VirtualBox** (free)
- Download: https://www.virtualbox.org/
- Install like any other app on your OS.

2. **Ubuntu LTS ISO** (e.g., 24.04 LTS or latest LTS)
- Download: https://ubuntu.com/download/desktop

3. (Optional) **Kali Linux ISO** (if you want a pentesting VM later)
- Download: https://kali.org/get-kali/
4. (Optional) **Hash-check tool** — to verify ISO integrity (advanced; optional)
---
## B. Create a new VM in VirtualBox (step-by-step)
### 1. Open VirtualBox → New VM
- Click **New**.
- Name: `ubuntu-lab` (or `kali-lab` if using Kali).
- Type: **Linux**.
- Version: **Ubuntu (64-bit)**.

### 2. Memory (RAM)
- Recommended: **4096 MB (4 GB)** if your host has >=8GB RAM.
- If your laptop has 8 GB total, use 2048 MB to stay safe.
### 3. Create a virtual hard disk
- Choose **Create a virtual hard disk now** → VDI (VirtualBox Disk Image) → **Dynamically allocated**.
- Size: **40 GB** (enough for OS and tools). You can choose 20 GB if space is tight.

### 4. VM settings (before starting)
- Select your VM → **Settings** → **System** tab:
- **Boot Order**: leave Optical then Hard Disk.
- **Enable EFI?** Usually keep unchecked for Ubuntu desktop standard install.
- **Processor**: give it 2 CPU cores (if your host has at least 4).
- **Acceleration**: ensure VT-x/AMD-V is enabled (on host BIOS/UEFI).
- **Display**: increase Video Memory to 128 MB.
- **Network**: Adapter 1 → **Attached to:** NAT (default) — good for internet access.
- Later, for lab exercises that need separate VMs to communicate, use **Host-only Adapter** or **Internal Network**; I’ll explain below.
- **Shared Folders** (optional): set up later if you want to share files between host and VM.

---
## C. Install Ubuntu on the VM
1. Start the VM → it prompts for a startup disk. Choose the **Ubuntu ISO** you downloaded.

2. Follow the Ubuntu installer:
- Language → Install Ubuntu.
- Keyboard layout.
- Updates & other software: choose **Normal installation** (so you get GUI apps). Tick **Download updates while installing** if you have good internet.
- **Installation type**: Erase disk and install Ubuntu (this refers to the virtual disk).
- Create your **username** (e.g., `student`), set password, and remember it.
- Continue until installation completes.
3. When asked, restart the VM. Remove the ISO from the virtual optical drive or choose “Discard” the virtual media.

---
## D. First boot and basic system updates
Once Ubuntu boots into the desktop:
Open **Terminal** (Ctrl+Alt+T) and run:
```bash
# update package lists
sudo apt update
# upgrade packages
sudo apt upgrade -y
# install recommended build tools (optional)
sudo apt install -y build-essential curl wget unzip
```
Take a screenshot of the terminal after `sudo apt update` completes.

**Troubleshooting:**
- If the VM has no internet, check VirtualBox Network settings (NAT should give access). Restart the VM after changing network mode.
---
## E. Install essential tools (Python, Git, Wireshark, VS Code)
### Python 3
Ubuntu includes Python 3. Verify:
```bash
python3 --version
# Example output: Python 3.11.6
```
If it's missing (very rare on desktop Ubuntu):
```bash
sudo apt install -y python3 python3-pip
```
### Git (version control)
```bash
sudo apt install -y git
git --version
```
Set your Git identity (replace with your name/email):
```bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```
### VS Code (recommended editor)
Download and install from Microsoft (snap or .deb). Example via snap:
```bash
sudo snap install --classic code
```
Or via .deb:
```bash
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install -y code
```
### Wireshark (network analyzer)
Wireshark GUI requires extra permissions to capture packets. Install:
```bash
sudo apt install -y wireshark
```
During install it may ask whether non-superusers should be allowed to capture — choose **Yes** if you want to run Wireshark without sudo (you will still need to add yourself to the `wireshark` group):
```bash
sudo usermod -aG wireshark $USER
# THEN log out and log back in, or restart the VM for group change to take effect.
```
Verify Wireshark launches from application menu.
### Additional useful tools
```bash
sudo apt install -y net-tools curl nmap tcpdump unzip
```
Take a screenshot of the installed apps or terminal outputs:

---
## F. Install GitHub CLI (optional) and create a repo for your lab
Install GitHub CLI (convenient):
```bash
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" |
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install -y gh
```
Authenticate (follow prompts):
```bash
gh auth login
```
Create a repo for your lab notes:
```bash
mkdir ~/lab-notes
cd ~/lab-notes
git init
echo "# Lab Notes" > README.md
git add README.md
git commit -m "Initial commit"
# optionally push to GitHub if you created a remote repo
```
---
## G. Snapshots: make your first snapshot
Snapshots let you revert the VM if something breaks.
In VirtualBox manager: select your VM → Snapshots → Take Snapshot.
Name it: `clean-install-1` and add a short description (e.g., "Ubuntu installed, base tools").

**Tip:** After major changes (e.g., installing Kali tools), take another snapshot.
---
## H. (Optional) Shared folders between host and VM
If you want to share files with the host:
In VirtualBox settings → Shared Folders → Add new:
- Folder Path: choose host folder
- Folder Name: `shared`
- Check **Auto-mount** and **Make Permanent**.
In Ubuntu VM, the shared folder will usually mount under `/media/sf_shared` (you may need to add your user to `vboxsf` group):
```bash
sudo usermod -aG vboxsf $USER
# log out and log in for group change
```
Take a screenshot of the shared folder appearing in the file manager.

---
## I. (Optional) Install Kali as a second VM or use Kali in VirtualBox
If you want a Kali VM for pentesting tools:
- Download Kali ISO (https://kali.org/get-kali/)
- Create a second VM (`kali-lab`) in VirtualBox (similar steps as Ubuntu)
- Allocate 4 GB RAM and 40 GB disk (preferably more if you plan to install many tools)
- After installation, take a snapshot `kali-clean`
**Alternatively:** use Kali’s prebuilt VirtualBox images from the Kali downloads page for faster setup.
---
## J. Networking modes explained (so your lab can simulate real networks)
- **NAT (default)** — VM can access internet; host can access internet; external devices cannot access VM directly. Good for safe browsing and updates.
- **Bridged Adapter** — VM appears as another device on your physical network. Useful if you need VM reachable from other devices on the LAN.
- **Host-only Adapter** — VM can communicate only with host (and other VMs on host-only network). Good for isolated multi-VM labs.
- **Internal Network** — VMs on the same host can talk to each other but not to host or internet (good for isolated multi-VM scenarios).
If you plan to set up multiple VMs (e.g., attacker + victim), use **Host-only** or **Internal Network** and give one adapter NAT for internet and one adapter Host-only for lab communication. Example: Adapter 1 = NAT, Adapter 2 = Host-only.
---
## K. Quick first lab checks (sanity tests)
Open Terminal → run:
```bash
# check network
ping -c 3 8.8.8.8
# check DNS
ping -c 3 google.com
# list network interfaces
ip a
# list python
python3 --version
```
Open Wireshark (Application Menu) → capture on `eth0` or the main interface → run `ping google.com` and observe ICMP packets.
Create and run a `hello.py`:
```python
# ~/hello.py
print("Hello, cyber lab!")
```
Run:
```bash
python3 hello.py
```
Take screenshots for each step:
- Terminal ping output: 
- Wireshark capture showing ICMP: 
- `hello.py` run output: 
---
## L. Extra security & convenience tips
- **Keep snapshots** before big changes.
- **Use strong passwords** for any accounts you create in the VM.
- **Disable shared clipboard** and drag-n-drop while running risky tests to prevent accidental cross-contamination (VirtualBox setting).
- **Take notes** in your Git repo — store commands you ran and what they did.
- **If experimenting with malware**: use isolated VMs with no shared folders, no host-only NAT, and revert snapshot immediately after analysis. Do not run malware on a VM with shared folders or bridged adapters to a corporate network.
---
## M. Common problems & fixes
- **VM won't boot or says VT-x not available**: enable virtualization (Intel VT-x / AMD-V) in your host machine's BIOS/UEFI.
- **No internet in VM**: check VirtualBox Network mode (use NAT), reinstall VirtualBox Guest Additions, or reboot VM.
- **Wireshark cannot capture as non-root**: ensure you selected the non-root capture during installation and add your user to `wireshark` group (see above), then logout/login.
- **Guest Additions not installed (screen resolution or shared clipboard problem)**: In VirtualBox menu (while VM running) → Devices → Insert Guest Additions CD image → run instructions inside the VM.