Assume root permissions are needed for most commands. You can use sudo or become root with su.
I would no longer recommend running apt-get dist-upgrade in competition. They may call it intelligent, but it has a bad track record of breaking critical services.
This script heavily borrows from Forty-Bot Linux Checklist
-
Read the readme
Take notes on neccessary services, users, and any other important information.
-
Do the Forensics Questions
Forensics questions can point you towards other vulnerabilities. Keep this in mind. (ex: a media file, find a hidden message, find a backdoor, etc)
- Locate files
locate *.mp3find -size 12934c (c is for bytes - Find Machine ID
hostnamctl
- Locate files
-
Install clamtk
apt-get install clamtkRun the scanfreshclam -
Install required services found in README.md
-
Account Configuration
-
Secure the /etc/shadow file
chmod 640 /etc/shadow -
Lock the root account
$ passwd -l root -
set
PermitRootLogin noin/etc/ssh/sshd_config -
Disable the guest account in
/etc/lightdm/lightdm.confallow-guest=false greeter-hide-users=true greeter-show-manual-login=true autologin-user=none -
Compare
/etc/passwdand/etc/groupto the readmeLook out for uid 0 and hidden users! Look for any repeating UID or GID Make sure no programs have a /bin/sh or /bin/bash Only root should have a UID and GID of 0
-
Delete unauthorized users
$ userdel -r $user $ groupdel $user -
Add users
$ useradd -G $group1,$group2 $user $ passwd $user -
Remove unauthorized users from adm and groups
$ gpasswd -d $user $group -
Change unsecure password for users
passwd $user -
Add authorized users to groups
$ gpasswd -a $user $group -
Check
/etc/sudoersand/etc/sudoers.dfor unauthorized users and groups.-
Remove any instances of
nopasswdand!authenticate, these allow sudo use without authentication -
Any commands listed can be run without a password (ex: /bin/chmod)
-
Group lines are preceded by
%
-
-
Wait to change user passwords until after password policy!
-
-
Password Policy
-
Change password expiration requirements in
/etc/login.defsFAILLOG_ENAB YES LOG_UNKFAIL_ENAB YES SYSLOG_SU_ENAB YES SYSLOG_SG_ENAB YES PASS_MAX_DAYS 30 PASS_MIN_DAYS 7 PASS_WARN_AGE 12 -
Add password history, minimum password length, and password complexity requirements in
/etc/pam.d/common-passwordPASSWORD LENGTH-
The file that controls password complexity is: INSTALL CRACKLIB PRIOR TO CHANGING COMMON-PASSWORD
$ apt-get install libpam-cracklibpassword required pam_unix.so obscure sha512 remember=12 use_authtok password required pam_cracklib.so retry=3 minlen=13 difok=4 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 maxrepeat=3/etc/pam.d/common-password- There is a line:
password [success=1 default=ignore] pam_unix.so obscure sha512- Which defines the basic rules for password complexity. You can add a minimum length override by changing it to:
password [success=1 default=ignore] pam_unix.so obscure sha512 minlen=12 -
REMOVE nullok after pam_unix.so since Null passwords do not authenticate:
-
Go to
sudo gedit /etc/pam.d/common-auth -
Remove nullok
auth [success=2 default=ignore]pam_unix.so nullok- It should look like this:
auth [success=2 default=ignore]pam_unix.so -
-
-
Enforce account lockout policy in
/etc/pam.d/common-authMUST COME FIRST
auth required pam_tally2.so deny=5 audit unlock_time=1800 onerr=fail even_deny_rootIn a terminal, type
sudo touch /usr/share/pam-configs/faillock, then sudo nano /usr/share/pam-configs/faillock`Name: Enforce failed login attempt counter Default: no Priority: 0 Auth-Type: Primary Auth: [default=die] pam_faillock.so authfail sufficient pam_faillock.so authsucctype
sudo touch /usr/share/pam-configs/faillock_notify, thensudo nano /usr/share/pam-configs/faillock_notifyName: Notify on failed login attempts Default: no Priority: 1024 Auth-Type: Primary Auth: requisite pam_faillock.so preauthType
sudo pam-auth-update. Select, with the spacebar, Notify on failed login attempts, and Enforce failed login attempt counter, and then select<Ok>. -
Change account expiry defaults in
/etc/default/useraddEXPIRE=30 INACTIVE=30 -
Check minimum and maximum password ages in
/etc/shadowUse
chageto change password expiration.$ chage -m $MIN -M $MAX $user -
CHANGE PASSWORDS---YOU WILL BE LOCKED OUT IF YOU DON'T!
Be sure to record new user passwords!
$ passwd $user
-
-
Check for unauthorized media
-
Find media files
$ find / -iname "*.$extension" -
Look through user home directories for any unauthorized media
$ ls -alR /homeThere also may be unauthorized network shares not under the /home directory
-
-
Network Security
-
Enable and configure UFW
$ ufw default deny incoming $ ufw default allow outgoing $ ufw allow $port/service $ ufw delete $rule $ ufw logging on $ ufw logging high $ ufw enable -
Check
/etc/hostsfile for suspicious entries -
Prevent IP Spoofing
$ echo "nospoof on" >> /etc/host.conf
-
-
Package Management
-
Verify the repositories listed in
/etc/apt/sources.list -
Verify Repositories
-
Check apt repository policy
$ apt-cache policy -
Check apt trusted keys
$ apt-key list
-
-
Updates
$ apt-get update $ apt-get -y upgrade $ apt-get -y dist-upgrade -
Enable automatic updates
-
Enable automatic updates: Click the Show Applications button on the bottom of the Launcher and click Software & Updates (you may select Settings on the pop-up box). In the Updates tab, select the dropdown box next to Automatically check for updates, and choose Daily. If prompted type the password of your current user account. The password for your current user account can be found in the README. Click Close (or Cancel if prompted to apply updates)
-
Install
unattended-upgrades$ apt-get install unattended-upgrades -
Reconfigure
unattended-upgrades$ dpkg-reconfigure unattended-upgrades -
Edit
/etc/apt/apt.conf.d/20auto-upgradesAPT::Periodic::Update-Package-Lists "1"; APT::Periodic::Download-Upgradeable-Packages "1"; APT::Periodic::AutocleanInterval "7"; APT::Periodic::Unattended-Upgrade "1"; -
Edit
/etc/apt/apt.conf.d/50auto-upgradesUnattended-Upgrade::Allowed-Origins { "${distro_id} stable"; "${distro_id} ${distro_codename}-security"; "${distro_id} ${distro_codename}-updates"; }; Unattended-Upgrade::Package-Blacklist { "libproxy1v5"; # since the school filter blocks the word proxy };
Look for points for packages mentioned in the README, along with bash (if vulnerable to Shellshock), the kernel, sudo, and sshd
-
-
Verify binaries match with
debsums-
Install
debsums$ apt-get install debsums -
Generate checksums for packages that don't come with them
$ debsums -g -
Verify checksums for all binaries
$ debsums -c -
Verify checksums for binaries and config files (false positives for legitimate changes by us)
$ debsums -a
-
-
Remove unauthorized and unused packages
-
Use deborphan to detect unneccessary packages
-
Install deborphan
$ apt-get install deborphan -
Search for unneccessary packages
$ deborphan --guess-all -
Delete unneccessary data packages
$ deborphan --guess-data | xargs sudo apt-get -y remove --purge -
Delete unneccessary libraries
$ deborphan | xargs sudo apt-get -y remove --purge
-
-
Look for hacking tools, games, and other unwanted/unneccessary packages
$ apt-cache policy $package $ which $package $ dpkg-query -l | grep -E '^ii' | lessOR
systemctl list-units --type=service --state=active sudo systemctl stop nginx sudo systemctl disable nginx -
Ensure all services are required
service --status-all
REMOVE ANY GAMES NOT SPECIFIED
BAD STUFF
john, nmap, vuze, frostwire, kismet, freeciv, minetest, minetest-server, medusa, hydra, truecrack, ophcrack, nikto, cryptcat, nc, netcat, tightvncserver, x11vnc, nfs, xinetdPOSSIBLY BAD STUFF
samba, postgresql, sftpd, vsftpd, apache, ftp, mysql, php, snmp, pop3, icmp, sendmail/postfix, dovecot, bind9, nginx, AisleRiot, manaplus, JTR,MEGA BAD STUFF
telnet, rlogind, rshd, rcmd, rexecd, rbootd, rquotad, rstatd, rusersd, rwalld, rexd, fingerd, tftpd, telnet, snmp, netcat, nc, nginx,apache2IF FTP REQUIRED INSTALLED SECURE IT:
sudo nano /etc/vsftpd.confanonymous_enable=ON local_enable=YES write_enable=YES chroot_local_user=YES -
-
-
Service & Application Hardening
-
Configure OpenSSH Server in
/etc/ssh/sshd_configProtocol 2 LogLevel VERBOSE X11Forwarding no MaxAuthTries 4 IgnoreRhosts yes HostbasedAuthentication no PermitRootLogin no PermitEmptyPasswords no -
Harden Firefox
- Block Popups
-
Configure apache2 in
/etc/apache2/apache2.confServerSignature Off ServerTokens Prod
-
-
Backdoor Detection and Removal
-
ss -ln -
If a port has
127.0.0.1:$portin its line, that means it's connected to loopback and isn't exposed. Otherwise, there should only be ports which are specified in the readme open (but there probably will be tons more). -
For each open port which should be closed
-
Find the program using the port
$ lsof -i $port -
Locate where the program is running from
$ whereis $program -
Find what package owns the file
$ dpkg -S $location -
Remove the responsible package
$ apt-get purge $package -
If there is no package, delete the file and kill the processes
$ rm $location; killall -9 $program -
Verify the port is closed
$ ss -l
-
-
-
Cron
-
Check your user's crontabs
$ crontab -e -
Check
/etc/cron.*/,/etc/crontab, and/var/spool/cron/crontabs/ -
Check init files in
/etc/init/and/etc/init.d/ -
Remove contents of
/etc/rc.local$ echo "exit 0" > /etc/rc.local -
Check user crontabs
$ crontab -u $user -l -
Deny users use of cron jobs
$ echo "ALL" >> /etc/cron.deny
-
-
Kernel Securing
Sysctl -p-
Add this to the bottom of the
/etc/sysctl.conffile-
Disable ICMP redirects
1. net.ipv4.conf.all.accept_redirects = 0 -
Disable IP redirecting
net.ipv4.ip_forward = 0 net.ipv4.tcp_syncookies=1 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 -
Disable IP spoofing
net.ipv4.conf.all.rp_filter=1 -
Disable IP source routing
net.ipv4.conf.all.accept_source_route=0 -
SYN Flood Protection
net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 5 net.ipv4.tcp_syncookies = 1 -
Disable IPV6
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 net.ipv6.conf.lo.disable_ipv6 -
APPLY CHANGES IMPORTANT
sudo sysctl --system
-
-
-
Kernel Debugging
- The file:
/etc/sysctl.confshould havekernel.sysrq = 0
- The file:
-
Kernel Hardening
-
Edit the
/etc/sysctl.conffilefs.file-max = 65535 fs.protected_fifos = 2 fs.protected_regular = 2 fs.suid_dumpable = 0 kernel.core_uses_pid = 1 kernel.dmesg_restrict = 1 kernel.exec-shield = 1 kernel.sysrq = 0 kernel.randomize_va_space = 2 kernel.pid_max = 65536 net.core.rmem_max = 8388608 net.core.wmem_max = 8388608 net.core.netdev_max_backlog = 5000 net.ipv4.tcp_rmem = 10240 87380 12582912 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_wmem = 10240 87380 12582912 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.all.redirects = 0 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.conf.default.log_martians = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.secure_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.icmp_echo_ignore_all = 1 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1 net.ipv4.ip_forward = 0 net.ipv4.ip_local_port_range = 2000 65000 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_syn_retries = 5 net.ipv4.tcp_timestamps = 9 # Disable IPv6 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 # Incase IPv6 is necessary net.ipv6.conf.default.router_solicitations = 0 net.ipv6.conf.default.accept_ra_rtr_pref = 0 net.ipv6.conf.default.accept_ra_pinfo = 0 net.ipv6.conf.default.accept_ra_defrtr = 0 net.ipv6.conf.default.autoconf = 0 net.ipv6.conf.default.dad_transmits = 0 net.ipv6.conf.default.max_addresses = 1 -
Load new sysctl settings
$ sysctl -p
-
-
Antivirus
-
Install
clamav,chkrootkit, andrkhunter$ apt-get install clamav chkrootkit rkhunter -
Run ClamAV
$ freshclam $ freshclam --help -
Run chkrootkit
$ chkrootkit -l -
Run RKHunter
$ rkhunter --update $ rkhunter --propupd $ rkhunter -c --enable all --disable none -
Look through
/var/log/rkhunter.log
-
-
Audit the System with Lynis
-
Install
$ cd /usr/local $ git clone https://github.com/CISOfy/lynis $ chown -R 0:0 /usr/local/lynis -
Audit the system with Lynis
$ cd /usr/local/lynis $ lynis audit system -
Look through
/var/log/lynis-report.datfor warnings and suggestions$ grep -E 'warning|suggestion' | sed -e 's/warning\[\]\=//g' | sed -e 's/suggestion\[\]\=//g'
-
-
Configure Auditd
-
Install
$ apt-get install auditd -
Enable
$ auditctl -e 1 -
Configure with
/etc/audit/auditd.conf
-
-
Check cronjobs
- Check these folders
/etc/cron.* /etc/crontab /var/spool/cron/crontabs- Check the init files
/etc/init /etc/init.d- Check for each user
crontab –u {USER} -l -
Check the runlevels if unable to boot into GUI
- To check the run level
runlevel- Runlevels
0-System halt;No activity 1-Single user 2-Multi-user, no filesystem 3-Multi-user, commandline only 4-user defineable 5-multi-users,GUI 6-Reboot- To change the run level
Telinit {level}
-
APACHE
-
Hide Apache Version number.
Add the following lines to the bottom of /etc/apache2/apache2.conf
ServerSignature Off ServerTokens Prod -
Make sure Apache is running under its own user account and group.
Add a separate user “apache”
Edit the
/etc/apache2/apache2.conffileUser apache Group apache -
Ensure that file outside the web root directory are not accessed. /etc/apache2/apache2.conf
<Directory /> Order Deny,Allow Dent from all Options -Indexes AllowOverride None </Directory> <Directory /html> Order Allow,Deny Allow from all </Directory> -
Turn off directory browsing, Follow symbolic links and CGI execution
Add Options
Noneto a<Directory /html>tag -
Install modsecurity
``` apt-get install mod_security service httpd restart ``` -
Lower the Timeout value in
/etc/apache2/apache2.confTimeout 45
-
-
MySQL
-
Restrict remote MySQL access
Edit
/etc/mysql/my.cnfBind-address=127.0.0.1 -
Disable use of LOCAL INFILE Edit
/etc/mysql/my.cnf[mysqld] local-infile=0 -
Create Application Specific user
root@Ubuntu:~# mysql –u root –p mysql> CREATE USER ‘myusr’@’localhost’ IDENTIFIED BY ‘password’; mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON mydb.* TO ‘myusr’@’localhost’ IDENTIFIED BY ‘password’; mysql> FLUSH PRIVILEGES; -
Improve Security with mysql_secure-installation
``` root@Ubuntu:~# mysql_secure_installation change the root password?: y Remove anonymous users?: y Disallow root login remotely?: y Remove test database and access to it?: y Reload privilege tables now?: y
-
-
PHP
-
Restrict PHP Information Leakage
Edit
/etc/php5/apaceh2/php.iniexpose_php = off -
Disable Remote Code Execution Edit
/etc/php5/apache2/php.iniallow_url_fopen=Off allow_url_include=Off -
Disable dangerous PHP Functions
Edit
/etc/php5/apache2/php.inidisable_functions=exec,shell_exec,passthru,system,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source,proc_open,pcntl_exec -
Enable Limits in PHP
Edit
/etc/php5/apache2/php.iniupload_max_filesize = 2M max_execution_time = 30 max_input_time = 60
-