tendang.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # Script by : OkkayKayyo
  3. #!/bin/bash
  4. clear
  5. MAX=1
  6. if [ -e "/var/log/auth.log" ]; then
  7. OS=1;
  8. LOG="/var/log/auth.log";
  9. fi
  10. if [ -e "/var/log/secure" ]; then
  11. OS=2;
  12. LOG="/var/log/secure";
  13. fi
  14. if [ $OS -eq 1 ]; then
  15. service ssh restart > /dev/null 2>&1;
  16. fi
  17. if [ $OS -eq 2 ]; then
  18. service sshd restart > /dev/null 2>&1;
  19. fi
  20. service dropbear restart > /dev/null 2>&1;
  21. if [[ ${1+x} ]]; then
  22. MAX=$1;
  23. fi
  24. cat /etc/passwd | grep "/home/" | cut -d":" -f1 > /root/user.txt
  25. username1=( `cat "/root/user.txt" `);
  26. i="0";
  27. for user in "${username1[@]}"
  28. do
  29. username[$i]=`echo $user | sed 's/'\''//g'`;
  30. jumlah[$i]=0;
  31. i=$i+1;
  32. done
  33. cat $LOG | grep -i dropbear | grep -i "Password auth succeeded" > /tmp/log-db.txt
  34. proc=( `ps aux | grep -i dropbear | awk '{print $2}'`);
  35. for PID in "${proc[@]}"
  36. do
  37. cat /tmp/log-db.txt | grep "dropbear\[$PID\]" > /tmp/log-db-pid.txt
  38. NUM=`cat /tmp/log-db-pid.txt | wc -l`;
  39. USER=`cat /tmp/log-db-pid.txt | awk '{print $10}' | sed 's/'\''//g'`;
  40. IP=`cat /tmp/log-db-pid.txt | awk '{print $12}'`;
  41. if [ $NUM -eq 1 ]; then
  42. i=0;
  43. for user1 in "${username[@]}"
  44. do
  45. if [ "$USER" == "$user1" ]; then
  46. jumlah[$i]=`expr ${jumlah[$i]} + 1`;
  47. pid[$i]="${pid[$i]} $PID"
  48. fi
  49. i=$i+1;
  50. done
  51. fi
  52. done
  53. cat $LOG | grep -i sshd | grep -i "Accepted password for" > /tmp/log-db.txt
  54. data=( `ps aux | grep "\[priv\]" | sort -k 72 | awk '{print $2}'`);
  55. for PID in "${data[@]}"
  56. do
  57. cat /tmp/log-db.txt | grep "sshd\[$PID\]" > /tmp/log-db-pid.txt;
  58. NUM=`cat /tmp/log-db-pid.txt | wc -l`;
  59. USER=`cat /tmp/log-db-pid.txt | awk '{print $9}'`;
  60. IP=`cat /tmp/log-db-pid.txt | awk '{print $11}'`;
  61. if [ $NUM -eq 1 ]; then
  62. i=0;
  63. for user1 in "${username[@]}"
  64. do
  65. if [ "$USER" == "$user1" ]; then
  66. jumlah[$i]=`expr ${jumlah[$i]} + 1`;
  67. pid[$i]="${pid[$i]} $PID"
  68. fi
  69. i=$i+1;
  70. done
  71. fi
  72. done
  73. j="0";
  74. for i in ${!username[*]}
  75. do
  76. if [ ${jumlah[$i]} -gt $MAX ]; then
  77. date=`date +"%Y-%m-%d %X"`;
  78. echo "$date - ${username[$i]} - ${jumlah[$i]}";
  79. echo "$date - ${username[$i]} - ${jumlah[$i]}" >> /root/log-limit.txt;
  80. kill ${pid[$i]};
  81. pid[$i]="";
  82. j=`expr $j + 1`;
  83. fi
  84. done
  85. if [ $j -gt 0 ]; then
  86. if [ $OS -eq 1 ]; then
  87. service ssh restart > /dev/null 2>&1;
  88. fi
  89. if [ $OS -eq 2 ]; then
  90. service sshd restart > /dev/null 2>&1;
  91. fi
  92. service dropbear restart > /dev/null 2>&1;
  93. j=0;
  94. fi