# VirtualBox

> **Skill Level**: Beginner to Intermediate\
> **Prerequisites**: Basic virtualization concepts

## Performance Optimization

```bash
# Enable nested virtualization (Intel)
VBoxManage modifyvm "VM Name" --nested-hw-virt on

# Allocate resources appropriately
VBoxManage modifyvm "VM Name" --cpus 4 --memory 8192 --vram 256

# Enable PAE/NX for 64-bit guests
VBoxManage modifyvm "VM Name" --pae on

# Use paravirtualized network adapter (faster)
VBoxManage modifyvm "VM Name" --nictype1 virtio

# Enable disk caching
VBoxManage storagectl "VM Name" --name "SATA Controller" --hostiocache on

# Use SSD optimization
VBoxManage storageattach "VM Name" --storagectl "SATA Controller" --port 0 --nonrotational on
```

## Network Configuration for Labs

### Internal Pentest Lab Network

```bash
# Create internal network for isolated testing
VBoxManage modifyvm "Kali" --nic1 nat --nic2 intnet --intnet2 "pentestlab"
VBoxManage modifyvm "Target-Windows" --nic1 intnet --intnet1 "pentestlab"
VBoxManage modifyvm "Target-Linux" --nic1 intnet --intnet1 "pentestlab"

# Host-only network for accessing VMs from host
VBoxManage hostonlyif create
VBoxManage hostonlyif ipconfig "vboxnet0" --ip 192.168.56.1 --netmask 255.255.255.0
VBoxManage modifyvm "Kali" --nic3 hostonly --hostonlyadapter3 "vboxnet0"
```

### NAT Network with Port Forwarding

```bash
# Create NAT network
VBoxManage natnetwork add --netname "PentestNAT" --network "10.0.2.0/24" --enable

# Port forwarding rules
VBoxManage natnetwork modify --netname "PentestNAT" --port-forward-4 "ssh:tcp:[]:2222:[10.0.2.15]:22"
VBoxManage natnetwork modify --netname "PentestNAT" --port-forward-4 "http:tcp:[]:8080:[10.0.2.15]:80"
```

## MacOS Guest Setup

```
# Tested in ElCapitan(10.11) to Sonoma(14)
# Find and download your desired vmdk file
# Add your VM using existing disk
# Set Chipset ICH9
# Enable PAE/NX
# Video Memory 128 MB
# After created: 
cd "C:\Program Files\Oracle\VirtualBox\"
VBoxManage.exe modifyvm "VM Name" --cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff
VBoxManage setextradata "VM Name" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac11,3"
VBoxManage setextradata "VM Name" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "VM Name" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple"
VBoxManage setextradata "VM Name" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage setextradata "VM Name" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1

# For Apple Silicon compatibility (limited support)
# Use UTM or Parallels instead for M1/M2/M3 Macs
```

## Windows Target Setup

```bash
# Download Windows evaluation VMs
# https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/

# Disable Windows Defender for testing
VBoxManage guestcontrol "Windows" run --exe "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" \
  --username Administrator --password password -- -Command "Set-MpPreference -DisableRealtimeMonitoring $true"
```

## Kali Linux Setup

```bash
# Download Kali VM
# https://www.kali.org/get-kali/#kali-virtual-machines

# First boot setup
sudo apt update && sudo apt full-upgrade -y

# Install additional tools
sudo apt install -y gobuster feroxbuster seclists wordlists

# Configure shared folders
VBoxManage sharedfolder add "Kali" --name "shared" --hostpath "/path/to/shared" --automount
# In Kali: mount -t vboxsf shared /mnt/shared
```

## Snapshots & Clones

```bash
# Take snapshot before testing
VBoxManage snapshot "VM Name" take "Clean-State" --description "Before exploitation"

# Restore snapshot
VBoxManage snapshot "VM Name" restore "Clean-State"

# Clone VM for multiple tests
VBoxManage clonevm "VM Name" --name "VM-Clone" --register --mode machine

# Linked clone (saves disk space)
VBoxManage clonevm "VM Name" --name "VM-Linked" --register --mode machine --options link
```

## Vulnerable Lab VMs

```bash
# Metasploitable 2/3
https://sourceforge.net/projects/metasploitable/

# VulnHub collection
https://www.vulnhub.com/

# DVWA (Docker)
docker run --rm -it -p 80:80 vulnerables/web-dvwa

# HackTheBox retired machines
# TryHackMe rooms
```

## Headless Operation

```bash
# Start VM headless (no GUI)
VBoxManage startvm "VM Name" --type headless

# Control headless VM
VBoxManage controlvm "VM Name" poweroff
VBoxManage controlvm "VM Name" pause
VBoxManage controlvm "VM Name" resume

# List running VMs
VBoxManage list runningvms
```

## Related Topics

* [Lab Setup Guide](/others/lab-setup-guide.md) - Docker labs and more
* [Docker/Kubernetes](/enumeration/cloud/docker-and-and-kubernetes.md) - Container testing


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentest-book.com/others/virtualbox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
