Cybersecurity-Mastery

Home › Offensive Security › Scanning

Scanning

Host discovery, port and service scanning, versioning and safe scan tuning.

Beginner⌨ ~60 min hands-on📖 ~20 min read

▶ Here to build, not read? Jump to the Hands-On Practice.

Prerequisites: Offensive Security Methodology · Reconnaissance

Overview

Host discovery, port and service scanning, versioning and safe scan tuning. In one line: scanning decides where trust is placed, and misplaced trust is where the security problem lives. That's the theory you need — the understanding comes from doing it, so the walkthrough below is the heart of this chapter.

How it works

Mechanically, scanning comes down to three things: what data is trusted, where it crosses a boundary, and what happens on the other side. The diagram traces that path; you'll walk it for real, step by step, in the practice below.

flowchart TD
    A["Scanning"] --> B["Concepts & terminology"]
    A --> C["Internal mechanics"]
    C --> D["Trust boundaries"]
    D --> E["Attack surface"]
    D --> F["Defensive controls"]
    E --> G["Detection & telemetry"]
    F --> G
    G --> H["Verification in the lab"]
🔑 Key terms
  • Trust boundary — where data or control passes between components of different privilege or trust.
  • Attack surface — the set of points an attacker can interact with.
  • Primary control — the single measure that most reduces this technique's impact.
  • Telemetry — the log or signal a defender uses to detect the technique.

Hands-On Practice

Tip
This is the main event. Bring up the lab, then work the walkthrough — every command has a ▸ Run button (needs the lab runner) and a 📋 Copy button. ~60 min, Kali attacker, fully local.

Mission. Go from 'a subnet exists' to a full service/vuln picture with escalating Nmap technique.

🧪 Lab setup — Offensive Security

  • metasploitable — boot-to-root Linux target (recon → exploit → loot)
  • dvwa / juice-shop — web foothold targets
  • AD forest (optional) — GOAD or a Windows Server eval VM for AD chapters — see notes
docker-compose.yml
# offsec-lab/docker-compose.yml  —  Offensive part environment
services:
  target-linux:
    image: tleemcjr/metasploitable2
    networks: [labnet]
    command: /bin/sh -c "/etc/rc.local; tail -f /dev/null"
  target-web:
    image: vulnerables/web-dvwa
    ports: ["8082:80"]
    networks: [labnet]

networks:
  labnet:
    driver: bridge
    internal: true

Target for this lesson: net-target (Metasploitable 2) on labnet. Full setup: Offensive Security lab environment.

Guided walkthrough

1Discover live hosts
command
nmap -sn 172.18.0.0/24
Expected output
Host is up (0.00040s latency). 172.18.0.2
Ping sweep finds targets without touching ports — cheap and quiet.
2Find open ports
command
nmap -p- --min-rate 2000 172.18.0.2
Expected output
21,22,23,25,80,139,445,3306,5432... open
A full TCP scan reveals the whole listening surface, not just the common ports.
3Fingerprint services
command
nmap -sV -sC 172.18.0.2
Expected output
vsftpd 2.3.4, OpenSSH 4.7p1, Apache 2.2.8, MySQL 5.0.51a...
Versions map to known CVEs; default scripts add quick wins.
4Targeted vuln scripts
command
nmap --script vuln -p 21,80,139 172.18.0.2
Expected output
ftp-vsftpd-backdoor: VULNERABLE (CVE-2011-2523)
NSE flags exploitable services so you know where to focus.
5Save everything
command
nmap -A -oA scan 172.18.0.2
Expected output
scan.nmap / .xml / .gnmap written.
Machine-readable output feeds the rest of your workflow and your report.

Live terminal

kali@scanning — start the lab runner for a live shelloffline
Start the Lab Runner (see labserver/README.md), then click Connect lab runner and paste the token. Until then, copy commands from the walkthrough and run them in your own Kali terminal.
$

Try it yourself

Note
Try each for real. Open the hint only when stuck, the solution only to check.

Challenge 1. Scan the same host as quietly as possible and compare what an IDS would see.

Hint

Slower timing, fewer ports, no version probes.

Solution

-T2 -sS --top-ports 20 produces far fewer packets than -A -T4 -p-; capture both in Wireshark to compare.

Challenge 2. Identify one service you could exploit and cite its CVE — don't exploit yet.

Hint

vsftpd 2.3.4 and UnrealIRCd both have famous backdoors here.

Solution

vsftpd 2.3.4 → CVE-2011-2523 backdoor; note it for the Exploitation chapter.

Challenge 3. Write an nmap command that only checks whether SMB signing is enforced.

Hint

There's an NSE script for exactly this.

Solution

nmap --script smb2-security-mode -p445 <ip>

Quick quiz

In a packet capture, how does a TCP SYN scan appear?
A SYN scan sends SYN and never completes the handshake (RST after SYN-ACK) — the half-open pattern an IDS keys on.

Detect & defend (blue-team view)

  • In a Wireshark capture, a SYN scan appears as many SYNs with no completed handshakes — the IDS signature.
  • Suricata/Snort ship port-scan rules; run one and watch your scan light it up.

Skills check

You can move on when you can, without notes:

Check Yourself

Quick self-test — answers hidden. If you can't answer without notes, redo the relevant walkthrough step.

Q1. In one sentence, what security problem does Scanning address or create?

Show answer

Scanning matters because its behaviour determines where trust is placed; misplacing that trust is the root of the associated bug class.

Q2. Name one trust boundary involved in Scanning and what crosses it.

Show answer

Any point where attacker-influenced data meets privileged processing — e.g. user input reaching an interpreter, or a token reaching a verifier.

Q3. Give one attack against Scanning and the single control that most reduces its impact.

Show answer

State the attack precisely, then the primary control (validation, encoding, isolation, authentication, or least privilege) — not a laundry list.

Interview angles

  • Walk me through how Scanning works, then tell me where you would attack it.
  • How would you detect Scanning being abused in an environment you defend?
  • What is the difference between mitigating and eliminating the risk associated with Scanning?

Pitfalls & Best Practice

Common mistakes

  • Treating scanning as a checkbox instead of understanding the mechanism — defences copied without comprehension fail silently.
  • Trusting client-side or default controls to enforce a server-side security property.
  • Testing only the happy path and never the abuse cases or malformed input.
  • Fixing the symptom (one payload) instead of the class (the missing control).

Do this instead

  • Push security decisions to a single, well-tested enforcement point rather than scattering checks.
  • Fail closed: when in doubt, deny and log, so misconfiguration reduces access rather than expanding it.
  • Instrument the trust boundaries so the same event is visible to offence (as a target) and defence (as a signal).
  • Validate your understanding of scanning empirically in the lab before trusting it in production.
  • Prefer safe, high-level APIs and secure defaults over hand-rolled primitives.

Reference

MITRE ATT&CK Mapping

TechniqueID
ATT&CK techniqueT1046
ATT&CK techniqueT1595.001
ATT&CK techniqueT1595.002

OWASP Mapping

  • See OWASP Top 10 for the relevant category when this applies to web systems.

CWE Mapping

  • No direct weakness ID; when this concept fails in code it usually surfaces as one of the CWE Top 25 entries.

CAPEC Mapping

  • No single attack pattern; see the CAPEC chapter to map behaviour to patterns.

CVE References

  • No canonical CVE for a concept page. Search the NVD for concrete instances when studying real cases.

NIST References

RFC References

  • No governing RFC for this topic. Where a protocol is involved, its RFC is linked from the relevant networking chapter.

Research Papers

  • Reflections on Trusting Trust — Ken Thompson, 1984
  • Smashing the Stack for Fun and Profit — Aleph One, Phrack 49, 1996
  • The Protection of Information in Computer Systems — Saltzer & Schroeder, 1975

Books

  • The Hacker Playbook 3 — Peter Kim
  • Penetration Testing — Georgia Weidman
  • Red Team Field Manual (RTFM) — Ben Clark
  • Advanced Penetration Testing — Wil Allsopp

Official Documentation


Part of the Offensive Security section of Cybersecurity-Mastery. 🟢 Beginner · ~60 min hands-on · Last updated 2026-08-12.

Cybersecurity-Mastery — interactive security learning · runs locally