3.2. Adding Service Signatures to NmapRecent versions of the popular port scanner Nmap can detect the type and version of services running on a network, as illustrated in Example 3-2. Example 3-2. Example Nmap version scan>nmap -sV 127.0.0.1 Starting nmap 3.50 ( http://www.insecure.org/nmap/ ) at 2003-07-05 17:12 EDT Interesting ports on localhost (127.0.0.1): (The 1658 ports scanned but not shown below are in state: closed) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 3.8.1p1 (protocol 2.0) Nmap run completed -- 1 IP address (1 host up) scanned in 1.104 seconds This scan is implemented as a series of probes and responses in the file nmap-service-probes. This file defines the probes that will be sent to the service to elicit some response, as well as a series of regular expressions against which to match responses to determine which services are running and, where possible, their versions. At a high level, the version-scanning methodology follows this process:
If a service responds to a probe sent during this process, but Nmap does not recognize the response, Nmap prints a fingerprint for the service that you can use to report the signature to the Nmap developers, as shown in Example 3-3. You can use this, together with the version and service information, to include a signature that recognizes this service in the nmap-service-probes file in the future. Example 3-3. Nmap unrecognized service>nmap -sV -p 4738 127.0.0.1 Starting nmap 3.50 ( http://www.insecure.org/nmap/ ) at 2003-07-05 17:39 EDT Interesting ports on localhost (127.0.0.1): PORT STATE SERVICE VERSION 4738/tcp open unknown 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at http://www.insecure.org/cgi-bin/ servicefp-submit.cgi : SF-Port4738-TCP:V=3.50%D=7/5%Time=40E9CA80%P=i686-pc-linux-gnu%r(NULL,59," SF:Login\x20with\x20USER\x20<name>\x20followed\x20by\x20PASS\x20<password> SF:\x20or\x20ANON\r\nCheck\x20privileges\x20with\x20PRIVS\r\n")%r(GenericL SF:ines,59,"Login\x20with\x20USER\x20<name>\x20followed\x20by\x20PASS\x20< SF:password>\x20or\x20ANON\r\nCheck\x20privileges\x20with\x20PRIVS\r\n")%r SF:(GetRequest,59,"Login\x20with\x20USER\x20<name>\x20followed\x20by\x20PA SF:SS\x20<password>\x20or\x20ANON\r\nCheck\x20privileges\x20with\x20PRIVS\ SF:r\n")%r(HTTPOptions,59,"Login\x20with\x20USER\x20<name>\x20followed\x20 SF:by\x20PASS\x20<password>\x20or\x20ANON\r\nCheck\x20privileges\x20with\x <cut> Nmap run completed -- 1 IP address (1 host up) scanned in 75.504 seconds At this point we have several options:
Regardless of which option you choose, it is very useful to know how to write your own probe and match signatures. 3.2.1. The nmap-service-probes FileThe keywords contained in the nmap-service-probes file are listed in Table 3-5.
3.2.1.1 ProbesA probe entry consists of the values shown in Table 3-6.
Here are some example probe strings:
3.2.1.2 MatchesA match entry consists of the values defined in Table 3-7.
Nmap uses the Perl Compatible Regular Expressions (libpcre) library for evaluating regular expressions. Perl regular expressions are documented at http://www.perldoc.com/perl5.8.0/pod/perlre.html. Here are some example match strings:
3.2.1.3 Soft matchesA soft match occurs when a service can be identified, but no additional information can be derived. A soft-match entry consists of the values defined in Table 3-8.
Here are some example soft-match strings:
3.2.1.4 portsports is a comma-separated list of ports, as well as port ranges (e.g., 35067-35090) on which the service will commonly run. This is used to ensure that probing is done efficiently, and therefore the ports entry should follow the Probe entry in nmap-service-probes. 3.2.1.5 sslportssslports is a comma-separated list of ports, as well as port ranges (e.g., 55522-55525) on which the service will commonly run over SSL. This is used to ensure that probing is done efficiently, and therefore the sslports entry should follow the Probe and ports enTRies in nmap-service-probes. 3.2.1.6 totalwaitmstotalwaitms is used to specify the timeout for a Probe. It is not needed unless the service you are probing does not respond immediately. If it is used, it should follow the Probe entry. |