From d541e795ba1405993cdc97d4bfaa12f947363e32 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 15 Jan 2010 05:39:25 +0000 Subject: [PATCH] Give more information about possible causes and solutions when WinPcap fails to load on Windows, in particular information about the NPF service and UAC. --- NmapOps.cc | 20 ++++++++++++++------ mswin32/winfix.cc | 5 +++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/NmapOps.cc b/NmapOps.cc index 5983a7b7f..79fa68be4 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -337,10 +337,18 @@ bool NmapOps::RawScan() { void NmapOps::ValidateOptions() { - const char *privreq = "root privileges"; + const char *privreq = "root privileges."; #ifdef WIN32 if (!o.have_pcap) - privreq = "that WinPcap version 3.1 or higher and iphlpapi.dll be installed. You seem to be missing one or both of these. Winpcap is available from http://www.winpcap.org. iphlpapi.dll comes with Win98 and later operating sytems and NT 4.0 with SP4 or greater. For previous windows versions, you may be able to take iphlpapi.dll from another system and place it in your system32 dir (e.g. c:\\windows\\system32)"; + privreq = "WinPcap version 3.1 or higher and\n\ +iphlpapi.dll. You seem to be missing one or both of these. Winpcap is\n\ +available from http://www.winpcap.org. iphlpapi.dll comes with Win98 and\n\ +later operating sytems and NT 4.0 with SP4 or greater. For previous windows\n\ +versions, you may be able to take iphlpapi.dll from another system and place\n\ +it in your system32 dir (e.g. c:\\windows\\system32).\n\ +On Windows Vista and Windows 7, The WinPcap NPF service must be started by an\n\ +administrator before WinPcap can be used. Running nmap.exe will open a UAC\n\ +dialog where you can start NPF if you have administrator privileges."; #endif @@ -404,19 +412,19 @@ void NmapOps::ValidateOptions() { if (!isr00t) { if (ackscan|finscan|idlescan|ipprotscan|maimonscan|nullscan|synscan|udpscan|windowscan|xmasscan|sctpinitscan|sctpcookieechoscan) { - fatal("You requested a scan type which requires %s.", privreq); + fatal("You requested a scan type which requires %s", privreq); } if (numdecoys > 0) { - fatal("Sorry, but decoys (-D) require %s.", privreq); + fatal("Sorry, but decoys (-D) require %s", privreq); } if (fragscan) { - fatal("Sorry, but fragscan requires %s.", privreq); + fatal("Sorry, but fragscan requires %s", privreq); } if (osscan) { - fatal("TCP/IP fingerprinting (for OS scan) requires %s.", privreq); + fatal("TCP/IP fingerprinting (for OS scan) requires %s", privreq); } } diff --git a/mswin32/winfix.cc b/mswin32/winfix.cc index 45cfd71e7..3d3cc17ba 100644 --- a/mswin32/winfix.cc +++ b/mswin32/winfix.cc @@ -153,8 +153,8 @@ static bool start_npf() { goto quit_error; } if (!QueryServiceStatus(npf, &service)) { - goto quit_error; error("Error in QueryServiceStatus"); + goto quit_error; } npf_running = (service.dwCurrentState & SERVICE_RUNNING) != 0; CloseServiceHandle(scm); @@ -173,7 +173,8 @@ static bool start_npf() { ret = (int) ShellExecute(0, "runas", "net.exe", "start npf", 0, SW_HIDE); if (ret <= 32) { - error("Unable to start npf service: error code %d.", ret); + error("Unable to start NPF service: ShellExecute returned %d.\n\ +Resorting to unprivileged (non-administrator) mode.", ret); return false; }