snort 笔记2 ----- 规则编写

本文详细介绍了Snort规则的结构和编写,包括规则头的三要素(动作、协议、IP地址与端口)、规则选项如content、nocase、flow、reference等,并给出了实例说明。此外,还讲解了不同类型的规则选项,如payload类型、non-payload类型、post-detection类型,以及如何写出高效的规则。最后,提到了规则优化技巧,如正确排序规则选项以提高检测效率。
摘要由CSDN通过智能技术生成

为了看懂rules,可以看下文,想要写好,就没那么简单了。^-^。

 

******************************************************************************************************************************************

 

I 总体结构分析:

alert tcp any any -> 192.168.1.0/24 111 (content:"|00 01 86 a5|"; msg: "mountd access";)

分析:

  • 多行之间用 / 分开
  • 规则包括:规则头rule header: alert tcp any any -> 192.168.1.0/24 111 和规则选项 rule options:(content:"|00 01 86 a5|"; msg: "mountd access";)

II  规则头:3个要素: who , where, what,how(行动)

 

  • 2.1 规则动作 rule action。告诉snort一旦匹配干什么事,原来的snort共5种:alert, log,pass,activate,dynamic

(alert:警报并且记录;    log:记录;   pass::丢弃(忽略); activate:报警并且激活另外一条dynamic规则;dynamic:被激活后log,也可自己自定义,参考manual)

******************************************

以下是2.9版本的mannal中新添加的action:

 

1. alert - generate an alert using the selected alert method, and then log the packet

2. log - log the packet

3. pass - ignore the packet

4. activate - alert and then turn on another dynamic rule

5. dynamic - remain idle until activated by an activate rule , then act as a log rule

6. drop - block and log the packet

7. reject - block the packet, log it, and then send a TCP reset if the protocol is TCP or an ICMP port unreachable

message if the protocol is UDP.

8. sdrop - block the packet but do not log it.

 

******************************************

  • 2.2 协议。snort当前可分析的协议包有:tcp,udp,ip,icmp。
  • 2.3 ip地址。ip地址可以用any定义任何地址,并且需要添加掩码(16-B类,24-C类,32-特定的机器),并且可以使用!操作符。如果ip地址是个列表,需要[192.168.1.0/24,10.1.1.0/24]类似,使用[],中间用逗号隔开,如果要加!,要加到[]外部。
  • 2.4 端口号。any表示全部,如果表示范围,eg:1:1024,中间用冒号隔开。但是:200也可,表示小于等于200的,反之:1024:表示大于等于1024的。当然也可以类似ip地址使用!否定操作符。
  • 2.5  方向操作符。规则所施加的流的方向. 单向,从源到目的 ->; 双向,既是源又是目标<>.

III 规则选项:nids的核心,所有选项用“;”隔开,规则选项关键字和他们的参数用“:”分开,snort中有42个规则选项关键字(老版本,新版本要多很多,下文会分别将其分类列出)

*****************************************

msg - 在报警和包日志中打印一个消息。
logto - 把包记录到用户指定的文件中而不是记录到标准输出。
ttl - 检查ip头的ttl的值。
tos 检查IP头中TOS字段的值。
id - 检查ip头的分片id值。
ipoption 查看IP选项字段的特定编码。
fragbits 检查IP头的分段位。
dsize - 检查包的净荷尺寸的值 。
flags -检查tcp flags的值。
seq - 检查tcp顺序号的值。
ack - 检查tcp应答(acknowledgement)的值。
window 测试TCP窗口域的特殊值。
itype - 检查icmp type的值。
icode - 检查icmp code的值。
icmp_id - 检查ICMP ECHO ID的值。
icmp_seq - 检查ICMP ECHO 顺序号的值。
content - 在包的净荷中搜索指定的样式。
content-list 在数据包载荷中搜索一个模式集合。
offset - content选项的修饰符,设定开始搜索的位置 。
depth - content选项的修饰符,设定搜索的最大深度。
nocase - 指定对content字符串大小写不敏感。
session - 记录指定会话的应用层信息的内容。
rpc - 监视特定应用/进程调用的RPC服务。
resp - 主动反应(切断连接等)。
react - 响应动作(阻塞web站点)。
reference - 外部攻击参考ids。
sid - snort规则id。
rev - 规则版本号。
classtype - 规则类别标识。
priority - 规则优先级标识号。
uricontent - 在数据包的URI部分搜索一个内容。
tag - 规则的高级记录行为。
ip_proto - IP头的协议字段值。
sameip - 判定源IP和目的IP是否相等。
stateless - 忽略刘状态的有效性。
regex - 通配符模式匹配。
distance - 强迫关系模式匹配所跳过的距离。
within - 强迫关系模式匹配所在的范围。
byte_test - 数字模式匹配。
byte_jump - 数字模式测试和偏移量调整

*****************************************


在2.9的mannal中把它们分为了4类:

*******************************************

 

general :These options provide information about the rule but do not have any affect during detection

对检测无影响

payload :These options all look for data inside the packet payload and can be inter-related

需要深入到包中的数据。

non-payload: These options look for non-payload data

不需要包数据。

post-detection :These options are rule specific triggers that happen after a rule has “fired.”

触发器,只有当一个规则触发后才发生。

*******************************************

 

 

在对各种分类介绍之前,我

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值