cek-ssh.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- https://icanhazip.com);
  6. echo "Checking VPS"
  7. clear
  8. echo " "
  9. echo " "
  10. if [ -e "/var/log/auth.log" ]; then
  11. LOG="/var/log/auth.log";
  12. fi
  13. if [ -e "/var/log/secure" ]; then
  14. LOG="/var/log/secure";
  15. fi
  16. data=( `ps aux | grep -i dropbear | awk '{print $2}'`);
  17. echo "-----=[ Dropbear User Login ]=-----";
  18. echo "ID | Username | IP Address";
  19. echo "-------------------------------------";
  20. cat $LOG | grep -i dropbear | grep -i "Password auth succeeded" > /tmp/login-db.txt;
  21. for PID in "${data[@]}"
  22. do
  23. cat /tmp/login-db.txt | grep "dropbear\[$PID\]" > /tmp/login-db-pid.txt;
  24. NUM=`cat /tmp/login-db-pid.txt | wc -l`;
  25. USER=`cat /tmp/login-db-pid.txt | awk '{print $10}'`;
  26. IP=`cat /tmp/login-db-pid.txt | awk '{print $12}'`;
  27. if [ $NUM -eq 1 ]; then
  28. echo "$PID - $USER - $IP";
  29. fi
  30. done
  31. echo " "
  32. echo "-----=[ OpenSSH User Login ]=-----";
  33. echo "ID | Username | IP Address";
  34. echo "-------------------------------------";
  35. cat $LOG | grep -i sshd | grep -i "Accepted password for" > /tmp/login-db.txt
  36. data=( `ps aux | grep "\[priv\]" | sort -k 72 | awk '{print $2}'`);
  37. for PID in "${data[@]}"
  38. do
  39. cat /tmp/login-db.txt | grep "sshd\[$PID\]" > /tmp/login-db-pid.txt;
  40. NUM=`cat /tmp/login-db-pid.txt | wc -l`;
  41. USER=`cat /tmp/login-db-pid.txt | awk '{print $9}'`;
  42. IP=`cat /tmp/login-db-pid.txt | awk '{print $11}'`;
  43. if [ $NUM -eq 1 ]; then
  44. echo "$PID - $USER - $IP";
  45. fi
  46. done
  47. if [ -f "/etc/openvpn/server/openvpn-tcp.log" ]; then
  48. echo " "
  49. echo "-----=[ OpenVPN TCP User Login ]=-----";
  50. echo "Username | IP Address | Connected Since";
  51. echo "-------------------------------------";
  52. cat /etc/openvpn/server/openvpn-tcp.log | grep -w "^CLIENT_LIST" | cut -d ',' -f 2,3,8 | sed -e 's/,/ /g' > /tmp/vpn-login-tcp.txt
  53. cat /tmp/vpn-login-tcp.txt
  54. fi
  55. echo "-------------------------------------"
  56. if [ -f "/etc/openvpn/server/openvpn-udp.log" ]; then
  57. echo " "
  58. echo "-----=[ OpenVPN UDP User Login ]=-----";
  59. echo "Username | IP Address | Connected Since";
  60. echo "-------------------------------------";
  61. cat /etc/openvpn/server/openvpn-udp.log | grep -w "^CLIENT_LIST" | cut -d ',' -f 2,3,8 | sed -e 's/,/ /g' > /tmp/vpn-login-udp.txt
  62. cat /tmp/vpn-login-udp.txt
  63. fi
  64. echo "-------------------------------------"
  65. echo "";