• ADADADADAD

    SQL注入通常会在哪些地方传递数值[ 网络知识 ]

    网络知识 时间:2024-12-03 15:10:26

    作者:文/会员上传

    简介:

    SQL注入通常会在web表单、cookies、url包含的参数值等地方传递数值,预防方法:1.采用PreparedStatement进行预编译,例如:String sql = "select* from users where username=? and

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    SQL注入通常会在web表单、cookies、url包含的参数值等地方传递数值,预防方法:

    1.采用PreparedStatement进行预编译,例如:

    String sql = "select* from users where username=? and password=?";

    Connection conn = null;

    PreparedStatement state = null;

    ResultSet result;

    conn = JdbcUtil.getConnection();

    System.out.println(sql);

    try {

    state = conn.prepareStatement(sql);

    state.setString(1, userName);

    state.setString(2, passWord);

    result = state.executeQuery();

    2.使用正则表达式过滤传入的参数,例如:

    要引入的包:

    import java.util.regex.*;

    正则表达式:

    private String CHECKsql = “^(.+)\\sand\\s(.+)|(.+)\\sor(.+)\\s$”;

    判断是否匹配:

    Pattern.matches(CHECKsql,targerStr);

    3.对字符串进行过滤,例如:

    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[] = split(inj_str,"|");

    for (int i=0 ; i < inj_stra.length ; i++ )

    {

    if (str.indexOf(inj_stra[i])>=0)

    {

    return true;

    }

    }

    return false;

    }

    4.使用javascript在客户端进行不安全字符屏蔽,例如JSP页面判断代码:

    functioncheck(a){

    return1;

    fibdn=newArray(”‘”,”\\”,”/”);

    i=fibdn.length;

    j=a.length;

    for(ii=0;ii<i;ii++)

    {for(jj=0;jj<j;jj++)

    {temp1=a.charAt(jj);

    temp2=fibdn[ii];

    if(tem’;p1==temp2)

    {return0;}

    }

    }

    return1;

    }

    SQL注入通常会在哪些地方传递数值.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: sql注入数值传递