服务器进行了重新升级,结果这两天每天晚上都有许多人用暴力攻击SSH端口,下面是截选的部分,据我所知,这应该是利用软件暴力猜解密码吧?有没有办法设置每小时只能登陆几次,密码输入多少次后锁定,或者自动将恶意地址加入阻挡列表?
Jul 16 10:29:24 sshd[23332]: Failed password for root from 220.192.74.106 port 1660 ssh2
Jul 16 10:29:28 sshd[23336]: Failed password for root from 220.192.74.106 port 1661 ssh2
Jul 16 10:29:32 sshd[23338]: Failed password for root from 220.192.74.106 port 1662 ssh2
Jul 16 10:29:34 sshd[23339]: Failed password for root from 220.192.74.106 port 1663 ssh2
Jul 16 10:29:35 sshd[23342]: Failed password for root from 220.192.74.106 port 1664 ssh2
Jul 16 10:29:36 sshd[23344]: Failed password for root from 220.192.74.106 port 1665 ssh2
Jul 16 10:29:41 sshd[23364]: Failed password for root from 220.192.74.106 port 1666 ssh2
Jul 16 10:29:43 sshd[23366]: Failed password for root from 220.192.74.106 port 1667 ssh2
Jul 16 10:29:47 sshd[23368]: Failed password for root from 220.192.74.106 port 1668 ssh2
Jul 16 10:29:47 sshd[23370]: Failed password for root from 220.192.74.106 port 1669 ssh2
Jul 16 10:29:48 sshd[23372]: Failed password for root from 220.192.74.106 port 1670 ssh2
Jul 16 10:29:54 sshd[23383]: Failed password for root from 220.192.74.106 port 1671 ssh2
5个地址,我都已经查过了,都是被人黑掉以后用来攻击我的肉鸡而已。
authen 回复于:2005-07-19 09:56:09
用证书认证。
KingRock_cn 回复于:2005-07-19 11:48:15
应该可以的
ayazero 回复于:2005-07-19 15:03:13
改用密钥认证的方式
wangrujun 回复于:2005-07-19 15:50:07
我也遇到过此类问题。麻烦问下楼主,怎么样才能查出是肉鸡对你攻击?谢谢。
clghxq 回复于:2005-07-20 19:33:13
引用:原帖由 "wangrujun"]我也遇到过此类问题。麻烦问下楼主,怎么样才能查出是肉鸡对你攻击?谢谢。 发表:
我也想问问
zhouw68 回复于:2005-08-01 13:33:11
1。屏蔽PING回应。
2。修改SSH的端口号。
3。限制能访问SSH服务的区域。
用这三招,能让你的服务器安静下来。
权老实 回复于:2005-08-01 18:40:35
引用:原帖由 "zhouw68" 发表: 1。屏蔽PING回应。
2。修改SSH的端口号。
3。限制能访问SSH服务的区域。
用这三招,能让你的服务器安静下来。
以前我的这样,没办法,我就改了端口,现在放心多了、、、、、
lgmyxbjfu 回复于:2005-08-01 21:16:23
引用:原帖由 "权老实" 发表:
以前我的这样,没办法,我就改了端口,现在放心多了、、、、、
要是对方用ssh协议连接你不同的端口,还是能知道你ssh所用的端口,那怎么办呢
剑心通明 回复于:2005-08-02 08:56:24
改用key的方式就可以了,不要用密码验证
zhouw68 回复于:2005-08-02 11:24:15
引用:原帖由 "lgmyxbjfu" 发表:
要是对方用ssh协议连接你不同的端口,还是能知道你ssh所用的端口,那怎么办呢
你的思路开扩,好。
1。升级SSH,IPTABLES,VSFTP等软件到最新版。
2。限制能访问SSH服务的区域,甚至用MAC地址限制访问。
3。密码复杂化。
4。关闭TELNET服务。
5。还有很多。
还有一点要认识到:
1。上网了,就没有绝对安全的东西。作为网管,多想多问,用心,尽力就可以了。
2。多到www.chinaunix.net逛逛。
Jambo 回复于:2005-08-02 11:36:13
向网管学习!!
因为他们遇到的问题是最多的!
frosty 回复于:2005-08-02 21:40:10
请问楼主 你是怎么判定
是肉鸡攻击你的?
mmhh516 回复于:2005-08-02 22:11:36
感觉应该是查询对方ip服务器的应用,如果是什么企业网站的托管主机或者是些小网站,那样就可以断定是肉机拉。
搂主,出来说说阿?
守夜人 回复于:2005-08-03 09:35:46
1 编个shell将这些暴力破解的IP屏蔽
2 用iptables限制ssh登陆的IP范围
ipaddr 回复于:2005-08-04 10:59:03
改端口,我觉得没多大作用.
一般攻击,都会先扫描一下的.
扫出你所有开放的端口,改成其它的,别人也知道.
sun198009 回复于:2005-08-04 11:22:04
引用:原帖由 "zhouw68" 发表:
你的思路开扩,好。
1。升级SSH,IPTABLES,VSFTP等软件到最新版。
2。限制能访问SSH服务的区域,甚至用MAC地址限制访问。
3。密码复杂化。
4。关闭TELNET服务。
5。还有很多。
还有一点要认识到:
1。上?.........
上面的操作都怎么做呀(具体谈谈给楼主)
haoyufu 回复于:2005-08-04 11:29:48
楼主还有什么现象啊
贴出来让大家分析分析
zhouw68 回复于:2005-08-05 08:26:51
引用:原帖由 "ipaddr" 发表: 改端口,我觉得没多大作用.
一般攻击,都会先扫描一下的.
扫出你所有开放的端口,改成其它的,别人也知道.
改端口,只是一招。还有IP访问限制等。SSH服务没必要向全世界开放吧。只对你的城市电信或网通IP网段开放就可以了。甚至用MAC地址绑定。其余的地域全屏蔽访问。
是一个综合手段,单单一个手段太单薄。
leo.huang 回复于:2005-08-05 10:43:45
安装防火墙,设定访问规则!
iclinux 回复于:2005-08-05 14:13:51
引用:原帖由 "zhouw68" 发表:
改端口,只是一招。还有IP访问限制等。SSH服务没必要向全世界开放吧。只对你的城市电信或网通IP网段开放就可以了。甚至用MAC地址绑定。其余的地域全屏蔽访问。
是一个综合手段,单单一个手段太单薄。
不能得到外网的MAC地址吧?
jun4772191 回复于:2005-08-05 15:58:34
只要把密码设复杂些就行了.暴力破解还能怎么样?
zhouw68 回复于:2005-08-05 16:37:25
引用:原帖由 "iclinux" 发表:
不能得到外网的MAC地址吧?
是我没说清楚。我的意思是:
我们自己的笔记本电脑的MAC和家里电脑的MAC地址。
对这二个地址开放,别的全屏蔽访问。
用MAC地址绑定,是指认可安全的MAC。
sorry.
happygrid 回复于:2005-08-05 17:50:34
这种暴力密码破解,可以采取多重方式进行防御:
1 设置强壮的密码,改变默认用户名
2 设置login规则,比如重试次数
3 进行访问控制,只允许指定网络访问sshd端口
4 改变默认sshd监听端口
5 其他安全措施
tony_list 回复于:2005-09-27 11:14:47
经过仔细研究,参考了网上很多资料,最后找到一片较正规的解决方案,供大家参考:
方法一:
規則:只要是透過ssh想要用root直接登入的ip都登錄拒絕名單
方法:
1.利用sshd[18362]: Failed password for root from 66.238.200.230 port 50060 ssh2這則訊息,取得IP
2.將取得的IP檢查拒絕名單是否有同樣的IP
3.如拒絕名單沒有此IP,將此IP登錄並新增iptables 規則
4.可以使用root 登入的ip只要加一行註解填入ip就可了
#!/bin/bash
#/usr/local/virus/iptables
dropfilepath="/usr/local/virus/iptables/dropip.txt"
denyfilepath="/usr/local/virus/iptables/iptables.deny"
networkcard="eth1"
#cut messager to get IP address
#sshd[18362]: Failed password for root from 66.238.200.230 port 50060 ssh2
cat /var/log/messages | grep ssh | grep Failed | grep root | cut -d ":" -f 4 | cut -d " " -f 7 | uniq | sort >; $dropfilepath
target1=`cat $dropfilepath`
if [ "$target1" = "" ]; then
echo "No IP Address Drop"
exit 0
fi
for i in $target1; do
if [ -f "$denyfilepath" ]; then
target2=`cat $denyfilepath | grep $i`
else
target2=$i
fi
if [ "$target2" = "" ]; then
if [ -f "$denyfilepath" ]; then
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP # From $0 "`date` >;>; $denyfilepath
else
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP # From $0 "`date` >; $denyfilepath
fi
/sbin/iptables -A INPUT -i $networkcard -s $i -j DROP
echo "IP: $i Add to $denyfilepath"
else
echo "IP: $i to use as drop"
fi
done
方法二:
前言
因為網路上很多小白會try我主機 自己手動block ip太麻煩 所以 自己寫了一個script來達到自動化阻擋ip 因為是第一次寫script 所以 有問 題的地方 大家一起來討論
PS:目前已修正過一次
1.需先使用鳥哥所寫的iptables script 並設定好 <鳥哥都有教 我跳過>;
http://linux.vbird.org/download/linux_security/iptables.rule
http://linux.vbird.org/download/linux_security/iptables.deny
2. TCP_Wrappers 設定 <也是鳥哥的方法>;
vi /etc/hosts.deny
貼上
代碼:
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
in.proftpd : ALL : spawn (/bin/echo Security notice from host `/bin/hostname`; \
/bin/echo; /usr/sbin/safe_finger @%h ) | \
/bin/mail -s "%d -%h security" root@localhost & \
: twist ( /bin/echo -e "\n\nWARNING connectin not allowed. Your attempt has been logged. \n\n\n警告您尚未允許登入,您的連線將 會被紀錄,並且作為以後的參考\n\n ". )
sshd : ALL : spawn (/bin/echo Security notice from host `/bin/hostname`; \
/bin/echo; /usr/sbin/safe_finger @%h ) | \
/bin/mail -s "%d -%h security" root@localhost & \
: twist ( /bin/echo -e "\n\nWARNING connectin not allowed. Your attempt has been logged. \n\n\n警告您尚未允許登入,您的連線將 會被紀錄,並且作為以後的參考\n\n ". )
3.在/usr/local/virus/iptables 下,建立 wip.txt <此檔案為排除阻擋的ip列表>;
vi wip.txt
代碼:
填上你不想被iptables阻擋的ip
4.在/usr/local/virus/iptables 下,建立自動檢查/var/log/messages 符合惡意登入ssh的script,將要阻擋的ip自動寫入iptables.deny中
vi sshd
貼上
代碼:
#!/bin/sh
# 2005/01/15 ver4 byBoolean@NTHU Email:boolean@boolean.ath.cx
#/usr/local/virus/iptables
nodenyip="/usr/local/virus/iptables/wip.txt"
workpath="/usr/local/virus/iptables/sshd_block_ip_now"
denyfile="/usr/local/virus/iptables/iptables.deny"
declare -i lognumber=2
grep sshd /var/log/messages | grep twist | grep WARNING | cut -d ":" -f 7 | cut -d " " -f 1 | sort | uniq >; $workpath
for (( m=1 ; m<=$lognumber ; m=m+1 )); do
if [ -f "/var/log/messages.$m" ]; then
grep sshd /var/log/messages.$m | grep twist | grep WARNING | cut -d ":" -f 7 | cut -d " " -f 1 | sort | uniq >;>; $workpath
else
echo "檔案 /var/log/messages.$m 並不存在 !!!!"
fi
done
if [ -f "$denyfile" ];then
cat $denyfile | cut -d " " -f 7 >;>; $workpath
rm -rf $denyfile
else
echo "不存在 $denyfile ,Script會依需要自動建立"
fi
cat $workpath | sort | uniq >; $workpath
target=`cat $workpath`
if [ "$target" = "" ]; then
echo "目前沒有添�[需要被阻擋IP的需要"
else
for i in $target; do
target1=`cat $nodenyip | grep $i`
if [ "$target1" = "" ]; then
if [ -f "$denyfile" ]; then
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP #auto" >;>; $denyfile
else
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP #auto" >; $denyfile
fi
echo "<<添�[>;>;IP: $i Add to $denyfile"
else
echo "<<去除>;>;According to the $nodenyip ,drop the IP: $i"
fi
done
fi
cat $denyfile | sort | uniq >; $denyfile
./iptables.rule
5.在/usr/local/virus/iptables 下,建立自動檢查/var/log/messages 符合惡意登入proftpd的script,將要阻擋的ip自動寫入iptables.deny 中<我proftpd是採用inetd啟動的方式>;
vi proftpd
貼上
代碼:
#!/bin/sh
# 2005/01/15 ver4 byBoolean@NTHU Email: boolean@boolean.ath.cx
#/usr/local/virus/iptables
nodenyip="/usr/local/virus/iptables/wip.txt"
workpath="/usr/local/virus/iptables/proftpd_block_ip_now"
denyfile="/usr/local/virus/iptables/iptables.deny"
declare -i lognumber=2
grep xinetd /var/log/messages | grep twist | grep WARNING | cut -d ":" -f 4 | cut -d " " -f 3 | sort | uniq >; $workpath
for (( m=1 ; m<=$lognumber ; m=m+1 )); do
if [ -f "/var/log/messages.$m" ]; then
grep xinetd /var/log/messages.$m | grep twist | grep WARNING | cut -d ":" -f 4 | cut -d " " -f 3 | sort | uniq >;>; $workpath
else
echo "The File /var/log/messages.$m does not exist !!!!"
fi
done
if [ -f "$denyfile" ];then
cat $denyfile | cut -d " " -f 7 >;>; $workpath
rm -rf $denyfile
else
echo "不存在 $denyfile ,Script會依需要自動建立"
fi
cat $workpath | sort | uniq >; $workpath
target=`cat $workpath`
if [ "$target" = "" ]; then
echo "目前沒有添�[需要被阻擋IP的需要"
else
for i in $target; do
target1=`cat $nodenyip | grep $i`
if [ "$target1" = "" ]; then
if [ -f "$denyfile" ]; then
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP #auto" >;>; $denyfile
else
echo "/sbin/iptables -A INPUT -i "'$EXTIF'" -s $i -j DROP #auto" >; $denyfile
fi
echo "<<添�[>;>;IP: $i Add to $denyfile"
else
echo "<<去除>;>;According to the $nodenyip ,drop the IP: $i"
fi
done
fi
cat $denyfile | sort | uniq >; $denyfile
./iptables.rule
6.更改檔案權限並設定為自動執行(每五分鐘)
chmod 755 sshd
chmod 755 proftpd
vi /etc/crontab
代碼:
*/5 * * * * root /usr/local/virus/iptables/sshd >; /dev/null 2>;&1
*/5 * * * * root /usr/local/virus/iptables/proftpd >; /dev/null 2>;&1
若古 回复于:2005-09-27 19:25:36
你把他的IP直接拉黑不就得了!
tony_list 回复于:2005-12-06 09:55:39
问题是对方会不断的换IP的,曾经试过直接DROP
killads 回复于:2005-12-06 15:51:05
请问楼主
管理员一般在哪里登陆服务器?假如在家里用adsl,那把adsl分配的ip段加到allow列表里好了,别的ip都deny
|