正则表达式攻击
今天在線上環境發現cpu利用率100%問題,top出來確實有個進程一直占著100%CPU,記下這個pid然后Shift+H查看線程占用資源情況,記下pid,這時pid其實是線程ID,到java堆棧去找要轉為十六進制;
jstack [pid] |grep -n 'nid=0x249c' 這一行就是占用資源的線程
"New I/O server worker #1-11" prio=10 tid=0x000000005d8e8000 nid=0x249c runnable [0x0000000042216000]java.lang.Thread.State: RUNNABLEat java.util.regex.Pattern$CharProperty$1.isSatisfiedBy(Pattern.java:3337)at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)at java.util.regex.Pattern$Curly.match0(Pattern.java:3770)at java.util.regex.Pattern$Curly.match(Pattern.java:3744)at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3366)at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)at java.util.regex.Pattern$Loop.match(Pattern.java:4295)at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)at java.util.regex.Pattern$Curly.match0(Pattern.java:3782)at java.util.regex.Pattern$Curly.match(Pattern.java:3744)at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3366)at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)at java.util.regex.Pattern$Loop.match(Pattern.java:4295)at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)at java.util.regex.Pattern$Curly.match0(Pattern.java:3782)at java.util.regex.Pattern$Curly.match(Pattern.java:3744)at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3366)at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)at java.util.regex.Pattern$Loop.match(Pattern.java:4295) .........通過上下文可以看到是在用戶登錄時,調用了一個正則運算,通過日志查看到這一行不正常信息
request.body:{"login_name":"..\\/...\\/..\\/.\\/..\\/...\\/..\\/.\\/..\\/...\\/..\\/.\\/..\\/...\\/..\\/.\\/..\\/...\\/..\\/.\\/..\\/...\\/..\\/.\\/etc\\/passwd","password":"***"}在本地試了下,果然重現了!
后來把正則表達式換成“^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$”就正常了...
?
轉載于:https://www.cnblogs.com/langke93/archive/2012/05/27/2520526.html
總結
- 上一篇: STL中mem_fun与mem_fun_
- 下一篇: 极品的C语言错误