码迷,mamicode.com
首页 > 数据库 > 详细

java防止sql注入

时间:2015-05-04 18:26:03      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:


public final static String filterSQLInjection(String s) {
    if (s == null || "".equals(s)) {
        return "";
    }
    try {
        s = s.trim().replaceAll("</?[s,S][c,C][r,R][i,I][p,P][t,T]>?", "");//script
        s = s.trim().replaceAll("[a,A][l,L][e,E][r,R][t,T]\\(", "").replace("\"", "");// alert
        s = s.trim().replace("\\.swf", "").replaceAll("\\.htc", "");
        s = s.trim().replace("\\.php\\b", "").replaceAll("\\.asp\\b", "");
        s = s.trim().replace("document\\.", "").replaceAll("[e,E][v,V][a,A][l,L]\\(", "");
        s = s.trim().replaceAll("‘", "").replaceAll(">", "");
        s = s.trim().replaceAll("<", "").replaceAll("=", "");
        s = s.trim().replaceAll(" [o,O][r,R]", "");
        s = s.trim().replaceAll("etc/", "").replaceAll("cat ", "");
        s = s.trim().replaceAll("/passwd ", "");
        s = s.trim().replaceAll("sleep\\(", "").replaceAll("limit ", "").replaceAll("LIMIT ", "");
        s = s.trim().replaceAll("[d,D][e,E][l,L][e,E][t,T][e,E] ", "");// delete
        s = s.trim().replaceAll("[s,S][e,E][l,L][e,E][c,C][t,T] ", "");// select;
        s = s.trim().replaceAll("[u,U][p,P][d,D][a,A][t,T][e,E] ", "");// update
        s = s.trim().replaceAll("[d,D][e,E][l,L][a,A][y,Y] ", "").replaceAll("waitfor ", "");
        s = s.trim().replaceAll("print\\(", "").replaceAll("md5\\(", "");
        s = s.trim().replaceAll("cookie\\(", "").replaceAll("send\\(", "");
        s = s.trim().replaceAll("response\\.", "").replaceAll("write\\(", "")
                .replaceAll("&", "");
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
    return s;
}

java防止sql注入

标签:

原文地址:http://my.oschina.net/u/1031131/blog/410423

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!