Snort3:使用说明(四)

Snort-3-logo_v.png

1 模式


模式说明备注
1嗅探器模式(sniffer)网络中读取数据包并显示到控制台snort2文档中明确区分了三种模式,snort3中对此表述有所弱化,合称为嗅探和记录
2数据包记录器模式将数据包记录到磁盘
3入侵防御系统模式(IPS)对网络流量进行检测和分析…

2 命令行选项

本章节会选择一些重要的命令行选项进行解读。

2.1 帮助

2.1.1 帮助信息(-?)

-? output matching command line option quick help (same as --help-options) (optional)

2.1.2 查看模块可用配置

–help-modules list all available modules with brief help # 所有模块简单帮助信息
–help-module output description of given module # 指定模块详细帮助信息

帮助信息中会显示模式的可用配置项,这些配置项可以 snort 配置文件中进行配置。

2.1.3 查看

2.2 输入

2.2.1 读取离线报文(-r …)

-r … (same as --pcap-list)
–pcap-file file that contains a list of pcaps to read - read mode is implied
–pcap-dir

a directory to recurse to look for pcaps - read mode is implied

  • 读取单个pcap文件-r xxx.pcap
  • 读取多个文件
    • 多次指定 -r 选项:-r aaa.pcap -r bbb.pcap
    • 读取pcap文件列表文件:--pcap-file pcap.txt
aaa.pcap
bbb.pcap
  • 读取pcap目录--pcap-dir pcap_dir

2.2.2 网口收包(-i)

-i … list of interfaces

2.3 输出

2.3.1 显示2层头部信息(-e)

-e display the second layer header info

实际验证,警报模式会影响该选项输出。

  • full +e时,可显示
  • fast+e时,未显示
  • fast+d+e 时,可显示

2.3.2 显示应用层数据(-d)

-d dump the Application Layer

该选项可以显示命中规则的数据包或-Lpcap模式捕获的数据包的应用层内容,以16进制和ASCII显示。

实际验证,警报模式会影响该选项输出。

  • full + d时,未显示
  • fast + d时,可显示。

2.3.3 记录模式(-L)

-L logging mode (none, dump, pcap, or log_*)`

序号参数说明备注
1none关闭默认
2dump显示数据包的序号,和OSI 2~4层头部信息。输出到命令行。可配置 -d 使用。
3pcap输出pcap文件通过-l指定输出目录,默认当前目录
4TODO
5log_*上述模式增加log_前缀,效果不变

示例:
读取pcap文件,显示到命令行。

admi@admibin♣ sudo ./snort -q  -L dump -r dns_baidu.pcap 
pkt:1
eth(DLT):  08:00:27:6E:50:00 -> 52:54:00:12:35:02  type:0x0800
ipv4(0x0800):  10.0.2.15 -> 172.16.11.222
        Next:0x11 TTL:64 TOS:0x0 ID:29046 IpLen:20 DgmLen:66 DF

pkt:2
eth(DLT):  52:54:00:12:35:02 -> 08:00:27:6E:50:00  type:0x0800
ipv4(0x0800):  172.16.11.222 -> 10.0.2.15
        Next:0x11 TTL:64 TOS:0x0 ID:28051 IpLen:20 DgmLen:98
udp(0x11):  SrcPort:53 DstPort:58886 Len:70

读取pcap文件(也可使用-i选项指定网口抓包),转存到 log 目录中。

admi@admibin♣ ./snort -q -l log -L pcap -r dns_baidu.pcap 

admi@admibin♣ tree log
log
└── log.pcap.1684317373

0 directories, 1 file

2.3.4 警报模式(-A)

-A set alert mode: none, cmg, or alert_*

命令行中最多指定一次。

序号参数说明备注
1none关闭警报默认
2fast快速警报模式带有时间戳、警报消息、源和目标 IP/端口的简单格式
3cmgcmg 样式同-A fast -d -e,增加了包头和负载内容输出
4full
比fast多了一些长度等信息
5json

6syslog

7talos

8unixsock
将警报发送到另一个程序可以侦听的 UNIX 套接字
9alert_*上述模式增加alert_前缀,效果不变
10unified2/u2二进制模式。待验证输出到 -l 指定的目录中,文件名unified2.log.

注意

  1. 在源码中警报(-A)和记录模式(-L)选项使用同一个变量存储,这意为IDS/IPS模式和数据包记录模式的互斥性。
  2. 如果在命令行中同时指定了-A和-L实际只会有一个生效(靠后的)

2.3.4.1 fast
01/15-04:23:11.946131 [**] [1:202:1] "alert dns 3 test" [**] [Priority: 5] {UDP} 192.168.31.31:53947 -> 192.168.31.1:53
01/15-04:23:11.950001 [**] [1:202:1] "alert dns 3 test" [**] [Priority: 5] {UDP} 192.168.31.1:53 -> 192.168.31.31:53947

2.3.4.2 cmg
01/15-04:23:11.946131 [**] [1:202:1] "alert dns 3 test" [**] [Priority: 5] {UDP} 192.168.31.31:53947 -> 192.168.31.1:53
48:F1:7F:52:B5:DE -> 8C:53:C3:CA:28:24 type:0x800 len:0x52
192.168.31.31:53947 -> 192.168.31.1:53 UDP TTL:64 TOS:0x0 ID:15755 IpLen:20 DgmLen:68
Len: 40

dns.raw[40]:
- - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - -
A2 92 01 00 00 01 00 00  00 00 00 00 09 61 6E 61  ........ .....ana
6C 79 74 69 63 73 08 64  6F 67 65 64 6F 67 65 03  lytics.d ogedoge.
63 6F 6D 00 00 01 00 01                           com..... 
- - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - -

01/15-04:23:11.950001 [**] [1:202:1] "alert dns 3 test" [**] [Priority: 5] {UDP} 192.168.31.1:53 -> 192.168.31.31:53947
8C:53:C3:CA:28:24 -> 48:F1:7F:52:B5:DE type:0x800 len:0x62
192.168.31.1:53 -> 192.168.31.31:53947 UDP TTL:64 TOS:0x0 ID:0 IpLen:20 DgmLen:84 DF
Len: 56

dns.raw[56]:
- - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - -
A2 92 81 80 00 01 00 01  00 00 00 00 09 61 6E 61  ........ .....ana
6C 79 74 69 63 73 08 64  6F 67 65 64 6F 67 65 03  lytics.d ogedoge.
63 6F 6D 00 00 01 00 01  C0 0C 00 01 00 01 00 00  com..... ........
00 80 00 04 78 19 FB CB                           ....x... 
- - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - -

2.3.4.3 full
[**] [1:202:1] "alert dns 3 test" [**]
[Priority: 5] 
01/15-04:23:11.946131 192.168.31.31:53947 -> 192.168.31.1:53
UDP TTL:64 TOS:0x0 ID:15755 IpLen:20 DgmLen:68
Len: 40

[**] [1:202:1] "alert dns 3 test" [**]
[Priority: 5] 
01/15-04:23:11.950001 192.168.31.1:53 -> 192.168.31.31:53947
UDP TTL:64 TOS:0x0 ID:0 IpLen:20 DgmLen:84 DF
Len: 56

2.3.4.4 talos

##### dns.pcap #####
        [1:202:1] alert dns 3 test (alerts: 2)
#####

2.3.4.5 unified2/u2
unified2.log.1683168982
unified2.log.1683169323
unified2.log.1683169327
unified2.log.1683169330

unified2/u2 是二进制格式,可通过snort3中附带的工具u2spewfoo转换将其文本内容。如 ./u2spewfoo log/unified2.log.1683169744

Packet
        sensor id: 0    event id: 1     event second: 1610655791
        packet second: 1610655791       packet microsecond: 946131
        linktype: 1     packet_length: 82
[    0] 8C 53 C3 CA 28 24 48 F1 7F 52 B5 DE 08 00 45 00  .S..($H..R....E.
[   16] 00 44 3D 8B 00 00 40 11 7D AD C0 A8 1F 1F C0 A8  .D=...@.}.......
[   32] 1F 01 D2 BB 00 35 00 30 8B 73 A2 92 01 00 00 01  .....5.0.s......
[   48] 00 00 00 00 00 00 09 61 6E 61 6C 79 74 69 63 73  .......analytics
[   64] 08 64 6F 67 65 64 6F 67 65 03 63 6F 6D 00 00 01  .dogedoge.com...
[   80] 00 01                                            ..
(Event)
        Snort ID: 0     Event ID: 1     Seconds: 1610655791.946131
        Policy ID:      Context: 0      Inspect: 0      Detect: 0
        Rule 1:202:1    Class: 0        Priority: 5
        MPLS Label: 0   VLAN ID: 0      IP Version: 0x44        IP Proto: 17
        Src IP: 192.168.31.31   Port: 53947
        Dst IP: 192.168.31.1    Port: 53
        App Name: none
        Status: allow   Action: pass

Packet
        sensor id: 0    event id: 1     event second: 1610655791
        packet second: 1610655791       packet microsecond: 946131
        linktype: 1     packet_length: 82
[    0] 8C 53 C3 CA 28 24 48 F1 7F 52 B5 DE 08 00 45 00  .S..($H..R....E.
[   16] 00 44 3D 8B 00 00 40 11 7D AD C0 A8 1F 1F C0 A8  .D=...@.}.......
[   32] 1F 01 D2 BB 00 35 00 30 8B 73 A2 92 01 00 00 01  .....5.0.s......
[   48] 00 00 00 00 00 00 09 61 6E 61 6C 79 74 69 63 73  .......analytics
[   64] 08 64 6F 67 65 64 6F 67 65 03 63 6F 6D 00 00 01  .dogedoge.com...
[   80] 00 01                                            ..

:::info
说明:
通过命令行,仅能指定输出警报信息到标准输出。可通过修改配置文件,来使其输出到文件中。见配置文件章节。
:::

要查看可用的警报类型,可以运行以下命令
$ ./snort --list-plugins | grep logger


2.3.4 日志目录(-l)

-l log to this directory instead of current directory

不指定时则默认为当前目录

$ snort -i eth0 -l log -Lpcap 

2.3.5 安静模式(-q)

-q quiet mode - suppress normal logging on stdout

其效果是,关闭统计等信息输出。

2.4 检测

2.4.1 checksum模式(-k)

-k checksum mode; default is all (all|noip|notcp|noudp|noicmp|none)

校验和模式。
:::warning
注意:
snort可能会忽略校验失败的数据包。实际使用时可能会因此而无法触发警报
:::

2.4.2 规则文件(-R)

-R include this rules file in the default policy

此选项可以多次指定,以设置多个规则文件。

./snort  -q -k none  -c snort.lua -A fast -r dns.pcap -R dummy_http.rules -R dummy_dns.rules 

2.4.3 规则文件目录(–rule-path)

–rule-path where to find rules files

2.4.4 配置文件(-c)

-c use this configuration

2.4.5 多线程(-z)

-z maximum number of packet threads (same as --max-packet-threads); 0 gets the number of CPU cores reported by the syst
em; default is 1 (0:max32)

3 配置文件

  • 配置文件的安装位置:${prefix}/etc/snort/snort.lua。每次执行安装后,注意安装路径下的配置文件都会被覆盖。
  • 如命令行和配置文件中通过进行了某项设置,最终以命令行为准。
  • snort被组织成内置模块和插件模块的集合。如果模块有参数,则由同名的 Lua 表配置。

alert_*

在配置文中定义了对应alert_*模块的表,即表示使能了该模式。配置文件支持同时开启多个警报模式


alert_fast = {} -- 这样配置就相同开启了fast模式。其它模式也是一样。

alert_fast =
{
    file = true,  -- 是否输出到文件
    packet= true  -- 是否输出数据包头部信息
}

按上述配置文件后,警报文件会输出到 -l 指定的目录中,文件名固定为 alert_fast.txt

admi@admibin♣ tree log
log
└── alert_fast.txt

4 错误使用

当不小心同时指定了 -r 和 afpacet 模式 -i 时,会抛出如下异常

admi@admibin♣ sudo ./snort -r pcap/get_doc.pcap --daq afpacket -i enp0s9

Couldn't construct a DAQ instance: afpacket_daq_instantiate: Interface name too long! (17) (-1)

参考

  1. Snort 3 User Manual
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值