rapid7 / metasploit-payloads

Unified repository for different Metasploit Framework payloads
Other
1.75k stars 673 forks source link

Don't listen on IPv6 when 0.0.0.0 srvhost is requested #685

Closed smashery closed 1 year ago

smashery commented 1 year ago

This brings Java meterp in line with other meterps when binding to 0.0.0.0. Previously, when trying to listen on all IPv4 interfaces, Java meterp would also listen on all IPv6 interfaces. Java's ServerSocketChannel class introduced this in Java 15: see here. Because of back-compat requirements, we can't just call it; otherwise trying to load it in older JVMs will fail. So we use reflection to try to call it, and fall back to the existing behaviour if it fails.

The PR also fixes an issue with the Java version detection, which we leverage to select the right version of the TCP server listening. Previously, the version detection was always capped at Java 6. This would have only affected the getpid command, which required Java 9, thus would have never used the "new" version of the code.

Verification

When performing verification, setting up a reverse port forward will not work (since the interface is ignored for that). Instead, use a capture module such as auxiliary/server/capture/telnet, set the srvhost to 0.0.0.0, and use netstat to verify.