【问题标题】:SSH Brute Force ProtectionSSH蛮力保护
【发布时间】:2018-02-09 05:45:17
【问题描述】:

我目前为 SSH 连接转发了我的树莓派端口,所以我可以在工作时访问它。

在查看“journalctl -xe”时,我看到了大量失败的 SSH 登录请求。

我已将我的树莓派更改为密钥登录,而不是基于密码。我还能做些什么来阻止这家伙试图闯入吗?或者更好的安全措施来阻止他访问它?

Dec 20 19:46:36 raspberrypi sshd[1929]: Received disconnect from 106.250.183.218 port 20371:11: Bye Bye [preauth]
Dec 20 19:46:36 raspberrypi sshd[1929]: Disconnected from 106.250.183.218 port 20371 [preauth]
Dec 20 19:47:58 raspberrypi sshd[1931]: Received disconnect from 221.194.47.245 port 37247:11:  [preauth]
Dec 20 19:47:58 raspberrypi sshd[1931]: Disconnected from 221.194.47.245 port 37247 [preauth]
Dec 20 19:48:50 raspberrypi sshd[1934]: Did not receive identification string from 23.254.161.114 port 51435
Dec 20 19:50:15 raspberrypi sshd[1935]: Did not receive identification string from 195.154.60.109 port 64642
Dec 20 19:50:15 raspberrypi sshd[1936]: Invalid user user from 195.154.60.109 port 64943
Dec 20 19:50:15 raspberrypi sshd[1936]: input_userauth_request: invalid user user [preauth]
Dec 20 19:50:15 raspberrypi sshd[1936]: error: Received disconnect from 195.154.60.109 port 64943:3: com.jcraft.jsch.JSchException: Auth fail [preauth]
Dec 20 19:50:15 raspberrypi sshd[1936]: Disconnected from 195.154.60.109 port 64943 [preauth]
Dec 20 20:02:05 raspberrypi sshd[1997]: Did not receive identification string from 195.154.60.109 port 51264
Dec 20 20:02:06 raspberrypi sshd[1998]: Invalid user user from 195.154.60.109 port 51418
Dec 20 20:02:06 raspberrypi sshd[1998]: input_userauth_request: invalid user user [preauth]
Dec 20 20:02:06 raspberrypi sshd[1998]: error: Received disconnect from 195.154.60.109 port 51418:3: com.jcraft.jsch.JSchException: Auth fail [preauth]
Dec 20 20:02:06 raspberrypi sshd[1998]: Disconnected from 195.154.60.109 port 51418 [preauth]
Dec 20 20:02:31 raspberrypi sshd[2002]: Did not receive identification string from 91.227.47.234 port 53975
Dec 20 20:02:32 raspberrypi sshd[2003]: Invalid user user from 91.227.47.234 port 53982
Dec 20 20:02:32 raspberrypi sshd[2003]: input_userauth_request: invalid user user [preauth]
Dec 20 20:02:32 raspberrypi sshd[2003]: Received disconnect from 91.227.47.234 port 53982:11: Bye Bye [preauth]
Dec 20 20:02:32 raspberrypi sshd[2003]: Disconnected from 91.227.47.234 port 53982 [preauth]
Dec 20 20:03:05 raspberrypi sshd[2023]: Did not receive identification string from 103.79.142.58 port 50841
Dec 20 20:03:08 raspberrypi sshd[2024]: Invalid user user from 103.79.142.58 port 52943
Dec 20 20:03:08 raspberrypi sshd[2024]: input_userauth_request: invalid user user [preauth]
Dec 20 20:03:08 raspberrypi sshd[2024]: error: Received disconnect from 103.79.142.58 port 52943:3: com.jcraft.jsch.JSchException: Auth fail [preauth]

【问题讨论】:

  • 如果您禁用了密码登录,那么这些蛮力尝试永远不会成功。 rate limiting ssh connections 有一些技巧,但我在实践中发现这些可能是个问题。

标签: security ssh brute-force


【解决方案1】:

您还可以使用 fail2ban 限制尝试次数。

默认配置对 ssh 服务器来说很好。

sudo apt-get update sudo apt-get install fail2ban

【讨论】:

    【解决方案2】:

    如果您不希望禁用对所有帐户的密码访问,通过 sshd_config 文件禁用 root 登录(如 @ramrunner 所述)肯定会减少绝大多数 SSH 蛮力尝试。尽管如此,这仍然会使您的其他登录帐户容易受到攻击。

    缓解这种情况的一种方法是将 iptables 配置为仅允许来自某些 IP 地址或 IP 块的外部 SSH 尝试。如果您的外部工作 IP 地址没有更改,您可以配置 iptables 以阻止所有外部 SSH 尝试,但您的工作 IP 除外。

    【讨论】:

      【解决方案3】:

      SSH 蛮力攻击可以从具有最少处理器 (CPU) 和内存 (RAM) 的低功率服务器中吸取资源。您的树莓派可能就是这种情况。

      我们开发了一个名为am-deny-hosts 的解决方案,有助于阻止这些攻击。它会下载已知 SSH 攻击者的 IP 地址黑名单并将其添加到 /etc/hosts.deny 文件中。

      它作为一个开源项目在GitHub 上发布。您将获得一组 shell 脚本来保护您的 raspberry PI,而不会占用大量时间、CPU 或内存。更重要的是,我们让安装变得非常简单。

      【讨论】:

        【解决方案4】:

        这个问题最好迁移到 serverfault 或 security.stackexchange。

        正如@larsks 所说,如果您禁用了密码登录,这些自动攻击都是徒劳的。确保你也有

        PermitRootLogin no
        

        在您的 sshd_config 中。如果您不想按照@larsks 链接将其限制在 iptables 中,您可以安装 fail2ban。 最后我发现在非标准端口上运行 sshd 也有助于自动扫描。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-09-28
          • 1970-01-01
          • 1970-01-01
          • 2019-03-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多