我使用 360 的防止 sql 注入的类,但是在thinkphp6后台使用vue axios登陆,出现 sql注入 不能判断,也就是无效。如果继续使用360的webscan类, 需要按照提供的格式加上对 input 获取参数的判断 ,如下图:
这里的作用就是要判断input,参数是自己定义的,对应的是下边的if ($this->webscan_post);
如果不是使用的该类判断,也要查看一下是否可以防止注入。
原来的判断格式:
if ($this->webscan_post)
{
foreach ($_POST as $key => $value)
{
if ($this->webscan_StopAttack($key, $value, $postfilter, "POST"))
return true;
}
}
使用对应的格式添加如下判断:
if ($this->webscan_input)
{
foreach (input('post.') as $key => $value)
{
if ($this->webscan_StopAttack($key, $value, $postfilter, "POST"))
return true;
}
}
if ($this->webscan_input)
{
foreach (input('get.') as $key => $value)
{
if ($this->webscan_StopAttack($key, $value, $getfilter, "GET"))
return true;
}
}
以登陆后台账号为例:
如果验证账号密码是下边的格式,是可以绕过验证的。
$con=" user_name='".trim(input('post.user_name')."' and password='".md5(trim(input('post.password')))."'";
$data = Db::name("admin")->field("role,user_name")->where($con)->find();
登陆后台:
说明:
账号使用 admin ‘ or ‘1=1 # 其中admin 任意,密码任意,即可登陆账号。
如下修改,不会被绕过:
$con['user_name'] = trim(input('post.user_name'));
$con['password'] = md5(trim(input('post.password')));
$data = Db::name("admin")->field("role,user_name")->where($con)->find();
打印了语句,发现英文 单引号 变成了 \’, 被转义了。