java jdbc_sql注入攻击数据 案例。

JDBC URL: jdbc:mysql://mysql.sqlpub.com:3306/huangjin

Username: XXXXXX

Password: fc12f7a5215e8e0a

请输入要查找的id:1 or 1=1

1, ml5 michael@email.com gmail 22

2, bb44 bob@email.com facebook 1

3, je22 jane@email.com github 49

4, ae5 alice@email.com facebook 64

5, ls5 lisa@email.com twitter 10

6, ay0 anthony@email.com facebook 1

7, je1 joe@email.com github 99

8, mk57 mark@email.com github 15

9, tt34 tim@email.com github 90

10, cc100 colton@email.com github 10

JDBC配置

config.properties

db.url=jdbc:mysql://mysql.sqlpub.com:3306/huangjin

db.username=XXXXXX

db.password=fc12f7a5215e8e0a

java 复制代码
package com.abc.project3;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
import java.util.Scanner;

public class D {
    public static void main(String[] args) throws IOException, SQLException {

        String dbUrl = null;
        String dbUsername = null;
        String dbPassword = null;

        Properties properties = new Properties();
        FileInputStream fis = null;

        String fName = "config.properties";
        File file = new File(fName);
        if (!file.isFile()) {
            System.err.println(fName + " 文件不存在");
            System.exit(0);
        }


        // 读取配置文件
        fis = new FileInputStream(fName);
        properties.load(fis);

        // 获取 JDBC 连接信息
        dbUrl = properties.getProperty("db.url");
        dbUsername = properties.getProperty("db.username");
        dbPassword = properties.getProperty("db.password");

        if(fis!=null)
            fis.close();

        // 打印 JDBC 连接信息
        System.out.println("JDBC URL: " + dbUrl);
        System.out.println("Username: " + dbUsername);
        System.out.println("Password: " + dbPassword);

        Connection con = DriverManager.getConnection(dbUrl,dbUsername,dbPassword);

        //4.获取执行者对象
        Statement stat = con.createStatement();
        String sql ="SELECT * FROM user WHERE id = ";
        ResultSet resultSet = null;
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入要查找的id:");
        String str =sc.nextLine();  // 注入攻击  1 or 1=1
        sc.close();
        resultSet = stat.executeQuery(sql + str);

        while(resultSet.next()){
            String  res =resultSet.getInt("ID")+", ";
                    res += resultSet.getString("username")+" ";
                    res += resultSet.getString("email")+" ";
                    res += resultSet.getString("authType")+" ";
            res += resultSet.getInt("reputation");
            System.out.println(res);
        }

        if (resultSet != null)
            resultSet.close();
        stat.close();
        con.close();



    }
}
相关推荐
014-code3 小时前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
lly2024064 小时前
组合模式(Composite Pattern)
开发语言
游乐码4 小时前
c#泛型约束
开发语言·c#
Dontla4 小时前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)
开发语言·windows·golang
chushiyunen4 小时前
python rest请求、requests
开发语言·python
铁东博客4 小时前
Go实现周易大衍筮法三变取爻
开发语言·后端·golang
baidu_huihui4 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳4 小时前
Python从入门到精通day63
开发语言·python
lbb 小魔仙4 小时前
Python_RAG知识库问答系统实战指南
开发语言·python
java1234_小锋4 小时前
Java高频面试题:Springboot的自动配置原理?
java·spring boot·面试