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();



    }
}
相关推荐
水云桐程序员7 小时前
C++可以写手机应用吗
开发语言·c++·智能手机
测试员周周7 小时前
【AI测试智能体】为什么传统测试方法对智能体失效?
开发语言·人工智能·python·功能测试·测试工具·单元测试·测试用例
RSTJ_16258 小时前
PYTHON+AI LLM DAY THREETY-NINE
开发语言·人工智能·python
想学习java初学者8 小时前
SpringBoot整合Vertx-Mqtt多租户(优化版)
java·spring boot·后端
AC赳赳老秦8 小时前
政企内网落地:OpenClaw 离线环境深度适配方案,无外网场景下本地化模型对接与全功能使用
java·大数据·运维·python·自动化·deepseek·openclaw
赏金术士9 小时前
Kotlin 从入门到进阶 之函数模块(核心基础)(二)
android·开发语言·kotlin
weixin_449173659 小时前
在 Java 中,‌线程安全的 List‌ 主要有以下几种实现方式,它们的效率取决于具体的使用场景(尤其是读写比例):
java·线程安全的list
砚底藏山河9 小时前
股票数据API接口:如何获取股票历历史分时KDJ数据
java·python·maven
MegaDataFlowers10 小时前
运行若依项目
java
加号310 小时前
【Qt】 应用程序发布:依赖库拷贝与部署指南
开发语言·qt