I have given the following grants for permission and calling CMD.EXE
appears to work like shown in below code example.
However, I cannot get any output from whoami.exe
. I can see that the default directory is C:\app\oramgr\product\12.1.0\dbhome_1\database\
that appears in the JJJ.TXT
file. However, the JJJ_WHOAMI.TXT
file contains nothing.
Any suggestions?
dbms_java.grant_permission('PWATSON', 'SYS:java.io.FilePermission', 'C:\WINDOWS\SYSTEM32\CMD.EXE', 'execute');
dbms_java.grant_permission('PWATSON', 'SYS:java.io.FilePermission', 'C:\Windows\System32\whoami.exe', 'execute');
dbms_java.grant_permission('PWATSON', 'SYS:java.lang.RuntimePermission', '*', 'writeFileDescriptor');
dbms_java.grant_permission('PWATSON', 'SYS:java.lang.RuntimePermission', '*', 'readFileDescriptor');
dbms_java.grant_permission('PWATSON', 'SYS:java.io.FilePermission', 'C:\Users\pwatson', 'read, write');
dbms_java.grant_permission('PWATSON', 'SYS:java.io.FilePermission', 'C:\Users\pwatson\*', 'read, write');
dbms_java.grant_permission('PWATSON', 'SYS:java.io.FilePermission', 'C:\temp', 'read');
SQL> select util.RUN_CMD('C:\WINDOWS\system32\cmd.EXE /c CD C:\Users\pwatson\src\java ^& ECHO ^%CD^% ^& EXIT 4') as y from dual;
Y
----------
4
C:\app\oramgr\product\12.1.0\dbhome_1\DATABASE
SQL> select util.RUN_CMD('C:\WINDOWS\system32\cmd.EXE /c ECHO ^%CD^% >jjj.txt ^& EXIT 7') as y from dual;
Y
----------
7
SQL> select util.RUN_CMD('C:\WINDOWS\system32\cmd.EXE /c C:\Windows\System32\whoami.exe >jjj_whoami.txt') as y from dual;
Y
----------
0
C:\app\oramgr\product\12.1.0\dbhome_1\database>type JJJ.TXT
C:\app\oramgr\product\12.1.0\dbhome_1\DATABASE
C:\app\oramgr\product\12.1.0\dbhome_1\database>type JJJ_WHOAMI.TXT
Maybe Oracle is a nobody when it runs whoami
on Windows? Good idea is to change the user who starts the service.
The third call is slightly different from the second. You didn't call for an exit.
Try the below:
select util.RUN_CMD('C:\WINDOWS\system32\cmd.EXE /c C:\Windows\System32\whoami.exe >jjj_whoami.txt ^& EXIT 8') as y from dual;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With