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



    }
}
相关推荐
程序员-珍4 分钟前
使用openapi生成前端请求文件报错 ‘Token “Integer“ does not exist.‘
java·前端·spring boot·后端·restful·个人开发
弱冠少年11 分钟前
websockets库使用(基于Python)
开发语言·python·numpy
长天一色12 分钟前
C语言日志类库 zlog 使用指南(第五章 配置文件)
c语言·开发语言
一般清意味……24 分钟前
快速上手C语言【上】(非常详细!!!)
c语言·开发语言
卑微求AC24 分钟前
(C语言贪吃蛇)16.贪吃蛇食物位置随机(完结撒花)
linux·c语言·开发语言·嵌入式·c语言贪吃蛇
2401_8572979130 分钟前
招联金融2025校招内推
java·前端·算法·金融·求职招聘
技术无疆34 分钟前
【Python】Streamlit:为数据科学与机器学习打造的简易应用框架
开发语言·人工智能·python·深度学习·神经网络·机器学习·数据挖掘
福大大架构师每日一题41 分钟前
23.1 k8s监控中标签relabel的应用和原理
java·容器·kubernetes
金灰1 小时前
HTML5--裸体回顾
java·开发语言·前端·javascript·html·html5
菜鸟一皓1 小时前
IDEA的lombok插件不生效了?!!
java·ide·intellij-idea