Skip to content

Java: Send the channel address info back to Metasploit - #781

Merged
jheysel-r7 merged 1 commit into
rapid7:masterfrom
zeroSteiner:fix/met/java-socket-channel-tests
Nov 13, 2025
Merged

Java: Send the channel address info back to Metasploit#781
jheysel-r7 merged 1 commit into
rapid7:masterfrom
zeroSteiner:fix/met/java-socket-channel-tests

Conversation

@zeroSteiner

@zeroSteiner zeroSteiner commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

The Java Meterpreter has inconsistent behavior in how the socket channels are handled in that it does not send the local address and local port information back to Metasploit. This becomes an issue when Metasploit requests that the OS environment on which the Java Meterpreter is running allocate the port by specifying port 0. When bound to port 0 in any of the three configurations (UDP, TCP client and TCP server), the port should be fetched from the socket and sent back to Metasploit. Metasploit can then use this information for socket communications. At least the Python, Windows and Mettle Meterpreter implementations do this already. I'll test PHP shortly and get a PR to fix it as well if it has the same issue.

Testing

The easiest way to test this is to use the module from rapid7/metasploit-framework#20689

  • Get a Java Meterpreter session
  • Run the post/test/socket_channels test suite
  • See all three "Allows binding to port 0" tests pass
  • Know that [-] FAILED: [UDP] Has the correct peer information is a separate issue requiring a different fix, ignore it for now

Demo

msf payload(java/meterpreter/reverse_tcp) > sessions -i -1
[*] Starting interaction with 1...

meterpreter > getuid
Server username: smcintyre
meterpreter > sysinfo
Computer        : fedora-vm
OS              : Linux 6.17.6-200.fc42.x86_64 (amd64)
Architecture    : x64
System Language : en_US
Meterpreter     : java/linux
meterpreter > run post/test/socket_channels
[*] Running against session 1
[*] Session type is meterpreter and platform is linux
[*] Running TCP client channel tests...
[+] [TCP-Client] Allows binding to port 0
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running TCP server channel tests...
[+] [TCP-Server] Allows binding to port 0
[+] [TCP-Server] Accepts a connection
[+] [TCP-Server] Has the correct peer information
[+] [TCP-Server] Receives data from the peer
[+] [TCP-Server] Sends data to the peer
[+] [TCP-Server] Propagates close events to the server
[+] [TCP-Server] Propagates close events to the peer
[+] [TCP-Server] Propagates close events from the peer
[*] Running UDP channel tests...
[+] [UDP] Allows binding to port 0
[-] FAILED: [UDP] Has the correct peer information
[+] [UDP] Receives data from the peer
[+] [UDP] Sends data to the peer
[-] Passed: 17; Failed: 1; Skipped: 0
meterpreter >

@jheysel-r7 jheysel-r7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good and are working as expected 👍

Testing

msf post(test/socket_channels) > run
[*] Running against session -1
[*] Session type is meterpreter and platform is linux
[*] Running TCP client channel tests...
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running UDP channel tests...
[-] FAILED: [UDP] Has the correct peer information
[+] [UDP] Receives data from the peer
[+] [UDP] Sends data to the peer
[*] Running TCP server channel tests...
[+] [TCP-Server] Accepts a connection
[+] [TCP-Server] Has the correct peer information
[+] [TCP-Server] Receives data from the peer
[+] [TCP-Server] Sends data to the peer
[+] [TCP-Server] Propagates close events to the server
[+] [TCP-Server] Propagates close events to the peer
[+] [TCP-Server] Propagates close events from the peer
[-] Passed: 14; Failed: 1; Skipped: 0
[*] Post module execution completed

@jheysel-r7
jheysel-r7 merged commit 8332cc6 into rapid7:master Nov 13, 2025
27 of 29 checks passed
zeroSteiner added a commit to zeroSteiner/metasploit-framework that referenced this pull request Nov 13, 2025
smcintyre-r7 pushed a commit that referenced this pull request Jul 6, 2026
…tests

Java: Send the channel address info back to Metasploit
smcintyre-r7 pushed a commit that referenced this pull request Jul 7, 2026
…tests

Java: Send the channel address info back to Metasploit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants