Skip to content

Commit 8332cc6

Browse files
authored
Merge pull request #781 from zeroSteiner/fix/met/java-socket-channel-tests
Java: Send the channel address info back to Metasploit
2 parents 58fce45 + d4e5820 commit 8332cc6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_channel_open.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private int executeUdpClient(Meterpreter meterpreter, TLVPacket request, TLVPack
8080
}
8181
Channel channel = new DatagramSocketChannel(meterpreter, ds);
8282
response.add(TLVType.TLV_TYPE_CHANNEL_ID, channel.getID());
83+
response.add(TLVType.TLV_TYPE_LOCAL_HOST, ds.getLocalAddress().getHostAddress());
84+
response.add(TLVType.TLV_TYPE_LOCAL_PORT, ds.getLocalPort());
8385
return ERROR_SUCCESS;
8486
}
8587

@@ -89,14 +91,15 @@ private int executeTcpServer(Meterpreter meterpreter, TLVPacket request, TLVPack
8991
ServerSocket ss = getSocket(localHost, localPort);
9092
Channel channel = new ServerSocketChannel(meterpreter, ss);
9193
response.add(TLVType.TLV_TYPE_CHANNEL_ID, channel.getID());
94+
response.add(TLVType.TLV_TYPE_LOCAL_HOST, ss.getInetAddress().getHostAddress());
95+
response.add(TLVType.TLV_TYPE_LOCAL_PORT, ss.getLocalPort());
9296
return ERROR_SUCCESS;
9397
}
9498

9599
protected ServerSocket getSocket(String localHost, int localPort) throws UnknownHostException, IOException {
96100
return new ServerSocket(localPort, 50, InetAddress.getByName(localHost));
97101
}
98102

99-
100103
private int executeTcpClient(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
101104
String peerHost = request.getStringValue(TLVType.TLV_TYPE_PEER_HOST);
102105
int peerPort = request.getIntValue(TLVType.TLV_TYPE_PEER_PORT);
@@ -124,6 +127,8 @@ private int executeTcpClient(Meterpreter meterpreter, TLVPacket request, TLVPack
124127
Channel channel = new SocketChannel(meterpreter, socket);
125128
channel.startInteract();
126129
response.add(TLVType.TLV_TYPE_CHANNEL_ID, channel.getID());
130+
response.add(TLVType.TLV_TYPE_LOCAL_HOST, socket.getLocalAddress().getHostAddress());
131+
response.add(TLVType.TLV_TYPE_LOCAL_PORT, socket.getLocalPort());
127132
return ERROR_SUCCESS;
128133
}
129134
}

0 commit comments

Comments
 (0)