Snort Readme

Snort的README文件都存放在/usr/local/share/doc/snort/目录下,并且已经以README.ipv6形式分好类以供查阅。

1.READERME.alert_order

1.1

Snort 会将抓取IP,ICMP,TCP,UDP协议的流量网络信息的头部存入数据库中,分别对应的表为iphdr,icmphdr,tcphdr,udphdr。hdr也就是header的意思。
  举个例子,如果只使用了如下这一条规则:
alert tcp 192.168.1.151 any -> 192.168.1.7 80 (msg:"PROTOCOL-TCP PACKAGE DETECTED"; sid:1000012; rev:1;)
  这就是抓取了一条tcp的流量,Snort会将此条流量的信息不仅存入tcphdr表,而且也会存入iphdr表。
  同理,规则中如果写ICMP的话,icmphdr和iphdr都会有对应包的头部信息,但是tcphdr不会有,因为他们根本没关系。
  再举个例子,也是假设只是用了如下这一条规则。
alert ip 192.168.1.151 any -> 192.168.1.7 any (msg:"PROTOCOL-IP PACKAGE DETECTED"; sid:1000013; rev:1;)
  虽然规则中过滤的是ip,但是查询数据库,发现还是会把tcp,icmp都会记录。
  通过上面这两个例子我们就会发现,不管规则中过滤的是哪个协议,Snort会把这个包的中用到的所有协议(上面提到的四种之内)记录在数据库中。

1.2

如果遇到如下这种怎么办

alert icmp 192.168.1.151 any -> 192.168.1.7 any (msg:"PROTOCOL-ICMP PACKAGE DETECTED"; sid:1000011; rev:1;)
alert tcp 192.168.1.151 any -> 192.168.1.7 80 (msg:"PROTOCOL-TCP PACKAGE DETECTED"; sid:1000012; rev:1;)
alert ip 192.168.1.151 any -> 192.168.1.7 any (msg:"PROTOCOL-IP PACKAGE DETECTED"; sid:1000013; rev:1;)

三种协议都有,到底匹配哪个?
测试从192.168.1.151ping192.168.1.7,本应该只发4个icmp包,但是在数据库的event表中看到了8个,查看其signature,发现icmp和ip的两条规则都触发了。


signature表

event表

上图中,第二列是cid,第三列是signature,发现同一时间触发了12,9两个,12是我自定义的ip那条规则的sig,9是icmp。
同时又看到iphdr和icmphdr表也同时都用8条数据,告警也多了8条,所以说一个ping命令,触发了ip和icmp的两条规则。
我又测试了从192.168.1.151访问192.168.1.7web网页,也同时触发了12和13这两条规则,不再赘述。

1.3

下面是协议相同的情况:
查看/usr/locale/share/doc/snort/README.alert_order帮助文件,

[root@localhost snort]# more README.alert_order 
ALERT ORDERING
--------------

The Snort 2.0 detection engine changes how the ordering of rules
affect which alerts fire.  Before Snort 2.0, knowing which alerts would fire
first was determined by the position of the rule during initialization.
If the rule was read before another rule, then the rule that was read first
would be the alert that was logged.

This has all changed with the 2.0 detection engine.  There are now two stages
that determine which alerts will fire for a packet.  Ideally, Snort would have
the ability to log all alerts in a packet, but the current output modules do
not allow for this.

The first stage in the 2.0 detection engine is rule set selection.  Depending
on the rule set that is selected, different alerts may be generated.  The
rule sets are select first by transport protocol and then by characteristics
within the specific transport protocol:

  * TCP/UDP:  selection based on source and destination ports
  * ICMP:     selection based on ICMP type
  * IP:       selection based on IP transport protocol (if not TCP/UDP/ICMP)

Each protocol also has a generic rule set associated with it.  This provides
for the case where a packet does not match any unique properties of the
transport protocol.

It is important to note that every packet matches against a generic rule set,
since every unique rule set includes the generic rule set.  For example, if
a packet with a destination port of 80 is inspected, the rule set that
contains destination port 80 rules is selected, not the generic rule set.

The rule set selected is important.  In the second stage of the 2.0
detection engine, which rules get matched are determined by the rule set that
is selected.

Once a rule set is selected, two general types of rules are matched against.
These rules are content and non-content rules.  The content rules have
higher rule ordering priority over non-content rules, so if a content rule
matches a packet and a non-content rule matches a packet, the content rule
will always win.  If no content rules match, then the non-content rule that
is first in the file (the old snort way) will win.  This doesn't
apply when a unique rule set has been selected because the unique non-content
rules are first in the inspection order.  For example,  if an ICMP packet of
type 8 is inspected, two rules will match the packet.  One of the rules
is a generic ICMP Echo Request with no type indicated, and the other rule is
an ICMP Echo Request with a itype:8.  The itype:8 rule will always fire 
regardless of it's position in the rule file because it is the more unique
rule (since it has an itype:8).

-- Examples --

Which rule fires when there are two identical rules:

alert tcp any any -> any any ( msg:"foo1"; content: "foo"; )
alert tcp any any -> any any ( msg:"foo2"; content: "foo"; )

foo1 fires because it is first in the rules file.  This applies for all rules
(uricontent, content, no-content) that are exactly the same.  The first rule
in the rule files alerts.

Which rule fires when there are two rule with the same content, but one rule
has any any ports and the other has a specific port?

alert tcp any any -> any any ( msg:"foo1"; content: "foo"; )
alert tcp any any -> any 80 ( msg:"foo2"; content: "foo"; )

foo2 fires because it is considered a unique rule because it specifies a port
and gets put in the unique rule group for port 80.  foo1 is considered a 
generic rule because it has no specific port characteristics.

Which rule fires when a uricontent rule and a content rule both match a
packet?

alert tcp any any -> any 80 ( msg:"foo1"; content: "foo"; )
alert tcp any any -> any 80 ( msg:"foo2"; uricontent: "foo"; )

foo2 fires (as long as http_inspect is on) because uricontent rules are
matched against the packet first, and if there is a uricontent match then
this rule takes priority over content and no-content rules.

Which rule fires when a content rule and a no-content rule both match a
packet?

alert tcp any any -> any any ( msg:"foo1"; content: "foo"; )
alert tcp any any -> any any ( msg:"foo2"; )

foo1 fires because content rules are matched against a packet first, and if
there is a content match, then any no-content rules that match the packet
also will take a lower priority than any content rule that matches a packet.

Which rule fires when two content rules match a packet?

alert tcp any any -> any any ( msg:"foo1"; content: "foo"; )
alert tcp any any -> any any ( msg:"foo2"; content: "foobar";)

foo2 fires because the content rule with the longer content string takes
the higher priority.

Which rule fires when two ICMP rules match a packet?

alert icmp any any -> any any ( msg:"ICMP-No-iType"; dsize:>800; )
alert icmp any any -> any any ( msg:"ICMP-iType"; itype:8; dsize:>800;)

ICMP-iType fires because it has an 'itype' parameter, which specifies the
ICMP rule as unique ('itype' is the only parameter for ICMP rules that
specify uniqueness, otherwise it's considered generic).

经过做实验验证,发现只要是IP地址不同,就不算是一个规则。

测试规则

发现5188和5199是同一个包,5190和5191是同一个包。
也就是一个包一次传输被Snort记录了两次。说明了,只要两条规则中IP地址不同(any也算不同),这两条规则就都会匹配。
上面README.alert_order中的情况都是IP地址相同的前提下讨论的。

最后一个例子验证README.alert_order中的内容。
然而失败了。
还是和上个实验一样的结果。

让我们举个最极端的例子好不好。

只有sid不同的两条rule
signature表
event表

这说明了。只要sid不同,规则match到的话都会记录。
啊啊~~~README.alert_oder神坑。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,132评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,802评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,566评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,858评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,867评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,695评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,064评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,705评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,915评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,677评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,796评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,432评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,041评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,992评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,223评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,185评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,535评论 2 343

推荐阅读更多精彩内容