| 1 | = 正規表示法 Rules = |
| 2 | |
| 3 | == 規則 == |
| 4 | |
| 5 | || [^w] || 不要有w的字串 || |
| 6 | || ^word || 待搜尋的字串(word)在行首 || |
| 7 | || word$ || 待搜尋的字串(word)在行尾 || |
| 8 | || . || 代表『任意一個』字符,一定是一個任意字符 || |
| 9 | || \ || 跳脫字符,將特殊符號的特殊意義去除 || |
| 10 | || * || 重複零個或多個的前一個 RE 字符 || |
| 11 | || {n,m} || 連續 n 到 m 個的『前一個 RE 字符』|| |
| 12 | || [] || 字元集合的 RE 特殊字符的符號 || |
| 13 | || + || 重複『一個或一個以上』的前一個 RE 字符 || |
| 14 | || ? ||『零個或一個』的前一個 RE 字符 || |
| 15 | || | || 用或( or )的方式找出數個字串 || |
| 16 | || ( ) || 找出『群組』字串 || |
| 17 | |
| 18 | == 範例 == |
| 19 | |
| 20 | {{{ |
| 21 | 找tast 或 test: t[ae]st |
| 22 | 不想要 oo 前面有 g: [^g]oo |
| 23 | oo 前面不想要有小寫字元: [^a-z]oo |
| 24 | 取得有數字的那一行 : [0-9] |
| 25 | 只列出在行首的 the : ^the |
| 26 | 不想要開頭是英文字母:^[^a-zA-Z] |
| 27 | 行尾結束為小數點 (.) 的那一行 : \.$ |
| 28 | 該行並沒有輸入任何資料:^$ |
| 29 | 任意一個字元 .,如找good,gxxd,... :g..d |
| 30 | 重複字元 * ,如找o,oo,oo...o:oo* |
| 31 | 找出 g 開頭與 g 結尾的字串:g.*g |
| 32 | 找出 g 後面接 2 到 5 個 o ,然後再接一個 g 的字串:go{2,5}g |
| 33 | }}} |
| 34 | |
| 35 | --------- |
| 36 | |
| 37 | == Snort Log 範例 == |
| 38 | {{{ |
| 39 | [**] [1:2189:3] BAD-TRAFFIC IP Proto 103 PIM [**] [[br]] |
| 40 | [Classification: Detection of a non-standard protocol or event] [Priority: 2] [[br]] |
| 41 | 07/08-14:58:56.295033 140.110.138.253 -> 224.0.0.13 [[br]] |
| 42 | PIM TTL:1 TOS:0xC0 ID:11423 IpLen:20 DgmLen:54 [[br]] |
| 43 | [Xref => http://cve.mitre.org/cgi-bin/cvename.cgi?name=2003-0567][Xref => http://www.securityfocus.com/bid/8211] [[br]] |
| 44 | }}} |
| 45 | * 開發工具 : [http://www.waterproof.fr/products/RegExpEditor/ Regular Expression Editor] |
| 46 | ----------- |
| 47 | |
| 48 | === [**] [1:2189:3] BAD-TRAFFIC IP Proto 103 PIM [**] === |
| 49 | |
| 50 | * 正規表示式: |
| 51 | |
| 52 | {{{ |
| 53 | ^\[\**\] \[([1-9]*):([1-9]*):([1-9]*)\] ([^[]*) |
| 54 | }}} |
| 55 | |
| 56 | * 結果: |
| 57 | |
| 58 | || 1 || [**] [1:2189:3] BAD-TRAFFIC IP Proto 103 PIM || |
| 59 | || 2 || 1 || |
| 60 | || 3 || 2189 || |
| 61 | || 4 || 3 || |
| 62 | || 5 || BAD-TRAFFIC IP Proto 103 PIM || |
| 63 | |
| 64 | === [Classification: Detection of a non-standard protocol or event] [Priority: 2] === |
| 65 | |
| 66 | * 正規表示式: |
| 67 | |
| 68 | {{{ |
| 69 | ^\[Classification: ([^]]*)\] \[Priority: ([1-9]*)\] |
| 70 | }}} |
| 71 | |
| 72 | * 結果: |
| 73 | |
| 74 | || 1 || [Classification: Detection of a non-standard protocol or event] [Priority: 2] || |
| 75 | || 2 || Detection of a non-standard protocol or event || |
| 76 | || 3 || 2 || |
| 77 | |
| 78 | === 07/08-14:58:56.295033 140.110.138.253 -> 224.0.0.13 === |
| 79 | |
| 80 | * 正規表示式: |
| 81 | |
| 82 | {{{ |
| 83 | (^[0-9]*)\/([0-9]*)\-([0-9]*)\:([0-9]*)\:([0-9]*)\.[0-9]* ([^ ]*) -> ([^$]*) |
| 84 | }}} |
| 85 | |
| 86 | * 結果: |
| 87 | |
| 88 | || 1 || 07/08-14:58:56.295033 140.110.138.253 -> 224.0.0.13 || |
| 89 | || 2 || 07 || |
| 90 | || 3 || 08 || |
| 91 | || 4 || 14 || |
| 92 | || 5 || 57 || |
| 93 | || 6 || 56 || |
| 94 | || 7 || 140.110.138.253 || |
| 95 | || 8 || 224.0.0.13 || |
| 96 | |
| 97 | === PIM TTL:1 TOS:0xC0 ID:11423 IpLen:20 DgmLen:54 === |
| 98 | |
| 99 | * 正規表示式: |
| 100 | |
| 101 | {{{ |
| 102 | ([^ ]*) TTL:([^ ]*) TOS:([^ ]*) ID:([^ ]*) IpLen:([^ ]*) DgmLen:([^ ]*) |
| 103 | }}} |
| 104 | |
| 105 | * 結果: |
| 106 | |
| 107 | || 1 || PIM TTL:1 TOS:0xC0 ID:11423 IpLen:20 DgmLen:54 || |
| 108 | || 2 || PIM || |
| 109 | || 3 || 1 || |
| 110 | || 4 || 0xC0 || |
| 111 | || 5 || 11078 || |
| 112 | || 6 || 20 || |
| 113 | || 7 || 54 || |
| 114 | |
| 115 | |
| 116 | === [Xref => http://cve.mitre.org/cgi-bin/cvename.cgi?name=2003-0567][Xref => http://www.securityfocus.com/bid/8211] === |
| 117 | |
| 118 | * 正規表示式: |
| 119 | |
| 120 | {{{ |
| 121 | \[Xref => ([^]]*)\] |
| 122 | }}} |
| 123 | |
| 124 | * 注意:只能找出第一個 [Xref => 的連結 |
| 125 | |
| 126 | * 結果: |
| 127 | |
| 128 | || 1 || [Xref => http://cve.mitre.org/cgi-bin/cvename.cgi?name=2003-0567] || |
| 129 | || 2 || http://cve.mitre.org/cgi-bin/cvename.cgi?name=2003-0567 || |