LibraryNetwork Scanning Fundamentals

Network Scanning Fundamentals

Learn about Network Scanning Fundamentals as part of OSCP Certification - Offensive Security Certified Professional

Network Scanning Fundamentals for Penetration Testing

Network scanning is a crucial first step in penetration testing. It involves actively probing a target network to discover live hosts, open ports, running services, and potential vulnerabilities. This process helps attackers (and defenders) understand the network's topology and identify potential entry points.

Why Network Scanning is Essential

Before any exploitation can occur, a penetration tester needs to know what they are up against. Network scanning provides this foundational intelligence. It answers critical questions like:

  • What devices are active on the network?
  • What operating systems are they running?
  • What services are exposed on these devices?
  • Are there any known vulnerabilities associated with these services or versions?

Key Concepts in Network Scanning

Host Discovery (Ping Sweeps)

The first step is often identifying which IP addresses on a network are actually active. This is commonly done using techniques like ICMP Echo Requests (traditional pings), ARP requests (on local networks), or TCP/UDP probes to common ports. A successful response indicates a live host.

What is the primary goal of host discovery in network scanning?

To identify which IP addresses on a network are active and responding.

Port Scanning

Once live hosts are identified, port scanning probes specific ports on those hosts to see if services are listening. Ports are numbered endpoints for network communication, with well-known ports assigned to common services (e.g., 80 for HTTP, 443 for HTTPS, 22 for SSH).

Port StateDescriptionImplication for PenTester
OpenA service is actively listening on this port.Potential attack vector; investigate the service.
ClosedNo service is listening, but the host is reachable.Less of an immediate concern, but indicates host is up.
FilteredA firewall or other network device is blocking access, preventing determination of open/closed.Indicates network segmentation or security controls; may require evasion techniques.

Common Port Scanning Techniques

Different techniques offer varying levels of stealth, speed, and accuracy. Understanding these is key for effective reconnaissance.

TCP SYN Scan (Stealth Scan): This is the most common and often default scan type. It sends a TCP SYN packet. If a SYN-ACK is received, the port is open. If an RST is received, the port is closed. If no response, it's filtered. Crucially, the connection is not fully established, making it stealthier than a full TCP connect scan. This technique is fundamental for identifying open TCP services.

📚

Text-based content

Library pages focus on text content

TCP Connect Scan: Attempts to complete the full TCP three-way handshake. If successful, the port is open. This is less stealthy as it leaves a record of connection establishment on the target system.

UDP Scan: Probes UDP ports. UDP is connectionless, so responses are less definitive. An ICMP Port Unreachable message indicates a closed port. No response might mean the port is open or filtered. UDP scans are generally slower and less reliable than TCP scans.

Service and Version Detection

Beyond just knowing a port is open, it's vital to identify the specific service running and its version. This information is critical for finding known exploits. Scanners achieve this by sending specific probes to open ports and analyzing the banner information or protocol responses.

Knowing the exact version of a service (e.g., Apache 2.4.41) is often the key to finding a specific exploit that targets a vulnerability in that version.

Operating System (OS) Fingerprinting

OS fingerprinting attempts to determine the operating system of the target host. This is done by analyzing subtle differences in how various operating systems respond to malformed or specific network packets (e.g., TCP window sizes, IP ID sequence, TTL values). Accurate OS detection can significantly narrow down the types of exploits that might be applicable.

Tools for Network Scanning

Several powerful tools are available for performing network scans. Proficiency with these tools is essential for any aspiring penetration tester.

Nmap (Network Mapper)

Nmap is the de facto standard for network scanning. It's incredibly versatile, supporting a wide range of scanning techniques, OS detection, version detection, and scripting capabilities (Nmap Scripting Engine - NSE) for more advanced tasks.

Masscan

Masscan is designed for extremely high-speed scanning of large networks. It can scan the entire internet in minutes by using asynchronous transmission and a custom TCP/IP stack.

Other Tools

Tools like hping3 and netcat (nc) can also be used for manual packet crafting and basic scanning tasks, offering a deeper understanding of the underlying network protocols.

Ethical Considerations and Best Practices

Network scanning can be intrusive. Always ensure you have explicit permission before scanning any network that you do not own or manage. Unauthorized scanning can have legal consequences and is unethical. When performing authorized scans, be mindful of network load and potential disruption.

Always obtain written authorization before conducting any penetration testing activities, including network scanning.

Learning Resources

Nmap Official Website(documentation)

The official Nmap website provides comprehensive documentation, tutorials, and download links for the most powerful network scanning tool.

Nmap Network Scanning Techniques(documentation)

Detailed explanations of various Nmap scanning techniques, including SYN, Connect, UDP, and more, with their pros and cons.

Offensive Security - Nmap Cheat Sheet(documentation)

A concise PDF cheat sheet from Offensive Security, perfect for quick reference of common Nmap commands and options.

Cybrary - Network Scanning Fundamentals(video)

A video course covering the basics of network scanning, including common tools and techniques, suitable for beginners.

Network Security Toolkit - Nmap Tutorial(tutorial)

A step-by-step tutorial on using Nmap for various network scanning tasks, often integrated with the Network Security Toolkit.

Wikipedia - Network Scanner(wikipedia)

An overview of network scanners, their purpose, types, and common applications in network administration and security.

Hacking Articles - TCP SYN Scan Explained(blog)

A blog post that breaks down the mechanics of a TCP SYN scan, explaining how it works and why it's a preferred method for stealth.

Kali Linux Documentation - Nmap(documentation)

Information on Nmap as a pre-installed tool in Kali Linux, with examples of its usage in a penetration testing context.

SANS Institute - Network Scanning Best Practices(documentation)

A poster and related resources from SANS Institute discussing ethical and effective practices for network scanning.

Masscan GitHub Repository(documentation)

The official GitHub repository for Masscan, including installation instructions, usage examples, and advanced configuration options.