撰写一组SNORT规则防御SQL注入(2)
";nocase; sid:10124; rev:1;)
12) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%63)|c|C|(\%43))((\%68)|h|H|(\%48))((\%72)|r|R|(\%52)) ((\%28)|\() /ix
";nocase; sid:10125; rev:1;)
13) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%6E)|n|N|(\%4E))((\%63)|c|C|(\%43))((\%68)|h|H|(\%48))((\%61)|a|A|(\%41)) ((\%72)|r|R|(\%52)) ((\%28)|\() /ix
";nocase; sid:10126; rev:1;)
14) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%73)|s|S|(\%53))((\%75)|u|U|(\%55))((\%62)|b|B|(\%42))((\%73)|s|S|(\%53)) ((\%74)|t|T|(\%54)) ((\%72)|r|R|(\%52)) ((\%69)|i|I|(\%49)) ((\%6E)|n|N|(\%4E)) ((\%67)|g|G|(\%47)) ((\%28)|\() /ix
";nocase; sid:10127; rev:1;)
15) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%61)|a|A|(\%41))((\%62)|b|B|(\%42))((\%63)|c|C|(\%43)) ((\%28)|\() /ix
";nocase; sid:10128; rev:1;)
16) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%61)|a|A|(\%41))((\%62)|b|B|(\%42))((\%73)|s|S|(\%53)) ((\%28)|\() /ix
";nocase; sid:10129; rev:1;)
3.5. 对常用利用函数的检测
部分数据库系统函数,常用于注入攻击的综合利用,具体利用原理前面都有叙述。这些常见的函数是 drop table, truncate, between and, net use, user>0, user<0, user_name(), db_name(), insert into <%|<?,
规则设计:
drop table: 攻击者利用该命令恶意毁坏数据库。
/(\%3D|=)+(\S|\s)+((\%64)|d|D|(\%44))((\%72)|r|R|(\%52))((\%6F)|o|O|(\%4F))((\%70)|p|P|(\%50))(\S+|\s+)((\%74)|t|T|(\%54))((\%61)|a|A|(\%61))((\%62)|b|B|(\%42))((\%6C)|l|L|(\%4C))((\%65)|e|E|(\%45)) /ix
:
/(\%3D|=)+(\S|\s)+((\%74)|t|T|(\%54))((\%72)|r|R|(\%52))((\%75)|u|U|(\%55))((\%6E)|c|C|(\%4E)) ((\%63)|c|C|(\%43))((\%61)|a|A|(\%61))((\%74)|t|T|(\%54))((\%66)|e|E|(\%45)) /ix
between and:
/(\%3D|=)+(\S|\s)+((\%62)|b|B|(\%42))((\%65)|e|E|(\%45))((\%74)|t|T|(\%54))((\%77)|w|W|(\%57))((\%65)|e|E|(\%65))((\%65)|e|E|(\%65))((\%6E)|n|N|(\%4E))(\S|\s)+((\%61)|a|A|(\%41))((\%6E)|n|N|(\%4E))((\%64)|d|D|(\%44))/ix
net use:
/(\%3D|=)+(\S|\s)+((\%6E)|n|N|(\%6e))((\%65)|e|E|(\%45))((\%74)|t|T|(\%54)) (\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))/ix
exec():
/(\%3D|=)+(\S|\s)+((\%65)|e|E|(\%45))((\%78)|x|X|(\%58))((\%65)|e|E|(\%45)) ((\%63)|c|C|(\%43)) ((\%28)|\() /ix
user>0|<0: 这是专用于对 SQLSERVER 取得数据库用户名的有效地攻击手段。
/(\%3D|=)+(\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45)) ((\%72)|r|R|(\%52)) ((\%3E)|>|<|(\%3C)) (0) /ix
user_name():
/(\%3D|=)+(\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))((\%72)|r|R|(\%52)) ((\%5F)| (_)) ((\%6E)|n|N|(\%4E)) ((\%61)|a|A|(\%41)) ((\%6D)|m|M|(\%4D)) ((\%65)|e|E|(\%45)) ((\%28)|\() /ix
db_name():
/(\%3D|=)+(\S|\s)+((\%64)|d|D|(\%44))((\%62)|b|B|(\%42)) ((\%5F)| (_)) ((\%6E)|n|N|(\%4E)) ((\%61)|a|A|(\%41)) ((\%6D)|m|M|(\%4D)) ((\%65)|e|E|(\%45)) ((\%28)|\() /ix
insert into + <%|<?:
/(\%3D|=)+(\S|\s)+((\%69)|i|I|(\%49))((\%6E)|n|N|(\%4E))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))((\%72)|r|R|(\%52))((\%74)|t|T|(\%54))(\S|\s)+((\%69)|i|I|(\%49))((\%6E)|n|N|(\%4E))((\%74)|t|T|(\%54))((\%6F)|o|O|(\%4F))(\S|\s)+((\%3c)|<)+((\%25)|(%)|(\?)|(\%3f))+/ix
修正后完整的规则如下:
17 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%64)|d|D|(\%44))((\%72)|r|R|(\%52))((\%6F)|o|O|(\%4F))((\%70)|p|P|(\%50))(\S+|\s+)((\%74)|t|T|(\%54))((\%61)|a|A|(\%61))((\%62)|b|B|(\%42))((\%6C)|l|L|(\%4C))((\%65)|e|E|(\%45)) /ix
";nocase; sid:10130; rev:1;)
18) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%74)|t|T|(\%54))((\%72)|r|R|(\%52))((\%75)|u|U|(\%55))((\%6E)|c|C|(\%4E)) ((\%63)|c|C|(\%43))((\%61)|a|A|(\%61))((\%74)|t|T|(\%54))((\%66)|e|E|(\%45)) /ix ";nocase; sid:10131; rev:1;)
19) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%62)|b|B|(\%42))((\%65)|e|E|(\%45))((\%74)|t|T|(\%54))((\%77)|w|W|(\%57))((\%65)|e|E|(\%65))((\%65)|e|E|(\%65))((\%6E)|n|N|(\%4E))(\S|\s)+((\%61)|a|A|(\%41))((\%6E)|n|N|(\%4E))((\%64)|d|D|(\%44))/ix ";nocase; sid:10132; rev:1;)
20 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%6E)|n|N|(\%6e))((\%65)|e|E|(\%45))((\%74)|t|T|(\%54)) (\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))/ix ";nocase; sid:10133; rev:1;)
21 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%65)|e|E|(\%45))((\%78)|x|X|(\%58))((\%65)|e|E|(\%45)) ((\%63)|c|C|(\%43)) ((\%28)|\() /ix
";nocase; sid:10134; rev:1;)
22 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45)) ((\%72)|r|R|(\%52)) ((\%3E)|>|<|(\%3C)) (0) /ix
";nocase; sid:10135; rev:1;)
23 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%75)|u|U|(\%55))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))((\%72)|r|R|(\%52)) ((\%5F)| (_)) ((\%6E)|n|N|(\%4E)) ((\%61)|a|A|(\%41)) ((\%6D)|m|M|(\%4D)) ((\%65)|e|E|(\%45)) ((\%28)|\() /ix
";nocase; sid:10136; rev:1;)
24 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%64)|d|D|(\%44))((\%62)|b|B|(\%42)) ((\%5F)| (_)) ((\%6E)|n|N|(\%4E)) ((\%61)|a|A|(\%41)) ((\%6D)|m|M|(\%4D)) ((\%65)|e|E|(\%45)) ((\%28)|\() /ix
";nocase; sid:10137; rev:1;)
25 ) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /(\%3D|=)+(\S|\s)+((\%69)|i|I|(\%49))((\%6E)|n|N|(\%4E))((\%73)|s|S|(\%53))((\%65)|e|E|(\%45))((\%72)|r|R|(\%52))((\%74)|t|T|(\%54))(\S|\s)+((\%69)|i|I|(\%49))((\%6E)|n|N|(\%4E))((\%74)|t|T|(\%54))((\%6F)|o|O|(\%4F))(\S|\s)+((\%3c)|<)+((\%25)|(%)|(\?)|(\%3f))+/ix
";nocase; sid:10138; rev:1;)
3.6. 检测危险字符 ‘ “ ; : ―― # ( 删除此条 sid:10170 )
主要危害:
这些字符用于 SQL 注入攻击中的攻击串的构造,如:造成 SQL 语句闭合、添加恶意语句等等。例如在登陆权限绕过注入攻击中,相关验证代码通常为为: $exec="select * from user where usr=’".$_POST[’usr’]."’ and psw=’".$_POST[’psw’]."’"; 攻击者通常使用‘号或者“号来闭合 SQL 语句,如提交类似请求: usr = ’admin’ , psw=’ 1’ or 1=1 order by id#’ 后,程序内部执行语句变为: select * from user where usr=’admin’ and psw=’1’ or 1=1 order by id#’ ,#号为 mysql 忽略后续语句的标记, 成功造成内部 SQL 语句的闭合,绕过登陆成功。对于不同的攻击情况,这些字符用于不同的数据库、脚本闭合、攻击串构造,属于通用的普遍的但是攻击又不可缺少特征。
检测要点:
1) 过滤上述的危险字符 ‘ “ # ―― ;
2) 由于该内容是使用表单提交或者 URL 提交,考察 HTTP 协议,故关联 TCP 流中的关键字 ? 和 = ;
规则设计:
正则表达式为: /((’)|(%27))|((")|(%22))|((\#)|(%23))|((--)|(%2d%2d))/ix ,即:检测‘号或者等值的 16 进制编码 | 检测 ” 号或者等值的 16 进制编码 | 检测 # 号或者等值的 16 进制编码 | 检测 -- 号或者等值的 16 进制编码
由于“号在实际脚本程序中,无法单独引起 SQL 语句的闭合,故规则中忽略该项;在 URL 中参数提交一般为 xxx.asp?a=xxx ,为了提高效率和准确率,故而在规则中增加检测?和=;另外在实际应用中发现,合法的 HTTP 协议流中也可能含有;号,为了避免误报,增加检测条件,即在 URL 中,=号后再来检测分号,即:
26) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; uricontent:”?”;pcre:" /((’)|(%27))|((")|(%22))|((\#)|(%23))|((--)|(%2d%2d))/ix ";nocase; sid:10139; rev:1;)
3.7. 过滤危险字符 1=1 1’=’1 1=2 1’=’2 1<>1 a=a a’=’a a<>a a’<>’a
这些明显冗余或歧意的字符用于 SQL 注入攻击中的攻击串的构造,主要和 or/and/union 联合使用来造成恶意 SQL 语句等。在网页脚本中,这种字符串一般用于平稳避过正常 SQL 语句,从而使得恶意构造的 SQL 语句得以执行,此类敏感字符串在常用 SQL 注入攻击工具中也是常见手段,属于通用的普遍的攻击特征。
检测要点:
1) 过滤上述的危险字符;
2) 由于该内容是使用表单提交或者 URL 提交,考察 HTTP 协议,故关联 TCP 流中的关键字 ? 和 = ;
3) 降低误报和漏报,优化检测效率。 1 = 1 , 1 = 2 ,类似的也可一构造 1 = 3 , 1<>4 等其他串。但是前者具有普遍性,在攻击手法和实际工具中最这类写法最常见,这里综合考虑,考虑到普遍性,对这类问题检测 1 = 1 , 1<>1 , 1 = 2 , 1<>2,a=a, a<>a 。
规则设计:
正则表达式为: /([=]+)(1=1)|(1’=’1)|(1=2)|(1<>1)|(a<>a)/ix
由于在实际脚本程序中,有需要‘号引起 SQL 语句的闭合的情况,故规则中增加检测‘号和数字字母的组合。修正后的表达式为: /([=]+)(1=1)|(1’=’1)|(1=2)|(1<>1)|(a<>a) |(a=a) (1’=’2)|(1’<>’1)|(a’<>’a) |(a’<>’a) /ix
在 URL 中参数提交一般为 xxx.asp?a=xxx ,为了提高效率和准确率,故而在规则中增加检测?和=,即:
27) alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:" 检测到 SQL 注入攻击特征字符 "; flow:to_server,established;uricontent:"?"; pcre:" /([=]+)(1=1)|(1’=’1)|(1=2)|(1<>1)|(a<>a) |(a=a) (1’=’2)|(1’<>’1)|(a’<>’a) |(a’<>’a) /ix ";nocase; sid:10140; rev:1;)
顶(1)
踩(0)
下一篇:ftp服务器暴力入侵防护
- 最新评论