首页 > 其他分享 >suricata(六)——suricata之IPS模式

suricata(六)——suricata之IPS模式

时间:2023-04-24 09:56:04浏览次数:39  
标签:-- suricata 模式 IPS install 6.0 root localhost

suricata之IPS模式

一、简介

suricata具有IDS(Intrusion Detection Systems,入侵检测系统)的功能外,还具有IPS(Intrusion Prevention System,入侵防御系统)功能,对不符合配置规则的报文进行直接阻断,对滥用报文进行限流以保护网络带宽资源。Suricata 本身是不具有拦截功能的,想要让它拦截包需要配合 iptables 使用。 首先要确定安装的suricata是否支持IPS模式,如果在安装编译的时候没有启用IPS模式,NFQueue默认为no

二、流量场景

1、经过设备的流量

该场景下,suricata部署机器为网关设备,iptables配置需要使用FORWARD

iptables -I FORWARD -j NFQUEUE

 

2、设备产生的流量

该场景下,suricata部署机器和主机为同一个设备,iptables配置需要使用INPUTOUTPUT

iptables -I INPUT -j NFQUEUE
iptables -I OUTPUT -j NFQUEUE

 

三、IDS和IPS区别

对比项 IDS引擎 IPS产品
部署方式 旁路部署 串联部署
部署位置 一般在交换机 一般在网络出入口
重要作用 监测告警 阻断攻击
  • 旁路
    • 在内网的支路上,流量一般不经过这里
    • 旁路一般是指通过交换机等网络设备的“端口镜像”功能来实现监控,在此模式下,监控设备只需要连接到交换机的指定镜像端口,所以形象的称之为“旁路监控”
    • 旁路监控模式部署起来比较灵活方便,只需要在交换机上面配置镜像端口即可,不会影响现有的网络结构
    • 旁路模式分析的是镜像端口拷贝过来的数据,对原始传递的数据包不会造成延时,不会对网速造成任何影响
    • 旁路监控设备一旦故障或者停止运行,不会影响现有网络的正常
    • 需要交换机支持端口镜像才可以实现监控
  • 串联
    • 串接在出口,所有出去的流量经过
    • 串联模式一般是通过网关或者网桥的模式来进行监控,由于监控设备做为网关或者网桥串联在网络中,所以称之为“串联监控模式”
    • 串联模式一般要作为网关或者网桥,所以需要对现有网络结构进行变动
    • 串联模式是串联在网络中的,那么所有的数据必须先经过监控系统,通过监控系统的分析检查之后,才能够发送到各个客户端,所以会对网速有一定的延时
    • 联监控设备如果出现故障,会导致网络中断,导致网络单点故障

 

四、安装IPS模式suricata

1、安装依赖

yum install epel-release

yum -y install gcc libpcap-devel pcre-devel libyaml-devel file-devel \
  zlib-devel jansson-devel nss-devel libcap-ng-devel libnet-devel tar make \
  libnetfilter_queue-devel lua-devel PyYAML libmaxminddb-devel rustc cargo \
  lz4-devel

 

2、安装suricata

1)解压

1 [root@localhost 16:21 /<path>]# tar -zxvf suricata-6.0.0.tar.gz

 

2)预编译

  • 查找pf_ring和:find / -name 'pfring.h'find / -name 'libpfring.so'
  • 查找hyperscan库路径: find / -name 'hs.h'find / -name 'libhs.so.5'
[root@localhost 16:22 /<path>]# cd suricata-6.0.0/
[root@localhost 16:23 /<path>/suricata-suricata-6.0.0]# ./autogen.sh   # 原生没有configure,需要该脚本来生成configure
[root@localhost 16:24 /<path>/suricata-suricata-6.0.0]# ./configure --disable-gccmarch-native \
--prefix=/usr --sysconfdir=/etc --localstatedir=/var \
--enable-pfring --with-libpfring-includes=/usr/local/include --with-libpfring-libraries=/usr/local/lib \
--with-libhs-includes=/usr/local/include/hs --with-libhs-libraries=/usr/local/lib64 \
--enable-geoip \
--enable-nfqueue

# --localstatedir 指定日志保存位置
# --prefix 指定安装位置
# --sysconfdir 指定配置文件保存位置
# --enable-pfring, --with-libpfring-includes, --with-libpfring-libraries  表示将pf_ring编译到suricata,库路径可能不尽相同,自行修改
# --with-libhs-includes, --with-libhs-libraries 表示将hyperscan编译到suricata,库路径可能不尽相同,自行修改
# --enable-nfqueue 开启IPS模式

## 执行完configure之后,如果没有报错,可以看到当前预编译的suricata,支持哪些功能
  • 预编译成功

    • 如果没有报错,可以看到当前预编译的suricata,支持哪些功能

  • 报错1

    ##### 如果configure时报出一下错误,根据提示,在当前目录下执行git clone https://github.com/OISF/libhtp,并重新执行./autogen.sh
    ##########################################################################################
    #ERROR: Libhtp is not bundled. Get libhtp by doing:
    #	git clone https://github.com/OISF/libhtp
    #Then re-run Suricata's autogen.sh and configure script.
    #Or, if libhtp is installed in a different location,
    #pass --enable-non-bundled-htp to Suricata's configure script.
    #Add --with-libhtp-includes=<dir> and --with-libhtp-libraries=<dir> if
    #libhtp is not installed in the include and library paths.
    ##########################################################################################
    # 解决LibHtp的报错
    [root@localhost 16:27 /<path>/suricata-suricata-6.0.0]# git clone https://github.com/OISF/libhtp
    [root@localhost 16:28 /<path>/suricata-suricata-6.0.0]# ./autogen.sh
    
    # 再次执行configure
    [root@localhost 16:29 /<path>/suricata-suricata-6.0.0]# ./configure --disable-............
    
  • 报错2

    ##### 如果configure时报出一下错误, 在命令起始位置加上LIBS="-lrt -lnuma" 
    ##########################################################################################
    ##checking for pfring_open in -lpfring... no
    ##
    ##   ERROR! --enable-pfring was passed but the library was not found or version is >4, go get it
    ##   from http://www.ntop.org/PF_RING.html
    ##########################################################################################
    
    [root@localhost 16:29 /<path>/suricata-suricata-6.0.0]# LIBS="-lrt -lnuma"  ./configure --disabl.........
    
  • 报错3

    ###################### 如果抛出以下错误,根据提示安装cbindgen,并加到PATH中 ######################
    ##########################################################################################
    #Warning: cbindgen too old or not found, it is required to 
    #      generate header files.
    #  To install: cargo install --force cbindgen
    #configure: error: cbindgen required
    ##########################################################################################
    
    [root@localhost 16:30 /<path>/suricata-suricata-6.0.0]# cargo install --force cbindgen   # 该步骤需要联网
    [root@localhost 16:40 /<path>/suricata-suricata-6.0.0]# export PATH=/root/.cargo/bin:$PATH
    
    # 再次执行configure
    [root@localhost 16:29 /<path>/suricata-suricata-6.0.0]# ./configure --disable-............
    
  • 报错4

    # 后续报错,缺什么依赖包,根据提示安装什么依赖包
    

 

3)编译安装

[root@localhost 16:45 /<path>/suricata-suricata-6.0.0]# make -j 4 && make install

 

4)添加htp库到系统目录

# 拷贝htp的库到lib中
[root@localhost 17:45 /<path>/suricata-suricata-6.0.0]# cp -d libhtp/htp/.libs/libhtp.so* /lib64/

########################### 如果不执行该步骤,在执行suricata命令时会报以下错误######################################
# [root@localhost ~]# suricata
# suricata: error while loading shared libraries: libhtp.so.2: cannot open shared object file: No such file or directory
############################################################################################################ 

 

5)添加库搜索路径

# 将pf_ring库路径加入到动态库搜索路径
[root@localhost suricata-suricata-6.0.0]# echo "/usr/local/lib" | tee --append /etc/ld.so.conf.d/usrlocal.conf
############################################################################################################
# 不将路径加到库搜索路径中,会出现找不到库文件的问题:
# [root@localhost suricata-suricata-6.0.0]# suricata
#  while loading shared libraries: libpfring.so.8: cannot open shared object file: No such file or directory
############################################################################################################

# 将hyperscan库路径加入到动态库搜索路径
[root@localhost suricata-suricata-6.0.0]# echo "/usr/local/lib64" | tee --append /etc/ld.so.conf.d/usrlocal.conf
############################################################################################################
# 不将路径加到库搜索路径中,会出现找不到库文件的问题:
# [root@localhost suricata-suricata-6.0.0]# suricata
# suricata: error while loading shared libraries: libhs.so.5: cannot open shared object file: No such file or directory
############################################################################################################

# 加载库
[root@localhost 16:45 /<path>/suricata-suricata-6.0.0]# ldconfig

 

6)生成conf目录、log目录等目录

# 生成conf目录、log目录等目录
[root@localhost 17:47 /<path>/suricata-suricata-6.0.0]# make install-conf
#install -d "/etc/suricata/"
#install -d "/var/log/suricata/files"
#install -d "/var/log/suricata/certs"
#install -d "/var/run/"
#install -m 770 -d "/var/run/suricata"

 

7)查看suricata信息

suricata  --build-info

 

5、生成规则文件

  • suricata-6.0.0引擎程序和规则是分开来安装的,因此需要单独安装suricata-update程序进行规则的安装。由于该程序是python写的,因此linux环境最好支持python同时安装pip工具
  • 安装完suricata-update,直接运行该程序,则会到指定的网站下载rules,下载到/var/lib/suricata/rules/
yum -y install epel-release
yum -y install python3-pip   # 由于在安装依赖时已经安装python3,所以可以忽略此步

# 安装suricata-update
pip3 install --upgrade suricata-update

# 执行,下载规则文件,会自动下载到/var/lib/suricata/rules中,执行该步骤后,不需要再执行make install-rules
suricata-update


# 修改/etc/suricata/suricata.yaml文件,将default-rule-path修改为/var/lib/suricata/rules
# 一定要修改,因为默认使用/etc/suricata/rules作为规则目录, 否则使用时,会出现找不到规则文件的问题


# 简单测试suricata
suricata -T

 

6、设置 iptables 的 NFQUEUE

需要设置 iptables 的 NFQUEUE,,以让 Suricata 能访问到相应的数据包,可以使用如下命令:

# 设置iptables
iptables -I INPUT  -j NFQUEUE
iptables -I OUTPUT  -j NFQUEUE

# 查看iptables
iptables -L

 

7、测试IPS模式

suricata -c /etc/suricata/suricata.yaml -q 0
  • 将baidu将入到drop规则中,此时发送到baidu的http包就无法发送出去,被丢弃
  • 但是别的不满足规则的包依然可以正常发送

 

8、清除iptables规则

  • 在不使用 Suricata 的时候,记得要 iptables -F 清除配置,不然机器就没法连接外网了

 

标签:--,suricata,模式,IPS,install,6.0,root,localhost
From: https://www.cnblogs.com/linagcheng/p/17348518.html

相关文章

  • 7 Best Practice Tips for PostgreSQL Bulk Data Loading
    7BestPracticeTipsforPostgreSQLBulkDataLoading  February19,2023Sometimes,PostgreSQLdatabasesneedtoimportlargequantitiesofdatainasingleoraminimalnumberofsteps.Thisiscommonlyknownasbulkdataimportwherethedatas......
  • 13、c++使用单例模式实现命名空间函数
    本案例实现一个test命名空间,此命名空间内有两个函数,分别为getName()和getNameSpace();声明命名空间及函数namespacetest{conststd::string&getName()和();conststd::string&getNameSpace();}命名空间内实现单例类实现一个单例类,构造函数要为private,自身对......
  • 单例 (Singleton)设计模式介绍
    单例(Singleton)设计模式1.什么是设计模式?什么是单例设计模式?设计模式:是在大量的实践中总结和理论化之后优选的代码结构、编程风格、以及解决问题的思考方式。设计模免去我们自己再思考和摸索。就像是经典的棋谱,不同的棋局,我们用不同的棋谱。”套路”单例设计模式:所谓类......
  • linux切换桌面模式
    指定运行级别(指定运行级别使用的是init0~6或者是systemctlget-default是查看当前运行级别。systemset-defaultmulti-user.target表示切换到运行级别3systemset-defaultgraphical.target表示切换到运行级别5) ......
  • docker网络模式
    一、docker网络概述1、docker网络实现的原理Docker使用Linux桥接,在宿主机虚拟一个Docker容器网桥(docker0),Docker启动一个容器时会根据Docker网桥的网段分配给容器一个IP地址,称为Container-IP,同时Docker网桥是每个容器的默认网关。因为在同一宿主机内的容器都接入同一......
  • 设计模式-工厂模式
    适用性1.当一个类不知道它所必须创建的对象的类的时候。2.当一个类希望由它的子类来指定它所创建的对象的时候。3.当类将创建对象的职责委托给多个帮助子类中的某一个,并且你希望将哪一个帮助子类是代理者这一信息局部化的时候。......
  • Eclipse默认标签TODO,XXX,FIXME和自定义标签[转]
    1TODO表示需要实现,但目前还未实现的功能2XXX勉强可以工作,但是需要改进的功能3FIXME代码是错误的,不能工作,需要修复4.自定义标签window-->preferences-->java-->compiler-->tags选择new,输入tag,选择priority,ok上述所有注释都会被eclipseta......
  • Eclipse中获取类的继承关系和被谁调用[转]
    Eclipse中的右键菜单中的opentypehierarchy可以获取类的继承关系。而opencallhierarchy的可以在项目中寻找当前函数都被谁在何处调用过。这个能够帮助理解当前函数的“可用之处”,尤其在阅读别人的代码的时候非常有用。......
  • 15分钟入门23种设计模式:图解,范例和对比
    本文力图在15分钟内,通过UML图解、范例和类比,让你对面向对象的23种设计模式形成提纲挈领的认识,从而让我们在面临代码设计问题时更加成竹在胸。本文源代码: UML, SampleCode。开门见山我们直奔主题,分类呈现23种设计模式的庐山真面目:创建型(5)Creational结构型(7)Structural......
  • 设计模式分类(创建型模式、结构型模式、行为模式) #2
    1.创建型模式创建型模式,就是创建对象的模式,抽象了实例化的过程。它帮助一个系统独立于如何创建、组合和表示它的那些对象。关注的是对象的创建,创建型模式将创建对象的过程进行了抽象,也可以理解为将创建对象的过程进行了封装,作为客户程序仅仅需要去使用对象,而不再关系创建对象过程......