All posts
Scanning with Nmap: Gathering Info
Security Nmap — Part 2
EN ES

Scanning with Nmap: Gathering Info

A practical Nmap scanning strategy: service fingerprinting, OS detection, timing control, and advanced flags.

4 min read by b4rt

Series: Nmap

  1. 1. Nmap Port Scanning Techniques
  2. 2. Scanning with Nmap: Gathering Info

Gathering Information with Nmap

The sequence of commands we’ll use is more of a recommendation than a standard. The strategy is as follows:

  1. Run a default scan using Nmap’s top 1000 ports.
  2. Run a scan of all 65535 ports.
  3. Once we have mapped the open ports, list them and use other arguments like -sV, -O, -sC.
  4. With the versions, OS, and characteristics of each port and service, use Nmap scripts.

Step 1 — Default scan

The first step is to run a default scan against Nmap’s most common port list:

nmap -Pn 192.168.1.28 -vv --reason

Flags used:

FlagDescription
-PnSkip host discovery when we already know the host is up
-vvVerbosity level 2 in the command output
--reasonShows why each port is in its reported state

In the quick scan results we can observe:

  • The -sS scan was used (the 3-way handshake was not completed).
  • With --reason we see the justification for each port’s state.
  • 3 open ports and one filtered were detected.

Step 2 — Full scan of all 65535 ports

The next step is to scan all ports:

nmap 192.168.1.28 -T4 -p 1-65535 -vv --reason

Additional flags:

FlagDescription
-T4Timing control. Default is T3. Higher number = more aggressive and less precise
-p 1-65535Port range to scan
--openShows only open ports, useful to reduce time on large scans

In the results we can see that, besides the 3 previous ports, a new one was detected (48500) — open but with no service name identified.


Step 3 — Service fingerprinting and OS detection

Once open ports are identified, we analyze them with -sV and -O to get versions and operating system:

nmap 192.168.1.28 -p 21,22,80,48500 -sV -O -vv --reason

Flags:

FlagDescription
-pPorts separated by commas
-sVNmap fingerprints ports to obtain service versions and names
-OAttempts to identify the operating system and version

Observations from the results:

  • Fingerprinting identified that port 48500 was running PostgreSQL.
  • The system was identified as Linux.
  • The OpenSSH service helped determine it was specifically a Debian system.

Advanced timing control

We need to consider time when scanning and combine parameters correctly. Two very useful flags:

FlagDescription
--host-timeoutMaximum time given to Nmap to gather host information. Less time = less accurate scan
--max-retriesHow many times Nmap will probe a given port

Some examples:

# Scan with 60-minute timeout and 10 retries
nmap 192.168.1.28 --host-timeout 60m --max-retries 10 -vv --reason

# Full port scan with 2-hour timeout
nmap 192.168.1.28 -p 1-65535 --host-timeout 120m --max-retries 5 -vvv --reason

Nmap timing templates

Using timing well is vital — rushing can cause Nmap to not work correctly. Also, we don’t always want to use -T5 — it’s easily detectable and, being very fast, tends to fail on unreliable networks. The Nmap author recommends using -T4.

TemplateNameDescription
-T0ParanoidVery slow, designed to evade IDS
-T1SneakySlow, for evading detection
-T2PoliteSlower than normal to reduce network load
-T3NormalDefault behavior
-T4AggressiveFaster, assumes a fast and reliable network
-T5InsaneExtremely fast, may miss information

In the next post we’ll see how to use Nmap Scripts (NSE) for more advanced analysis, because as I mentioned at the start, Nmap isn’t just for gathering information…

Tags: #nmap #hacking #security #ports #tcp #pentest #linux #fingerprint

Comments

Stay in the loop

New posts about Linux, debugging, and systems programming. No noise, no spam — just signal.