This Bash script performs a comprehensive security audit of a Linux system. It checks executables, running processes, installed packages, file permissions, firewall status, network activity, kernel integrity, and more. It’s ideal for system administrators looking for a quick snapshot of a system’s security state.
The script includes the following security checks:
- Permissions of executables in
/bin,/usr/bin,/sbin, and/usr/sbin - Top memory-consuming running processes
- Running systemd services
- User and group accounts on the system
- SUID/SGID files
- Installed packages and their versions (supports
dpkg,rpm, andpacman) - Alerts for sensitive packages like
rsync,samba-common, andpython3-yaml
- Checksums for critical binaries (
/bin/ls,/bin/bash, etc.) - Permissions of sensitive files like
/etc/passwd,/etc/shadow,/etc/sudoers - Kernel image checksum validation
- dmesg logs for kernel warnings and errors
- Loaded kernel modules and their metadata
- Open ports and listening processes (via
ss) - Active network connections
- Port scanning (1–1024) using
nc - Firewall rules from
ufwand/oriptables - Protocol restriction via custom iptables rules
- DNS configuration (
/etc/resolv.confandresolvectl) - Available backups in
/var/backups - Files in
/tmp, with cleanup of old temporary files - Crontab entries related to backup tasks
-
Give execute permissions:
chmod +x audit_script.sh
-
Run the script with root privileges:
sudo ./audit_script.sh
⚠️ Some checks require root access (e.g., firewall status, kernel file access, and/tmpcleanup).
The script will generate multiple .txt output files in the current directory, such as:
output_executables_permissions.txtoutput_running_processes.txtoutput_firewall.txtoutput_kernel_checksum.txtoutput_module_checksums.txtoutput_scan_ports.txt- ...and more
These files contain detailed logs and results for each check performed.
- Make sure the system has common tools like
ps,awk,dpkg,rpm,iptables,ufw,sha256sum, etc. - You can safely delete or archive the output
.txtfiles after review. - Some modules or binaries might not be available depending on your Linux distribution.