mysql注入求解
$id = $_GET['id'];$sql = "select * from admin where id='$id'";
echo $sql;
变量用单引号包起来后
在url处输入http://localhost/sqlinject/1.php?id=1' and 1=2/*
输出的sql语句 为select * from admin where id='1' and 1=2/*'
在url处输入http://localhost/sqlinject/1.php?id=1' and 1=2--
输出的sql语句为select * from admin where id='1' and 1=2--'
/*和-- 都没能注释后面的单引号,这该怎么注入自己的语句呢?? 你试试这样:
在url处输入http://localhost/sqlinject/1.php?id=1' and 1=2--'
输出的sql语句为select * from admin where id='1' and 1=2--''
这样的话''就应该没有什么影响了,个人理解啊
mysql注释符是-- ,在--后面有个空格,你试试--%20
http://localhost/sqlinject/1.php?id=1' and 1=2 and '1'='1
select * from admin where id='1' and 1=2 and '1'='1'
Re: mysql注入求解
遇到这种情况,关键在于MySQL的注释语法细节。你输入的 `--` 后面直接跟了单引号,没有空格,MySQL会把 `--` 当作两个减号,而不是注释符。同样,`/*` 需要与 `*/` 成对使用,你只用了开始注释符,没有结束符,后面的单引号被当作注释内容,实际上并没有被忽略,所以整个语句仍然包含多余的单引号,导致语法错误或查询异常。 解决方法有两个: 1. **在 `--` 后面加一个空格**(或制表符、换行等空白字符): ``` ?id=1' and 1=2 -- ``` 注意 `--` 后面必须有一个空格,这样 `--` 才会将后面的 `'` 注释掉。输出SQL变为: `select * from admin where id='1' and 1=2 -- '` 后面的单引号被注释,语句正常。 2. **使用 `#` 注释符**(MySQL也支持): ``` ?id=1' and 1=2 # ``` `#` 会注释掉后面的所有内容,包括单引号。输出SQL变为: `select * from admin where id='1' and 1=2 #'` 同样可以绕过。 另外,如果能闭合前面的单引号,也可以尝试用 `1' or '1'='1` 这样构造恒真条件,但既然你想用注释,记得加上空格或改用 `#` 即可。
页:
[1]