Skip to content

Commit e98d510

Browse files
committed
Fix incorrect network prefix in Java Meterpreter
Apparently, getNetworkPrefixLength can return -1, which confuses the Ruby side. Therefore fall back to guessing the prefix in this case, as we do it for Java <= 1.6.
1 parent 1365dfe commit e98d510

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

external/source/javapayload/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_config_get_interfaces_V1_6.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public Address[] getAddresses(NetworkInterface iface) throws IOException {
2424
if (ip == null)
2525
continue;
2626
int prefixLength = addr.getNetworkPrefixLength();
27+
if (prefixLength == -1 && ip.length == 4) {
28+
// guess netmask by network class...
29+
if ((ip[0] & 0xff) < 0x80) {
30+
prefixLength = 8;
31+
} else if ((ip[0] & 0xff) < 0xc0) {
32+
prefixLength = 16;
33+
} else {
34+
prefixLength = 24;
35+
}
36+
}
2737
byte[] scopeId = null;
2838
if (addr.getAddress() instanceof Inet6Address) {
2939
ByteBuffer bb = ByteBuffer.allocate(4);

0 commit comments

Comments
 (0)