java 过滤脚本_Java正则表达式过滤脚本威胁--封装类

package org.john;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class TestMarvin {

/**

* 正则表达式过滤脚本威胁

* Title: webCourse2010

* Description:

* Copyright: Copyright (c) 2011

* Create DateTime: Nov 21, 2011 1:55:29 PM

* CVS last modify person: rexqing

* CVS last modify DateTime: Nov 21, 2011 1:55:29 PM

* CVS last version:

* @author 邓清泉

*/

public static String replseJs(String html)

{

try

{

Pattern replse1 = Pattern.compile("]*?>[\\s\\S]*?",Pattern.CASE_INSENSITIVE);

Pattern replse2 = Pattern.compile("]*?>[\\s\\S]*?",Pattern.CASE_INSENSITIVE);

Pattern replse3 = Pattern.compile("]*?>[\\s\\S]*?",Pattern.CASE_INSENSITIVE);

Pattern replse4 = Pattern.compile("]*?>[\\s\\S]*?",Pattern.CASE_INSENSITIVE);

Pattern replse5 = Pattern.compile("\\s*");

Pattern replse6 = Pattern.compile("javascript");

Pattern replse7 = Pattern.compile("expression\\([^)]+\\)");

Pattern replse8 = Pattern.compile("]*?>",Pattern.CASE_INSENSITIVE);

Pattern replse9 = Pattern.compile("]*?>",Pattern.CASE_INSENSITIVE);

Pattern replse10 = Pattern.compile("(?i)on[A-Za-z]*[\\s]*?="); //匹配不区分大小写的on + w(有无空格) + =

Matcher matcher1 = replse1.matcher(html);

html = matcher1.replaceAll("");

Matcher matcher2 = replse2.matcher(html);

html = matcher2.replaceAll("");

Matcher matcher3 = replse3.matcher(html);

html = matcher3.replaceAll("");

Matcher matcher4 = replse4.matcher(html);

html = matcher4.replaceAll("");

Matcher matcher5 = replse5.matcher(html);

html=matcher5.replaceAll("");

Matcher matcher6 = replse6.matcher(html);

html=matcher6.replaceAll("");

Matcher matcher7 = replse7.matcher(html);

html=matcher7.replaceAll("");

Matcher matcher8 = replse8.matcher(html);

html=matcher8.replaceAll("");

Matcher matcher9 = replse9.matcher(html);

html=matcher9.replaceAll("");

Matcher matcher10 = replse10.matcher(html);

html=matcher10.replaceAll("");

}catch (Exception e) {

e.printStackTrace();

}

return html;

}

public static void main(String[] args) {

String str1="";

String str2="111222";

String str3="";

String str4="3333";

String str5="expression(^\\ghhhhhhhhhhhhhhhhh)";

String str6="Onclick =";

System.out.println("1:"+replseJs(str1));

System.out.println("2:"+replseJs(str2));

System.out.println("3:"+replseJs(str3));

System.out.println("4:"+replseJs(str4));

System.out.println("5:"+replseJs(str5));

System.out.println("6:"+replseJs(str6));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值