Всем привет! Помогите с задачкой: необходимо написать bash скрипт который осуществляет поиск количества попыток взлома по протоколу ssh с каждого ip и блокировку последнего с помощью iptables, если количество попыток превысило 10. В данном случае используйте регулярные выражения для поиска ip, отсортируйте результат по количеству попыток взлома для вывода результата. Пример файла журнала:
- May 13 10:17:29 [sshd] Invalid user tplink from 5.188.10.176 port 43464
- May 13 10:17:30 [sshd] Connection closed by invalid user tplink 5.188.10.176 port 43464 [preauth]
- May 13 10:17:34 [sshd] Invalid user ubnt from 5.188.10.176 port 44124
- May 13 10:17:34 [sshd] Connection closed by invalid user ubnt 5.188.10.176 port 44124 [preauth]
- May 13 10:17:40 [sshd] Invalid user user from 5.188.10.176 port 47032
- May 13 10:17:40 [sshd] Connection closed by invalid user user 5.188.10.176 port 47032 [preauth]
- May 13 10:20:21 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 10:20:22 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.172.188 user=root
- May 13 10:20:24 [sshd] error: PAM: Authentication failure for root from 61.177.172.188
- May 13 10:20:25 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 10:20:25 [sshd] Postponed keyboard-interactive for root from 61.177.172.188 port 44714 ssh2 [preauth]
- May 13 10:20:25 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.172.188 user=root
- May 13 10:20:27 [sshd] error: PAM: Authentication failure for root from 61.177.172.188
- May 13 10:20:27 [sshd] Failed keyboard-interactive/pam for root from 61.177.172.188 port 44714 ssh2
- May 13 10:20:28 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 10:20:28 [sshd] Postponed keyboard-interactive for root from 61.177.172.188 port 44714 ssh2 [preauth]
- May 13 10:20:28 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.172.188 user=root
- May 13 10:20:30 [sshd] error: PAM: Authentication failure for root from 61.177.172.188
- May 13 10:20:30 [sshd] Failed keyboard-interactive/pam for root from 61.177.172.188 port 44714 ssh2
- May 13 10:20:30 [sshd] error: maximum authentication attempts exceeded for root from 61.177.172.188 port 44714 ssh2 [preauth]
- May 13 10:20:30 [sshd] Disconnecting authenticating user root 61.177.172.188 port 44714: Too many authentication failures [preauth]
- May 13 14:17:10 [sshd] Connection closed by invalid user admin 5.188.10.176 port 50341 [preauth]
- May 13 14:17:17 [sshd] Did not receive identification string from 5.188.10.176 port 38547
- May 13 14:17:55 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 14:21:29 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=58.218.198.165 user=root
- May 13 14:21:31 [sshd] error: PAM: Authentication failure for root from 58.218.198.165
- May 13 14:21:31 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 14:21:31 [sshd] Postponed keyboard-interactive for root from 58.218.198.165 port 63705 ssh2 [preauth]
- May 13 14:21:31 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=58.218.198.165 user=root
- May 13 14:21:34 [sshd] error: PAM: Authentication failure for root from 58.218.198.165
- May 13 14:21:34 [sshd] Failed keyboard-interactive/pam for root from 58.218.198.165 port 63705 ssh2
- May 13 14:21:34 [sshd] Connection closed by authenticating user root 58.218.198.165 port 63705 [preauth]
- May 13 14:25:05 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 14:25:05 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=58.218.198.165 user=root
- May 13 14:25:07 [sshd] error: PAM: Authentication failure for root from 58.218.198.165
- May 13 14:25:07 [sshd] Connection closed by authenticating user root 58.218.198.165 port 45058 [preauth]
- May 13 14:28:42 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 14:28:42 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=58.218.198.165 user=root
- May 13 14:28:44 [sshd] error: PAM: Authentication failure for root from 58.218.198.165
- May 13 14:28:44 [sshd] pam_tally2(sshd:auth): Tally overflowed for user root
- May 13 14:28:44 [sshd] Postponed keyboard-interactive for root from 58.218.198.165 port 25219 ssh2 [preauth]
- May 13 14:28:45 [sshd] pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=58.218.198.165 user=root
- May 13 14:28:46 [sshd] error: PAM: Authentication failure for root from 58.218.198.165
- May 13 14:28:46 [sshd] Failed keyboard-interactive/pam for root from 58.218.198.165 port 25219 ssh2
- May 13 14:28:46 [sshd] Connection closed by authenticating user root 58.218.198.165 port 25219 [preauth]
- May 13 14:36:03 [sshd] Connection closed by 58.218.198.165 port 47806 [preauth]
- May 13 14:57:05 [sshd] Invalid user camera from 5.188.10.176 port 45714
- May 13 14:57:06 [sshd] Connection closed by invalid user camera 5.188.10.176 port 45714 [preauth]
- May 13 14:57:20 [sshd] Connection closed by authenticating user cron 5.188.10.176 port 56035 [preauth]
- May 13 14:57:29 [sshd] Invalid user default from 5.188.10.176 port 42027
- May 13 14:57:30 [sshd] Connection closed by invalid user default 5.188.10.176 port 42027 [preauth]
- May 13 15:30:59 [sshd] Invalid user default from 5.188.10.176 port 51196
- May 13 15:31:00 [sshd] Connection closed by invalid user default 5.188.10.176 port 51196 [preauth]
- May 13 15:31:40 [sshd] Did not receive identification string from 5.188.10.176 port 44919
- May 13 15:37:50 [sshd] Invalid user admin from 212.91.77.226 port 28681
- May 13 15:37:50 [sshd] Connection closed by invalid user admin 212.91.77.226 port 28681 [preauth]