cek.sh 2.4 KB

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