從SQL注入利用的角度看待MySQL內置函數

注入經常使用函數

數據庫相關

  • database() --- 返回當前數據庫名
  • @@datadir --- 讀取數據庫路徑
  • @@basedir --- 讀取數據庫安全路徑
  • @@version_compile_os --- 返回當前操做系統

UDF相關

  • version() || @@version --- 返回MySQL服務器的版本
  • show variables like "%plugin%"; --- 查看mysql插件路徑
  • show variables like '%version_%'; --- 查看系統版本、位數

用戶相關

  • User() || System_user() --- 用戶名
  • Current_Uere() --- 當前登錄用戶名
  • Session_User() --- 鏈接數據庫的用戶名
  • Connection_id() --- 返回當前客戶的鏈接ID

hash

  • md5()
  • password() --- 登陸密碼用這個函數加密後存入表中

other

  • Found_Rows() --- 返回最後一個SELECT查詢進行檢索的總行數
  • Benchmark(count,expr) --- 將表達式expr重複運行count次
  • sleep()

File讀寫類函數

MySQL讀寫系統文件須要一些特定的設置,具體內容在:https://www.cnblogs.com/mysticbinary/articles/11346191.htmlphp

  • into dumpfile()
  • into outfile()
  • load_file()
  • system cat /test.php
  • system vim /test.php

字符串類函數

注入經常使用

  • length() 返回字符串的字節數
  • char_length() 返回的纔是字符數
  • locate(sub_str,string)
  • position(sub_str in string)
  • instr(str,sub_str)

Base64加解密(繞過WAF)

  • to_base64()

繞過waf example:html

select to_base64(load_file('/usr/share/metasploit-framework/data/exploits/mysql/lib_mysqludf_sys_64.dll')) 
into dumpfile '/tmp/udf.b64';
  • from_base64()

繞過waf example:mysql

select from_base64("TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAA8AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1v
ZGUuDQ0KJAAAAAAAAAAzwu3gd6ODs3ejg7N3o4OzafEQs3Wjg7Np8QCzfaODs2nxB7N1o4OzUGX4
s3Sjg7N3o4KzW6ODs2nxCrN2o4OzafEWs3Wjg7Np8RGzdqODs2nxErN2o4OzUmljaHejg7MAAAAA
AAAAAAAAAAAAAAAAUEUAAGSGBgBwsYNLAAAAAAAAAADwACIgCwIJAAASAAAAFgAAAAAAADQaAAAA
EAAAAAAAgAEAAAAAEAAAAAIAAAUAAgAAAAAABQACAAAAAAAAgAAAAAQAADPOAAACAEABAAAQAAAA
AAAAEAAAAAAAAAAAEAAAAAAAABAAAAAAAAAAAAAAEAAAAAA5AAAFAgAAQDQAADwAAAAAYAAAsAIA
AABQAABoAQAAAAAAAAAAAAAAcAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAwAABwAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAAR
EAAAABAAAAASAAAABAAAAAAAAAAAAAAAAAAAIAAAYC5yZGF0YQAABQsAAAAwAAAADAAAABYAAAAA") 
into dumpfile "D:\\MySQL\\mysql-5.7.21-winx64\\mysql-5.7.21-winx64\\lib\\plugin\\udf.dll";

判斷字符串所在位置

  • find_in_set(sub_string,str_set)
  • field(s,str1,str2,...,strN)
  • elt(n,str1,str2,...,strN)

合併

  • concat()
  • concat_ws()

長度

  • lower(string)
  • upper(string)
  • left(string,x)
  • right(string,x)

填充

  • lpad()
  • rpad()

消除空格

  • ltrim(string) --- 刪除行首空格
  • rtrim(string) --- 刪除行尾空格
  • trim(string) --- 刪除行首和行尾空格
  • trim(substring from string) --- 刪除行首和行尾的字符串substring

其餘

  • repeat(string,x)
  • replace(string,a,b)
  • insert(string,p1,len,instead_string)
  • substring(string,x,y)
  • strcmp()
  • reverse()

數學類函數

to-dosql


日期時間類函數

返回當前日期

  • curdate()
    數據庫

  • current_date()vim

  • curtime()安全

  • current_time()服務器

  • now()
    函數

  • current_timestamp()加密

  • localtime()

  • localtimestamp

  • localtimestamp()

  • sysdate()


流程控制\條件判斷類函數

  • if()

  • ifnull() --- 若是value1不爲空則返回value1,不然返回value2。總之就是給定一個非null值。容許value2爲null。

  • nullif() --- 若是expr1等於expr2,則返回null,不然返回expr1。也就是說,二者不相等時取前者,不然取NULL。若是expr1和expr2任意一個爲null,則直接返回null。

  • case語句
    reference:http://www.javashuo.com/article/p-slkefvmk-de.html

select t.name,t.sex, case when t.sex = '0' then 'man'
when t.sex='1' then 'women' else 'other' end from test_tb as t;


類型轉換類函數

  • cast()
  • convert()

參考

http://www.javashuo.com/article/p-xxqkwxyl-hb.html

相關文章
相關標籤/搜索