-
Notifications
You must be signed in to change notification settings - Fork 25
/
start.sh
executable file
·492 lines (423 loc) · 23.5 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#!/bin/bash
# Start Damn Vulnerable Drone simulator
# ANSI color codes
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to display help/usage information
show_help() {
echo """
.--------------------------------------------------------------------------------.
.###+ .##### ####+ .####
#######.######-+#+#### .###+##.######+.######-
-####### .#+##### .#####+# .#+#####
+#.######.+.#####. .# .+#######+. +# +#####--######+-#
+#. .#####+ +####- .####+- --##### +#
#+ +###+-#++ ### +##.##- ##+-####- #+
## +######+###.+-## .++. ..## -##---##+#######- #-
+##-############-.##. -######+ -# .##.+############-##
-######- .##+#.. ##########. -#-+#-#+ #######
##############+##.# ########## .-+-#-##############.
+#++ -###### ....###
## .+ . ..-#+##-
## ####+. .-+#######+
-#. .######.+#.-#######-##
## .### .+.-##
###++. +#-# .+###.
.######- .#######
-####+ #########.- - . .########- .#####
+###+##-######+-##########.# + --.##########.######-#######
#####+# . #+############################### +#+####+
#+ +#####.+.######+ - ## +#. ..#######-.######. #-
## -#####+ .#..#. ## #+ --##### -#.
#- -#####++#++ ## #+ #- #- ###++####+. #+
## +#######++##- ## . ## ###+#######+-.#.
#######--###- -## -## .+###.########
######- .#### .###+ #######
++. +#############- +#############..-+-
.---. .----.
.--------------------------------------------------------------------------------.
|░█▀▄░█▀█░█▄█░█▀█░░░█░█░█░█░█░░░█▀█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█▀▄░█▀▄░█▀█░█▀█░█▀▀|
|░█░█░█▀█░█░█░█░█░░░▀▄▀░█░█░█░░░█░█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█░█░█▀▄░█░█░█░█░█▀▀|
|░▀▀░░▀░▀░▀░▀░▀░▀░░░░▀░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀░░▀▀▀░▀▀▀░░░▀▀░░▀░▀░▀▀▀░▀░▀░▀▀▀|
'--------------------------------------------------------------------------------'
"""
echo "Usage: sudo $0 [OPTION]"
echo "Start the Damn Vulnerable Drone simulator."
echo ""
echo "Options:"
echo " --wifi Start the simulation with a virtual drone Wi-Fi network."
echo " --no-wifi Start the simulation with instant access to the drone network (default)."
echo " -h, --help Display this help and exit."
echo ""
echo "Example:"
echo " sudo $0 --wifi # Starts with virtual Wi-Fi"
echo " sudo $0 --no-wifi # Starts without virtual Wi-Fi"
}
check_virtual_interface() {
interface=$1
phy_device=$(readlink -f "/sys/class/net/$interface/device/ieee80211" 2>/dev/null)
if [[ -n "$phy_device" && "$phy_device" =~ "mac80211_hwsim" ]]; then
return 1
else
return 0
fi
}
if [ "$EUID" -ne 0 ]; then
echo "This script must be run with sudo privileges."
echo "Please run it again with 'sudo ./stop.sh'"
exit 1
fi
# Default value for wifi_simulation if no argument is provided
wifi_simulation=""
# Process command-line arguments
for arg in "$@"
do
case $arg in
--wifi)
wifi_simulation="y"
shift # Remove --wifi from processing
;;
--no-wifi)
wifi_simulation="n"
shift # Remove --no-wifi from processing
;;
-h|--help)
show_help
exit 0
;;
*)
# Unknown option
echo "Unknown option: $arg"
show_help
exit 1
;;
esac
done
# Check if a card is virtual
check_virtual_interface() {
interface=$1
phy_device=$(readlink -f "/sys/class/net/$interface/device/ieee80211" 2>/dev/null)
if [[ -n "$phy_device" && "$phy_device" =~ "mac80211_hwsim" ]]; then
return 1
else
return 0
fi
}
# Clean up
clean_up_and_setup() {
echo -e "${CYAN}[+] Running System clean up...${NC}"
# Stop Docker Compose services
echo "[+] Stopping Docker Compose services..."
docker compose down
# Function to delete wireless interfaces
delete_wireless_interface() {
sudo iw dev "$1" del >/dev/null 2>&1
}
# Get a list of all wireless interfaces
wireless_interfaces=$(iw dev | awk '$1=="Interface"{print $2}' | tac)
# Iterate over each wireless interface and delete if check_virtual_interface returns 1
for interface in $wireless_interfaces; do
if ! check_virtual_interface "$interface"; then
echo "Removing $interface..."
delete_wireless_interface "$interface"
fi
done
# Start services
sudo modprobe -r mac80211_hwsim
sudo service networking start
sudo service NetworkManager start
echo -e "${CYAN}[+] System Ready...${NC}"
}
# Get the first virtual card
first_virtual_card() {
# Get a list of all wireless interfaces
wireless_interfaces=$(iw dev | awk '$1=="Interface"{print $2}' | tac)
# Iterate over each wireless interface and delete if check_virtual_interface returns 1
for int in $wireless_interfaces; do
if ! check_virtual_interface "$int"; then
echo "$int"
return # Exit the loop once the first virtual card is found
fi
done
}
# Get next virtual card number
increment_interface_number() {
local interface="$1"
local number=$(echo "$interface" | grep -o '[0-9]*$')
local incremented_number=$((number + 1))
local interface_prefix=$(echo "$interface" | sed 's/[0-9]*$//')
echo "${interface_prefix}${incremented_number}"
}
clean_up_and_setup
# Read the ID line from /etc/os-release
OS_ID=$(grep ^ID= /etc/os-release 2>/dev/null | cut -d= -f2)
# Remove quotes if they exist
OS_ID=${OS_ID//\"/}
# Only ask if wifi_simulation was not set by command-line arguments
if [ -z "$wifi_simulation" ]; then
if [ "$OS_ID" = "kali" ]; then
echo "Do you want to start the simulation with a virtual drone Wi-Fi network? By selecting 'No' you will start the simulation with instant access to the drone network. (Enter 'y (Yes)' or 'n (No)'): "
read wifi_simulation
else
echo -e "${RED}Warning: You are not running on Kali Linux!"
echo -e "${RED}Non-Kali Linux systems have not been tested with the start.sh script."
echo ""
echo -e "${RED}Instead use the provided Docker Compose file to start the environment."
echo -e "${RED}i.e (docker compose up --build)"
exit 1
fi
fi
# Get Version from version.txt file
get_version() {
local version_file="$(dirname "$0")/version.txt"
if [ -f "$version_file" ]; then
local version=$(cat "$version_file")
echo "$version"
else
echo "Version file not found"
fi
}
# Example usage
version=$(get_version)
if [ "$wifi_simulation" = "y" ]; then
# Make sure we are running as root
WIFI_ENABLED="True"
export WIFI_ENABLED
if [ "$EUID" -ne 0 ]; then
echo "To deploy virtual wifi you must run this script with sudo privileges."
echo "Please run it again with 'sudo ./start.sh'"
exit 1
fi
echo -e "${CYAN}[+] Starting simulation with a virtual Wi-Fi network..."
LOG_FILE="dvd.log"
{
# Start Docker Compose
echo -e "${CYAN}[+] Starting Docker Pull...${NC}"
docker compose pull
echo -e "${CYAN}[+] Starting Docker Build...${NC}"
docker compose build
# Print current time
echo -e "${CYAN}[+] Starting Docker Lab Environment - $(date)${NC}"
# Load necessary kernel modules
echo -e "${CYAN}[+] Loading kernel modules...${NC}"
sudo modprobe mac80211_hwsim radios=4
# Set the first virtual card into monitor mode
first_virtual_card_name=$(first_virtual_card)
echo "First virtual Card: ${first_virtual_card_name}"
# Check if a virtual card was found
if [ -n "$first_virtual_card_name" ]; then
# Set the first virtual card into monitor mode
output=$(sudo airmon-ng start "$first_virtual_card_name" 2>&1)
else
echo "Error: No virtual card found. Check that modprobe mac80211_hwsim is working..."
exit 1
fi
# Look for lines with PIDs and extract them
# This regex looks for lines that start with space(s), followed by numbers (PID), and then space/tab and text (process name)
pids=($(echo "$output" | grep -oP '^\s*\K[0-9]+(?=\s+\S)'))
# Kill the processes
for pid in $pids; do
echo "Killing process $pid"
sudo kill $pid
done
# Start Docker Compose
echo -e "${CYAN}[+] Starting Docker Compose...${NC}"
docker compose up -d
echo -e "${CYAN}[+] Fetching Docker Compose logs...${NC}"
docker compose logs -f &
# Wait for Docker containers to start up
# Check for Docker containers readiness
MAX_RETRIES=100
RETRY_INTERVAL=10
RETRY_COUNT=0
while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
echo -e "${CYAN}[+] Checking if Docker containers are ready (attempt $((RETRY_COUNT + 1))/$MAX_RETRIES)...${NC}"
if docker ps | grep -q 'companion-computer' && docker ps | grep -q 'ground-control-station'; then
echo -e "${CYAN}[+] Docker containers are ready.${NC}"
break
else
((RETRY_COUNT++))
sleep $RETRY_INTERVAL
fi
done
if [[ $RETRY_COUNT -eq $MAX_RETRIES ]]; then
echo "${RED}[+] Docker containers did not become ready in time.${NC}"
exit 1
fi
# Determine Docker bridge network IP address
DOCKER_BRIDGE_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
echo -e "${CYAN}[+] Docker bridge network IP: $DOCKER_BRIDGE_IP${NC}"
# Get PIDs of Docker containers and move interfaces
echo -e "${CYAN}[+] Moving interfaces to Docker containers...${NC}"
# Companion Computer gets the next interface
companion_computer_interface=$(increment_interface_number "$first_virtual_card_name")
CC_PID=$(docker inspect --format '{{ .State.Pid }}' companion-computer)
CC_PHY_INTERFACE=$(iw dev | awk '/phy#/{phy=$0} /Interface '"$companion_computer_interface"'/{print phy; exit}')
CC_PHY_INTERFACE=$(echo "$CC_PHY_INTERFACE" | awk -F'#' '{print "phy"$2}')
sudo iw phy "$CC_PHY_INTERFACE" set netns "$CC_PID"
# Ground Control Station gets the next interface
gcs_interface=$(increment_interface_number "$companion_computer_interface")
GCS_PID=$(docker inspect --format '{{ .State.Pid }}' ground-control-station)
GCS_PHY_INTERFACE=$(iw dev | awk '/phy#/{phy=$0} /Interface '"$gcs_interface"'/{print phy; exit}')
GCS_PHY_INTERFACE=$(echo $GCS_PHY_INTERFACE | awk -F'#' '{print "phy"$2}')
sudo iw phy $GCS_PHY_INTERFACE set netns $GCS_PID
# CC Access Point Setup
echo -e "${CYAN}[+] Setting up Access Point on Companion Computer...${NC}"
# Execute multiple commands in the companion-computer container
docker exec companion-computer sh -c '
# Set IP address for companion computer
ip a a 192.168.13.1/24 dev '"$companion_computer_interface"' &&
echo "[companion-computer] IP address set for '"$companion_computer_interface"'" ||
{ echo "[companion-computer] Failed to set IP address for '"$companion_computer_interface"'."; exit 1; }
# Update interface name in dnsmasq.conf
sed -i "s/wlan1/'"${companion_computer_interface}"'/" /etc/dnsmasq.conf &&
echo "[companion-computer] Interface name updated in dnsmasq.conf." ||
{ echo "[companion-computer] Failed to update interface name in dnsmasq.conf."; exit 1; }
# Update interface name in hostapd.conf
sed -i "s/wlan1/'"${companion_computer_interface}"'/" /etc/hostapd.conf &&
echo "[companion-computer] Interface name updated in hostapd.conf." ||
{ echo "[companion-computer] Failed to update interface name in hostapd.conf."; exit 1; }
# Create dhcpd.leases file if it doesnt exist
if [ ! -f /var/lib/dhcp/dhcpd.leases ]; then
touch /var/lib/dhcp/dhcpd.leases &&
echo "[companion-computer] Created dhcpd.leases file." ||
{ echo "[companion-computer] Failed to create dhcpd.leases file."; exit 1; }
fi
# Set permissions for dhcpd.leases file
chmod 644 /var/lib/dhcp/dhcpd.leases &&
echo "[companion-computer] Permissions set for dhcpd.leases." ||
{ echo "[companion-computer] Failed to set permissions for dhcpd.leases."; exit 1; }
# Start hostapd in the background with nohup
nohup hostapd /etc/hostapd.conf > /var/log/hostapd.log 2>&1 &
echo "[companion-computer] hostapd started."
# Pause for a few seconds to allow hostapd to initialize
sleep 5
# Clean up previous dhcpd PID file if it exists
rm -f /var/run/dhcpd.pid
service isc-dhcp-server start
service dnsmasq start
service isc-dhcp-server stop
service dnsmasq stop
# Start dhcpd in debug mode
dhcpd -d &
echo "[companion-computer] dhcpd started in debug mode."
'
service NetworkManager start
kali_interface=$(increment_interface_number "$gcs_interface")
# Ground Control Station Access Point Setup
echo -e "${CYAN}[+] Setting up Ground Control Station Access Point...${NC}"
# Execute commands in the ground-control-station container
docker exec ground-control-station sh -c "
wpa_supplicant -B -i '"$gcs_interface"' -c /etc/wpa_supplicant/wpa_supplicant.conf -D nl80211;
ip addr add 192.168.13.14/24 dev '"$gcs_interface"';
ip route add default via 192.168.13.1 dev '"$gcs_interface"';
echo '${CYAN}[ground-control-station] IP address set for '"$gcs_interface"'.${NC}' ||
{ echo '${RED}[ground-control-station] Failed to set IP address for '"$gcs_interface"'.${NC}'; exit 1; }
"
echo """
.--------------------------------------------------------------------------------.
.###+ .##### ####+ .####
#######.######-+#+#### .###+##.######+.######-
-####### .#+##### .#####+# .#+#####
+#.######.+.#####. .# .+#######+. +# +#####--######+-#
+#. .#####+ +####- .####+- --##### +#
#+ +###+-#++ ### +##.##- ##+-####- #+
## +######+###.+-## .++. ..## -##---##+#######- #-
+##-############-.##. -######+ -# .##.+############-##
-######- .##+#.. ##########. -#-+#-#+ #######
##############+##.# ########## .-+-#-##############.
+#++ -###### ....###
## .+ . ..-#+##-
## ####+. .-+#######+
-#. .######.+#.-#######-##
## .### .+.-##
###++. +#-# .+###.
.######- .#######
-####+ #########.- - . .########- .#####
+###+##-######+-##########.# + --.##########.######-#######
#####+# . #+############################### +#+####+
#+ +#####.+.######+ - ## +#. ..#######-.######. #-
## -#####+ .#..#. ## #+ --##### -#.
#- -#####++#++ ## #+ #- #- ###++####+. #+
## +#######++##- ## . ## ###+#######+-.#.
#######--###- -## -## .+###.########
######- .#### .###+ #######
++. +#############- +#############..-+-
.---. .----.
.--------------------------------------------------------------------------------.
|░█▀▄░█▀█░█▄█░█▀█░░░█░█░█░█░█░░░█▀█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█▀▄░█▀▄░█▀█░█▀█░█▀▀|
|░█░█░█▀█░█░█░█░█░░░▀▄▀░█░█░█░░░█░█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█░█░█▀▄░█░█░█░█░█▀▀|
|░▀▀░░▀░▀░▀░▀░▀░▀░░░░▀░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀░░▀▀▀░▀▀▀░░░▀▀░░▀░▀░▀▀▀░▀░▀░▀▀▀|
'--------------------------------------------------------------------------------'
"""
echo -e "${CYAN}------------------------------------------------------"
echo -e "${CYAN}[+] Build Complete."
echo -e "${CYAN}[+] Version: ${version}"
echo -e "${CYAN}------------------------------------------------------"
echo -e "${CYAN}[+] - Virtual interface ${first_virtual_card_name}mon put into monitoring mode."
echo -e "${CYAN}[+] - Virtual interface ${kali_interface} is available for regular wifi networking."
echo -e "${CYAN}------------------------------------------------------"
echo -e "${CYAN}[+] Damn Vulnerable Drone Lab Environment is running..."
echo -e "${CYAN}[+] Log file: dvd.log"
echo -e "${CYAN}[+] Simulator: http://localhost:8000"
echo -e "${CYAN}------------------------------------------------------${NC}"
} 2>&1 | tee -a "$LOG_FILE"
elif [ "$wifi_simulation" = "n" ]; then
WIFI_ENABLED="False"
export WIFI_ENABLED
LOG_FILE="dvd.log"
{
echo -e "${CYAN}Starting simulation assuming drone network connectivity access..."
echo -e "${CYAN}[+] Starting Docker Compose...${NC}"
docker compose up --build -d
docker compose logs -f &
echo """
.--------------------------------------------------------------------------------.
.###+ .##### ####+ .####
#######.######-+#+#### .###+##.######+.######-
-####### .#+##### .#####+# .#+#####
+#.######.+.#####. .# .+#######+. +# +#####--######+-#
+#. .#####+ +####- .####+- --##### +#
#+ +###+-#++ ### +##.##- ##+-####- #+
## +######+###.+-## .++. ..## -##---##+#######- #-
+##-############-.##. -######+ -# .##.+############-##
-######- .##+#.. ##########. -#-+#-#+ #######
##############+##.# ########## .-+-#-##############.
+#++ -###### ....###
## .+ . ..-#+##-
## ####+. .-+#######+
-#. .######.+#.-#######-##
## .### .+.-##
###++. +#-# .+###.
.######- .#######
-####+ #########.- - . .########- .#####
+###+##-######+-##########.# + --.##########.######-#######
#####+# . #+############################### +#+####+
#+ +#####.+.######+ - ## +#. ..#######-.######. #-
## -#####+ .#..#. ## #+ --##### -#.
#- -#####++#++ ## #+ #- #- ###++####+. #+
## +#######++##- ## . ## ###+#######+-.#.
#######--###- -## -## .+###.########
######- .#### .###+ #######
++. +#############- +#############..-+-
.---. .----.
.--------------------------------------------------------------------------------.
|░█▀▄░█▀█░█▄█░█▀█░░░█░█░█░█░█░░░█▀█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█▀▄░█▀▄░█▀█░█▀█░█▀▀|
|░█░█░█▀█░█░█░█░█░░░▀▄▀░█░█░█░░░█░█░█▀▀░█▀▄░█▀█░█▀▄░█░░░█▀▀░░░█░█░█▀▄░█░█░█░█░█▀▀|
|░▀▀░░▀░▀░▀░▀░▀░▀░░░░▀░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀░░▀▀▀░▀▀▀░░░▀▀░░▀░▀░▀▀▀░▀░▀░▀▀▀|
'--------------------------------------------------------------------------------'
"""
echo -e "${CYAN}------------------------------------------------------"
echo -e "${CYAN}[+] Build Complete."
echo -e "${CYAN}[+] Version: ${version}"
echo -e "${CYAN}------------------------------------------------------"
echo -e "${CYAN}[+] Damn Vulnerable Drone Lab Environment is running..."
echo -e "${CYAN}[+] Log file: dvd.log"
echo -e "${CYAN}[+] Simulator: http://localhost:8000"
echo -e "${CYAN}------------------------------------------------------"
} 2>&1 | tee -a "$LOG_FILE"
else
echo "Invalid input. Please start the script again and enter 'y' (Yes) or 'n' (No)."
exit 1
fi