Knock on every door in the building
The site named one other host. But a building has more doors than its signs show.
Enumeration knocks on every door of every host in scope, notes which open, and asks what is behind each one.
The one rule
Warning
Scan only the hosts in scope, in your own lab copy. Scanning a network you do not have written permission to test can be a crime: in the UK under the Computer Misuse Act 1990. A scan of all 65,535 ports sends tens of thousands of connections.
Quick check: the rule
Have a go
Quick check: the rule
3 questionsBy the end of this lesson
Note
I can list the open ports and services on the hosts in scope with Nmap.
Key words
| Word | What it means | Example |
|---|---|---|
| Enumeration | listing what each host offers | |
| Connect scan | a scan that completes each connection | -sT |
| Open port | a port where a service answers | |
| Version detection | asking each service what it is | -sV |
| Privileges | what an account is allowed to do |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
4 questionsWho the scanner runs as decides the scan
A SYN scan builds its own packets, which needs root. The lab's scanner runs as an unprivileged account, as a cautious team would set it up.
So the lessons use a connect scan, -sT. It completes every connection, which is slower and shows in more logs.
Ask who the scanner runs as
docker exec scanner idShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try a SYN scan
docker exec scanner nmap -sS -Pn -p 8080 wwwShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsThe default scan is not every port
With no -p, Nmap tries the 1,000 ports it finds open most often. -Pn skips the check that a host is up, and -iL - reads the scope file again.
Run the default scan first, then all 65,535 ports with -p-. --open hides the closed ones.
Scan the 1,000 common ports
docker exec -i scanner nmap -sT -Pn -iL - < scope.txtShown here, not run. Press Start lab to type it into your own lab’s terminal.
Scan every port
docker exec -i scanner nmap -sT -Pn -p- --open -iL - < scope.txtShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsA common mistake
Warning
Many people think a default scan checks every port. It checks 1,000, and the cache's port is not one of them. When the scope allows it, scan every port of every host, or say in the report which ports you did not scan.
A version is what the service says
-sV sends each open port a few probes and matches the answers. It names the software and a version.
Those names come from banners, so treat them as claims. The cache, for one, runs Valkey, which answers as Redis.
Ask each service what it is
docker exec scanner nmap -sT -Pn -sV --open -p 8080,8000,6379 www intranet cacheShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try it: open or expected?
# The ports a full scan found, and the ones the college expected.
found = {"www": [8080], "intranet": [8000], "cache": [6379]}
expected = {"www": [8080], "intranet": [8000], "cache": []}
for host, ports in found.items():
for port in ports:
if port not in expected[host]:
print(host, port, "is open and nobody expected it")
# Add 6379 to the cache in expected. What changes?
Make a free account to save your work and track your progress.
How a defender sees a scan
A connect scan leaves a connection in every log it touches. A version scan also asks the web site for odd paths, such as /nmaplowercheck followed by a number.
The fix for enumeration is fewer doors: close what is not needed, and let only the portal reach the cache.
Find the version scan in the site's log
docker logs www 2>&1 | grep nmapShown here, not run. Press Start lab to type it into your own lab’s terminal.
Save the scan for a program
docker exec -i scanner nmap -sT -Pn -p- --open -oG - -iL - < scope.txtShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check nothing reached the supplier
docker logs hrShown here, not run. Press Start lab to type it into your own lab’s terminal.
Assignment: read a scan into a table
Nmap's grepable output (-oG -) has a line per host such as Host: 172.19.0.6 (www.lab)\tPorts: 8080/open/tcp//http-proxy///\tIgnored State: closed (65534). Several ports are separated by , . Write two functions.
open_ports(text) returns a dictionary from each host to a list of (port, service) tuples for its open ports, port a whole number, in the order given. The host is the name in brackets up to its first dot, or the address when the brackets are empty. Lines without Ports: are skipped. unexpected(found, expected) returns a sorted list of (host, port) for every open port in found that is not in expected, a dictionary from host to a list of ports. A host missing from expected expects nothing.
def open_ports(text):
return {}
def unexpected(found, expected):
return []
Make a free account to save your work and track your progress.
Exit quiz
Have a go