linux被恶意登录ssh、vsftpd,解决小脚本
2018-02-05 21:06
267 查看
偶然登录zabbix监控时突然看见显示进程过多,随即登录服务器杀死进程,查看/var/log/secure发现这样的错误:Feb 5 20:42:42 instance-m63fnpbp login: pam_securetty(remote:auth): access denied: tty 'pts/2' is not secure !
Feb 5 20:42:43 instance-m63fnpbp login: pam_unix(remote:auth): check pass; user unknown
Feb 5 20:42:43 instance-m63fnpbp login: pam_unix(remote:auth): authentication failure; logname= uid=0 euid=0 tty=pts/2 ruser= rhost=177-139-13-74.dsl.telesp.net.brFAILED LOGIN SESSION FROM 177-139-13-74.dsl.telesp.net.br FOR (unknown), User not known to
the underlying authentication module
为了防止ip二次恶意登录,特意写了个脚本,脚本如下,(新手,欢迎大家批评指正!)
#!/bin/bash
max_limt=0
black_file=black.txt//得到的黑名单ip,包含恶意登录次数
if [ ! -f $black_file ];
then
touch $black_file
fi
cat /var/log/secure|grep 'Failed'|awk '{print $(NF-3)}'|sort|uniq -c>$black_file
awk '{print $(NF-0)}' $black_file>final_file.txt //只包含ip的文件,个人爱好,可用awk直接从黑名单中提取
for i in `cat final_file.txt`
do
is_exist=$(grep "$i" /etc/hosts.deny|wc -l)//
if [ "$is_exist" -eq "$max_limt" ];
then
echo "sshd:$i">>/etc/hosts.deny
echo "vsftpd:$i">>/etc/hosts.deny
fi
done
最后将其加入了crontab中,由于服务器恶意登录频繁,所以一小时检查一次,可根据个人情况实际选择。
59 * * * * /root/xxxx.sh
Feb 5 20:42:43 instance-m63fnpbp login: pam_unix(remote:auth): check pass; user unknown
Feb 5 20:42:43 instance-m63fnpbp login: pam_unix(remote:auth): authentication failure; logname= uid=0 euid=0 tty=pts/2 ruser= rhost=177-139-13-74.dsl.telesp.net.brFAILED LOGIN SESSION FROM 177-139-13-74.dsl.telesp.net.br FOR (unknown), User not known to
the underlying authentication module
为了防止ip二次恶意登录,特意写了个脚本,脚本如下,(新手,欢迎大家批评指正!)
#!/bin/bash
max_limt=0
black_file=black.txt//得到的黑名单ip,包含恶意登录次数
if [ ! -f $black_file ];
then
touch $black_file
fi
cat /var/log/secure|grep 'Failed'|awk '{print $(NF-3)}'|sort|uniq -c>$black_file
awk '{print $(NF-0)}' $black_file>final_file.txt //只包含ip的文件,个人爱好,可用awk直接从黑名单中提取
for i in `cat final_file.txt`
do
is_exist=$(grep "$i" /etc/hosts.deny|wc -l)//
if [ "$is_exist" -eq "$max_limt" ];
then
echo "sshd:$i">>/etc/hosts.deny
echo "vsftpd:$i">>/etc/hosts.deny
fi
done
最后将其加入了crontab中,由于服务器恶意登录频繁,所以一小时检查一次,可根据个人情况实际选择。
59 * * * * /root/xxxx.sh
相关文章推荐
- linux系统SSH免密码登录--已解决
- linux.ssh脚本自动登录
- Linux下ssh登录速度慢的解决办法
- Linux SSH远程登录慢的解决方法
- linux下设置了SSH免密码登录但还是需要输入密码的解决办法
- centos ssh内网登录慢及vsftpd登录慢的解决办法
- linux下设置了SSH免密码登录但还是需要输入密码的解决办法
- linux下的ssh、telnet登录脚本(tcl)
- Linux管理工作,实例讲解工作中使用ssh证书登录的实际流程,讲解ssh证书登录的配置原理,基于配置原理,解决实际工作中,windows下使用SecureCRT证书登录的各种问题,以及实现hadoo
- 解决linux中ssh登录Warning:Permanently added (RSA) to the list of known hosts
- Linux 终端登录SSH:解决SSH的Access Denied 和 make xconfig的使用
- Linux下ssh登录速度慢的解决办法
- Linux SSH登录很慢的解决方法
- linux中ssh可以登录sftp不能登录解决办法
- windows+java程序SSH登录linux调用shell脚本
- Linux 终端登录SSH:解决SSH的Access Denied 和 make xconfig的使用
- Linux下实现SSH免密码登录和实现秘钥的管理、分发、部署SHELL脚本分享
- Linux SSH远程登录慢的解决方法
- 解决Linux ssh登录马上退出问题
- Linux 中无法使用 root 用户通过 SSH 远程登录解决方法