mirror of
https://github.com/rapid7/metasploit-payloads
synced 2024-12-08 23:33:07 +01:00
IPv6 resolution and remove nix
This commit is contained in:
parent
9b775f33d3
commit
071ff00a38
@ -10,10 +10,11 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
DWORD resolve_host(LPCSTR hostname, u_short ai_family, struct in_addr *result)
|
||||
DWORD resolve_host(LPCSTR hostname, u_short ai_family, struct in_addr *result, struct in6_addr *result6)
|
||||
{
|
||||
struct addrinfo hints, *list;
|
||||
struct in_addr addr;
|
||||
struct in6_addr addr6;
|
||||
struct sockaddr_in *sockaddr_ipv4;
|
||||
struct sockaddr_in6 *sockaddr_ipv6;
|
||||
int iResult;
|
||||
@ -29,7 +30,8 @@ DWORD resolve_host(LPCSTR hostname, u_short ai_family, struct in_addr *result)
|
||||
#endif
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_socktype = 0;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_protocol = IPPROTO_UDP;
|
||||
hints.ai_family = ai_family;
|
||||
|
||||
dprintf("Attempting to resolve '%s'", hostname);
|
||||
@ -39,9 +41,7 @@ DWORD resolve_host(LPCSTR hostname, u_short ai_family, struct in_addr *result)
|
||||
if (iResult != NO_ERROR)
|
||||
{
|
||||
dprintf("Unable to resolve host Error: %x.", iResult);
|
||||
#ifndef _WIN32
|
||||
dprintf("Error msg: %s", gai_strerror(iResult));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -49,9 +49,11 @@ DWORD resolve_host(LPCSTR hostname, u_short ai_family, struct in_addr *result)
|
||||
case AF_INET:
|
||||
sockaddr_ipv4 = (struct sockaddr_in *) list->ai_addr;
|
||||
addr = sockaddr_ipv4->sin_addr;
|
||||
memcpy((void*)result, &addr, sizeof(addr));
|
||||
memcpy((void*)result, &addr, sizeof(result));
|
||||
case AF_INET6:
|
||||
//todo
|
||||
sockaddr_ipv6 = (struct sockaddr_in6 *) list->ai_addr;
|
||||
addr6 = sockaddr_ipv6->sin6_addr;
|
||||
memcpy((void*)result6, &addr6, sizeof(struct in6_addr));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -71,10 +73,12 @@ DWORD request_resolve_host(Remote *remote, Packet *packet)
|
||||
Packet *response = packet_create_response(packet);
|
||||
LPCSTR hostname = NULL;
|
||||
struct in_addr addr;
|
||||
struct in6_addr addr6;
|
||||
u_short ai_family = AF_INET;
|
||||
int iResult;
|
||||
|
||||
hostname = packet_get_tlv_value_string(packet, TLV_TYPE_HOST_NAME);
|
||||
ai_family = packet_get_tlv_value_uint(packet, TLV_TYPE_ADDR_TYPE);
|
||||
|
||||
if (!hostname)
|
||||
{
|
||||
@ -83,14 +87,15 @@ DWORD request_resolve_host(Remote *remote, Packet *packet)
|
||||
}
|
||||
else
|
||||
{
|
||||
iResult = resolve_host(hostname, ai_family, &addr);
|
||||
iResult = resolve_host(hostname, ai_family, &addr, &addr6);
|
||||
if (iResult == NO_ERROR)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr, sizeof(addr));
|
||||
#else
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &(addr.s_addr), sizeof(addr.s_addr));
|
||||
#endif
|
||||
if (ai_family == AF_INET)
|
||||
{
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr, sizeof(struct in_addr));
|
||||
} else {
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr6, sizeof(struct in_addr6));
|
||||
}
|
||||
packet_add_tlv_uint(response, TLV_TYPE_ADDR_TYPE, ai_family);
|
||||
}
|
||||
else
|
||||
@ -109,21 +114,23 @@ DWORD request_resolve_hosts(Remote *remote, Packet *packet)
|
||||
Tlv hostname = {0};
|
||||
int index = 0;
|
||||
int iResult;
|
||||
u_short ai_family = packet_get_tlv_value_uint(packet, TLV_TYPE_ADDR_TYPE);
|
||||
|
||||
while( packet_enum_tlv( packet, index++, TLV_TYPE_HOST_NAME, &hostname ) == ERROR_SUCCESS )
|
||||
{
|
||||
struct in_addr addr = {0};
|
||||
u_short ai_family = AF_INET;
|
||||
|
||||
iResult = resolve_host((LPCSTR)hostname.buffer, ai_family, &addr);
|
||||
struct in6_addr addr6 = {0};
|
||||
|
||||
iResult = resolve_host((LPCSTR)hostname.buffer, ai_family, &addr, &addr6);
|
||||
|
||||
if (iResult == NO_ERROR)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr, sizeof(struct in_addr));
|
||||
#else
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &(addr.s_addr), sizeof(addr.s_addr));
|
||||
#endif
|
||||
if (ai_family == AF_INET)
|
||||
{
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr, sizeof(struct in_addr));
|
||||
} else {
|
||||
packet_add_tlv_raw(response, TLV_TYPE_IP, &addr6, sizeof(struct in_addr6));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -337,6 +337,7 @@ Command customCommands[] =
|
||||
{ EMPTY_DISPATCH_HANDLER },
|
||||
},
|
||||
|
||||
#ifdef WIN32
|
||||
// Resolve
|
||||
{ "stdapi_net_resolve_host",
|
||||
{ request_resolve_host, { 0 }, 0 },
|
||||
@ -346,6 +347,7 @@ Command customCommands[] =
|
||||
{ request_resolve_hosts, { 0 }, 0 },
|
||||
{ EMPTY_DISPATCH_HANDLER },
|
||||
},
|
||||
#endif
|
||||
|
||||
// Socket
|
||||
{ "stdapi_net_socket_tcp_shutdown",
|
||||
|
Loading…
Reference in New Issue
Block a user