Redbeanphp中的SQL查询

时间:2015-06-01 09:39:52

标签: php mysql pdo

我试图使用redbeansphp执行以下代码(在php pdo的顶部工作)。 问题是当我以类似 - “id; DROP TABLE users;”的格式传递有效的id时,如果id匹配数据库中的任何id,则返回结果。虽然sql注入不起作用。我也尝试过其他注射方法。它们都不起作用。但是为什么即使ID不正确我也能得到结果。 还有一件事是,如果我在id前面添加任何代码,那么结果就不会出现。 有什么帮助吗?

$article =  R::getAll( 'SELECT AVG(rating) FROM reviews WHERE id =?', array($Id));

        //throwing an exception if the query is unsuccesful
        if(!$article){
            throw new Exception();
        }

        //response message 
        $arr=array('status' => 'successful', 'message' => 'Reviews found','Reviews'=> $article );
        $app->response()->header('Content-Type', 'application/json');
        $msg=json_encode($arr);
        $app->response->body($msg );

1 个答案:

答案 0 :(得分:0)

经过大量研究并浏览redbeans文件后,我遇到了用于绑定参数的 abs() 函数。它基本上是将绝对值返回给任何"数字"输入。 因此,如果输入abs(" 11; DROP TABLE用户;"),该函数会将其转换为11。

所以,这就是为什么即使给出了无效的输入(在它之前有有效的id),也可以得到一个没有任何sql注入的有效输出。