mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Check if an interface is known to pcap before adding its name servers.
Kenneth Frazier reported that sometimes Nmap would use name servers from inactive interfaces. Let's try checking the interface GUIDs against those known by libpcap. http://seclists.org/nmap-dev/2013/q1/292
This commit is contained in:
30
nmap_dns.cc
30
nmap_dns.cc
@@ -860,6 +860,30 @@ static void connect_dns_servers() {
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
static bool interface_is_known_by_guid(const char *guid) {
|
||||
struct interface_info *iflist;
|
||||
int i, n;
|
||||
|
||||
iflist = getinterfaces(&n, NULL, 0);
|
||||
if (iflist == NULL)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
char pcap_name[1024];
|
||||
char *pcap_guid;
|
||||
|
||||
if (!DnetName2PcapName(iflist[i].devname, pcap_name, sizeof(pcap_name)))
|
||||
continue;
|
||||
pcap_guid = strchr(pcap_name, '{');
|
||||
if (pcap_guid == NULL)
|
||||
continue;
|
||||
if (strcmp(guid, pcap_guid) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reads the Windows registry and adds all the nameservers found via the
|
||||
// add_dns_server() function.
|
||||
void win32_read_registry() {
|
||||
@@ -892,6 +916,12 @@ void win32_read_registry() {
|
||||
|
||||
for (i=0; sz = sizeof(buf), RegEnumKeyEx(hKey, i, buf, &sz, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; i++) {
|
||||
|
||||
if (!interface_is_known_by_guid(buf)) {
|
||||
if (o.debugging > 1)
|
||||
log_write(LOG_PLAIN, "Interface %s is not known; ignoring its nameservers.\n", buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
Snprintf(keyname, sizeof(keyname), "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", buf);
|
||||
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname,
|
||||
|
||||
Reference in New Issue
Block a user