Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates a windows qcow for minimega #515

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ testing/tests/assets/style.css
*.vim*
**/quadlet/output
**/lme-environment.env

**/env.sh
171 changes: 139 additions & 32 deletions testing/v2/installers/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,153 @@
There are readmes for each of the installer directories.
# Installation Guide
#### Attention: Run these commands in the order presented in this document. Some commands depend on variables set in previous commands. Not all commands need to be run. There are some optional commands depending on the testing scenario.

## Initial Setup Variables
First, set these variables in your terminal:

```bash
# Required variables
export RESOURCE_GROUP="your-group-name"
export PUBLIC_IP="your-effective-public-ip/32" # Get this from https://www.whatismyip.com/
export VM_SIZE="Standard_D8_v4"
export LOCATION="westus"
export AUTO_SHUTDOWN_TIME="00:00"
export LME_USER="lme-user"
```

You'll need to follow the steps in [Azure Authentication](/testing/v2/installers/azure/build_azure_linux_network.md#authentication) and
[Python Setup](/testing/v2/installers/azure/build_azure_linux_network.md#setup) prior to running the steps below.
[Python Setup](/testing/v2/installers/azure/build_azure_linux_network.md#setup) prior to running the steps below.

Quick Start
## Quick Start
All commands are run from the installer directory:

```bash
./azure/build_azure_linux_network.py -g your-group-name -s 0.0.0.0 -vs Standard_D8_v4 -l westus -ast 00:00
./minimega/install.sh lme-user $(cat your-group-name.ip.txt) your-group-name.password.txt
./ubuntu_qcow_maker/install.sh lme-user $(cat your-group-name.ip.txt) your-group-name.password.txt
./install_v2/install.sh lme-user $(cat your-group-name.ip.txt) your-group-name.password.txt branch
cd testing/v2/installers
```

#reminder activiate venv first: `source ~/LME/venv/bin/activate`
./azure/build_azure_linux_network.py -g lme-cbaxley-m1 -s 0.0.0.0 -vs Standard_D8_v4 -l westus -ast 00:00 -pub Canonical -io 0001-com-ubuntu-server-noble-daily -is 24_04-daily-lts-gen2
### Creating Azure Machine(s)

Linux only:
```bash
./azure/build_azure_linux_network.py -g $RESOURCE_GROUP -s $PUBLIC_IP -vs $VM_SIZE -l $LOCATION -ast $AUTO_SHUTDOWN_TIME
```

## creating clients:
Windows:
Linux and Windows (just add the -w flag):
```bash
./azure/build_azure_linux_network.py -g $RESOURCE_GROUP -s $PUBLIC_IP -vs $VM_SIZE -l $LOCATION -ast $AUTO_SHUTDOWN_TIME -w
```
az vm create `
--resource-group xxxxxx `
--nsg NSG1 `
--image Win2019Datacenter `
--admin-username admin-user `
--admin-password xxxxxxxxxxxxxx `
--vnet-name VNet1 `
--subnet SNet1 `
--public-ip-sku Standard `
--name WINDOWS

After VM creation, set these additional variables:
```bash
# These are generated during VM creation
export VM_IP=$(cat $RESOURCE_GROUP.ip.txt)
export VM_PASSWORD=$(cat $RESOURCE_GROUP.password.txt)
```

Ubuntu:
### Installing lme-v2
```bash
./install_v2/install.sh $LME_USER $VM_IP $RESOURCE_GROUP.password.txt your-branch-name
```
az vm create `
--resource-group XXXXX `
--nsg NSG1 `
--image Ubuntu2204 `
--admin-username admin-user `
--admin-password XXXXXXXX `
--vnet-name VNet1 `
--subnet SNet1 `
--public-ip-sku Standard `
--name linux-client

## Setting Up Minimega Clients

### Connecting to VMs

#### You connect to these from the host azure machine

To connect to the Ubuntu machine:
```bash
sudo su
minimega -e vm info
# Find the ip of the ubuntu machine
ssh vmuser@<ip> # Password: vmuser
```

For web UI access: Browse to http://host-machine-ip:9001
- Ubuntu credentials: `vmuser`/`vmuser`
- Windows credentials: `Admin`/`minimega!1`

To SSH into Windows:
```bash
ssh Test@<ip> # Password: minimega!1
```

### Installing Minimega Service
```bash
./minimega/install.sh $LME_USER $VM_IP $RESOURCE_GROUP.password.txt
```

### Setting Up Ubuntu Minimega VMs
```bash
./ubuntu_qcow_maker/install.sh $LME_USER $VM_IP $RESOURCE_GROUP.password.txt
```

### Setting Up Windows Minimega VMs
1. Set up the environment file:
```bash
cp ./windows_qcow/.env.example ./windows_qcow/.env
# Edit the .env file and update your resource group name
```

2. Install Windows VM:
```bash
scp -r windows_qcow ubuntu_qcow_maker $LME_USER@$VM_IP:/home/$LME_USER
ssh $LME_USER@$VM_IP
cd /home/lme-user/windows_qcow
sudo ./install_local.sh
# Follow the device code login prompts
# Press enter for subscription and tenant prompts
```

## Optional: Ubuntu 24.04 Setup
Remember to activate venv first:
```bash
source ~/LME/venv/bin/activate
```

Create the network:
```bash
./azure/build_azure_linux_network.py \
-g $RESOURCE_GROUP \
-s "0.0.0.0" \
-vs $VM_SIZE \
-l $LOCATION \
-ast $AUTO_SHUTDOWN_TIME \
-pub Canonical \
-io 0001-com-ubuntu-server-noble-daily \
-is 24_04-daily-lts-gen2
```

## Creating Additional VMs (Non-Network Attack Scenarios)

### Windows VM
First, set a secure password for the Windows VM:
```bash
export WINDOWS_PASSWORD="SecurePass123!" # Must contain 12+ chars, uppercase, lowercase, numbers, and symbols
```
```bash
az vm create \
--resource-group $RESOURCE_GROUP \
--nsg NSG1 \
--image Win2019Datacenter \
--admin-username admin-user \
--admin-password $WINDOWS_PASSWORD \
--vnet-name VNet1 \
--subnet SNet1 \
--public-ip-sku Standard \
--name WINDOWS
```

### Ubuntu VM
Note: Use the $VM_PASSWORD that was set earlier after initial VM creation (see "After VM creation, set these additional variables" section above)
```bash
az vm create \
--resource-group $RESOURCE_GROUP \
--nsg NSG1 \
--image Ubuntu2204 \
--admin-username admin-user \
--admin-password $VM_PASSWORD \
--vnet-name VNet1 \
--subnet SNet1 \
--public-ip-sku Standard \
--name linux-client
```
12 changes: 6 additions & 6 deletions testing/v2/installers/azure/build_azure_linux_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,23 +639,23 @@ def main(
"--ports",
type=int,
nargs="+",
default=[22, 443, 5601, 9200],
help="Ports to open. Default: [22, 443, 5601, 9200]",
default=[22, 443, 5601, 9200, 9001],
help="Ports to open. Default: [22, 443, 5601, 9200, 9001]",
)
parser.add_argument(
"-pr",
"--priorities",
type=int,
nargs="+",
default=[1001, 1002, 1003, 1004],
help="Priorities for the ports. Default: [1001, 1002, 1003, 1004]",
default=[1001, 1002, 1003, 1004, 1005],
help="Priorities for the ports. Default: [1001, 1002, 1003, 1004, 1005]",
)
parser.add_argument(
"-pt",
"--protocols",
nargs="+",
default=["Tcp", "Tcp", "Tcp", "Tcp"],
help="Protocols for the ports. Default: ['Tcp', 'Tcp', 'Tcp', 'Tcp']",
default=["Tcp", "Tcp", "Tcp", "Tcp", "Tcp"],
help="Protocols for the ports. Default: ['Tcp', 'Tcp', 'Tcp', 'Tcp', 'Tcp']",
)
parser.add_argument(
"-vs",
Expand Down
102 changes: 98 additions & 4 deletions testing/v2/installers/ubuntu_qcow_maker/create_tap.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
#!/usr/bin/env bash

# Default values
TAP_NAME="100"
TAP_NAME="100" # Match the vm config net value
IP_ADDRESS="10.0.0.1/24"
FORCE=false
MAX_WAIT=10 # Maximum seconds to wait for interface

# Extract just the IP without the subnet mask for comparison
IP_ONLY="${IP_ADDRESS%/*}"

# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -t, --tap TAP/VLAN name (default: 100)"
echo " -i, --ip IP address (default: 10.0.0.1/24)"
echo " -f, --force Force recreation of TAP interface"
echo " -h, --help Show this help message"
echo
echo "Example:"
echo " $0 -t 200 -i 192.168.1.1/24"
exit 1
}

# Function to check if VLAN already exists
check_vlan_exists() {
local vlan="$1"
if sudo /opt/minimega/bin/minimega -e "tap" | grep -q "| $vlan$"; then
return 0 # VLAN exists
fi
return 1 # VLAN doesn't exist
}

# Function to wait for interface to be ready
wait_for_interface() {
local count=0
while [ $count -lt $MAX_WAIT ]; do
if ip addr show | grep -A 2 "mega_tap" | grep -q "inet $IP_ADDRESS\\|inet $IP_ONLY/"; then
return 0
fi
sleep 1
count=$((count + 1))
echo "Still waiting... ($count/$MAX_WAIT)"
done
return 1
}

# Parse command line arguments
while [[ $# -gt 0 ]]; do
Expand All @@ -13,14 +55,66 @@ while [[ $# -gt 0 ]]; do
;;
-i|--ip)
IP_ADDRESS="$2"
IP_ONLY="${IP_ADDRESS%/*}"
shift 2
;;
-f|--force)
FORCE=true
shift
;;
-h|--help)
show_usage
;;
*)
echo "Unknown argument: $1"
exit 1
show_usage
;;
esac
done

# Execute the minimega command with the provided or default arguments
sudo /opt/minimega/bin/minimega -e tap create "$TAP_NAME" ip "$IP_ADDRESS"
# Check if VLAN already exists
if check_vlan_exists "$TAP_NAME"; then
if [ "$FORCE" = true ]; then
echo "VLAN $TAP_NAME already exists, but -f was specified. Cleaning up..."
sudo /opt/minimega/bin/minimega -e "clear tap"
sleep 1
else
echo "VLAN $TAP_NAME already exists. Current configuration:"
sudo /opt/minimega/bin/minimega -e "tap"
echo -e "\nUse -f to force recreation if needed."
exit 0
fi
fi

# Create the TAP interface
echo "Creating TAP interface for vm config net ${TAP_NAME} with IP ${IP_ADDRESS}..."
sudo /opt/minimega/bin/minimega -e "tap create ${TAP_NAME} ip ${IP_ADDRESS}"

# Verify creation with timeout
echo "Waiting for interface to be ready..."
if wait_for_interface; then
echo "TAP interface created successfully!"
echo -e "\nInterface details:"
ip addr show | grep -A 2 "mega_tap"
echo -e "\nThis interface will work with: vm config net ${TAP_NAME}"

# Show minimega tap status
echo -e "\nMinimega TAP status:"
sudo /opt/minimega/bin/minimega -e "tap"
exit 0
else
echo "Note: Interface appears to exist but IP verification failed."
echo "Current interfaces:"
ip addr show | grep -A 2 "mega_tap"

# Show minimega tap status
echo -e "\nMinimega TAP status:"
sudo /opt/minimega/bin/minimega -e "tap"

# If interface exists but verification failed, still exit successfully
if ip addr show | grep -q "mega_tap"; then
echo "Interface exists and should work with: vm config net ${TAP_NAME}"
exit 0
fi
exit 1
fi
Loading