Opening Framing: From Intelligence to Attack Surface
Reconnaissance told you about the organization. Now it's time to discover exactly what's running on their systems. Scanning and enumeration move from passive intelligence gathering to active interaction with target systems.
Port scanning reveals open services. Service enumeration identifies what's running on those ports. Deep enumeration extracts usernames, shares, configurations, and other details that enable exploitation.
This week covers network scanning with Nmap, service enumeration techniques, and how to systematically extract information from discovered services.
Key insight: Every open port is a potential entry point. Thorough enumeration ensures you don't miss opportunities.
1) Network Scanning Fundamentals
Understanding how scanning works:
Port States:
Open:
- Service accepting connections
- Potential attack vector
- Needs enumeration
Closed:
- Port accessible but no service
- Host is reachable
- Firewall allows traffic
Filtered:
- No response received
- Firewall blocking
- Can't determine if open/closed
Unfiltered:
- Port accessible
- Can't determine open/closed
- Seen in ACK scans
TCP Scanning Methods:
TCP Connect Scan (-sT):
- Completes full TCP handshake
- SYN → SYN-ACK → ACK
- Most reliable
- Easily logged
- Slower
TCP SYN Scan (-sS):
- "Stealth" scan
- Sends SYN, waits for SYN-ACK
- Doesn't complete handshake
- Faster, less logged
- Requires root/admin
TCP handshake:
Client Server
|--- SYN ----->|
|<- SYN-ACK ---|
|--- ACK ----->|
[Connection established]
SYN scan stops here:
|--- SYN ----->|
|<- SYN-ACK ---|
|--- RST ----->|
[Connection reset]
Other Scan Types:
UDP Scan (-sU):
- Scans UDP ports
- Much slower than TCP
- Essential for DNS, SNMP, DHCP
- Open ports often don't respond
FIN/NULL/Xmas Scans:
- Send malformed packets
- Attempt to bypass firewalls
- Less reliable on Windows
- -sF, -sN, -sX
ACK Scan (-sA):
- Maps firewall rules
- Doesn't find open ports
- Shows filtered vs unfiltered
Version Detection (-sV):
- Probes open ports
- Identifies services and versions
- Essential for vulnerability assessment
Key insight: Different scan types serve different purposes. SYN scans are fast and stealthy; connect scans are reliable; UDP scans catch services others miss.
2) Mastering Nmap
Nmap is the essential scanning tool:
Basic Syntax:
nmap [scan type] [options] [target]
Target specification:
nmap 192.168.1.1 # Single IP
nmap 192.168.1.1-254 # Range
nmap 192.168.1.0/24 # CIDR notation
nmap target.com # Hostname
nmap -iL targets.txt # File input
Common scans:
# Quick scan - top 1000 ports
nmap 192.168.1.1
# Full port scan
nmap -p- 192.168.1.1
# Specific ports
nmap -p 22,80,443,8080 192.168.1.1
# Port range
nmap -p 1-1000 192.168.1.1
# Service version detection
nmap -sV 192.168.1.1
# OS detection
nmap -O 192.168.1.1
# Aggressive scan (OS, versions, scripts, traceroute)
nmap -A 192.168.1.1
Nmap Scripting Engine (NSE):
NSE extends Nmap's functionality:
# Default scripts (safe)
nmap -sC 192.168.1.1
# Specific script
nmap --script=http-title 192.168.1.1
# Script category
nmap --script=vuln 192.168.1.1
# Multiple scripts
nmap --script=http-title,http-headers 192.168.1.1
Script categories:
- auth: Authentication bypass
- broadcast: Network discovery
- brute: Brute force attacks
- default: Safe, useful scripts
- discovery: Service discovery
- exploit: Actual exploits (careful!)
- fuzzer: Fuzzing tests
- intrusive: May crash services
- malware: Malware detection
- safe: Won't harm targets
- version: Version detection
- vuln: Vulnerability checks
# List available scripts
ls /usr/share/nmap/scripts/
nmap --script-help=*http*
Professional Nmap Usage:
# Comprehensive scan workflow:
# 1. Host discovery
nmap -sn 192.168.1.0/24 -oG hosts.txt
# 2. Quick port scan on live hosts
nmap -iL live_hosts.txt -p- --min-rate=1000 -oA quick_scan
# 3. Detailed scan on open ports
nmap -iL live_hosts.txt -p [open_ports] -sV -sC -oA detailed_scan
# Output formats:
-oN normal.txt # Normal output
-oG grepable.txt # Grepable format
-oX scan.xml # XML output
-oA basename # All formats
# Speed/timing:
-T0 # Paranoid (very slow, IDS evasion)
-T1 # Sneaky
-T2 # Polite
-T3 # Normal (default)
-T4 # Aggressive
-T5 # Insane (fast, may miss ports)
# Useful combinations:
# Stealth scan with version detection
nmap -sS -sV -p- -T4 -oA full_scan target.com
# Vulnerability scan
nmap -sV --script=vuln -oA vuln_scan target.com
Key insight: Nmap is incredibly powerful, but it takes practice to use effectively. Learn the options—they matter.
3) Service Enumeration
Once you find open ports, enumerate the services:
SMB Enumeration (445/139):
# Nmap SMB scripts
nmap -p 445 --script=smb-enum-shares,smb-enum-users 192.168.1.1
# smbclient - list shares
smbclient -L //192.168.1.1 -N
# smbmap - show permissions
smbmap -H 192.168.1.1
# enum4linux - comprehensive SMB enum
enum4linux -a 192.168.1.1
# Access a share
smbclient //192.168.1.1/share_name
Information to extract:
- Share names and permissions
- User accounts
- Password policy
- OS version
- Domain/workgroup
HTTP/HTTPS Enumeration (80/443):
# Nmap HTTP scripts
nmap -p 80,443 --script=http-title,http-headers,http-methods 192.168.1.1
# Directory brute forcing
gobuster dir -u http://target.com -w /usr/share/wordlists/dirb/common.txt
# More thorough
gobuster dir -u http://target.com -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html
# Feroxbuster (faster, recursive)
feroxbuster -u http://target.com -w /usr/share/seclists/Discovery/Web-Content/common.txt
# Nikto - web vulnerability scanner
nikto -h http://target.com
# Curl for manual inspection
curl -I http://target.com
curl -X OPTIONS http://target.com -v
Things to find:
- Admin panels
- Configuration files
- Backup files (.bak, .old)
- Source code files
- API endpoints
- Hidden directories
FTP Enumeration (21):
# Nmap FTP scripts
nmap -p 21 --script=ftp-anon,ftp-syst 192.168.1.1
# Manual connection
ftp 192.168.1.1
# Anonymous login
Username: anonymous
Password: anonymous@
# Check for:
# - Anonymous access
# - Write permissions
# - Sensitive files
# - FTP version (CVEs)
SSH Enumeration (22):
# Banner grab
nc 192.168.1.1 22
# Nmap scripts
nmap -p 22 --script=ssh-auth-methods,ssh-hostkey 192.168.1.1
# Check for:
# - SSH version
# - Supported authentication methods
# - Key types
# - Known vulnerabilities (old versions)
DNS Enumeration (53):
# Zone transfer attempt (if allowed)
dig axfr @192.168.1.1 target.com
# DNS enumeration
dnsrecon -d target.com -t std
# Nmap DNS scripts
nmap -p 53 --script=dns-zone-transfer 192.168.1.1
Key insight: Each service has its own enumeration techniques. Generic scanning finds the ports; service-specific enumeration finds the vulnerabilities.
4) SNMP Enumeration
SNMP often reveals extensive system information:
SNMP Basics:
- Simple Network Management Protocol
- UDP port 161
- Community strings act as passwords
- Default: "public" (read), "private" (write)
- SNMPv1 and v2c send community strings in cleartext
Why SNMP matters:
- System information
- Network configuration
- Running processes
- Installed software
- User accounts
- ARP tables
SNMP Enumeration Commands:
# Check if SNMP is open
nmap -sU -p 161 192.168.1.1
# Brute force community strings
onesixtyone -c /usr/share/seclists/Discovery/SNMP/common-snmp-community-strings.txt 192.168.1.1
# Enumerate with known community string
snmpwalk -v2c -c public 192.168.1.1
# Get system info
snmpwalk -v2c -c public 192.168.1.1 system
# Get running processes
snmpwalk -v2c -c public 192.168.1.1 hrSWRunName
# Get installed software
snmpwalk -v2c -c public 192.168.1.1 hrSWInstalledName
# Get network interfaces
snmpwalk -v2c -c public 192.168.1.1 ifDescr
# Nmap SNMP scripts
nmap -sU -p 161 --script=snmp-info,snmp-processes,snmp-interfaces 192.168.1.1
Useful OIDs:
Common OIDs to query:
1.3.6.1.2.1.1 - System info
1.3.6.1.2.1.1.1.0 - System description
1.3.6.1.2.1.1.5.0 - Hostname
1.3.6.1.2.1.25.1 - Host resources
1.3.6.1.2.1.25.4.2 - Running processes
1.3.6.1.2.1.25.6.3 - Installed software
# Example: Get hostname
snmpget -v2c -c public 192.168.1.1 1.3.6.1.2.1.1.5.0
Key insight: SNMP is often overlooked but can reveal everything about a system—including credentials in some cases.
5) Enumeration Automation and Organization
Efficient enumeration requires organization:
Automated Enumeration Tools:
AutoRecon:
# Comprehensive automated scanning
autorecon 192.168.1.1
# Creates organized directory structure
# Runs service-specific scans automatically
nmapAutomator:
# Staged scanning approach
./nmapAutomator.sh 192.168.1.1 All
Legion (GUI):
# Graphical interface for scanning/enumeration
# Good for visualizing results
Organizing Enumeration Results:
Directory structure:
target_192.168.1.1/
├── nmap/
│ ├── initial_scan.nmap
│ ├── full_port_scan.nmap
│ ├── service_scan.nmap
│ └── vuln_scan.nmap
├── web/
│ ├── gobuster.txt
│ ├── nikto.txt
│ └── screenshots/
├── smb/
│ ├── enum4linux.txt
│ └── shares.txt
├── snmp/
│ └── snmpwalk.txt
└── notes.md
Enumeration Checklist:
Per-port enumeration checklist:
□ Port 21 (FTP)
□ Banner grab
□ Anonymous login attempt
□ Version → CVE check
□ Port 22 (SSH)
□ Banner/version
□ Auth methods
□ Version → CVE check
□ Port 25/587 (SMTP)
□ VRFY/EXPN commands
□ Open relay check
□ Port 53 (DNS)
□ Zone transfer attempt
□ DNS enumeration
□ Port 80/443 (HTTP/S)
□ Technology fingerprinting
□ Directory brute forcing
□ Vulnerability scanning
□ robots.txt, sitemap.xml
□ Port 139/445 (SMB)
□ Share enumeration
□ User enumeration
□ Null session check
□ Port 161 (SNMP)
□ Community string brute force
□ Full SNMP walk
□ Port 389/636 (LDAP)
□ Anonymous bind
□ User enumeration
□ Port 3306 (MySQL)
□ Version detection
□ Default credentials
□ Port 3389 (RDP)
□ NLA check
□ Version/CVE
Key insight: Checklists prevent missed opportunities. Systematic enumeration beats random poking every time.
Real-World Context: Scanning in Engagements
How scanning works in professional pentesting:
Noise Considerations: Real scans generate logs and alerts. Discuss with the client whether stealth matters. Some tests intentionally test detection capabilities; others prioritize thoroughness over stealth.
Scan Timing: Production networks may be sensitive to scan traffic. Coordinate timing, use appropriate scan speeds, and have emergency contacts ready.
False Positives: Nmap and other tools sometimes misidentify services. Always verify interesting findings manually before including in reports.
MITRE ATT&CK Mapping:
- T1046 - Network Service Discovery: Port scanning
- T1135 - Network Share Discovery: SMB enumeration
- T1087 - Account Discovery: User enumeration
- T1018 - Remote System Discovery: Host discovery
Key insight: Scanning is noisy. In real engagements, balance thoroughness with operational considerations.
Guided Lab: Network Scanning Exercise
Practice comprehensive scanning against lab targets.