天天看點

SQL注入中information_schema

實驗簡介

實驗所屬系列:WEB安全應用

實驗目的

通過本次實驗,掌握SQL注入中,通過information_schema這個資料庫爆庫名、表名以及字段名的原理。

實驗環境

windows 7、安裝wamp環境

預備知識

MySQL文法:https://dev.mysql.com/doc/refman/5.7/en/select.html

MySQL查詢資料:http://www.runoob.com/mysql/mysql-select-query.html

實驗步驟

在phpmyadmin中,在左側點選information_schema資料庫。 展開後如下圖,顯示了該資料庫中的所有表

 也可以執行如下SQL語句來檢視該庫中的所有表:

      show tables;

SQL注入中information_schema

想要檢視資料庫的資料儲存目錄,可以執行select @@datadir

SQL注入中information_schema

輕按兩下桌面的WampServer運作。彈出來的清單中點選MySQL,再選擇MySQL控制台。

SQL注入中information_schema

 彈出一個指令行視窗,這就是mysql用戶端,此時要求輸入密碼,root的密碼為空,直接回車

SQL注入中information_schema

 使用指令use information_schema,進入information_schema 資料庫

首先執行show databases;檢視所有的資料庫,然後再執行select schema_name from schemata;。

執行desc tables,看表結構

SQL注入中information_schema

 執行select count(*) from tables;,檢視有多少條記錄

SQL注入中information_schema

 目前資料有142條

SQL語句為:select * from tables limit 141,1\G 查詢任意一條語句

SQL注入中information_schema

 檢視sqli資料庫中的表,SQL語句為:show tables from sqli;

SQL注入中information_schema

想要通過information_schema資料庫來查詢sqli資料庫中所有的表,使用如下SQL語句:

      select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'sqli';

SQL注入中information_schema

 desc COLUNMS 語句

SQL注入中information_schema

 首先确定該表有多少條記錄,執行select count(*) from colum

查詢最後一條語句

SQL注入中information_schema

 檢視sqli的user表是否存在該字段,執行SQL語句:show columns from sqli.user;

SQL注入中information_schema

通過information_schema資料庫的columns表查詢sqli資料庫中user表中所有的字段,可以執行如下SQL語句:

      select column_name from information_schema.columns where TABLE_SCHEMA='sqli' and TABLE_NAME='user';

SQL注入中information_schema

 查詢結果一緻。

分析與思考

為什麼網上的SQL注入語句中,資料庫名都是用的字元的16進制值、

在處理sql注入時,我們通常對完整的ASCII碼範圍不感興趣,因為并非所有字元在資料庫中都是有效或者是允許的,因為這我麼們隻關注ascii碼範圍在32~126,他留下了一個94個字元。該範圍用7位表示。

SQL注入中information_schema

為什麼網上的SQL注入語句中,資料庫名都是用的字元的16進制值?