Skip to content

Instantly share code, notes, and snippets.

@kpodp0ra
Last active April 27, 2023 20:04
Show Gist options
  • Save kpodp0ra/2c066da39b5bb3e56daf2269180aafb5 to your computer and use it in GitHub Desktop.
Save kpodp0ra/2c066da39b5bb3e56daf2269180aafb5 to your computer and use it in GitHub Desktop.
Bash script that displays various system information related to security like open ports and fail2ban configuration.
#!/bin/bash
echo "MOTD:"
cat /etc/issue.net
echo
# List fail2ban jails
echo "Fail2ban jails:"
fail2ban-client status | grep 'Jail list:' | sed 's/ //g' | cut -d: -f2
echo
# Print last 10 logins
echo "Last 10 logins:"
last -n 10
echo
# Print last 10 failed logins
echo "Last 10 failed logins:"
lastb -n 10
echo
# Get and print cron jobs without comments
echo "Cron jobs: $(crontab -l | grep -v '^#')"
echo
# Get and print open ports
echo "SSH port is: $(grep Port\ /etc/ssh/sshd_config | awk '{print $2}')"
echo "Open ports: $(netstat -lnt | awk 'NR>2{print $4}' | grep -Ev '(127.0.0.1:|::1:)' | awk -F: '{print $NF}' | sort -n | uniq | tr '\n' ' ')"
echo
# Get and print iptables
echo "Iptables:"
iptables -n --list|grep "spt:\|dpt:\|dports\|sports"
echo
# Get and print ssh users
echo "AllowUsers is: $(grep AllowUsers /etc/ssh/sshd_config | awk '{print $2}')"
echo "Available users: $(cat /etc/shadow | grep '^[^:]*:[^\*!]' | cut -d: -f1)"
echo
echo
echo "Port Details:"
netstat -lntup | grep -Ev '(127.0.0.1:|::1:)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment