Snort mailing list archives
Matching PCRE
From: Paul Schmehl <pschmehl_lists () tx rr com>
Date: Tue, 19 Jan 2010 14:23:58 -0600
I wrote a rule to try and catch sql injection attempts. It's been through quite a few iterations. This is the current rule: alert tcp any any -> $HOME_NET $PORT_HTTP (msg: "SQL Injection Attempt - something = same thing"; content: "GET"; http_method; uricontent:"?"; uricontent:"="; pcre:"/(\w+).?=.?\1[\s\n\r\)]+/U"; classtype:web-application-attack; sid:3000006; rev:15;) This rule is catching sql injection attempts pretty well. For example: 000 : 47 45 54 20 2F 7E 72 63 62 30 31 32 32 30 30 2F GET /~rcb012200/ 010 : 63 67 69 2D 62 69 6E 2F 63 6F 64 65 76 69 65 77 cgi-bin/codeview 020 : 2E 70 6C 3F 66 69 6C 65 6E 61 6D 65 3D 73 63 69 .pl?filename=sci 030 : 74 65 75 73 65 72 2E 70 72 6F 70 65 72 74 69 65 teuser.propertie 040 : 73 27 25 32 30 41 6E 64 25 32 30 63 68 61 72 28 s'%20And%20char( 050 : 31 32 34 29 25 32 62 28 53 65 6C 65 63 74 25 32 124)%2b(Select%2 060 : 30 43 61 73 74 28 43 6F 75 6E 74 28 31 29 25 32 0Cast(Count(1)%2 070 : 30 61 73 25 32 30 76 61 72 63 68 61 72 28 38 30 0as%20varchar(80 080 : 30 30 29 29 25 32 42 63 68 61 72 28 31 32 34 29 00))%2Bchar(124) 090 : 25 32 30 46 72 6F 6D 25 32 30 5B 73 79 73 6F 62 %20From%20[sysob 0a0 : 6A 65 63 74 73 5D 25 32 30 57 68 65 72 65 25 32 jects]%20Where%2 0b0 : 30 31 3D 31 29 3E 30 25 32 30 61 6E 64 25 32 30 01=1)>0%20and%20 0c0 : 27 27 3D 27 20 48 54 54 50 2F 31 2E 31 0D 0A 55 ''=' HTTP/1.1..U 0d0 : 73 65 72 2D 41 67 65 6E 74 3A 20 63 7A 33 32 74 ser-Agent: cz32t 0e0 : 73 0D 0A 48 6F 73 74 3A 20 77 77 77 2E 75 74 64 s..Host: www.utd 0f0 : 61 6C 6C 61 73 2E 65 64 75 0D 0A 43 6F 6F 6B 69 allas.edu..Cooki 100 : 65 3A 20 58 2D 4D 61 70 70 69 6E 67 2D 6B 6A 69 e: X-Mapping-kji 110 : 63 67 68 6B 63 3D 36 31 41 36 37 39 35 36 45 37 cghkc=61A67956E7 120 : 36 34 31 35 41 42 37 44 42 34 35 44 32 42 30 46 6415AB7DB45D2B0F 130 : 33 44 42 32 39 33 0D 0A 0D 0A 3DB293.... I'm using this site to check against for matches: http://www.regextester.com/index2.html - which is pretty handy, because I can see exactly what matched in a packet and tweak the rule to avoid matching on stuff that really isn't sql injection. As with anything like this, it's impossible to avoid *some* matches (some would call them false positives but I know Marty would disagree), so I am also catching packets like this: 000 : 47 45 54 20 2F 73 74 61 74 3F 6C 69 6E 6B 5F 69 GET /stat?link_i 010 : 64 3D 45 6E 74 72 65 7A 53 79 73 74 65 6D 32 2E d=EntrezSystem2. 020 : 50 45 6E 74 72 65 7A 2E 50 75 62 6D 65 64 2E 50 PEntrez.Pubmed.P 030 : 75 62 6D 65 64 5F 52 65 73 75 6C 74 73 50 61 6E ubmed_ResultsPan 040 : 65 6C 2E 45 6E 74 72 65 7A 5F 50 61 67 65 72 2E el.Entrez_Pager. 050 : 50 61 67 65 26 6C 69 6E 6B 5F 6E 61 6D 65 3D 45 Page&link_name=E 060 : 6E 74 72 65 7A 53 79 73 74 65 6D 32 2E 50 45 6E ntrezSystem2.PEn 070 : 74 72 65 7A 2E 50 75 62 6D 65 64 2E 50 75 62 6D trez.Pubmed.Pubm 080 : 65 64 5F 52 65 73 75 6C 74 73 50 61 6E 65 6C 2E ed_ResultsPanel. 090 : 45 6E 74 72 65 7A 5F 50 61 67 65 72 2E 50 61 67 Entrez_Pager.Pag 0a0 : 65 26 6C 69 6E 6B 5F 73 69 64 3D 38 26 6C 69 6E e&link_sid=8&lin 0b0 : 6B 5F 68 72 65 66 3D 68 74 74 70 25 33 41 25 32 k_href=http%3A%2 0c0 : 46 25 32 46 77 77 77 2E 6E 63 62 69 2E 6E 6C 6D F%2Fwww.ncbi.nlm 0d0 : 2E 6E 69 68 2E 67 6F 76 2E 6C 69 62 70 72 6F 78 .nih.gov.libprox 0e0 : 79 2E 75 74 64 61 6C 6C 61 73 2E 65 64 75 25 32 y.utdallas.edu%2 0f0 : 46 73 69 74 65 73 25 32 46 65 6E 74 72 65 7A 25 Fsites%2Fentrez% 100 : 32 33 26 6C 69 6E 6B 5F 74 65 78 74 3D 4E 65 78 23&link_text=Nex 110 : 74 25 32 30 25 33 45 26 6C 69 6E 6B 5F 63 6C 61 t%20%3E&link_cla 120 : 73 73 3D 61 63 74 69 76 65 25 32 43 70 61 67 65 ss=active%2Cpage 130 : 5F 6C 69 6E 6B 25 32 43 6E 65 78 74 26 6C 69 6E _link%2Cnext&lin 140 : 6B 5F 63 6F 6F 72 5F 78 3D 35 35 33 26 6C 69 6E k_coor_x=553&lin 150 : 6B 5F 63 6F 6F 72 5F 79 3D 32 34 32 37 26 6C 69 k_coor_y=2427&li 160 : 6E 6B 5F 73 63 72 6F 6C 6C 5F 78 3D 30 26 6C 69 nk_scroll_x=0&li 170 : 6E 6B 5F 73 63 72 6F 6C 6C 5F 79 3D 32 30 33 30 nk_scroll_y=2030 180 : 26 6A 73 65 76 65 6E 74 3D 63 6C 69 63 6B 26 6E &jsevent=click&n 190 : 63 62 69 5F 70 69 6E 67 61 63 74 69 6F 6E 3D 74 cbi_pingaction=t 1a0 : 69 6D 65 72 26 6E 63 62 69 5F 70 68 69 64 3D 33 imer&ncbi_phid=3 1b0 : 39 36 42 30 42 30 33 42 35 36 30 38 34 30 31 30 96B0B03B56084010 1c0 : 30 30 30 30 30 30 30 30 30 41 30 41 30 42 39 26 000000000A0A0B9& 1d0 : 6E 63 62 69 5F 74 69 6D 65 73 69 6E 63 65 6C 6F ncbi_timesincelo 1e0 : 61 64 3D 38 30 35 36 34 20 48 54 54 50 2F 31 2E ad=80564 HTTP/1. 1f0 : 31 0D 0A 41 63 63 65 70 74 3A 20 2A 2F 2A 0D 0A 1..Accept: */*.. 200 : 52 65 66 65 72 65 72 3A 20 68 74 74 70 3A 2F 2F Referer: http:// 210 : 77 77 77 2E 6E 63 62 69 2E 6E 6C 6D 2E 6E 69 68 www.ncbi.nlm.nih 220 : 2E 67 6F 76 2E 6C 69 62 70 72 6F 78 79 2E 75 74 .gov.libproxy.ut 230 : 64 61 6C 6C 61 73 2E 65 64 75 2F 73 69 74 65 73 dallas.edu/sites 240 : 2F 65 6E 74 72 65 7A 0D 0A 41 63 63 65 70 74 2D /entrez..Accept- 250 : 4C 61 6E 67 75 61 67 65 3A 20 65 6E 2D 75 73 0D Language: en-us. 260 : 0A 41 63 63 65 70 74 2D 45 6E 63 6F 64 69 6E 67 .Accept-Encoding 270 : 3A 20 67 7A 69 70 2C 20 64 65 66 6C 61 74 65 0D : gzip, deflate. 280 : 0A 55 73 65 72 2D 41 67 65 6E 74 3A 20 4D 6F 7A .User-Agent: Moz 290 : 69 6C 6C 61 2F 34 2E 30 20 28 63 6F 6D 70 61 74 illa/4.0 (compat 2a0 : 69 62 6C 65 3B 20 4D 53 49 45 20 36 2E 30 3B 20 ible; MSIE 6.0; 2b0 : 57 69 6E 64 6F 77 73 20 4E 54 20 35 2E 31 3B 20 Windows NT 5.1; 2c0 : 53 56 31 3B 20 2E 4E 45 54 20 43 4C 52 20 31 2E SV1; .NET CLR 1. 2d0 : 31 2E 34 33 32 32 3B 20 2E 4E 45 54 20 43 4C 52 1.4322; .NET CLR 2e0 : 20 32 2E 30 2E 35 30 37 32 37 29 0D 0A 48 6F 73 2.0.50727)..Hos 2f0 : 74 3A 20 77 77 77 2E 6E 63 62 69 2E 6E 6C 6D 2E t: www.ncbi.nlm. 300 : 6E 69 68 2E 67 6F 76 2E 6C 69 62 70 72 6F 78 79 nih.gov.libproxy 310 : 2E 75 74 64 61 6C 6C 61 73 2E 65 64 75 0D 0A 43 .utdallas.edu..C 320 : 6F 6F 6B 69 65 3A 20 4A 53 45 53 53 49 4F 4E 49 ookie: JSESSIONI 330 : 44 56 49 53 54 41 3D 50 68 57 54 4C 56 38 51 70 DVISTA=PhWTLV8Qp 340 : 78 6C 51 73 37 4A 30 52 72 39 6C 57 79 4C 51 68 xlQs7J0Rr9lWyLQh 350 : 37 70 6D 78 66 56 34 64 79 68 4C 4E 77 6E 34 70 7pmxfV4dyhLNwn4p 360 : 51 5A 44 48 73 4C 67 47 4B 47 54 21 2D 31 38 31 QZDHsLgGKGT!-181 370 : 35 37 33 37 37 36 39 21 70 6C 6D 73 31 62 2E 75 5737769!plms1b.u 380 : 74 64 61 6C 6C 61 73 2E 65 64 75 21 38 30 21 2D tdallas.edu!80!- 390 : 31 21 2D 31 38 35 32 32 36 36 37 38 36 21 70 6C 1!-1852266786!pl 3a0 : 6D 73 31 63 2E 75 74 64 61 6C 6C 61 73 2E 65 64 ms1c.utdallas.ed 3b0 : 75 21 38 30 21 2D 31 3B 20 4B 2D 4A 53 45 53 53 u!80!-1; K-JSESS 3c0 : 49 4F 4E 49 44 56 49 53 54 41 2D 6E 6F 6A 65 6E IONIDVISTA-nojen 3d0 : 65 6C 69 3D 30 32 35 37 41 44 46 45 43 33 41 32 eli=0257ADFEC3A2 3e0 : 43 44 37 37 44 32 45 34 37 42 38 43 38 46 35 39 CD77D2E47B8C8F59 3f0 : 38 36 30 30 3B 20 76 69 73 74 61 5F 61 75 74 68 8600; vista_auth 400 : 5F 74 79 70 65 5F 63 6F 6F 6B 69 65 3D 6E 6F 6E _type_cookie=non 410 : 53 53 4F 4C 6F 67 69 6E 3B 20 65 7A 70 72 6F 78 SSOLogin; ezprox 420 : 79 3D 46 34 44 65 6F 4D 57 62 42 71 72 48 71 38 y=F4DeoMWbBqrHq8 430 : 57 3B 20 73 5F 73 65 73 73 3D 25 32 30 73 5F 63 W; s_sess=%20s_c 440 : 63 25 33 44 74 72 75 65 25 33 42 25 32 30 73 5F c%3Dtrue%3B%20s_ 450 : 73 71 25 33 44 6E 69 68 6E 63 62 69 70 72 6F 64 sq%3Dnihncbiprod 460 : 25 32 35 33 44 25 32 35 32 35 32 36 70 69 64 25 %253D%252526pid% 470 : 32 35 32 35 33 44 65 6E 74 72 65 7A 25 32 35 32 25253Dentrez%252 480 : 35 32 35 33 41 70 75 62 6D 65 64 25 32 35 32 35 5253Apubmed%2525 490 : 32 35 33 41 61 64 76 61 6E 63 65 64 25 32 35 32 253Aadvanced%252 4a0 : 35 32 36 70 69 64 74 25 32 35 32 35 33 44 31 25 526pidt%25253D1% 4b0 : 32 35 32 35 32 36 6F 69 64 25 32 35 32 35 33 44 252526oid%25253D 4c0 : 66 75 6E 63 74 69 6F 6E 68 61 6E 64 6C 65 45 76 functionhandleEv 4d0 : 65 6E 74 25 32 35 32 35 32 35 32 38 65 25 32 35 ent%25252528e%25 4e0 : 32 35 32 35 32 39 25 32 35 32 35 32 35 37 42 76 252529%2525257Bv 4f0 : 61 72 72 65 74 75 72 6E 56 61 6C 75 65 25 32 35 arreturnValue%25 500 : 32 35 32 35 33 44 74 72 75 65 25 32 35 32 35 32 25253Dtrue%25252 510 : 35 33 42 65 25 32 35 32 35 32 35 33 44 65 25 32 53Be%2525253De%2 520 : 35 32 35 32 35 37 43 25 32 35 32 35 32 35 37 43 525257C%2525257C 530 : 66 69 78 45 76 65 6E 74 25 32 35 32 35 32 35 32 fixEvent%2525252 540 : 38 77 69 6E 8win which is fine, because it matches the pcre and I can easily see that it's a "false positive". However, *this* "match" has me stumped. There does not appear to be a match, yet it's triggering this alert. Is it possible that the pcre engine in snort has some kind of flaw in it? Or does the flaw exist in the regex tester website? I don't see a match, but then it's very easy to get bogged down in packets like this a miss something. 000 : 47 45 54 20 2F 64 63 73 31 6F 65 71 73 38 38 67 GET /dcs1oeqs88g 010 : 30 6F 61 77 6B 65 39 6F 75 67 6E 62 34 6E 5F 31 0oawke9ougnb4n_1 020 : 72 38 71 2F 64 63 73 2E 67 69 66 3F 26 64 63 73 r8q/dcs.gif?&dcs 030 : 64 61 74 3D 31 32 36 33 39 33 31 31 32 35 38 31 dat=126393112581 040 : 32 26 64 63 73 73 69 70 3D 77 77 77 2E 75 74 64 2&dcssip=www.utd 050 : 61 6C 6C 61 73 2E 65 64 75 26 64 63 73 75 72 69 allas.edu&dcsuri 060 : 3D 2F 61 68 2F 61 74 65 63 2F 26 64 63 73 72 65 =/ah/atec/&dcsre 070 : 66 3D 68 74 74 70 3A 2F 2F 73 65 61 72 63 68 2E f=http://search. 080 : 79 61 68 6F 6F 2E 63 6F 6D 2F 73 65 61 72 63 68 yahoo.com/search 090 : 3B 5F 79 6C 74 3D 41 30 67 65 75 38 46 36 44 56 ;_ylt=A0geu8F6DV 0a0 : 5A 4C 5A 4F 49 41 78 59 52 58 4E 79 6F 41 25 33 ZLZOIAxYRXNyoA%3 0b0 : 46 66 72 32 3D 73 67 2D 67 61 63 25 32 36 73 61 Ffr2=sg-gac%26sa 0c0 : 64 6F 3D 31 25 32 36 70 3D 75 74 25 32 30 64 61 do=1%26p=ut%20da 0d0 : 6C 6C 61 73 25 32 30 61 72 74 73 25 32 30 61 6E llas%20arts%20an 0e0 : 64 25 32 30 74 65 63 68 6E 6F 6C 6F 67 79 25 32 d%20technology%2 0f0 : 36 66 72 3D 79 66 70 2D 74 2D 38 38 37 25 32 36 6fr=yfp-t-887%26 100 : 70 71 73 74 72 3D 75 74 25 32 30 64 61 6C 6C 61 pqstr=ut%20dalla 110 : 73 25 32 30 61 72 74 73 25 32 30 41 25 32 36 67 s%20arts%20A%26g 120 : 70 72 69 64 3D 30 65 2E 72 6F 77 65 69 51 61 43 prid=0e.roweiQaC 130 : 68 79 34 5F 74 42 5F 42 58 63 41 25 32 36 73 61 hy4_tB_BXcA%26sa 140 : 63 3D 31 25 32 36 73 61 6F 3D 31 26 57 54 2E 63 c=1%26sao=1&WT.c 150 : 6F 5F 66 3D 37 36 2E 31 38 33 2E 31 37 33 2E 31 o_f=76.183.173.1 160 : 35 37 2D 32 32 38 31 32 32 38 33 30 34 2E 33 30 57-2281228304.30 170 : 30 35 33 39 30 31 26 57 54 2E 76 74 5F 73 69 64 053901&WT.vt_sid 180 : 3D 37 36 2E 31 38 33 2E 31 37 33 2E 31 35 37 2D =76.183.173.157- 190 : 32 32 38 31 32 32 38 33 30 34 2E 33 30 30 35 33 2281228304.30053 1a0 : 39 30 31 2E 31 32 36 33 39 33 31 30 33 38 31 32 901.126393103812 1b0 : 35 26 57 54 2E 74 7A 3D 2D 36 26 57 54 2E 62 68 5&WT.tz=-6&WT.bh 1c0 : 3D 31 33 26 57 54 2E 75 6C 3D 65 6E 2D 75 73 26 =13&WT.ul=en-us& 1d0 : 57 54 2E 63 64 3D 33 32 26 57 54 2E 73 72 3D 31 WT.cd=32&WT.sr=1 1e0 : 30 32 34 78 37 36 38 26 57 54 2E 6A 6F 3D 59 65 024x768&WT.jo=Ye 1f0 : 73 26 57 54 2E 74 69 3D 55 6E 69 76 65 72 73 69 s&WT.ti=Universi 200 : 74 79 25 32 30 6F 66 25 32 30 54 65 78 61 73 25 ty%20of%20Texas% 210 : 32 30 61 74 25 32 30 44 61 6C 6C 61 73 25 32 30 20at%20Dallas%20 220 : 41 72 74 25 32 30 25 32 36 25 32 30 54 65 63 68 Art%20%26%20Tech 230 : 6E 6F 6C 6F 67 79 26 57 54 2E 6A 73 3D 59 65 73 nology&WT.js=Yes 240 : 26 57 54 2E 6A 76 3D 31 2E 33 26 57 54 2E 63 74 &WT.jv=1.3&WT.ct 250 : 3D 6C 61 6E 26 57 54 2E 68 70 3D 30 26 57 54 2E =lan&WT.hp=0&WT. 260 : 62 73 3D 31 30 30 33 78 38 35 37 26 57 54 2E 66 bs=1003x857&WT.f 270 : 69 3D 59 65 73 26 57 54 2E 66 76 3D 31 30 2E 30 i=Yes&WT.fv=10.0 280 : 26 57 54 2E 74 76 3D 38 2E 30 2E 33 26 57 54 2E &WT.tv=8.0.3&WT. 290 : 73 70 3D 40 40 53 50 4C 49 54 56 41 4C 55 45 40 sp=@@SPLITVALUE@ 2a0 : 40 26 57 54 2E 63 67 5F 6E 3D 41 48 26 57 54 2E @&WT.cg_n=AH&WT. 2b0 : 63 67 5F 73 3D 41 54 45 43 26 57 54 2E 76 74 5F cg_s=ATEC&WT.vt_ 2c0 : 66 5F 74 6C 68 3D 31 32 36 33 39 33 31 31 30 36 f_tlh=1263931106 2d0 : 20 48 54 54 50 2F 31 2E 31 0D 0A 41 63 63 65 70 HTTP/1.1..Accep 2e0 : 74 3A 20 2A 2F 2A 0D 0A 41 63 63 65 70 74 2D 4C t: */*..Accept-L 2f0 : 61 6E 67 75 61 67 65 3A 20 65 6E 2D 75 73 0D 0A anguage: en-us.. 300 : 55 41 2D 43 50 55 3A 20 78 38 36 0D 0A 55 73 65 UA-CPU: x86..Use 310 : 72 2D 41 67 65 6E 74 3A 20 4D 6F 7A 69 6C 6C 61 r-Agent: Mozilla 320 : 2F 34 2E 30 20 28 63 6F 6D 70 61 74 69 62 6C 65 /4.0 (compatible 330 : 3B 20 4D 53 49 45 20 37 2E 30 3B 20 57 69 6E 64 ; MSIE 7.0; Wind 340 : 6F 77 73 20 4E 54 20 35 2E 31 3B 20 59 50 43 20 ows NT 5.1; YPC 350 : 33 2E 32 2E 30 3B 20 46 75 6E 57 65 62 50 72 6F 3.2.0; FunWebPro 360 : 64 75 63 74 73 3B 20 2E 4E 45 54 20 43 4C 52 20 ducts; .NET CLR 370 : 31 2E 31 2E 34 33 32 32 3B 20 2E 4E 45 54 20 43 1.1.4322; .NET C 380 : 4C 52 20 32 2E 30 2E 35 30 37 32 37 3B 20 4F 66 LR 2.0.50727; Of 390 : 66 69 63 65 4C 69 76 65 43 6F 6E 6E 65 63 74 6F ficeLiveConnecto 3a0 : 72 2E 31 2E 33 3B 20 4F 66 66 69 63 65 4C 69 76 r.1.3; OfficeLiv 3b0 : 65 50 61 74 63 68 2E 30 2E 30 29 0D 0A 48 6F 73 ePatch.0.0)..Hos 3c0 : 74 3A 20 75 74 64 77 73 61 70 70 34 2E 75 74 64 t: utdwsapp4.utd 3d0 : 61 6C 6C 61 73 2E 65 64 75 0D 0A 43 6F 6E 6E 65 allas.edu..Conne 3e0 : 63 74 69 6F 6E 3A 20 4B 65 65 70 2D 41 6C 69 76 ction: Keep-Aliv 3f0 : 65 0D 0A 0D 0A e.... -- Paul Schmehl, Senior Infosec Analyst As if it wasn't already obvious, my opinions are my own and not those of my employer. ******************************************* "It is as useless to argue with those who have renounced the use of reason as to administer medication to the dead." Thomas Jefferson ------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Snort-sigs mailing list Snort-sigs () lists sourceforge net https://lists.sourceforge.net/lists/listinfo/snort-sigs
Current thread:
- Matching PCRE Paul Schmehl (Jan 19)
- Re: Matching PCRE Guise McAllaster (Jan 19)
- Re: Matching PCRE Guise McAllaster (Jan 19)
- Re: Matching PCRE Matt Olney (Jan 19)
- Re: Matching PCRE Paul Schmehl (Jan 19)
- Re: Matching PCRE Paul Schmehl (Jan 19)
- Re: Matching PCRE Joel Esler (Jan 19)
- Re: Matching PCRE Matt Olney (Jan 19)
- Re: Matching PCRE Paul Schmehl (Jan 19)
- Re: Matching PCRE Guise McAllaster (Jan 19)
- Re: Matching PCRE Guise McAllaster (Jan 19)