30 Mins

4. Service Version Detection & Banner Grabbing

Service Version Detection (-sV): Banner Grabbing and Protocol Probing

Service version detection is a technique used to determine what software and version is running on an open port. While a simple port scan identifies a port as open, -sV probes the service to gather specific response signatures.

When Nmap uses -sV, it first performs a TCP connect scan. If the port is open, it listens for a service banner. If no banner is sent, Nmap sends a series of probes designed to elicit a response from various protocols, matching the responses against the nmap-service-probes database.

This process is essential for identifying outdated software. For example, an Apache 2.2.15 server is significantly more vulnerable to CVEs than version 2.4.58. Accurate versioning allows security teams to prioritize patching efforts effectively.

Security Operator Note: Always pair -sV with -sC (default scripts) to gather even more granular information such as SSL certificates and HTTP headers.
Text
nmap -sV -p 80,443,22 192.168.1.10

Tuning Version Intensity (--version-intensity 0 to 9)

Nmap allows you to control the intensity of version probes using the --version-intensity flag. The intensity ranges from 0 (lightest) to 9 (most exhaustive).

Intensity 0 is equivalent to --version-light, sending only the most common probes for quick results. Intensity 7 is the default level, while intensity 9 ensures that every single possible probe is attempted against every port.

Selecting the right intensity is a balance between speed and accuracy. In stealth-conscious environments, lower intensity is preferred to avoid triggering Intrusion Detection Systems (IDS) with malformed packet signatures.

Security Operator Note: High intensity levels (8-9) are slow but useful for legacy systems or obscure protocols where standard probes fail.
Text
nmap -sV --version-intensity 9 192.168.1.10

Manual Banner Grabbing using Netcat (nc) and Telnet

Manual banner grabbing is a fundamental skill for confirming findings without automated tools. By connecting directly to a port, you can capture the initial greeting or banner sent by the application.

Netcat (nc) is the 'Swiss Army Knife' of networking. By sending a request to a service, you force the server to identify itself. Telnet is often used for legacy services like SMTP, POP3, or HTTP where the service waits for user input.

Below is a comparison of manual interaction methods for different protocols.

Security Operator Note: Always terminate your manual HTTP request with two carriage return/line feed pairs (\r\n\r\n) to mimic a legitimate browser request.
MethodCommand
Netcatecho 'HEAD / HTTP/1.0\r\n\r\n' | nc -nv 192.168.1.10 80
Telnettelnet 192.168.1.10 25

Identifying Outdated or Vulnerable Service Releases

Once you have gathered the version string, the next step is mapping it to known vulnerabilities. This is often automated with scripts, but understanding the raw logic is vital.

In this Python example, we create a simple socket connection to extract the banner. We then compare the captured string against a mock dictionary of known vulnerable patterns to demonstrate how detection logic works.

This logic is the foundation for tools like Searchsploit or local vulnerability scanning scripts.

Security Operator Note: Always sanitize banner strings before outputting them to a database to prevent injection attacks during your reporting phase.
Python 3
import socket
def get_banner(ip, port):
    try:
        s = socket.socket()
        s.settimeout(2)
        s.connect((ip, port))
        banner = s.recv(1024)
        return banner.decode().strip()
    except Exception as e:
        return "Error"

# Mock simulation of version comparison
service_info = "SSH-2.0-OpenSSH_7.2p2"
if "OpenSSH_7.2" in service_info:
    print(f"Detected {service_info}: Potential vulnerability identified (CVE-2016-6210)")
else:
    print(f"Detected {service_info}: No immediate match")

Knowledge Check

Ready to test your understanding of 4. Service Version Detection & Banner Grabbing?

Back