forked from qeeqbox/chameleon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_centos.sh
123 lines (106 loc) · 3.2 KB
/
run_centos.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
echo -e "\nQeeqBox Chameleon v$(jq -r '.version' info) CentOS starter script -> https://github.com/qeeqbox/Chameleon"
echo -e "Current servers (DNS, HTTP Proxy, HTTP, HTTPS, SSH, POP3, IMAP, STMP, RDP, VNC, SMB, SOCK5, TELNET and Postgres)\n"\
echo "[x] Install & update pre-requirements"
sudo yum update -y
sudo yum install -y curl jq > /dev/null
fix_ports_deploy () {
echo "[x] Fixing ports"
cp docker-compose-temp.yml docker-compose-dep.yml
ports=""
ports_dockerfile="PORTS="
for i in $(jq .honeypots[].port config.json); do
ports+=" - '$i:$i'\n"
ports_dockerfile+="$i "
done
sed -i '/{temp}/c\'"${ports}"'' docker-compose-dep.yml
sed -i '$!N;/^\n$/{$q;D;};P;D;' docker-compose-dep.yml
echo $ports_dockerfile > .env
sed -i 's/^[ \t]*//;s/[ \t]*$//' .env
}
setup_requirements () {
echo "[x] Install & update requirements"
sudo yum update -y
sudo yum install -y yum-utils xdg-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce --allowerasing
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo service docker restart
which docker-compose && echo "Good"
which docker && echo "Good"
}
wait_on_web_interface () {
until $(curl --silent --head --fail http://localhost:3000 --output /dev/null); do
sleep 5
done
xdg-open http://localhost:3000
}
test_project () {
sudo docker-compose -f docker-compose-test.yml up --build --remove-orphan
}
dev_project () {
sudo docker-compose -f docker-compose-dev.yml up --build --remove-orphan
}
dep_project () {
sudo docker-compose -f docker-compose-dep.yml up --build --force-recreate --no-deps --remove-orphan
}
stop_containers () {
sudo docker-compose -f docker-compose-test.yml down -v 2>/dev/null
sudo docker-compose -f docker-compose-dev.yml down -v 2>/dev/null
sudo docker stop $(docker ps | grep chameleon_ | awk '{print $1}') 2>/dev/null
sudo docker kill $(docker ps | grep chameleon_ | awk '{print $1}') 2>/dev/null
}
deploy_aws_project () {
echo "Will be added later on"
}
test () {
echo "[x] Init test"
stop_containers
wait_on_web_interface &
setup_requirements
test_project
stop_containers
kill %% 2>/dev/null
}
dev () {
echo "[x] Init dev"
stop_containers
wait_on_web_interface &
setup_requirements
dev_project
stop_containers
kill %% 2>/dev/null
}
deploy () {
echo "[x] Init deploy"
stop_containers
wait_on_web_interface &
setup_requirements
fix_ports_deploy
dep_project
stop_containers
kill %% 2>/dev/null
}
if [[ "$1" == "test" ]]; then
test
fi
if [[ "$1" == "dev" ]]; then
dev
fi
if [[ "$1" == "deploy" ]]; then
deploy
fi
kill %% 2>/dev/null
while read -p "`echo -e '\nChoose an option:\n1) Setup requirements (docker, docker-compose)\n2) Test the project (All servers and Sniffer)\n7) Run deploy\n8) Run dev\n9) Run test\n>> '`"; do
case $REPLY in
"1") setup_requirements;;
"2") test_project;;
"7") deploy;;
"8") dev;;
"9") test;;
*) echo "Invalid option";;
esac
done