ModSecurity 规则分析(四)

分析目标:

owasp-modsecurity-crs-3.3-dev的正则规则。

规则类型:

正则表达式

用途:

识别select、having、union等多个sql注入关键字,识别information_schem等数据库名,识别xp_cmdshell、exec等执行语句。

原规则:

"@rx (?i:(?:["'`](?:;?s*?(?:having|select|union)bs*?[^s]|s*?!s*?["'`w])|(?:c(?:onnection_id|urrent_user)|database)s*?([^)]*?|u(?:nion(?:[w(s]*?select| select @)|sers*?([^)]*?)|s(?:chemas*?([^)]*?|elect.*?w?user()|into[s+]+(?:dump|out)files*?["'`]|s*?exec(?:ute)?.*?Wxp_cmdshell|fromW+information_schemaW|exec(?:ute)?s+master.|wiifs*?())"

规则内容:

ModSecurity 规则分析(四)

分析结果:

ModSecurity 规则分析(四)

测试例程:

//原始规则
"@rx (?i:(?:["'`](?:;?s*?(?:having|select|union)bs*?[^s]|s*?!s*?["'`w])|(?:c(?:onnection_id|urrent_user)|database)s*?([^)]*?|u(?:nion(?:[w(s]*?select| select @)|sers*?([^)]*?)|s(?:chemas*?([^)]*?|elect.*?w?user()|into[s+]+(?:dump|out)files*?["'`]|s*?exec(?:ute)?.*?Wxp_cmdshell|fromW+information_schemaW|exec(?:ute)?s+master.|wiifs*?())"

//规则详解
//该表达式,是以下多个表达式的集成:

/*
( : 反斜杠转义字符,为了使用(
s :空白字符
s+ :空格出现一次或多次
d : 数字
s*? :空格出现或不出现,非贪婪模式
( : 转义,匹配(
| : 或
w+ : 可以构成单词的字符出现一次或多次
*/

/*
//"或’或` 有无空格 不接有无空格 "或’或`或可以构成单词的字符
["'`]s*?!s*?["'`w]
//"或’或` 有无; 有无空格 having 单词的边界 有无空格 除了空格的字符
["'`];?s*?havingbs*?[^s]
//"或’或` 有无; 有无空格 select 单词的边界 有无空格 除了空格的字符
["'`];?s*?selectbs*?[^s]
//"或’或` 有无; 有无空格 union 单词的边界 有无空格 除了空格的字符
["'`];?s*?unionbs*?[^s]
//有无空格 exec. 有无任意字符 不能构成单词的字符 cmdshell
s*?exec.*?Wxp_cmdshell
//有无空格 execute. 有无任意字符 不能构成单词的字符 cmdshell
s*?execute.*?Wxp_cmdshell
//可以构成单词的字符 有无空格 (
//【注意】:这里似乎有错,应该是wif
wiifs*?(
//connection_id 有无空格 ( 除了)之外的字符出现或不出现
connection_ids*?([^)]*?
//与上类似
current_users*?([^)]*?
//与上类似
databases*?([^)]*?

execs+master.
executes+master.
fromW+information_schemaW

//info 一个或多个空格 dumpfile 有或无空格 “或‘或`
into[s+]+dumpfiles*?["'`]
//与上类似
into[s+]+outfiles*?["'`]
//schema 有无空格 ( 一个除了)之外的字符出现或不出现
schemas*?([^)]*?

select.*?w?user(
union select @
union[w(s]*?select
users*?([^)]*?

 */

//测试程序
var regexp = /(?:["'`](?:;?s*?(?:having|select|union)bs*?[^s]|s*?!s*?["'`w])|(?:c(?:onnection_id|urrent_user)|database)s*?([^)]*?|u(?:nion(?:[w(s]*?select| select @)|sers*?([^)]*?)|s(?:chemas*?([^)]*?|elect.*?w?user()|into[s+]+(?:dump|out)files*?["'`]|s*?exec(?:ute)?.*?Wxp_cmdshell|fromW+information_schemaW|exec(?:ute)?s+master.|wiifs*?()/;

var test_result
test_result = regexp.test("union select @");
console.log(test_result);

test_result = regexp.test("into outfile '");
console.log(test_result);

test_result = regexp.test("into outfile abc'");
console.log(test_result);

test_result = regexp.test("abc;execute master.123");
console.log(test_result);

test_result = regexp.test("abc;select a b c user(");
console.log(test_result);

test_result = regexp.test("select a b c user(");
console.log(test_result);

例程执行:

ModSecurity 规则分析(四)

其它:

如果需要对规则、代码进行加密,可使用JShaman这个专业的JS代码加密平台:

这样,即使公开、发布,规则、代码逻辑等,都不会泄露。

ModSecurity 规则分析(四)

展开阅读全文

页面更新:2024-03-11

标签:规则   斜杠   正则   表达式   空格   边界   语句   贪婪   有无   单词   字符   例程   类似   代码   测试   数码

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top