1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-07-18 21:09:41 +02:00
pandora-box/install.sh

277 lines
9.8 KiB
Bash
Raw Normal View History

2022-07-13 07:35:21 +02:00
#!/usr/bin/bash
2024-01-02 12:13:27 +01:00
#
# This file is part of the Pandora-box distribution
2022-07-07 19:59:14 +02:00
# Copyright (c) 2022 Didier Barzin.
2024-01-02 12:13:27 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2022-07-07 19:59:14 +02:00
# the Free Software Foundation, version 3.
#
2024-01-02 12:13:27 +01:00
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2022-07-07 19:59:14 +02:00
# General Public License for more details.
#
2024-01-02 12:13:27 +01:00
# You should have received a copy of the GNU General Public License
2022-07-07 19:59:14 +02:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e # stop on error
set -x # echo on
2022-07-06 17:55:07 +02:00
2023-02-13 22:10:34 +01:00
#================================
# Install script for Pandora-Box
#================================
cd /home/$SUDO_USER
# remove need restart
apt remove -y needrestart
#---------------------
2024-01-02 12:13:27 +01:00
# Python
2023-02-13 22:10:34 +01:00
#---------------------
apt update && apt upgrade -y
2025-02-19 17:54:48 +01:00
apt install -y python-is-python3 python3-pip python3-venv
2023-02-13 22:10:34 +01:00
apt install -y libssl-dev
2025-02-19 16:31:56 +01:00
su - $SUDO_USER -c "python -m venv /home/$SUDO_USER/.local"
2023-02-13 22:10:34 +01:00
#---------------------
2025-02-19 16:31:56 +01:00
# Poetry
2023-02-13 22:10:34 +01:00
#---------------------
2025-02-19 16:31:56 +01:00
# su - $SUDO_USER -c "curl -sSL https://install.python-poetry.org | python3 -"
# su - $SUDO_USER -c "poetry --version"
su - $SUDO_USER -c "pip install poetry"
2023-02-13 22:10:34 +01:00
#---------------------
2025-01-07 19:03:12 +01:00
# Valkey
2023-02-13 22:10:34 +01:00
#---------------------
2025-01-07 19:03:12 +01:00
apt install -y build-essential tcl pkg-config
2023-02-13 22:10:34 +01:00
2025-02-19 14:46:57 +01:00
if [ ! -d "valkey" ]; then
git clone https://github.com/valkey-io/valkey.git
cd valkey
git checkout 8.0
2025-02-19 16:31:56 +01:00
make -j4
2025-02-19 14:46:57 +01:00
# Optionally, you can run the tests:
# make test
cd ..
chown -R $SUDO_USER valkey
2023-04-27 13:33:38 +02:00
fi
2023-02-13 22:10:34 +01:00
#---------------------
# Kvrocks
#---------------------
2024-01-21 20:14:02 +01:00
apt-get update
apt install -y git gcc g++ make cmake autoconf automake libtool python3 libssl-dev
2023-02-13 22:10:34 +01:00
2025-02-19 14:46:57 +01:00
if [ ! -d "kvrocks" ]; then
git clone --recursive https://github.com/apache/incubator-kvrocks.git kvrocks
cd kvrocks
git checkout 2.10
2025-02-20 10:01:33 +01:00
./x.py build -j4
2025-02-19 14:46:57 +01:00
cd ..
chown -R $SUDO_USER kvrocks
2023-04-27 13:33:38 +02:00
fi
2023-02-13 22:10:34 +01:00
#---------------------
# Pandora
#---------------------
2025-02-19 14:46:57 +01:00
if [ ! -d "pandora" ]; then
git clone https://github.com/pandora-analysis/pandora.git
chown -R $SUDO_USER pandora
2023-04-27 13:40:40 +02:00
fi
2023-02-13 22:10:34 +01:00
2023-03-05 15:01:44 +01:00
# fix broken packages
apt-get install --fix-broken -y
2023-02-13 22:10:34 +01:00
# install packages
2024-01-21 20:14:02 +01:00
apt install -y python3-dev # for compiling things
apt install -y libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 # For HTML -> PDF
apt install -y libreoffice-nogui # For Office -> PDF
apt install -y exiftool # for extracting exif information
apt install -y unrar # for extracting rar files
2025-03-08 16:57:24 +01:00
apt install -y libxml2-dev libxslt1-dev antiword unrtf poppler-utils tesseract-ocr flac ffmpeg lame libmad0 libsox-fmt-mp3 sox libjpeg-dev swig # for textract
2024-01-21 20:14:02 +01:00
apt install -y libssl-dev # seems required for yara-python
apt install -y libcairo2-dev # Required by reportlab
2023-03-10 14:13:22 +01:00
apt install -y rsyslog cron # log logging
2025-06-25 12:27:42 +02:00
apt install -y ntfs-3g # for NTFS filesystems
2023-02-13 22:10:34 +01:00
2023-03-05 15:01:44 +01:00
# autoremove old stuff
apt autoremove -y
2023-02-13 22:10:34 +01:00
# set .env
2023-11-08 14:43:29 +00:00
cd pandora
2023-02-13 22:10:34 +01:00
2023-03-27 12:51:09 +02:00
su - $SUDO_USER -c "cd ~/pandora; poetry install"
2025-02-20 10:01:33 +01:00
su - $SUDO_USER -c "cd ~/pandora; echo PANDORA_HOME=\"/home/$SUDO_USER/pandora\"" >> .env
2023-03-27 12:51:09 +02:00
su - $SUDO_USER -c "cd ~/pandora; cp config/generic.json.sample config/generic.json"
2023-02-13 22:10:34 +01:00
2025-02-19 16:31:56 +01:00
# don't forget to change storage_db_hostname in config/generic.json. It should be "kvrocks"
2024-01-02 12:13:27 +01:00
# Copy default config file
2023-03-27 12:51:09 +02:00
su - $SUDO_USER -c "cp ~/pandora/config/logging.json.sample ~/pandora/config/logging.json"
2023-02-19 14:21:54 +00:00
2023-02-13 22:10:34 +01:00
# install yara-python
2025-02-19 14:46:57 +01:00
apt install -y python3-yara
2023-02-13 22:10:34 +01:00
# ClamAV
2025-04-22 11:36:50 +02:00
cd /home/$SUDO_USER
apt-get install -y hdparm clamav-daemon
2025-04-09 15:17:59 +02:00
2024-01-02 12:13:27 +01:00
# In order for the module to work, you need the signatures.
2023-02-13 22:10:34 +01:00
# Running the command "freshclam" will do it but if the script is already running
# (it is started by the systemd service clamav-freshclam)
2024-01-02 12:13:27 +01:00
# You might want to run the commands below:
2023-02-13 22:10:34 +01:00
2025-04-22 11:36:50 +02:00
systemctl stop clamav-freshclam.service # Stop the service
freshclam # Run the signatures update
systemctl start clamav-freshclam.service # Start the service so we keep getting the updates
2025-04-09 15:17:59 +02:00
2025-04-22 11:36:50 +02:00
service clamav-daemon start
2023-02-13 22:10:34 +01:00
# Comodo
wget https://download.comodo.com/cis/download/installs/linux/cav-linux_x64.deb
dpkg --ignore-depends=libssl0.9.8 -i cav-linux_x64.deb
wget http://cdn.download.comodo.com/av/updates58/sigs/bases/bases.cav -O /opt/COMODO/scanners/bases.cav
2025-04-05 08:38:19 +02:00
# Configure Pandora workers
2025-04-07 15:29:22 +02:00
# su - $SUDO_USER -c "cd ~/pandora; for file in pandora/workers/*.sample; do cp -i ${file} ${file%%.sample}; done"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp base.yml.sample base.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp blocklists.yml.sample blocklists.yml"
2025-04-22 11:36:50 +02:00
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp comodo.yml.sample comodo.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp clamav.yml.sample clamav.yml"
2025-04-08 09:25:25 +02:00
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp extractor.yml.sample extractor.yml"
2025-04-07 15:29:22 +02:00
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp hashlookup.yml.sample hashlookup.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp pdf.yml.sample pdf.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp xmldeobfuscator.yml.sample xmldeobfuscator.yml"
2025-04-08 09:25:25 +02:00
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp yara.yml.sample yara.yml"
2025-04-07 15:29:22 +02:00
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp yara_signature_base.yml.sample yara_signature_base.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp yarahq_full.yml.sample yarahq_full.yml"
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; cp yarahub.yml.sample yarahq_full.yml"
2025-04-07 10:57:39 +02:00
2025-04-08 09:25:25 +02:00
# Increase the number of replica
su - $SUDO_USER -c "cd ~/pandora/pandora/workers; sed -i 's/replicas: 1/replicas: 5/' base.yml"
2025-04-09 14:22:47 +02:00
# Disable UNO Server -> "disable_unoserver": true,
su - $SUDO_USER -c "cd ~/pandora/config; sed -i 's/\"disable_unoserver\"\: false/\"disable_unoserver\"\: true/' generic.json"
2025-04-05 08:57:01 +02:00
# remove some workers
2025-04-05 09:00:29 +02:00
# rm pandora/workers/preview.yml
2025-04-04 21:06:00 +02:00
2025-04-22 11:36:50 +02:00
# Update Pandora
2024-01-21 19:09:56 +01:00
su - $SUDO_USER -c "cd ~/pandora; poetry run update --yes"
2023-02-13 22:10:34 +01:00
2023-03-05 11:50:24 +01:00
# Remove files from quarantine after 180 days
{ crontab -l -u $SUDO_USER; echo '0 * * * * find /var/quarantine/* -type f -mtime +180 -delete '; } | crontab -u $SUDO_USER -
{ crontab -l -u $SUDO_USER; echo '5 * * * * find /var/quarantine/* -type d -empty -mtime +180 -delete '; } | crontab -u $SUDO_USER -
2023-03-05 12:27:10 +01:00
# Remove old Pandora task files every hour
2023-03-05 11:50:24 +01:00
{ crontab -l -u $SUDO_USER; echo '30 * * * * find ~/pandora/tasks/* -type f -mtime +1 -delete '; } | crontab -u $SUDO_USER -
{ crontab -l -u $SUDO_USER; echo '35 * * * * find ~/pandora/tasks/* -type d -empty -mtime +1 -delete'; } | crontab -u $SUDO_USER -
2023-03-05 13:21:50 +01:00
# Poweroff at 20:00 (green energy)
2023-04-28 08:48:44 +02:00
echo '0 20 * * * /sbin/poweroff' >> /etc/crontab
2023-03-05 13:21:50 +01:00
2022-06-28 22:49:48 +02:00
#---------------------
2022-07-04 17:29:59 +02:00
# Pandora-box
2022-06-28 22:49:48 +02:00
#---------------------
2023-02-15 11:25:39 +01:00
cd /home/$SUDO_USER/pandora-box
2022-06-28 22:49:48 +02:00
2025-04-18 09:13:37 +02:00
# FIM, psmisc (for killall) and vim
2025-02-19 14:46:57 +01:00
apt --fix-broken install -y
2025-04-18 09:13:37 +02:00
apt install -y fim psmisc vim
2025-02-19 14:46:57 +01:00
2025-04-18 09:13:37 +02:00
# Add exfat filesystem
apt install exfat-fuse exfatprogs
# Allow sudo_user users to mount and umount devices
echo "$SUDO_USER ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount" > /etc/sudoers.d/usbmount
2025-04-17 13:21:00 +02:00
2022-06-28 22:49:48 +02:00
# Python libraries
su - $SUDO_USER -c "./.local/bin/pip install pypandora psutil pyudev"
2022-06-28 22:49:48 +02:00
2023-02-15 15:09:37 +01:00
# create /media/box folder
2023-11-16 15:04:22 +01:00
if [ ! -d "/media/box" ];
2023-02-19 20:33:32 +01:00
then
echo "Create /media/box folder."
2023-03-10 14:13:22 +01:00
mkdir /media/box
2023-02-19 20:33:32 +01:00
else
echo "No /media/box folder needed."
2023-03-10 14:13:22 +01:00
fi
2023-02-15 15:09:37 +01:00
2022-06-28 22:49:48 +02:00
# Quarantine folder
2022-07-04 20:24:06 +02:00
mkdir -p /var/quarantine
2022-07-04 17:29:59 +02:00
chown $SUDO_USER /var/quarantine
2022-06-28 22:49:48 +02:00
# Suppress all messages from the kernel (and its drivers) except panic messages from appearing on the console.
2022-07-04 17:29:59 +02:00
echo "kernel.printk = 3 4 1 3" | tee -a /etc/sysctl.conf
2022-07-05 20:14:07 +02:00
# Set Permanently ulimit -n / open files in ubuntu
echo "fs.file-max = 65535" | tee -a /etc/sysctl.conf
2022-06-28 22:49:48 +02:00
# allow write to /dev/fb0
2022-07-04 17:29:59 +02:00
usermod -a -G video $SUDO_USER
2022-06-28 22:49:48 +02:00
2022-06-30 10:32:30 +02:00
# allow read mouse input
2022-07-04 17:29:59 +02:00
usermod -a -G input $SUDO_USER
2022-06-30 10:32:30 +02:00
2022-07-12 16:31:57 +00:00
# allow read mouse input
usermod -a -G tty $SUDO_USER
2023-02-22 13:10:31 +01:00
# allow write to /var/log
usermod -a -G syslog $SUDO_USER
2023-02-22 15:55:18 +01:00
# logrotate
2024-01-21 22:59:19 +01:00
apt install logrotate
2023-02-22 15:55:18 +01:00
echo "/var/log/pandora-box.log {" > /etc/logrotate.d/pandora-box
echo " rotate 12" >> /etc/logrotate.d/pandora-box
echo " monthly" >> /etc/logrotate.d/pandora-box
echo " compress" >> /etc/logrotate.d/pandora-box
2023-02-22 16:35:38 +01:00
echo " missingok" >> /etc/logrotate.d/pandora-box
2023-02-22 15:55:18 +01:00
echo " notifempty" >> /etc/logrotate.d/pandora-box
echo "}" >> /etc/logrotate.d/pandora-box
2023-03-05 13:49:50 +01:00
echo "/var/log/pandora_message.log {" > /etc/logrotate.d/pandora_message
echo " rotate 12" >> /etc/logrotate.d/pandora_message
echo " monthly" >> /etc/logrotate.d/pandora_message
echo " compress" >> /etc/logrotate.d/pandora_message
echo " missingok" >> /etc/logrotate.d/pandora_message
echo " notifempty" >> /etc/logrotate.d/pandora_message
echo "}" >> /etc/logrotate.d/pandora_message
echo "/var/log/pandora_error.log {" > /etc/logrotate.d/pandora_error
echo " rotate 12" >> /etc/logrotate.d/pandora_error
echo " monthly" >> /etc/logrotate.d/pandora_error
echo " compress" >> /etc/logrotate.d/pandora_error
echo " missingok" >> /etc/logrotate.d/pandora_error
echo " notifempty" >> /etc/logrotate.d/pandora_error
echo "}" >> /etc/logrotate.d/pandora_error
2022-07-06 17:55:07 +02:00
# Start Pandora at boot
2022-07-06 19:10:16 +02:00
cp pandora.service /etc/systemd/system/pandora.service
2022-07-06 18:41:41 +02:00
sed -i "s/_USER_/$SUDO_USER/g" /etc/systemd/system/pandora.service
systemctl daemon-reload
systemctl enable pandora
2022-06-28 22:49:48 +02:00
2025-02-20 09:07:56 +01:00
# Autologin user on getty1 at boot
2022-07-04 20:24:06 +02:00
mkdir -p /etc/systemd/system/getty@tty1.service.d
echo "[Service]" > /etc/systemd/system/getty@tty1.service.d/override.conf
echo "ExecStart=" >> /etc/systemd/system/getty@tty1.service.d/override.conf
2025-02-20 09:07:56 +01:00
echo "ExecStart=-/sbin/agetty --autologin $SUDO_USER --noclear %I \$TERM" >> /etc/systemd/system/getty@tty1.service.d/override.conf
2022-07-04 20:24:06 +02:00
2023-02-13 21:28:53 +01:00
# Copy ini file
2023-03-27 12:51:09 +02:00
su - $SUDO_USER -c "cp ~/pandora-box/pandora-box.ini.curses ~/pandora-box/pandora-box.ini"
2023-02-13 21:28:53 +01:00
2025-02-20 09:07:56 +01:00
# Do not print messages on console
echo "mesg n" >> /home/$SUDO_USER/.bashrc
2025-04-08 11:29:09 +02:00
# Add path to Poetry
2025-04-09 15:17:59 +02:00
echo "export PATH=\"/home/$SUDO_USER/.local/bin:$PATH\"" >> /home/$SUDO_USER/.bashrc
2025-04-08 11:29:09 +02:00
2025-02-20 09:07:56 +01:00
# Exec pandora at login
echo "exec pandora-box/pandora-box.py" >> /home/$SUDO_USER/.bashrc
2023-02-13 21:28:53 +01:00
# Reboot
2023-03-10 14:13:22 +01:00
echo "You may reboot the server."