snort环境及IDS测试

本文介绍内容如下:

1.snort规则

2.snort环境搭建

3.snort模式

4.snort执行参数

5.snort IDS测试

6.关于snort.conf参考:https://blog.csdn.net/jo_say/article/details/6302367

测试部分参考:https://www.cnblogs.com/lasgalen/p/4512755.html

Snort规则

Snort和suircata是一种网络规则检测引擎(network threat detection engine).,前者兼容后者。

https://i-blog.csdnimg.cn/blog_migrate/22231daea9ddfbbedb1ab7fa8c7504a7.webp?x-image-process=image/format,png

规则头部:

头部从左到右分别为规则行为(drop,pass,alert,log),协议,源地址,源端口,方向,目的地址,目的端口

规则选项:

规则内容用分号分割,每一项都是一个key-value的键值对


Meta-settings

  • msg:"description"; 描述字段,报警的时候的一些描述信息,比如某某某攻击等的
  • sid: 1; 每条规则id
  • rev: 3; 修订版本 1-
  • gid: 2; 组ID
  • classtype:trojan-activity; 查看classification.config文件中的配置,后面有优先级。
  • reference: bugtraq, 123; http://www.securityfocus.com/bid 或者 reference: url, www.info.nl
  • priority:1; 优先级1-255 1-4常用 优先级越小越优先
  • target:[src_ip|dest_ip] 报警时候回上报这个格式的,含义是[攻击源|攻击目标]

Header-Keyword

  • ttl:10 数据包中的ttl
  • ipopts:
  • sameip;当数据报文的源和目的IP相同时候
  • ip_proto:<name|id>
    • 1 ICMP
    • 6 TCP
    • 17 UDP
  • id:1 每一个IP报文发送后id+1,一个IP报文的多个分片ID一致
  • geoip
    - geoip: src, RU;
    - geoip: both, CN, RU;
    - geoip: dst, CN, RU, IR;
    - geoip: both, US, CA, UK;
    - geoip: any, CN, IR;
  • TCP关键字:
    • ack:0;
    • seq:0;
    • window:55808;
    • 等等...
  • ICMP关键字:
    • itype:8;
    • itype:>10;
    • icode 和itype类似
    • icmp_id 和 icmp_seq

prefilter 预过滤

prefilter之前的规则属于预过滤规则

payload 关键字

content:”root”;nocase     //检查内容字符串+检测内容修饰语

content:”root”;offset:5;depth:7; //指定匹配开始位置(默认0字节开始)和结束位置

content:”root”;content:”admin”;distance:1;within:7;   //distance指定上一次匹配结束位置后下一次匹配开始位置距离,within限定本次匹配必须出现在上一次匹配结束后的多少个字节内。

HTTP 关键字

请求字段

Keyword

Means

Direction

http_uri

客户端请求的URL内容

Request

http_method

Modifier

Request

http_request_line

Sticky Buffer

Request

http_client_body

Modifier

Request

http_header

Modifier

Both

http_raw_header

Modifier

Both

http_cookie

Modifier

Both

http_user_agent

Modifier

Request

http_host

Modifier

Request

http_raw_host

Modifier

Request

http_accept

Sticky Buffer

Request

http_accept_lang

Sticky Buffer

Request

http_accept_enc

Sticky Buffer

Request

http_referer

Sticky Buffer

Request

http_connection

Sticky Buffer

Request

http_content_type

Sticky Buffer

Both

http_content_len

Sticky Buffer

Both

http_start

Sticky Buffer

Both

http_protocol

Sticky Buffer

Both

http_header_names

Sticky Buffer

Both

响应字段

Keyword

Sticky or Modifier

Direction

http_stat_msg

Modifier

Response

http_stat_code

Modifier

Response

http_response_line

Sticky Buffer

Response

http_header

Modifier

Both

http_raw_header

Modifier

Both

http_cookie

Modifier

Both

http_server_body

Modifier

Response

file_data

Sticky Buffer

Response

http_content_type

Sticky Buffer

Both

http_content_len

Sticky Buffer

Both

http_start

Sticky Buffer

Both

http_protocol

Sticky Buffer

Both

http_header_names

Sticky Buffer

Both

以上用法

content:"xxxxxx";http_xxxx;
 

流信息关键字

  • flow:to_client 关键字:
    • to_client
    • to_server
    • from_client
    • from_server
    • established
    • not_established
    • stateless
    • only_stream
    • no_stream
    • only_frag
    • no_frag
  • stream_size
    • >
    • <
    • =
    • !=
    • >=
    • <=

文件关键字

  • filename:"a.php";
  • fileext:"jpg";
  • filemagic:"";
  • filestore:[request|response],[file|tx|ssn]
  • filenmd5:[!]filename; filenmd5:md5-blacklist;
  • filesize:5 > < 也可以

阈值

  • threshold: type <threshold|limit|both>, track <by_src|by_dst>, count
  • detection_filter: track <by_src|by_dst>, count

DNS关键字

dns_query;content:"域名"

通信流量

通信流量:根据TCP协议网络流量状态编写规则

三次握手:

1. 客户端向服务器的监听端口发送SYN包来发起连接

2. 此时,服务器需要向客户端回复一个SYN/ACK包

3. 一旦收到该包,客户端会回复给服务器一个ACK包 数据流规则有一些专用选项,分为三类: 1. 状态选项 2. 定向选项 3. 流量模式状态 配置格式:flow:<option>,<option>,<option> 有效声明选项分别为 1. established:只匹配已经建立TCP会话连接的流量 2. stateless:不论是否已建立TCP会话连接均匹配 方向选项分别为: 1. to_server:从客户端到服务端的流量 2. from_server:从服务端到客户端的流量 3. to_client:从服务端到客户端的流量 4. from _client:从客户端到服务端的流量 no_stream:待匹配数据是重组后的流 only_stream:待匹配数据是单独的数据包 协议头检测 1. TTL:匹配指定的TTL指,可使用关系运算符(< , <=, >=, >),可以用来识别操作系统类型 2. dsize:匹配一个指定payload大小的数据包,可使用关系运算符(< , <=, >=, >) 3. itype:匹配指定的ICMP类型值

4. icode:匹配指定的ICMP代码值 5. ip_proto:匹配指定的IP协议,如IGMP、GRE

搭建snort环境

参考:https://www.cnblogs.com/lsdb/p/8023884.html

Snort模式

Snort模式

嗅探器模式

-它从网络中读取数据包,并在控制台(屏幕)上以连续流的形式显示它们。

数据包记录器模式

 -它将数据包记录到磁盘。

网络入侵检测系统(NIDS)模式

-对网络流量执行检测和分析。这是最复杂和可配置的模式。

Snort执行参数

短参数

Snort –i ens33   //指定网络接口

-b              //用二进制文件保存数据包

-c <cf>           //进入IDS模式,并且从cf读取配置信息

-d                                  //显示包的应用层信息

-D                                 //后台运行->默认日志写在/var/log/snort/alert

-e                                  //显示数据链路层信息

-I <if>                           //报警时加上接口信息

-J <port>                     //in-line模式时,只捕获<port>端口报文

-K <file>                      //设置保存文件格式。Pcap是默认格式,none关闭记录

-N                                 //关闭保存日志包功能

-n <count>                 //捕获<count>个报文后终止程序

-o                                  //改变规则顺序。Alert,pass等

-v                                  //从网络上读取数据包然后显示在控制台,只显示头部信息

-vd                                //可以显示分组数据及标题

-vde                             //更详细

-V                                 //查看version并退出

-Z <path>                   //设置性能监视器路径

-?                               //help

长参数选项

 

--dynamic-engine-lib <file>
            指定动态监测引擎文件

    --dynamic-detection-lib <file>
            指定一个动态规则库文件

    --dynamic-detection-lib-dir <path>
            指定所有动态规则库路径

    --dump-dynamic-rules <path>
            为所有加载的规则库创建根规则文件

    --dynamic-preprocessor-lib <file>
            指定动态预处理库文件

    --dynamic-preprocessor-lib-dir <path>
            指定动态预处理库路径

    --dump-dynamic-preproc-genmsg <path>
            为所有加载的预处理库生成gen-msg.map文件到路径<path>.

    --alert-before-pass
            在pass之前处理alert, drop, sdrop, or reject. 默认是pass before alert, drop, etc.

    --treat-drop-as-alert
            Converts drop, and reject rules into alert rules during startup. sdrop rules are not loaded.将drop处理为alert。

    --process-all-events
            Process all triggered events in group order, per Rule Ordering configuration.  Default stops after first group.

    --pid-path <path>
            Specify the path for Snort's PID file. 为SnortPID文件指定路径。

    --create-pidfile
            Create PID file, even when not in Daemon mode. 创建PID文件。

    --enable-inline-test
            Runs snort in "inline test mode". This option cannot be used with -Q. 在线测试模式

测试

snort -i ens33 -n 5 -dev -l ./log    //输出ens33五个数据包到当前log目录下

snort -dv -r snort.log.1552668614   //把二进制文件信息打印在终端

snort -dv -r snort.log.1552668614 udp //只打印udp包

 

 

===》规则:local.rules,内容如下:

alert icmp ![192.168.126.130/32] any -> 192.168.126.130/32 any (logto:”log”; msg:”alert icmp !!!!!!”; sid:1000001)

CentOS7的ip:192.168.126.130(ens33为nat)

本机ip:172.24.178.65(vm8:192.168.126.2)

snort -i ens33 -dev -l ./log -c /etc/snort/snort.conf

结果:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值