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));
}
}