COMP-221 · Lesson 11 of 12 · 20 min

Reading reconnaissance tool output

▶ Video coming soon A video version of this lesson is on the way.

By the end of October, Ironwhistle's Prairiefold share held more than 400 files of reconnaissance output: Nmap scans in three formats, DNS results, certificate lists, crawl logs, packet captures, wireless surveys and BloodHound data. Ana Sokolova-Reyes called it the haystack. Her question to Tobias, at the weekly quality review, was simple: if someone points at any line in our target profile, can you show them the evidence behind it within two minutes? He could, mostly. This lesson is about making that a reliable yes.

Reading tool output accurately is tested throughout the PenTest+ exam, often in performance-based questions that show a screen of output and ask what it means. This lesson covers reading the main output formats, objective 2.3's modification of scripts for reconnaissance and enumeration, including the logic constructs and languages it lists (Bash, Python and PowerShell), and objective 2.4's expectation that you can use tool results, not just run tools.

The habits of reading output

Experienced testers read output in the same order every time. First, the command: what was actually run, with which options, against which targets? Second, the context: when, from where, with which privileges? Third, the summary lines, which often reveal problems such as hosts skipped or timeouts. Only then the details. Many misreadings come from skipping the first step, for example interpreting a scan as complete when it only covered the top 100 ports.

Questions to answer before interpreting a scan.
QuestionWhere to find the answer in Nmap output
What was run?The command line recorded at the top of normal and XML output
When, and how long did it take?Start time at the top; elapsed time in the final summary
Were hosts treated as up without discovery?The -Pn option in the command line
Which ports were covered?The -p or --top-ports option; the scaninfo element in XML
Why is a port in this state?The REASON column with --reason, for example syn-ack, reset or no-response
Were any hosts skipped or timed out?Warnings in the output and the final host counts

Nmap output formats

Nmap writes several output formats, and Ironwhistle saved all three with -oA on every scan.

Nmap output formats.
FormatOptionBest for
Normal-oNPeople reading results; matches the screen
XML-oXOther tools, reports and scripts; the most complete format
Grepable-oGQuick filtering with command-line tools; one line per host; deprecated but still widely used
All three-oA basenameEvidence: one scan, every format

XML is the format to trust for anything automated. It records every host, port, state, reason, service fingerprint and script result in a structured way, and tools from vulnerability scanners to reporting platforms import it. Nmap also ships with a stylesheet that turns XML into a readable HTML report, which Ironwhistle used when sharing raw results with Felix.

An abbreviated host element from Nmap XML output. method="probed" with conf="10" means version detection confirmed the service; method="table" would mean a guess from the port number.
<host starttime="1791306241" endtime="1791306655">
  <status state="up" reason="echo-reply"/>
  <address addr="203.0.113.44" addrtype="ipv4"/>
  <ports>
    <extraports state="filtered" count="65533"/>
    <port protocol="tcp" portid="3389">
      <state state="open" reason="syn-ack"/>
      <service name="ms-wbt-server" product="Microsoft Terminal Services" ostype="Windows" method="probed" conf="10"/>
    </port>
  </ports>
</host>

The method and conf attributes are a detail worth remembering. They show whether the service name came from actual probing or only from Nmap's table of common port assignments, which is exactly the distinction lesson 5 warned about in the SERVICE column.

Reading other tools' output

Every tool in this course has its own output style, and the exam may show any of them. A few patterns cover most cases.

Reading the main reconnaissance tools.
ToolKey things to readCommon misreading
digStatus, flags (aa for authoritative), answer section, TTLTreating NOERROR with no answers as NXDOMAIN
theHarvester and AmassEach result's source; resolved addressesAssuming every name found is live and in scope
tcpdumpTimestamp, source and destination with ports, flags such as [S] and [S.] for SYN and SYN-ACKConfusing direction of a conversation
WiresharkProtocol hierarchy, conversations, display filter resultsReading only the first packets of a long capture
NetExec share listingHost line (OS, signing, SMBv1) and permissions per shareMissing the signing:False detail in the host line
airodump-ngENC, CIPHER, AUTH and ESSID columns; stations tableTreating a blank ESSID as no network
Directory brute forceStatus code, size, words, redirectsTrusting 200 responses from a catch-all page
A TCP handshake in tcpdump: SYN, SYN-ACK (shown as [S.]), ACK, then the first data push, which here is the start of a TLS handshake.
sudo tcpdump -nn -i eth0 host 192.0.2.25 and tcp port 443 -c 4
Output
10:14:02.118274 IP 192.0.2.200.51544 > 192.0.2.25.443: Flags [S], seq 3410992212, win 64240, length 0
10:14:02.118893 IP 192.0.2.25.443 > 192.0.2.200.51544: Flags [S.], seq 1182930441, ack 3410992213, win 65160, length 0
10:14:02.118951 IP 192.0.2.200.51544 > 192.0.2.25.443: Flags [.], ack 1, win 502, length 0
10:14:02.121540 IP 192.0.2.200.51544 > 192.0.2.25.443: Flags [P.], seq 1:518, ack 1, win 502, length 517

Why testers modify scripts

Objective 2.3 asks you to modify scripts, not to write large programs from scratch. In practice, testers constantly adapt small scripts: a loop that resolves a list of names, a filter that pulls open ports out of grepable output, a PowerShell snippet that checks connectivity to a list of hosts from a Windows foothold. The exam typically shows a short script and asks what it does, what is wrong with it, or which change would make it do something new. Recognizing the building blocks matters more than memorizing syntax.

The same logic constructs in the three languages objective 2.3 names.
ConstructBashPowerShellPython
Variablename=value, read back with a dollar-sign prefixDollar-sign prefix on every variablename = value, no prefix
Loop over itemsfor x in list; do ... doneforeach (x in list) with prefixed variables, or ForEach-Objectfor x in items:
Loop while truewhile condition; do ... donewhile (condition) { }while condition:
Conditionalif [ test ]; then ... fiif (condition) { } else { }if condition: ... else:
Equality test= for strings, -eq for numbers-eq (case-insensitive by default)==
Boolean operatorsDouble ampersand for AND, double pipe for OR, exclamation mark for NOT-and, -or, -notand, or, not
String match[[ string =~ regex ]]-match and -likeThe re library, or "in" for substrings
ArithmeticArithmetic expansion with double parenthesesOrdinary operators such as + and *Ordinary operators such as + and *
ReuseFunctions; source other scriptsFunctions, modules, cmdletsFunctions, classes, imported libraries

A Bash example: resolving and scoping names

Tobias's first script took the candidate names from lesson 3, resolved each one, and marked whether its address was inside the in-scope block. The first version worked, but had a weakness Ana spotted straight away.

Version 1: a while loop reads names, dig resolves them, a regular expression and an arithmetic test decide scope.
#!/usr/bin/env bash
# Resolve candidate names and flag whether each address is in scope (203.0.113.0/26)
while read -r name; do
    ip=$(dig +short "$name" A | head -n1)
    if [[ $ip =~ ^203\.0\.113\.([0-9]+)$ ]] && (( BASH_REMATCH[1] <= 63 )); then
        echo "$name,$ip,IN-SCOPE"
    else
        echo "$name,$ip,CHECK"
    fi
done < candidates.txt > resolved.csv

Reading it line by line: the while loop reads one name at a time from candidates.txt; the dig command substitution captures the first A record; the conditional uses a regular expression match with =~ to check the address begins with 203.0.113 and captures the last octet, then an arithmetic comparison checks it is 63 or less; the two echo lines write comma-separated results; and the redirection at the end sends all output to a CSV file.

Ana's point was about the first answer from dig. If a name is a CNAME, dig +short prints the alias target first, not an address, so the regular expression fails and the name is marked CHECK even when the final address is in scope. Worse, if a name had several A records, only the first was checked. The modification Tobias made was to filter dig's output to lines that look like addresses and to loop over every address returned, checking each, and to mark names with no address as NO-ANSWER instead of leaving the field empty. That is exactly the kind of modification objective 2.3 describes: understand what the script does, see where it fails on real data, and change it.

Version 2: a function for the scope test, a filter for address lines, a for loop over every address, and a NO-ANSWER case.
#!/usr/bin/env bash
# Version 2: handle aliases, multiple addresses and names with no answer
in_scope() {                       # function: is this IPv4 address in 203.0.113.0/26?
    [[ $1 =~ ^203\.0\.113\.([0-9]+)$ ]] && (( BASH_REMATCH[1] <= 63 ))
}
while read -r name; do
    addrs=$(dig +short "$name" A | grep -E "^[0-9.]+$")
    if [[ -z $addrs ]]; then
        echo "$name,,NO-ANSWER"; continue
    fi
    for ip in $addrs; do
        if in_scope "$ip"; then echo "$name,$ip,IN-SCOPE"; else echo "$name,$ip,CHECK"; fi
    done
done < candidates.txt > resolved.csv

Filtering scan results on the command line

Grepable Nmap output has one line per host, which makes simple filters easy. Typical tasks are listing hosts with a particular port open, or counting how many hosts expose each service. Pipelines of grep, cut, awk, sort and uniq do this quickly.

Filtering grepable output: hosts with a given port open, and a count of open services across the server network.
# Hosts with RDP open, from grepable output
grep "3389/open" E1-tcp-all-20261006.gnmap | awk "{print \$2}"

# Count open ports across all internal servers, most common first
grep -oE "[0-9]+/open/tcp//[a-z0-9-]*" HO-tcp-top1000.gnmap | cut -d/ -f1,5 | sort | uniq -c | sort -rn | head
Output
     68 445/microsoft-ds
     66 135/msrpc
     41 3389/ms-wbt-server
     19 80/http
     17 443/https
      6 1433/ms-sql-s
      4 22/ssh
      3 161/snmp

A PowerShell example: checking reachability from Windows

On a Windows foothold, PowerShell is the natural language. It passes objects rather than text between commands, which makes filtering by property easy. A common reconnaissance snippet tests whether a list of hosts accept connections on a port, useful for checking segmentation from a branch workstation.

A foreach loop, a conditional joining two tests with -and, a -notlike pattern that skips addresses 192.0.2.10 to 192.0.2.19 (the domain controllers, which every workstation must reach), and objects exported to CSV.
# Which head office servers accept SMB from this branch workstation?
$servers = Get-Content .\HO-servers.txt
foreach ($s in $servers) {
    $r = Test-NetConnection -ComputerName $s -Port 445 -WarningAction SilentlyContinue
    if ($r.TcpTestSucceeded -and $s -notlike "192.0.2.1?") {
        [PSCustomObject]@{ Server = $s; Port = 445; Reachable = $true }
    }
} | Export-Csv .\BR07-to-HO-smb.csv -NoTypeInformation

The exam might ask what this snippet produces (a CSV of servers reachable on 445, excluding the domain controller range) or how to change it, for example to test several ports by adding an inner loop over a list of port numbers, or to record unreachable servers as well by moving the object creation outside the if statement and setting Reachable to the test result.

Python: libraries, functions and classes

Python is the third language objective 2.3 names, and the one most reconnaissance tools are written in. What the objective expects is recognition of how Python scripts are structured. Libraries are imported to provide capabilities: socket for raw network connections, a DNS library for lookups, an HTTP library for web requests, an XML or JSON parser for tool output, and wrappers that run Nmap and return its results as data structures. Functions group steps that are reused, such as resolving a name or checking scope. Classes bundle data and behaviour, for example a Host class holding an address, names and open ports, with a method that reports whether the host is in scope.

Pseudocode with the structure of a typical Python reconnaissance script: a class, a function that parses Nmap XML, a loop, and a conditional combining two tests with a Boolean AND.
DEFINE class Host with address, names (list), ports (list)
    METHOD in_scope(): RETURN address is inside 203.0.113.0/26

FUNCTION load_nmap_xml(file):
    hosts = empty list
    FOR EACH host element in parsed XML of file:
        h = new Host(address of element)
        FOR EACH port element with state "open":
            ADD (port number, service name, method) to h.ports
        ADD h to hosts
    RETURN hosts

FOR EACH h IN load_nmap_xml("E1-tcp-all-20261006.xml"):
    IF h.in_scope() AND any port in h.ports has number 3389:
        PRINT h.address, "RDP exposed"

From output to a target list

Scripts and filters exist to turn many files into one trustworthy picture. Ironwhistle's process followed the same steps every time.

Six boxes joined by arrows: raw output from Nmap XML, DNS, CT and crawl logs; parse fields, not screen text; normalize names, IPs, ports and versions; merge and dedupe by host; check scope and flag out-of-scope entries; and a target list with source and time. A note says keep the raw files: every line in the report must trace back to evidence.
The path from raw output to a target list.

Parsing structured formats rather than screen text avoids errors when output layouts change. Normalizing means writing names in lower case, removing trailing dots from DNS names, using one format for addresses, and recording versions consistently. Merging by host brings together the DNS names, open ports, fingerprints and web findings for each address. The scope check runs again at this stage, because merging can pull in addresses from passive sources that were never checked. Finally, every row in the target list keeps a pointer to the files it came from and when they were produced.

Quality checks

Ana's weekly review used a short checklist. Do the host counts in the target list match the scan summaries? Does every external host in the list have a full TCP scan and a top-100 UDP scan on record? Does every service with a version claim have a probed result rather than a table guess? Are any out-of-scope addresses present anywhere other than the out-of-scope register? Are personal data and secrets masked in working files? Errors caught here are cheap; errors caught by a client reading the final report are not.

Worked problem

What does this script do, and what is wrong with it?

A colleague shares a one-line Bash loop for banner grabbing: a for loop over every address in live.txt that runs nc -nv -w 2 against each address on port 22. The live.txt file contains internal and external hosts. What does it do, and what should be changed before running it?

Show solution
  1. It loops over every address in live.txt and opens a netcat connection to port 22 with a two-second timeout, printing any SSH banner.
  2. It does not check scope or the testing window: live.txt mixes internal and external hosts, and running it from the wrong test point would send traffic to the wrong networks.
  3. It produces no record of which output came from which host beyond netcat's own messages, and nothing is saved to a file.
  4. Modify it to read a scope-checked target file for one test point, prefix each banner with the host and time, and redirect output to an evidence file.

Answer: It grabs SSH banners from every host in the file; add a scope-checked target list, labelled output and a saved evidence file before use.

Common mistakes

  • MistakeInterpreting results without checking the command and options used.

    InsteadRead the command, context and summary lines before the details.

  • MistakeParsing normal output with fragile text matching.

    InsteadUse XML or JSON output for anything automated.

  • MistakeTaking the first line of dig output as the address.

    InsteadFilter for address records and handle aliases and multiple answers.

  • MistakeRunning a colleague's script without reading it.

    InsteadRead every line, check its targets against scope, and make it log its output.

  • MistakeDiscarding raw files once the target list is built.

    InsteadKeep raw evidence so every line in the profile can be traced.

Summary and key terms

  • Read output in order: command, context, summary, details.
  • Nmap writes normal, XML and grepable output; save all three with -oA and use XML for automation.
  • In Nmap XML, method="probed" marks a confirmed service and method="table" a guess.
  • Objective 2.3 expects you to read and modify short Bash, PowerShell and Python scripts.
  • Loops, conditionals, Boolean, string and arithmetic operators, functions, libraries and classes are the building blocks.
  • Raw output becomes a target list by parsing, normalizing, merging, scope checking and recording sources.
  • Quality checks catch errors before the client does.
Grepable output
Nmap's one-line-per-host output format designed for command-line filtering.
Command substitution
In Bash, running a command and using its output as a value.
Regular expression
A pattern for matching text, used with =~ in Bash and -match in PowerShell.
Pipeline
Passing the output of one command to the next; text in Bash, objects in PowerShell.
Library
Reusable code imported into a script to provide capabilities such as networking or parsing.
Class
A definition that bundles data and the functions that act on it.
Normalization
Converting data into a consistent format before merging.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which Nmap output format should a reporting script read, and why?

    Show answer

    XML, because it is the most complete and structured format.

  2. In tcpdump output, what does Flags [S.] indicate?

    Show answer

    A SYN-ACK packet: SYN with the acknowledgement flag shown as a dot.

  3. How would you change the PowerShell snippet to test ports 445 and 3389?

    Show answer

    Add an inner loop over a list containing both ports, passing each to Test-NetConnection and recording the port in the output object.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz