misp-packer/scripts/bootstrap.sh

632 lines
24 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
## Source of the vercomp function: https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
##vercomp () {
## if [[ $1 == $2 ]]
## then
## return 0
## fi
## local IFS=.
## local i ver1=($1) ver2=($2)
## # fill empty fields in ver1 with zeros
## for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
## do
## ver1[i]=0
## done
## for ((i=0; i<${#ver1[@]}; i++))
## do
## if [[ -z ${ver2[i]} ]]
## then
## # fill empty fields in ver2 with zeros
## ver2[i]=0
## fi
## if ((10#${ver1[i]} > 10#${ver2[i]}))
## then
## return 1
## fi
## if ((10#${ver1[i]} < 10#${ver2[i]}))
## then
## return 2
## fi
## done
## return 0
##}
2017-08-23 11:55:44 +02:00
MISP_BRANCH='2.4'
# Grub config (reverts network interface names to ethX)
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
DEFAULT_GRUB=/etc/default/grub
# Ubuntu version
UBUNTU_VERSION="$(lsb_release -r -s)"
2017-08-23 11:55:44 +02:00
# Database configuration
DBHOST='localhost'
DBNAME='misp'
DBUSER_ADMIN='root'
DBPASSWORD_ADMIN="$(openssl rand -hex 32)"
DBUSER_MISP='misp'
DBPASSWORD_MISP="$(openssl rand -hex 32)"
# Webserver configuration
PATH_TO_MISP='/var/www/MISP'
MISP_BASEURL=''
2017-08-23 11:55:44 +02:00
MISP_LIVE='1'
FQDN='localhost'
# Timing creation
TIME_START=$(date +%s)
2017-08-23 11:55:44 +02:00
# OpenSSL configuration
OPENSSL_C='LU'
OPENSSL_ST='State'
OPENSSL_L='Location'
OPENSSL_O='Organization'
OPENSSL_OU='Organizational Unit'
OPENSSL_CN='Common Name'
OPENSSL_EMAILADDRESS='info@localhost'
# GPG configuration
GPG_REAL_NAME='Autogenerated Key'
GPG_COMMENT='WARNING: MISP AutoGenerated VM consider this Key VOID!'
2018-06-10 16:44:35 +02:00
GPG_EMAIL_ADDRESS='admin@admin.test'
2017-08-23 11:55:44 +02:00
GPG_KEY_LENGTH='2048'
GPG_PASSPHRASE='Password1234'
2017-08-23 11:55:44 +02:00
# php.ini configuration
upload_max_filesize=50M
post_max_size=50M
max_execution_time=300
memory_limit=512M
2018-01-28 17:16:24 +01:00
PHP_INI=/etc/php/7.1/apache2/php.ini
## Starting Ubuntu 18.04 php71 is default
##vercomp 18.04 ${UBUNTU_VERSION}
##case $? in
## 0) op='=';PHP_INI='/etc/php/7.1/apache2/php.ini';;
## 1) op='>';PHP_INI='/etc/php/7.1/apache2/php.ini';;
## 2) op='<';PHP_INI='/etc/php/7.0/apache2/php.ini';;
##esac
PHP_INI='/etc/php/7.1/apache2/php.ini'
2017-08-23 11:55:44 +02:00
echo "--- Installing MISP… ---"
2018-01-25 09:00:10 +01:00
# echo "--- Configuring GRUB ---"
#
# for key in GRUB_CMDLINE_LINUX
# do
# sudo sed -i "s/^\($key\)=.*/\1=\"$(eval echo \${$key})\"/" $DEFAULT_GRUB
# done
# sudo grub-mkconfig -o /boot/grub/grub.cfg
2017-08-23 11:55:44 +02:00
2017-09-06 09:22:58 +02:00
echo "--- Updating packages list ---"
2017-08-23 11:55:44 +02:00
sudo apt-get -qq update
echo "--- Upgrading and autoremoving packages ---"
sudo apt-get -y upgrade
sudo apt-get -y autoremove
2017-08-23 11:55:44 +02:00
2017-09-06 09:22:58 +02:00
echo "--- Install base packages ---"
sudo apt-get -y install curl net-tools gcc git gnupg-agent make python openssl redis-server sudo tmux vim virtualenvwrapper zip > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
2017-09-06 09:22:58 +02:00
echo "--- Installing and configuring Postfix ---"
2017-08-23 11:55:44 +02:00
# # Postfix Configuration: Satellite system
# # change the relay server later with:
# sudo postconf -e 'relayhost = example.com'
# sudo postfix reload
echo "postfix postfix/mailname string `hostname`.misp.local" | debconf-set-selections
2017-08-23 11:55:44 +02:00
echo "postfix postfix/main_mailer_type string 'Satellite system'" | debconf-set-selections
sudo apt-get install -y postfix > /dev/null 2>&1
2017-09-06 09:22:58 +02:00
echo "--- Installing MariaDB specific packages and settings ---"
2017-08-23 11:55:44 +02:00
sudo apt-get install -y mariadb-client mariadb-server > /dev/null 2>&1
# Secure the MariaDB installation (especially by setting a strong root password)
2018-01-25 08:50:56 +01:00
sleep 10 # give some time to the DB to launch...
sudo systemctl restart mariadb.service
sleep 10
2017-08-23 11:55:44 +02:00
sudo apt-get install -y expect > /dev/null 2>&1
## do we need to spawn mysql_secure_install with sudo in future?
2017-08-23 11:55:44 +02:00
expect -f - <<-EOF
set timeout 10
spawn mysql_secure_installation
expect "Enter current password for root (enter for none):"
send -- "\r"
expect "Set root password?"
send -- "y\r"
expect "New password:"
send -- "${DBPASSWORD_ADMIN}\r"
expect "Re-enter new password:"
send -- "${DBPASSWORD_ADMIN}\r"
expect "Remove anonymous users?"
send -- "y\r"
expect "Disallow root login remotely?"
send -- "y\r"
expect "Remove test database and access to it?"
send -- "y\r"
expect "Reload privilege tables now?"
send -- "y\r"
expect eof
EOF
sudo apt-get purge -y expect > /dev/null 2>&1
2017-09-06 09:22:58 +02:00
echo "--- Installing Apache2 ---"
2017-08-23 11:55:44 +02:00
sudo apt-get install -y apache2 apache2-doc apache2-utils > /dev/null 2>&1
echo "--- Installing mod-wsgi-py3 for misp-dashboard ---"
sudo apt-get install -y libapache2-mod-wsgi-py3 > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
sudo a2dismod status > /dev/null 2>&1
sudo a2enmod ssl > /dev/null 2>&1
sudo a2enmod rewrite > /dev/null 2>&1
sudo a2dissite 000-default > /dev/null 2>&1
sudo a2ensite default-ssl > /dev/null 2>&1
2017-09-06 09:22:58 +02:00
echo "--- Installing PHP-specific packages ---"
2017-08-23 11:55:44 +02:00
sudo apt-get install -y libapache2-mod-php php php-cli php-crypt-gpg php-dev php-json php-mysql php-opcache php-readline php-redis php-xml > /dev/null 2>&1
echo "--- Configuring PHP ---"
for key in upload_max_filesize post_max_size max_execution_time max_input_time memory_limit
do
sudo sed -i "s/^\($key\).*/\1 = $(eval echo \${$key})/" $PHP_INI
done
2017-08-23 11:55:44 +02:00
2017-09-06 09:22:58 +02:00
echo "--- Restarting Apache ---"
2017-08-23 11:55:44 +02:00
sudo systemctl restart apache2 > /dev/null 2>&1
2017-09-06 09:22:58 +02:00
echo "--- Retrieving MISP ---"
## Double check perms.
sudo mkdir $PATH_TO_MISP
2017-08-23 11:55:44 +02:00
sudo chown www-data:www-data $PATH_TO_MISP
cd $PATH_TO_MISP
sudo -u www-data git clone -b $MISP_BRANCH https://github.com/MISP/MISP.git $PATH_TO_MISP
2017-08-23 11:55:44 +02:00
#git checkout tags/$(git describe --tags `git rev-list --tags --max-count=1`)
sudo -u www-data git config core.filemode false
# chown -R www-data $PATH_TO_MISP
# chgrp -R www-data $PATH_TO_MISP
# chmod -R 700 $PATH_TO_MISP
2017-09-06 09:22:58 +02:00
echo "--- Installing Mitre's STIX ---"
sudo apt-get install -y python-dev python3-dev python-pip python3-pip libxml2-dev libxslt1-dev zlib1g-dev python-setuptools > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
cd $PATH_TO_MISP/app/files/scripts
sudo -u www-data git clone https://github.com/CybOXProject/python-cybox.git
sudo -u www-data git clone https://github.com/STIXProject/python-stix.git
cd $PATH_TO_MISP/app/files/scripts/python-cybox
sudo python3 setup.py install > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
cd $PATH_TO_MISP/app/files/scripts/python-stix
sudo python3 setup.py install > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
# install mixbox to accomodate the new STIX dependencies:
cd $PATH_TO_MISP/app/files/scripts/
sudo -u www-data git clone https://github.com/CybOXProject/mixbox.git
cd $PATH_TO_MISP/app/files/scripts/mixbox
sudo python3 setup.py install > /dev/null 2>&1
2017-08-23 11:55:44 +02:00
echo "--- Installing misp-dashboard ---"
cd /var/www
sudo mkdir misp-dashboard
sudo chown www-data:www-data misp-dashboard
sudo -u www-data git clone https://github.com/SteveClement/misp-dashboard.git
cd misp-dashboard
sudo /var/www/misp-dashboard/install_dependencies.sh
sudo sed -i "s/^host\ =\ localhost/host\ =\ 0.0.0.0/g" /var/www/misp-dashboard/config/config.cfg
echo "--- Retrieving CakePHP… ---"
2017-08-23 11:55:44 +02:00
# CakePHP is included as a submodule of MISP, execute the following commands to let git fetch it:
cd $PATH_TO_MISP
sudo -u www-data git submodule init
sudo -u www-data git submodule update
# Once done, install CakeResque along with its dependencies if you intend to use the built in background jobs:
cd $PATH_TO_MISP/app
sudo -u www-data php composer.phar require kamisama/cake-resque:4.1.2
sudo -u www-data php composer.phar config vendor-dir Vendor
sudo -u www-data php composer.phar install
# Enable CakeResque with php-redis
sudo phpenmod redis
# To use the scheduler worker for scheduled tasks, do the following:
sudo -u www-data cp -fa $PATH_TO_MISP/INSTALL/setup/config.php $PATH_TO_MISP/app/Plugin/CakeResque/Config/config.php
echo "--- Setting the permissions… ---"
2017-08-23 11:55:44 +02:00
sudo chown -R www-data:www-data $PATH_TO_MISP
sudo chmod -R 750 $PATH_TO_MISP
sudo chmod -R g+ws $PATH_TO_MISP/app/tmp
sudo chmod -R g+ws $PATH_TO_MISP/app/files
sudo chmod -R g+ws $PATH_TO_MISP/app/files/scripts/tmp
echo "--- Creating a database user… ---"
2017-08-23 11:55:44 +02:00
sudo mysql -u $DBUSER_ADMIN -p$DBPASSWORD_ADMIN -e "create database $DBNAME;"
sudo mysql -u $DBUSER_ADMIN -p$DBPASSWORD_ADMIN -e "grant usage on *.* to $DBNAME@localhost identified by '$DBPASSWORD_MISP';"
sudo mysql -u $DBUSER_ADMIN -p$DBPASSWORD_ADMIN -e "grant all privileges on $DBNAME.* to '$DBUSER_MISP'@'localhost';"
sudo mysql -u $DBUSER_ADMIN -p$DBPASSWORD_ADMIN -e "flush privileges;"
# Import the empty MISP database from MYSQL.sql
2018-01-25 08:58:08 +01:00
sudo -u www-data cat /var/www/MISP/INSTALL/MYSQL.sql | mysql -u $DBUSER_MISP -p$DBPASSWORD_MISP $DBNAME
2017-08-23 11:55:44 +02:00
echo "--- Configuring Apache… ---"
2017-08-23 11:55:44 +02:00
# !!! apache.24.misp.ssl seems to be missing
#cp $PATH_TO_MISP/INSTALL/apache.24.misp.ssl /etc/apache2/sites-available/misp-ssl.conf
# If a valid SSL certificate is not already created for the server, create a self-signed certificate:
sudo openssl req -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=$OPENSSL_C/ST=$OPENSSL_ST/L=$OPENSSL_L/O=<$OPENSSL_O/OU=$OPENSSL_OU/CN=$OPENSSL_CN/emailAddress=$OPENSSL_EMAILADDRESS" -keyout /etc/ssl/private/misp.local.key -out /etc/ssl/private/misp.local.crt > /dev/null
2017-08-23 11:55:44 +02:00
2018-04-06 07:11:15 +02:00
echo "--- Adding Listen 8001 for misp-dashboard ---"
sudo sed -i '/Listen 80/a Listen 0.0.0.0:8001' /etc/apache2/ports.conf
echo "--- Add a VirtualHost for MISP and misp-dashboard ---"
## Again double check this perm madness ;)
2017-08-23 11:55:44 +02:00
sudo cat > /etc/apache2/sites-available/misp-ssl.conf <<EOF
<VirtualHost *:80>
ServerAdmin admin@misp.local
ServerName misp.local
DocumentRoot $PATH_TO_MISP/app/webroot
<Directory $PATH_TO_MISP/app/webroot>
Options -Indexes
AllowOverride all
Require all granted
</Directory>
LogLevel warn
ErrorLog /var/log/apache2/misp.local_error.log
CustomLog /var/log/apache2/misp.local_access.log combined
ServerSignature Off
2017-08-23 11:55:44 +02:00
</VirtualHost>
EOF
sudo cat > /etc/apache2/sites-available/misp-dashboard.conf <<EOF
<VirtualHost *:8001>
ServerAdmin admin@misp.local
ServerName misp.local
DocumentRoot /var/www/misp-dashboard
WSGIDaemonProcess misp-dashboard \
user=misp group=misp \
python-home=/var/www/misp-dashboard/DASHENV \
processes=1 \
threads=15 \
maximum-requests=5000 \
listen-backlog=100 \
queue-timeout=45 \
socket-timeout=60 \
connect-timeout=15 \
request-timeout=60 \
inactivity-timeout=0 \
deadlock-timeout=60 \
graceful-timeout=15 \
eviction-timeout=0 \
shutdown-timeout=5 \
send-buffer-size=0 \
receive-buffer-size=0 \
header-buffer-size=0 \
response-buffer-size=0 \
server-metrics=Off
WSGIScriptAlias / /var/www/misp-dashboard/misp-dashboard.wsgi
<Directory /var/www/misp-dashboard>
WSGIProcessGroup misp-dashboard
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
LogLevel info
ErrorLog /var/log/apache2/misp-dashboard.local_error.log
CustomLog /var/log/apache2/misp-dashboard.local_access.log combined
ServerSignature Off
</VirtualHost>
EOF
2017-08-23 11:55:44 +02:00
# cat > /etc/apache2/sites-available/misp-ssl.conf <<EOF
# <VirtualHost *:80>
# ServerName misp.local
#
# Redirect permanent / https://$FQDN
#
# LogLevel warn
# ErrorLog /var/log/apache2/misp.local_error.log
# CustomLog /var/log/apache2/misp.local_access.log combined
# ServerSignature Off
# </VirtualHost>
#
# <VirtualHost *:443>
# ServerAdmin me@me.local
# ServerName misp.local
# DocumentRoot $PATH_TO_MISP/app/webroot
#
# <Directory $PATH_TO_MISP/app/webroot>
# Options -Indexes
# AllowOverride all
# Require all granted
# </Directory>
#
# SSLEngine On
# SSLCertificateFile /etc/ssl/private/misp.local.crt
# SSLCertificateKeyFile /etc/ssl/private/misp.local.key
# #SSLCertificateChainFile /etc/ssl/private/misp-chain.crt
#
# LogLevel warn
# ErrorLog /var/log/apache2/misp.local_error.log
# CustomLog /var/log/apache2/misp.local_access.log combined
# ServerSignature Off
# </VirtualHost>
# EOF
# activate new vhost
sudo a2dissite default-ssl
sudo a2ensite misp-ssl
sudo a2ensite misp-dashboard
2017-08-23 11:55:44 +02:00
2017-09-06 09:22:58 +02:00
echo "--- Restarting Apache ---"
2017-08-23 11:55:44 +02:00
sudo systemctl restart apache2 > /dev/null 2>&1
2017-09-06 09:22:58 +02:00
echo "--- Configuring log rotation ---"
2017-08-23 11:55:44 +02:00
sudo cp $PATH_TO_MISP/INSTALL/misp.logrotate /etc/logrotate.d/misp
2017-09-06 09:22:58 +02:00
echo "--- MISP configuration ---"
2017-08-23 11:55:44 +02:00
# There are 4 sample configuration files in /var/www/MISP/app/Config that need to be copied
sudo -u www-data cp -a $PATH_TO_MISP/app/Config/bootstrap.default.php /var/www/MISP/app/Config/bootstrap.php
sudo -u www-data cp -a $PATH_TO_MISP/app/Config/database.default.php /var/www/MISP/app/Config/database.php
sudo -u www-data cp -a $PATH_TO_MISP/app/Config/core.default.php /var/www/MISP/app/Config/core.php
sudo -u www-data cp -a $PATH_TO_MISP/app/Config/config.default.php /var/www/MISP/app/Config/config.php
sudo -u www-data cat > $PATH_TO_MISP/app/Config/database.php <<EOF
<?php
class DATABASE_CONFIG {
public \$default = array(
'datasource' => 'Database/Mysql',
//'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => '$DBHOST',
'login' => '$DBUSER_MISP',
'port' => 3306, // MySQL & MariaDB
//'port' => 5432, // PostgreSQL
'password' => '$DBPASSWORD_MISP',
'database' => '$DBNAME',
'prefix' => '',
'encoding' => 'utf8',
);
}
EOF
# and make sure the file permissions are still OK
sudo chown -R www-data:www-data $PATH_TO_MISP/app/Config
sudo chmod -R 750 $PATH_TO_MISP/app/Config
# Set some MISP directives with the command line tool
2017-08-28 08:12:20 +02:00
sudo $PATH_TO_MISP/app/Console/cake Live $MISP_LIVE
2017-08-23 11:55:44 +02:00
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_event_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_object_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_object_reference_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_attribute_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_sighting_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_user_notifications_enable" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_organisation_notifications_enable" true
2017-08-23 11:55:44 +02:00
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "GnuPG.email" "admin@admin.test"
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "GnuPG.homedir" "/var/www/MISP/.gnupg"
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "GnuPG.password" "Password1234"
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.host_org_id" 1
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.email" "info@admin.test"
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.disable_emailing" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.contact" "info@admin.test"
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.disablerestalert" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "MISP.showCorrelationsOnIndex" true
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Session.autoRegenerate" 0
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Session.timeout" 600
sudo $PATH_TO_MISP/app/Console/cake Admin setSetting "Session.cookie_timeout" 3600
echo "--- Generating a GPG encryption key… ---"
2017-08-23 11:55:44 +02:00
sudo apt-get install -y rng-tools haveged
sudo -u www-data mkdir $PATH_TO_MISP/.gnupg
sudo chmod 700 $PATH_TO_MISP/.gnupg
cat >/tmp/gen-key-script <<EOF
2017-08-23 11:55:44 +02:00
%echo Generating a default key
Key-Type: default
Key-Length: $GPG_KEY_LENGTH
Subkey-Type: default
Name-Real: $GPG_REAL_NAME
Name-Comment: $GPG_COMMENT
2017-08-23 11:55:44 +02:00
Name-Email: $GPG_EMAIL_ADDRESS
Expire-Date: 0
Passphrase: $GPG_PASSPHRASE
2017-08-23 11:55:44 +02:00
# Do a commit here, so that we can later print "done"
%commit
%echo done
EOF
sudo -u www-data gpg --homedir $PATH_TO_MISP/.gnupg --batch --gen-key /tmp/gen-key-script
rm /tmp/gen-key-script
2017-08-23 11:55:44 +02:00
# And export the public key to the webroot
sudo -u www-data sh -c "gpg --homedir $PATH_TO_MISP/.gnupg --export --armor $GPG_EMAIL_ADDRESS > $PATH_TO_MISP/app/webroot/gpg.asc"
2017-08-23 11:55:44 +02:00
echo "--- Making the background workers start on boot… ---"
2017-08-23 11:55:44 +02:00
sudo chmod 755 $PATH_TO_MISP/app/Console/worker/start.sh
2017-08-28 08:12:20 +02:00
# With systemd:
# sudo cat > /etc/systemd/system/workers.service <<EOF
# [Unit]
# Description=Start the background workers at boot
#
# [Service]
# Type=forking
# User=www-data
# ExecStart=$PATH_TO_MISP/app/Console/worker/start.sh
#
# [Install]
# WantedBy=multi-user.target
# EOF
# sudo systemctl enable workers.service > /dev/null
# sudo systemctl restart workers.service > /dev/null
# With initd:
if [ ! -e /etc/rc.local ]
then
echo '#!/bin/sh -e' | sudo tee -a /etc/rc.local
echo 'exit 0' | sudo tee -a /etc/rc.local
chmod u+x /etc/rc.local
2017-08-28 08:12:20 +02:00
fi
# redis-server requires the following /sys/kernel tweak
sed -i -e '$i \echo never > /sys/kernel/mm/transparent_hugepage/enabled\n' /etc/rc.local
sed -i -e '$i \echo 1024 > /proc/sys/net/core/somaxconn\n' /etc/rc.local
sed -i -e '$i \sysctl vm.overcommit_memory=1\n' /etc/rc.local
sed -i -e '$i \sudo -u www-data bash /var/www/MISP/app/Console/worker/start.sh\n' /etc/rc.local
sed -i -e '$i \sudo -u www-data misp-modules -l 0.0.0.0 -s &\n' /etc/rc.local
sed -i -e '$i \sudo -u www-data bash /var/www/misp-dashboard/start_all.sh\n' /etc/rc.local
sed -i -e '$i \sudo -u misp /usr/local/src/viper/viper-web -p 8888 -H 0.0.0.0 &\n' /etc/rc.local
sed -i -e '$i \git_dirs="/usr/local/src/misp-modules/ /var/www/misp-dashboard /usr/local/src/faup /usr/local/src/mail_to_misp /usr/local/src/misp-modules /usr/local/src/viper /var/www/misp-dashboard"\n' /etc/rc.local
sed -i -e '$i \for d in $git_dirs; do\n' /etc/rc.local
sed -i -e '$i \ echo "Updating ${d}"\n' /etc/rc.local
sed -i -e '$i \ cd $d && sudo git pull &\n' /etc/rc.local
sed -i -e '$i \done\n' /etc/rc.local
2017-08-23 11:55:44 +02:00
echo "--- Installing MISP modules… ---"
sudo apt-get install -y libpq5 libjpeg-dev libfuzzy-dev > /dev/null 2>&1
2017-08-29 11:45:39 +02:00
cd /usr/local/src/
sudo git clone https://github.com/MISP/misp-modules.git
cd misp-modules
2018-05-23 02:22:05 +02:00
# pip3 install
2017-08-29 11:45:39 +02:00
sudo pip3 install -I -r REQUIREMENTS > /dev/null 2>&1
sudo pip3 install -I . > /dev/null 2>&1
sudo pip3 install lief 2>&1
sudo pip3 install maec 2>&1
sudo pip3 install pymisp python-magic > /dev/null 2>&1
sudo pip3 install git+https://github.com/kbandla/pydeep.git > /dev/null 2>&1
2018-05-23 02:22:05 +02:00
# pip2 install
2018-04-20 23:27:17 +02:00
sudo pip2 install pymisp python-magic > /dev/null 2>&1
sudo pip2 install git+https://github.com/kbandla/pydeep.git > /dev/null 2>&1
sudo pip2 install lief 2>&1
# install STIX2.0 library to support STIX 2.0 export:
sudo pip3 install stix2 > /dev/null 2>&1
2017-08-29 11:45:39 +02:00
# With systemd:
2017-08-23 11:55:44 +02:00
# sudo cat > /etc/systemd/system/misp-modules.service <<EOF
# [Unit]
# Description=Start the misp modules server at boot
#
# [Service]
# Type=forking
# User=www-data
# ExecStart=/bin/sh -c 'misp-modules -l 0.0.0.0 -s &'
#
# [Install]
# WantedBy=multi-user.target
# EOF
# sudo systemctl enable misp-modules.service > /dev/null
# sudo systemctl restart misp-modules.service > /dev/null
2017-08-29 11:45:39 +02:00
# With initd:
# sudo sed -i -e '$i \sudo -u www-data misp-modules -l 0.0.0.0 -s &\n' /etc/rc.local
2017-08-29 11:45:39 +02:00
echo "--- Installing viper-framework ---"
cd /usr/local/src/
apt-get install -y libssl-dev swig python3-ssdeep p7zip-full unrar sqlite python3-pyclamd exiftool radare2
pip3 install SQLAlchemy PrettyTable python-magic 2>&1
git clone https://github.com/viper-framework/viper.git
cd viper
git submodule init
git submodule update
pip3 install -r requirements.txt > /dev/null 2>&1
sudo -u misp /usr/local/src/viper/viper-cli -h > /dev/null 2>&1
sudo -u misp /usr/local/src/viper/viper-web -p 8888 -H 0.0.0.0 &
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/src/viper"' |sudo tee /etc/environment
echo "--- Installing mail2misp ---"
cd /usr/local/src/
sudo apt-get install -y cmake
sudo git clone https://github.com/MISP/mail_to_misp.git
sudo git clone git://github.com/stricaud/faup.git
cd faup
sudo mkdir -p build
cd build
sudo cmake .. && sudo make
sudo make install
sudo ldconfig
cd ../../
cd mail_to_misp
sudo pip3 install -r requirements.txt > /dev/null 2>&1
sudo cp mail_to_misp_config.py-example mail_to_misp_config.py
echo "--- Generating Certificate ---"
sudo openssl req -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=LU/ST=/L=Luxembourg/O=CIRCL/OU=VM AutoGen/CN=localhost/emailAddress=admin@admin.test" -keyout /etc/ssl/private/misp.local.key -out /etc/ssl/private/misp.local.crt
2017-08-29 11:45:39 +02:00
echo "--- Setting the permissions… ---"
sudo chown -R www-data:www-data $PATH_TO_MISP
sudo chmod -R 750 $PATH_TO_MISP
sudo chmod -R g+ws $PATH_TO_MISP/app/tmp
sudo chmod -R g+ws $PATH_TO_MISP/app/files
sudo chmod -R g+ws $PATH_TO_MISP/app/files/scripts/tmp
2017-08-23 11:55:44 +02:00
echo "--- Restarting Apache… ---"
2017-08-23 11:55:44 +02:00
sudo systemctl restart apache2 > /dev/null 2>&1
sleep 5
echo "--- Updating the galaxies… ---"
2017-08-23 11:55:44 +02:00
sudo -E $PATH_TO_MISP/app/Console/cake userInit -q > /dev/null
AUTH_KEY=$(mysql -u $DBUSER_MISP -p$DBPASSWORD_MISP misp -e "SELECT authkey FROM users;" | tail -1)
2018-02-16 10:22:50 +01:00
echo "--- Updating the galaxies… ---"
curl --header "Authorization: $AUTH_KEY" --header "Accept: application/json" --header "Content-Type: application/json" -o /dev/null -s -X POST http://127.0.0.1/galaxies/update
2017-08-23 11:55:44 +02:00
echo "--- Updating the taxonomies… ---"
2018-02-16 10:22:50 +01:00
curl --header "Authorization: $AUTH_KEY" --header "Accept: application/json" --header "Content-Type: application/json" -o /dev/null -s -X POST http://127.0.0.1/taxonomies/update
echo "--- Updating the warning lists… ---"
curl --header "Authorization: $AUTH_KEY" --header "Accept: application/json" --header "Content-Type: application/json" -o /dev/null -s -X POST http://127.0.0.1/warninglists/update
2018-05-23 02:06:52 +02:00
echo "--- Updating the notice lists… ---"
curl --header "Authorization: $AUTH_KEY" --header "Accept: application/json" --header "Content-Type: application/json" -o /dev/null -s -X POST http://127.0.0.1/noticelists/update
2018-02-16 10:22:50 +01:00
echo "--- Updating the object templates… ---"
curl --header "Authorization: $AUTH_KEY" --header "Accept: application/json" --header "Content-Type: application/json" -o /dev/null -s -X POST http://127.0.0.1/objectTemplates/update
2017-08-23 11:55:44 +02:00
echo "--- Setting Baseurl ---"
sudo $PATH_TO_MISP/app/Console/cake Baseurl ""
2017-08-23 11:55:44 +02:00
echo "--- Enabling MISP new pub/sub feature (ZeroMQ)… ---"
sudo apt-get install -y pkg-config python-redis python-zmq python3-zmq > /dev/null 2>&1
echo "--- Configuring viper ---"
sed -i "s/^misp_url\ =/misp_url\ =\ http:\/\/localhost/g" ~/.viper/viper.conf
sed -i "s/^misp_key\ =/misp_key\ =\ $AUTH_KEY/g" ~/.viper/viper.conf
# Setting viper-web admin user password to 'Password1234'
sqlite3 ~/.viper/admin.db 'UPDATE auth_user SET password="pbkdf2_sha256$100000$iXgEJh8hz7Cf$vfdDAwLX8tko1t0M1TLTtGlxERkNnltUnMhbv56wK/U="'
echo "--- Configuring mail2misp ---"
sudo sed -i "s/^misp_url\ =\ 'YOUR_MISP_URL'/misp_url\ =\ 'http:\/\/localhost'/g" /usr/local/src/mail_to_misp/mail_to_misp_config.py
sudo sed -i "s/^misp_key\ =\ 'YOUR_KEY_HERE'/misp_key\ =\ '$AUTH_KEY'/g" /usr/local/src/mail_to_misp/mail_to_misp_config.py
echo "--- Setting the permissions… ---"
sudo chown -R www-data:www-data $PATH_TO_MISP
sudo chmod -R 750 $PATH_TO_MISP
sudo chmod -R g+ws $PATH_TO_MISP/app/tmp
sudo chmod -R g+ws $PATH_TO_MISP/app/files
sudo chmod -R g+ws $PATH_TO_MISP/app/files/scripts/tmp
sudo chmod 700 $PATH_TO_MISP/.gnupg
sudo chown -R misp:misp ~misp/.viper
2017-08-23 11:55:44 +02:00
echo "--- Setting Baseurl ---"
sudo $PATH_TO_MISP/app/Console/cake Baseurl ""
echo "\e[32mMISP is ready\e[0m"
echo "Login and passwords for the MISP image are the following:"
echo "Web interface (default network settings): $MISP_BASEURL"
echo "MISP admin: admin@admin.test/admin"
echo "Shell/SSH: misp/Password1234"
echo "MySQL: $DBUSER_ADMIN/$DBPASSWORD_ADMIN - $DBUSER_MISP/$DBPASSWORD_MISP"
echo "MySQL: $DBUSER_ADMIN/$DBPASSWORD_ADMIN - $DBUSER_MISP/$DBPASSWORD_MISP" > ~/mysql.txt
chown misp:misp ~/mysql.txt
TIME_END=$(date +%s)
TIME_DELTA=$(expr ${TIME_END} - ${TIME_START})
echo "The generation took ${TIME_DELTA} seconds"