SQL注入问题

2021/5/16 19:55:32

本文主要是介绍SQL注入问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

SQL注入问题

SQL存在漏洞,会被攻击导致数据泄露SQL会被拼接 or

​ 下方代码可以查询全部数据库内容:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQL注入 {
    public static void main(String[] args) {
        // 正常登录 login("saxon","123456");
        login(" 'or' 1=1"," 'or' 1=1");   //查出了所有数据
    }
    public static void login(String username,String password) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            conn = jdbcUtils.getConnection();
            st = conn.createStatement();
            //select * from users where `NAME` = ''or' 1=1' AND  `password` = ''or' 1=1'
            String sql = "select * from users where `NAME` = '" + username +"' AND  `password` = '"+ password + "' ";
            rs = st.executeQuery(sql);
            while (rs.next()) {
                System.out.println(rs.getString("NAME"));
                System.out.println(rs.getString("password"));
                System.out.println("=============");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}



这篇关于SQL注入问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程