全球主机交流论坛

标题: 自动屏蔽扫描ssh:22的php,并email通知 [打印本页]

作者: lazyzhu    时间: 2012-8-10 10:40
标题: 自动屏蔽扫描ssh:22的php,并email通知
IPXcore老板写的,原文如下:
Not sure if it's limited only to us, but we have a problem with having our customer's VPSes sshscanned for weak passwords.

So I have developed a simple PHP script to parse the output of netstat -n | grep :22, then counts how many IP addresses the remote IP is attempting to connect to, then add iptables rules when it determines an attack is happening. It will only add an iptable rule if a DROP rule for the IP does not exist already.

As we only run OpenVZ, it has only been tested on OpenVZ nodes. I am curious for feedback on if it works for Xen or KVM nodes.

It is being released to the community. You can find it here: http://pastebin.com/kfWaJa9q

Install it by writing it anywhere on your node, (I have mine in /sbin), editing the variables at the top of the script, then adding a crontab entry for root.
This will run it every 5 minutes:

*/5 * * * *  /usr/bin/php /sbin/sshcheck.php

(update to reflect your php binary, and where you put the script)

You will get reports in your email like this:

Hello, this is sshcheck.php running on sapphire.ipxcore.com

Current time: Thu, 09 Aug 12 19:33:49 -0600

Adding iptables DROP rule. Remove it with:
iptables -D FORWARD -s 218.203.165.153 -j DROP

IP 218.203.165.153 is involved in a brute force attack against the
following IPs:

Count: 13
1.2.3.157:22
1.2.3.136:22
1.2.3.108:22
1.2.3.31:22
1.2.3.201:22
1.2.3.32:22
1.2.3.195:22
1.2.3.11:22
1.2.3.32:22
1.2.3.180:22
1.2.3.103:22
1.2.3.108:22
1.2.3.122:22

Tested with PHP 5.1.6 (Centos 5), PHP 5.3.3 (Centos 6), PHP 5.3.3-7+squeeze13 (Debian Squeeze).

Upcoming/to-do/V2.0:
-check that destination IPs are unique
-add method for iptables drop for a specified timeframe only
-proper source code commenting


http://www.lowendtalk.com/discussion/4185/sshcheck.php-blocking-ssh-bruteforce-attempts-against-client-vps-containers
作者: Administrator    时间: 2012-8-10 10:41
提示: 作者被禁止或删除 内容自动屏蔽
作者: lazyzhu    时间: 2012-8-10 10:43
Administrator 发表于 2012-8-10 10:41
通知。。。不怕烦么。。。

看过代码再说...
作者: Kokgog    时间: 2012-8-10 10:43
换个端口....把22做成蜜罐, 谁连就把谁的ip扔进iptables........
作者: lazyzhu    时间: 2012-8-10 10:44
Kokgog 发表于 2012-8-10 10:43
换个端口....把22做成蜜罐, 谁连就把谁的ip扔进iptables........

什么蜜罐对咩咩最有效...
作者: Administrator    时间: 2012-8-10 10:46
提示: 作者被禁止或删除 内容自动屏蔽
作者: Kokgog    时间: 2012-8-10 10:47
lazyzhu 发表于 2012-8-10 10:44
什么蜜罐对咩咩最有效...


http://s.taobao.com/search?q=%B7%E4%C3%DB%D1%F2%C4%CC%D4%ED

骚年,来,嗑一块吧...
作者: lazyzhu    时间: 2012-8-10 10:52
Kokgog 发表于 2012-8-10 10:47
http://s.taobao.com/search?q=%B7%E4%C3%DB%D1%F2%C4%CC%D4%ED

骚年,来,嗑一块吧...

咩咩正品?
作者: lovettww    时间: 2012-8-10 10:55
你们在搞基吗?
作者: Jetso    时间: 2012-8-10 10:58
本当に退屈な
作者: zidane    时间: 2012-8-10 10:58
提示: 作者被禁止或删除 内容自动屏蔽
作者: 用户名    时间: 2012-8-10 11:11
denyhosts撸过
作者: lazyzhu    时间: 2012-8-10 11:16
用户名 发表于 2012-8-10 11:11
denyhosts撸过

Py写的,
作者: 群英主机    时间: 2012-8-10 11:28
提示: 作者被禁止或删除 内容自动屏蔽
作者: Kokgog    时间: 2012-8-10 11:29
lazyzhu 发表于 2012-8-10 11:16
Py写的,

为神马不是js写的,为神马
作者: Kokgog    时间: 2012-8-10 11:30
lazyzhu 发表于 2012-8-10 10:52
咩咩正品?

这个得@咩咩 来鉴定
作者: alect    时间: 2012-8-10 11:30
还不如直接换端口
作者: lazyzhu    时间: 2012-8-10 11:32
Kokgog 发表于 2012-8-10 11:29
为神马不是js写的,为神马

你可以用node.js来写个,
作者: lazyzhu    时间: 2012-8-10 11:35
alect 发表于 2012-8-10 11:30
还不如直接换端口

有多少人会改端口呢?
不然会有这么多喜欢扫小鸡的人吗?
作者: 过客    时间: 2012-8-10 12:16
难道为了D回去么?不是?那何必呢,直接改端口+私钥,搞定。
作者: hepac    时间: 2012-8-10 13:46
母鸡关闭22,客户自然只能换端口,一劳永逸
作者: huyez    时间: 2012-8-10 13:49
提示: 作者被禁止或删除 内容自动屏蔽
作者: 远坂时臣    时间: 2012-8-11 20:40
- - php写的 我一般是sh写的就好了,还要劳烦跑php,资源伤不起~跑php也有可能遇到权限问题吧~
作者: 火雪心    时间: 2012-8-11 21:52
晕死,成千上万的扫,通知累死




欢迎光临 全球主机交流论坛 (https://loc.516000.xyz/) Powered by Discuz! X3.4