diff --git a/java/meterpreter/meterpreter/src/main/java/com/metasploit/meterpreter/TLVType.java b/java/meterpreter/meterpreter/src/main/java/com/metasploit/meterpreter/TLVType.java index 96d61f98c..3d036831c 100644 --- a/java/meterpreter/meterpreter/src/main/java/com/metasploit/meterpreter/TLVType.java +++ b/java/meterpreter/meterpreter/src/main/java/com/metasploit/meterpreter/TLVType.java @@ -121,6 +121,7 @@ public interface TLVType { public static final int TLV_TYPE_CONNECT_RETRIES = TLVPacket.TLV_META_TYPE_UINT | 1504; public static final int TLV_TYPE_SHUTDOWN_HOW = TLVPacket.TLV_META_TYPE_UINT | 1530; + public static final int TLV_TYPE_RESOLVE_HOST_ENTRY = TLVPacket.TLV_META_TYPE_GROUP | 1550; // Registry public static final int TLV_TYPE_HKEY = TLVPacket.TLV_META_TYPE_QWORD | 1000; diff --git a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_host.java b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_host.java index 835263f89..ac50fdef2 100644 --- a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_host.java +++ b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_host.java @@ -10,13 +10,17 @@ import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.List; +import java.util.ArrayList; + public class stdapi_net_resolve_host implements Command { private static final int AF_INET = 2; private static final int AF_INET6 = 23; - public static InetAddress resolve_host(String host, int family) { + public static List resolve_host(String host, int family) { InetAddress[] inetAddresses; + List addressList = new ArrayList(); try { inetAddresses = InetAddress.getAllByName(host); } catch (UnknownHostException e) { @@ -25,27 +29,37 @@ public static InetAddress resolve_host(String host, int family) { for (InetAddress address : inetAddresses) { if (family == AF_INET6) { if (address instanceof Inet6Address) { - return address; + addressList.add(address); } } else if (family == AF_INET) { if (address instanceof Inet4Address) { - return address; + addressList.add(address); } } else { - return address; + addressList.add(address); } } - return null; + if (addressList.isEmpty()) { + return null; + } else { + return addressList; + } } public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception { String host = request.getStringValue(TLVType.TLV_TYPE_HOST_NAME); int family = request.getIntValue(TLVType.TLV_TYPE_ADDR_TYPE); - InetAddress inetAddress = resolve_host(host, family); - if (inetAddress != null) { - response.addOverflow(TLVType.TLV_TYPE_IP, inetAddress.getAddress()); - response.addOverflow(TLVType.TLV_TYPE_ADDR_TYPE, family); + int return_val = ERROR_FAILURE; + List inetAddresses = resolve_host(host, family); + if (inetAddresses != null) { + TLVPacket addrTLV = new TLVPacket(); + return_val = ERROR_SUCCESS; + for(int i = 0; i < inetAddresses.size(); i++){ + addrTLV.addOverflow(TLVType.TLV_TYPE_IP, inetAddresses.get(i).getAddress()); + addrTLV.addOverflow(TLVType.TLV_TYPE_ADDR_TYPE, family); + } + response.addOverflow(TLVType.TLV_TYPE_RESOLVE_HOST_ENTRY, addrTLV); } - return ERROR_SUCCESS; + return return_val; } } diff --git a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_hosts.java b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_hosts.java index 2f047090a..935b40112 100644 --- a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_hosts.java +++ b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_net_resolve_hosts.java @@ -15,12 +15,17 @@ public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket respons int family = request.getIntValue(TLVType.TLV_TYPE_ADDR_TYPE); for (int i=0;i inetAddresses = stdapi_net_resolve_host.resolve_host(host, family); + TLVPacket addrTLV = new TLVPacket(); + if (inetAddresses != null) { + for(int j = 0; j < inetAddresses.size(); j++){ + addrTLV.addOverflow(TLVType.TLV_TYPE_IP, inetAddresses.get(j).getAddress()); + addrTLV.addOverflow(TLVType.TLV_TYPE_ADDR_TYPE, family); + } + response.addOverflow(TLVType.TLV_TYPE_RESOLVE_HOST_ENTRY, addrTLV); } else { - response.addOverflow(TLVType.TLV_TYPE_IP, new byte[0]); + addrTLV.addOverflow(TLVType.TLV_TYPE_IP, new byte[0]); + response.addOverflow(TLVType.TLV_TYPE_RESOLVE_HOST_ENTRY, addrTLV); response.addOverflow(TLVType.TLV_TYPE_ADDR_TYPE, family); } }