-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·171 lines (145 loc) · 5.8 KB
/
install.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
#!/bin/bash
###
## Perception Installer
## Copyright (C) 2017 CriticalSecurity, LLC (https://www.critical-sec.com/)
## See the file 'LICENSE.txt' for the license information
###
# Check if is it root
if [ $EUID -ne 0 ]; then
echo "You must be root."
exit 1
fi
kernel=$(uname -r)
hostname=$(hostname)
install_log="/tmp/python-perception-install.log"
es_pgp_key="deb https://artifacts.elastic.co/packages/5.x/apt stable main"
es_config="/etc/elasticsearch/elasticsearch.yml"
unsupported="Perception is built for Kali Linux, this system is unsupported"
dmi_product_id="/sys/devices/virtual/dmi/id/product_uuid"
product_uuid="/etc/product_uuid"
python_shebang="#!/usr/bin/python2"
generator_msg="# generated via install.sh"
importsys="import sys"
ifnamemain="if __name__ == \"__main__\":"
py_sysexit=" sys.exit(main())"
etc_perception="/etc/perception/"
perception_config="/usr/local/lib/python2.7/dist-packages/perception/config/"
postgresql_config="/etc/postgresql/9.6/main/postgresql.conf"
perceptiond="/usr/bin/perceptiond"
perception_cli="/usr/bin/perception_cli"
perceptiond_service="perceptiond.service"
end_msg="\n[*] Perception installation is complete\n[*] Complete the configuration at /etc/perception/config/configuration.py\n[*] To start the Perception Daemon on boot type \"systemctl enable perceptiond.service\""
standalone_install(){
DBPASSWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - >> ${install_log}
apt-get install apt-transport-https -y >> ${install_log}
echo ${es_pgp_key} >> /etc/apt/sources.list.d/elastic-5.x.list
apt-get update && apt-get install -y elasticsearch rabbitmq-server openjdk-8-jdk >> ${install_log}
sed -i "s/#cluster.name: my-application/cluster.name: perception_cluster/" ${es_config} >> ${install_log}
sed -i "s/#node.name: node-1/node.name: ${hostname}/" ${es_config} >> ${install_log}
sed -i "s/port = 5435/port = 5432/" ${postgresql_config} >> ${install_log}
systemctl enable postgresql.service elasticsearch.service rabbitmq-server.service ntp.service >> ${install_log}
systemctl start postgresql.service elasticsearch.service rabbitmq-server.service ntp.service >> ${install_log}
sed -i "s/perceptiondb_user_password/${DBPASSWD}/" ${etc_perception}"config/configuration.py" >> ${install_log}
su postgres bash -c "psql -c \"CREATE USER perceptiondb_user WITH PASSWORD '${DBPASSWD}';\""
su postgres -c "createdb perceptiondb --owner=perceptiondb_user"
cd "/usr/local/lib/python2.7/dist-packages/perception/database/"
alembic upgrade head
cd ~/
echo -e ${end_msg}
exit 0
}
if [[ ! "$kernel" =~ "kali4" ]];
then
echo ${unsupported}
exit 1
fi
read -r -p "[!] Is this installation of Perception for a standalone install? [Y/N]: " contained_input
apt-get install -y python-setuptools python-alembic > ${install_log}
python setup.py sdist > ${install_log}
if [ $? -eq 0 ];
then
chmod 666 ${install_log}
perception_zip=$(ls -1 dist | tr '\n' '\0' | xargs -0 -n 1 basename)
# make sure pip2 is installed
which pip2 >> ${install_log}
if [ $? -ne 0 ];
then
apt-get install python-pip -y >> ${install_log}
fi
# use pip2 to install or upgrade
pip2 install --upgrade dist/${perception_zip} >> ${install_log}
if [ $? -eq 0 ];
then
cat ${dmi_product_id} > ${product_uuid}
if [ ! -L ${etc_perception} ];
then
mkdir ${etc_perception} >> ${install_log}
ln -s ${perception_config} ${etc_perception} >> ${install_log}
fi
if [[ ! -f ${perceptiond} ]];
then
echo ${python_shebang} > ${perceptiond};
echo ${generator_msg} >> ${perceptiond};
echo >> ${perceptiond};
echo ${importsys} >> ${perceptiond};
echo >> ${perceptiond};
echo "from perception.daemon import main" >> ${perceptiond};
echo >> ${perceptiond};
echo >> ${perceptiond};
echo ${ifnamemain} >> ${perceptiond};
echo "${py_sysexit}" >> ${perceptiond};
echo >> ${perceptiond};
chmod +x ${perceptiond}
fi
if [[ ! -f ${perception_cli} ]];
then
echo ${python_shebang} > ${perception_cli};
echo ${generator_msg} >> ${perception_cli};
echo >> ${perception_cli};
echo ${importsys} >> ${perception_cli};
echo >> ${perceptiond};
echo "from perception.shell import main" >> ${perception_cli};
echo >> ${perception_cli};
echo >> ${perception_cli};
echo ${ifnamemain} >> ${perception_cli};
echo "${py_sysexit}" >> ${perception_cli};
echo >> ${perception_cli};
chmod +x ${perception_cli}
fi
fi
if [[ ! -f "/etc/systemd/system/perceptiond.service" ]];
then
cp ${perceptiond_service} "/etc/systemd/system/perceptiond.service" >> ${install_log}
if [[ ! -f ${etc_perception}"configuration.py" ]];
then
cp ${perception_config}"configuration-example.py" ${etc_perception}"config/configuration.py" >> ${install_log}
chmod 640 ${etc_perception}"config/configuration.py" >> ${install_log}
fi
fi
case ${contained_input} in
[nN][oO])
echo -e ${end_msg}
exit 0
;;
[nN])
echo -e ${end_msg}
exit 0
;;
[yY][eE][sS])
standalone_install
echo -e ${end_msg}
exit 0
;;
[yY])
standalone_install
echo -e ${end_msg}
exit 0
;;
esac
elif [ $? -ne 0 ];
then
echo "[!] The python-perception package did not install properly"
echo "[*] Please review the install log: ${install_log}"
exit 1
fi