Solaris 10 NTP服务放大攻击漏洞加固

Solaris 10 NTP服务放大攻击漏洞加固

欢迎来到 来到大浪涛天的博客

Solaris 10 NTP服务放大攻击漏洞加固

1. 前言

  • NTP 放大攻击其实就是 DDoS 的一种。通过 NTP 服务器,可以把很小的请求变成很大的响应,这些响应可以直接指向到受害者的电脑。NTP 放大使用的是 MONLIST 命令。MONLIST 命令会让 NTP 服务器返回使用 NTP 服务的最后 600 个 客户端 IP。通过一个有伪造源地址的 NTP 请求,NTP 服务器会将响应返回给那个伪造的 IP 地址。你可以想象,如果我们伪造受害者的 IP 对大量的 NTP 服务器发送 MONLIST 请求,这将形成 DOS 攻击。
  • 标准NTP 服务提供了一个 monlist查询功能,也被称为MON_GETLIST,该功能主要用于监控 NTP 服务器的服务状况,当用户端向NTP服务提交monlist查询时,NTP 服务器会向查询端返回与NTP 服务器进行过时间同步的最后 600 个客户端的 IP,响应包按照每 6 个 IP 进行分割,最多有 100 个响应包。由于NTP服务使用UDP协议,攻击者可以伪造源发地址向NTP服务进行monlist查询,这将导致NTP服务器向被伪造的目标发送大量的UDP数据包,理论上这种恶意导向的攻击流量可以放大到伪造查询流量的100倍。

2. 怎么发现是否被NTP攻击

如果网络上检测到大流量的UDP 123端口的数据,就可以确认正在遭受此类攻击

3. 如何防范NTP放大攻击?

方法一:
升级服务程序版本
将系统中的NTP服务升级到 ntpd 4.2.7p26 或之后的版本,因为 ntpd 4.2.7p26 版本后,服务默认是关闭monlist查询功能的。
方法二:
关闭服务的monlist查询功能:
首先查询问题主机的REQ_MON_GETLIST和REQ_MON_GETLIST_1请求是否可用。具体操作方法:

ntpq -c rv<localhost/remotehost>

ntpdc -c sysinfo<localhost/remotehost>

ntpdc -n -c monlist<localhost/remotehost>

如果上述功能可用,可尝试通过修改ntp.conf文件解决问题,具体操作建议是在上述配置文件中增加下面的配置:
允许发起时间同步的IP,与本服务器进行时间同步,但是不允许修改ntp服务信息,也不允许查询服务器的状态信息(如monlist)

IPV4:restrict default kod nomodify notrap nopeer noquery
IPv6:restrict -6 default kod nomodify notrap nopeer noquery

另外,还可以配置限制访问命令,如:restrict default noquery
修改并保存配置文件之后,请重启ntpd服务。

4. 测试如上步骤对NTP的影响

因为默认生产环境配置好了NTP服务,不建议做大的改动,比如更新版本。配置文件改动相对来说风险小一点,但是也存在一定风险,特别是对双机和数据库应用,配置文件改动后服务重新启动和时间同步都需要比较长的一段时间,这一段时间客户端根据自己的时钟在走,如果同步的时候与服务端的时钟存在微小的差距都可能会引起生产库的异常,严重的话数据库可能会down掉,因此操作重启服务前一定要确认好风险评估。

5. 具体测试操作

5.1 配置NTP服务端

选一台Centos7做为服务端,配置操作如下:

  1. 安装ntp,ntpdate软件包
    yum install -y ntp ntpdate
  2. 编辑配置文件
[root@test03 etc]# egrep  -v "^$|#" /etc/ntp.conf 
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict 10.211.55.3
restrict ::1
restrict 10.211.55.0 mask 255.255.255.0 nomodify 
server ntp1.aliyun.com iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
  1. 启动ntp服务
systemctl start ntpd 
systemctl enable ntpd

5.2 客户端solaris系统配置

  1. 确认安装包,及安装包版本
bash-3.2# pkginfo -i|grep ntp
system      SUNWntp4r                        NTPv4 (root)
system      SUNWntp4u                        NTPv4 (usr)
system      SUNWntpr                         NTP, (Root)
system      SUNWntpu                         NTP, (Usr)
bash-3.2# for n in pkginfo -i|grep ntp |awk '{print $2}';do pkginfo -l $n; done;
   PKGINST:  SUNWntp4r
      NAME:  NTPv4 (root)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2009.07.02.12.26
   BASEDIR:  /
    VENDOR:  Oracle Corporation
      DESC:  Network Time Protocol v4, NTP Daemon and Utilities (root)
    PSTAMP:  sfw10-patch-x20110415100807
  INSTDATE:  Nov 16 2019 14:47
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:       18 installed pathnames
                  14 shared pathnames
                  12 directories
                   1 executables
                  31 blocks used (approx)

   PKGINST:  SUNWntp4u
      NAME:  NTPv4 (usr)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2009.07.02.12.26
   BASEDIR:  /
    VENDOR:  Sun Microsystems, Inc.
      DESC:  Network Time Protocol v4, NTP Daemon and Utilities (4.2.5) (usr)
    PSTAMP:  sfw10-patch-x20100616075006
  INSTDATE:  Nov 16 2019 14:47
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:      240 installed pathnames
                  13 shared pathnames
                  22 directories
                   8 executables
                5683 blocks used (approx)

   PKGINST:  SUNWntpr
      NAME:  NTP, (Root)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.21.16.34
   BASEDIR:  /
    VENDOR:  Oracle Corporation
      DESC:  Network Time Protocol v3, NTP Daemon and Utilities (xntpd)
    PSTAMP:  on10ptchfeatx20130110213944
  INSTDATE:  Nov 16 2019 14:46
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:       15 installed pathnames
                  11 shared pathnames
                  11 directories
                   1 executables
                  14 blocks used (approx)

   PKGINST:  SUNWntpu
      NAME:  NTP, (Usr)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.21.16.34
   BASEDIR:  /
    VENDOR:  Oracle Corporation
      DESC:  Network Time Protocol v3, NTP Daemon and Utilities (xntpd)
    PSTAMP:  on10ptchfeatx20130110213945
  INSTDATE:  Nov 16 2019 14:45
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:        9 installed pathnames
                   4 shared pathnames
                   4 directories
                   5 executables
                 840 blocks used (approx)
bash-3.2# cat /etc/release
                    Oracle Solaris 10 1/13 s10x_u11wos_24a X86
  Copyright (c) 1983, 2013, Oracle and/or its affiliates. All rights reserved.
                            Assembled 17 January 2013

bash-3.2# uname -a
SunOS solaris10 5.10 Generic_147148-26 i86pc i386 i86pc
  1. 准备配置文件
    cp -p /etc/inet/ntp.client /etc/inet/ntp.conf
  2. 编辑配置文件
vi  /etc/inet/ntp.conf
bash-3.2# vi /etc/inet/ntp.conf 
"/etc/inet/ntp.conf" 12 lines, 328 characters 
# ident "@(#)ntp.client 1.3     00/07/17 SMI"
#
# /etc/inet/ntp.client
#
# An example file that could be copied over to /etc/inet/ntp.conf; it
# provides a configuration for a host that passively waits for a server
# to provide NTP packets on the ntp multicast net.
#

#multicastclient 224.0.1.1
server 10.211.55.3
  1. 启动ntp服务
bash-3.2# svcadm enable svc:/network/ntp:default
 bash-3.2# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
 10.211.55.3     84.16.73.33      2 -  301   64    0     0.46  673645. 16000.0

5.3 验证是否同步

客户端

date [-u] mmddHHMM[[cc]yy][.SS]
bash-3.2# date 041822382020 
Sat Apr 18 22:38:00 CST 2020

服务端

bash-3.2# date 041822382020 
Sat Apr 18 22:38:00 CST 2020

客户端再验证

bash-3.2# date
Sat Apr 18 22:45:27 CST 2020

5.4 客户端加固后再测试

进行安全加固,在客户端上/etc/inet/ntp.conf追加如下内容

disable monitor
restrict default  nomodify notrap nopeer noquery

然后再执行查看命令

 bash-3.2# ntpq -p
 localhost: timed out, nothing received
***Request timed out

修改时间后再查看是否同步

bash-3.2# date 041822482020  
Sat Apr 18 22:48:00 CST 2020

同步需要几分钟时间,请耐心等待

bash-3.2# date
Sat Apr 18 22:56:21 CST 2020
[root@test03 ~]# date
2020年 04月 18日 星期六 22:56:21 CST

查看日志和服务,确认是否同步与服务是否正常

bash-3.2# tail -3 /var/adm/messages
Apr 18 22:36:18 solaris10 xntpd[3313]: [ID 774427 daemon.notice] time reset (step) 39.749515 s
Apr 18 22:44:13 solaris10 xntpd[3313]: [ID 774427 daemon.notice] time reset (step) 28.024240 s
Apr 18 22:54:50 solaris10 xntpd[3313]: [ID 774427 daemon.notice] time reset (step) 61.061617 s
bash-3.2# svcs ntp
STATE          STIME    FMRI
online         22:29:13 svc:/network/ntp:default

6. 总结

配置文件改动相对来说风险小一点,但是也存在一定风险,特别是对双机和数据库应用,配置文件改动后服务重新启动和时间同步都需要比较长的一段时间,这一段时间客户端根据自己的时钟在走,如果同步的时候与服务端的时钟存在微小的差距都可能会引起生产库的异常,严重的话数据库可能会down掉,因此操作重启服务前一定要确认好风险评估。

原文地址:https://www.cnblogs.com/chacha51/p/13764835.html