forked from tms2744/SSI-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compose-bash.sh
82 lines (72 loc) · 2.14 KB
/
compose-bash.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
#!/bin/bash
# initalize variables
# z=$(($1+2))
#z is the number of devices
z=$(($1))
experiment_num=$2
scan_time=$3
subnet=$4
gateway=$5
if [ $7 ]; then
NETWORK_NAME=$7
else
NETWORK_NAME="SSID"
fi
SHARED_VOLUME=$(pwd)
START_SSH_PORT=220$z
START_TCP_PORT=999$z
START_HTTP_PORT=800$z
#iaddr=$1+1
ipV4="172.50.0.$(($z+1))"
SHARED_VOLUME_HOME=$SHARED_VOLUME:/purple/
OUT=docker-compose.yml
# Create the docker-compose.yml file
echo "version: '3'" > $OUT
echo "services:" >> $OUT
write_entry () {
echo " dev$1:" >> $OUT
echo " container_name: dev$1" >> $OUT
echo " build:" >> $OUT
echo " context: ." >> $OUT
echo " dockerfile: Dockerfile" >> $OUT
echo " ports:" >> $OUT
echo " - \"${START_SSH_PORT}:22\"" >> $OUT
echo " - \"${START_TCP_PORT}:9000\"" >> $OUT
echo " - \"${START_HTTP_PORT}:80\"">> $OUT
START_SSH_PORT=$(($START_SSH_PORT-1))
START_TCP_PORT=$(($START_TCP_PORT-1))
START_HTTP_PORT=$(($START_HTTP_PORT-1))
echo " networks: " >> $OUT
echo ' '"${NETWORK_NAME}"':' >> $OUT
echo " ipv4_address: 172.50.0.$(($1+1))" >> $OUT
echo " hostname: dev$1" >> $OUT
echo " volumes:" >> $OUT
echo ' - '"${SHARED_VOLUME}"':/purple' >> $OUT
echo " cap_add:" >> $OUT
echo " - NET_ADMIN" >> $OUT
echo " command: python3 /opt/internal.py $1 ${experiment_num} ${scan_time} $z 0" >> $OUT
if [ $2 ]; then
echo " depends_on:" >> $OUT
echo " - dev$2" >> $OUT
fi
echo " stdin_open: true" >> $OUT
echo " tty: true" >> $OUT
echo " " >> $OUT
}
# Write target (victim) host w/ no dependency
write_entry $z
# Write Stepping-stone hosts & attacker (all depending on prior host)
for ((i=z-1; i>0; i--))
do
j=$(($i+1))
write_entry $i $j
done
echo "volumes:" >> $OUT
echo " purple:" >> $OUT
echo "networks:" >> $OUT
echo ' '"${NETWORK_NAME}"':' >> $OUT
echo " ipam:" >> $OUT
echo " driver: default" >> $OUT
echo " config:" >> $OUT
echo " - subnet: $subnet" >> $OUT
echo " gateway: $gateway" >> $OUT