Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active July 14, 2019 12:43
Show Gist options
  • Save chapmanjacobd/3624bfad145274b6095806a1ba960050 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/3624bfad145274b6095806a1ba960050 to your computer and use it in GitHub Desktop.
run file after start
#!/bin/bash
# create new user
adduser -m --disabled-password --gecos "" bluehat
usermod -aG sudo bluehat
#usermod -aG wheel bluehat
echo "bluehat ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
su bluehat
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
#generate your RSA keys: ssh-keygen -t rsa -b 4096 -f cinsects
#before: ssh [email protected] -p 22 -o PreferredAuthentications=password -o PubkeyAuthentication=no
#after: ssh [email protected] -p 22 -o "IdentitiesOnly=yes" -i ~/.ssh/cinsects
cat <<EOT >> ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAMk1QNDGipHOweLKZUuaMDwKiTPS5ZWXboniwDkOK17GvMr2OoGVw0fCvvR69m/yhzuMbfTCo/yNONBb8rN28B+Q7PJJfXXYhumT6Vly/TBfMZP9iw2BVyYWhOAoMhUZd80RfQjAxrUxg3DoB1rgFt2kes8OcaSqTu51GSlpGfL1UPVViiCRyWoSk1q8kR8iLdaCT8tbbAuvDjziEdckLc2MtoMOq67KoNcZc+flykv+Ek+wH02NpnRBkaSbxu0qVsrKNTwKdThds944j/jDUzlCO0y3KumMc+WoA9jPuZ7a6JlwPm335SYR8E6XSPPWrsFTzim1YqGNQfSlmBY+nOMv9EUO3Ipu4NmJxG5mSPNPyAv7aIbRlM4rEnUpar19AMJVlESg0jnFYGxwAMaEPdSN5DxxOxhmIQ4sFpMootz2YkqSxX6z5pRla9X88fPOLJIBa+LxmaLDYfG9Uv0bznJEQZdEx/+Tb8Aq/zKTHJaZ3CmfPCOJ6SiKPJiBHl7HB1HWWAGwJD/PzNJ1oTm5BIppe9xie2t2tqLxSumNOY2807PpBcllJV2OLluFzoI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zTt4dlrtn4915Xxk7MhJ4P04FxuQ13mxO+Ev8pKt9ZyH1Ak83uLuGrqFVzZAkQ1FirIjCos3rnAKTXCxxxT6tTLr+m7XfqUcYq+m+8FHSRx8SfVIfAdtMt6HlzBP0wUqoYit8k+y/5XPGRVMmYw3dMiQ== andry@tapakila01
EOT
chmod go-w $HOME $HOME/.ssh
chmod 600 ~/.ssh/authorized_keys
exit
# harden sshd config
cat <<EOT >> /etc/ssh/sshd_config
PermitRootLogin no
AllowUsers bluehat
EOT
/etc/init.d/sshd restart
# repair DNS(?)
echo nameserver 1.1.1.1 > /etc/resolv.conf
systemctl restart systemd-networkd
ping deb.debian.org
#ufw allow out 53,113,123/udp
chattr +i /etc/resolv.conf
apt install wget
wget https://download.configserver.com/csf.tgz
sha256sum csf.tgz
#check if match
echo dfb9318213a3e6be207ac6595b6743b0a5a5bf311508dfe0d8cf8d84ad110a87
echo "if different verify here: https://www.configserver.com/checksums.txt"
read -p "Proceed? (y/^c) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
tar -xzf csf.tgz
fi
ufw disable
cd csf
sh install.sh
perl /usr/local/csf/bin/csftest.pl
apt upgrade
#watch the logs in real time
journalctl -f &
#also for each service that we need to maintain
tail -f /var/log/apache2/access.log &
# maybe we could use this to work together https://github.com/zolrath/wemux
# it would be good if we could setup `logwatch` to send a message to IRC or discord every couple of hours
apt install logwatch
logwatch --detail med --range Today --format text --output stdout
# it would be good to install SELinux but I don't know how well Debian is supported
# this looks cool ansible-galaxy install dev-sec.os-hardening
wget https://downloads.cisofy.com/lynis/lynis-2.7.5.tar.gz
tar -xzf lynis-2.7.5.tar.gz
./lynis audit system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment