Will do as will say
分类: Java
2008-08-14 09:30:09
sql_inj.java为一个改进的防注入bean,编译后将class文件放在tomcat的classes下的sql_inj目录中。
sql_inj.java代码:
====================================================================
package sql_inj;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.lang.String;
public class sql_inj{
public static boolean sql_inj(String str)
{
String inj_str = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|;|or|-|+|,";//这里的东西还可以自己添加
String[] inj_stra=inj_str.split("\\|");
for (int i=0 ; i < inj_stra.length ; i++ )
{
if (str.indexOf(inj_stra[i])>=0)
{
return true;
}
}
return false;
}
}
====================================================================
JSP页面判断代码:
====================================================================
<%
String currenturl = request.getRequestURI()+(request.getQueryString()==null?"":("?"+request.getQueryString()));
if (sql_inj.sql_inj(currenturl)){ //判断url及参数中是否包含注入代码,是的话就跳转到某页。
response.sendRedirect("/");
return;
}
//out.println(currenturl);
%>