第一次感觉来自渗透的攻击

本来是整理一下服务器上的日志文件,没啥用的该删的就删了。
闲着就点开看了几个 其中 vsftpd 服务就发现了异常
在这里插入图片描述
很明显这个 106.13.115.251的ip 在模仿用户登录我的 ftp服务 短时间内就登录多次并使用了不同的用户名来尝试。一下就出一身冷汗,这个企业级的数据可不是随便能泄露的。

赶紧查看 sshd 关键日志
在这里插入图片描述
这个 1.204.13.110的ip竟然现在还在不断的连接我的 服务器 就日志来看还没有拿到服务器登录权限
先下手为强,先给这个ip干掉
宁可错杀不可放过 先墙了在说
iptables -I INPUT -s 106.13.115.251 -j DROP
iptables -I INPUT -s 1.204.13.110 -j DROP

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200811163853302.png
在这里插入图片描述
赶紧的干掉

// 查看防火墙状态
service iptables status
// 开启防火墙
service iptables start
// 重启防火墙
service iptables restart
// 关闭防火墙
service iptables stop

// 屏蔽某个IP
iptables -I INPUT -s ... -j DROP
// 屏蔽某个IP段
iptables -I INPUT -s ..0.0/24 -j DROP
// 只允许某个IP访问
iptables -A INPUT -s ... -j DROP

一些解决方法
[https://www.cnblogs.com/kevingrace/p/6245859.html]
(https://www.cnblogs.com/kevingrace/p/6245859.html)

/etc/hosts.deny 增加

# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: 1.204.13.*

如果在/etc/hosts.allow和/etc/hosts.deny文件里配置了相关服务(如sshd、ftp)的ip限制后,发现不生效!
原因可能如下:
1)/etc/hosts.allow 与 /etc/hosts.deny 只对ssh应用调用了tcp_wrappers的服务器才起作用;
2)查看服务器的ssh是否支持tcp_wrappers。使用下面两个命令:
   # strings /usr/sbin/sshd|grep hosts_access
   # ldd `which sshd` | grep libwrap
3)如果上面的两个查看命令都没有结果,说明本机的ssh不支持tcp_wrappers
4)一般centos6默认的ssh都是支持tcp_wrappers的。但要是将服务器的ssh升级到openssh6.7之后,则就不支持了!
   因为从openssh6.7开始,ssh官方就移除了对tcp wrappers的支持!!!!
5)也就是说,centos6系统下默认的ssh版本(OpenSSH_5.3p1)如果升级到了openssh6.7之后,ssh应用就不支持tcp wrappers了。
   这样/etc/hosts.allow和/etc/hosts.deny文件里的限制设置也就无效了!
6)但是centos7默认的ssh版本是OpenSSH_7.4p1,centos7下默认的ssh版本是支持tcp wrappers的!
 
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
 
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
 
[root@localhost ~]# ldd `which sshd` | grep libwrap
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007fd302fc9000)
         
[root@localhost ~]# strings /usr/sbin/sshd|grep hosts_access
hosts_access

编辑脚本 /usr/local/bin/secure_ssh.sh

#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /usr/local/bin/black.list
for i in `cat  /usr/local/bin/black.list`
do
  IP=`echo $i |awk -F= '{print $1}'`
  NUM=`echo $i|awk -F= '{print $2}'`
  if [ ${#NUM} -gt 1 ]; then
    grep $IP /etc/hosts.deny > /dev/null
    if [ $? -gt 0 ];then
      echo "sshd:$IP:deny" >> /etc/hosts.deny
    fi
  fi
done

3、将secure_ssh.sh脚本放入cron计划任务,每1分钟执行一次。

# crontab -e
*/1 * * * *  sh /usr/local/bin/secure_ssh.sh

阅读原文

多查看服务器日志,提早发现,提早处理 避免更大的问题发现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值