mysql - 试图了解我的页面是否易受攻击

标签 mysql sql sql-injection

我正在用一个小而简单的数据库创建一个 php 页面。

当我在线访问它并尝试在 url 中传递参数“length”时:index.php/?length=1 它工作正常并获取数据。

如果我添加像 index.php/?length=1' 这样的单引号,我在页面上没有 SQL 错误...

但是如果我使用 index.php/?length=-1 我会在我的页面中看到 SQL 错误。

这是否意味着我的页面易受攻击?

如何进一步测试并解决问题?

编辑:添加代码

$length = $wpdb->get_results( $wpdb->prepare("SELECT `title`, `website`, `material`, `color`, `width`, `height`, `group`, `category`, `numbers_positive`, `numbers_negative`, `custom` FROM {$wpdb->shirts} WHERE `id` = '%d' ORDER BY `rank` ASC, `id` ASC", intval($shirt_id)) );

if (!isset($shirt[0])) return false;

$shirt= $shirt[0];
$shirt->title = htmlspecialchars(stripslashes($shirt->title), ENT_QUOTES);
$shirt->custom = maybe_unserialize($shirt->custom);
$shirt->color = maybe_unserialize($shirt->color);
if ( $this->hasBridge() ) {
    global $lmBridge;
    $shirt->shirtColor = $lmBridge->getShirtColor($shirt->color);
}
$shirt = (object)array_merge((array)$shirt,(array)$shirt->custom);
unset($shirt->custom);

return $shirt;

最佳答案

是的,从您提供的 URL 示例来看,您似乎接受了用户输入并将其直接插入到您的 MySQL 语句中。那绝对是最糟糕的。您应该始终解析用户输入,因为来自用户的直接输入可能导致字符串被转义并删除数据库中的每个表。这是一个很好的例子:Bobby Tables

此外,这是一个引起广泛讨论的话题。有一个很好的答案here

编辑* 使用 WordPress 框架并查看您的代码,它并没有看起来那么糟糕。

关于mysql - 试图了解我的页面是否易受攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46008815/

相关文章:

php - PHP 中的 mysqli 类是否可以 100% 防止 sql 注入(inject)?

php - PDO 准备好的语句是否足以防止 SQL 注入(inject)?

c# - 使用 MySqlDataAdapter/MySqlCommandBuilder 强制 autoinc 字段

mysql - 有没有更简单的方法来查找 MySQL 中某些值的 MODE(S)

php - Apache 在运行 Controller 的索引页时崩溃

mysql - 类似的 SQL 查询返回不同的结果

MYSQL:选择给定行中包含重复数据的行(主键检查不带主键)

php - fatal error : Maximum execution time of 30 seconds exceeded

mysql - mysql中计算合规性的优化方法

php - 在 SQL 注入(inject)中使用嵌套 SQL 子查询