Port scanning is a crucial step in the penetration testing process. It involves probing a target system to identify open ports and the services running on them. This information helps pentesters understand the attack surface and potential vulnerabilities of the target system.
Key Concepts
-
Ports and Protocols:
- Ports: Logical endpoints for communication. Ports are numbered from 0 to 65535.
- Protocols: Rules governing data communication. Common protocols include TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).
-
Types of Port Scans:
- TCP Connect Scan: Establishes a full TCP connection.
- SYN Scan: Sends SYN packets to identify open ports without completing the handshake.
- UDP Scan: Probes UDP ports, which can be slower and less reliable.
- Xmas Scan: Sends packets with the FIN, PSH, and URG flags set.
- ACK Scan: Used to map firewall rulesets.
-
Tools for Port Scanning:
- Nmap: A powerful and widely-used network scanning tool.
- Masscan: Known for its speed, capable of scanning the entire Internet in minutes.
- Zenmap: A graphical interface for Nmap.
Practical Example: Using Nmap for Port Scanning
Basic TCP Connect Scan
-sT
: Specifies a TCP connect scan.<target-ip>
: The IP address of the target system.
SYN Scan
-sS
: Specifies a SYN scan.
UDP Scan
-sU
: Specifies a UDP scan.
Comprehensive Scan
-p-
: Scans all 65535 ports.
Example Explanation
- This command performs both SYN and UDP scans on all ports of the target IP
192.168.1.1
.
Practical Exercises
Exercise 1: Basic TCP Connect Scan
- Perform a TCP connect scan on a local machine.
- Identify the open ports and the services running on them.
Solution:
- This command scans the local machine (
127.0.0.1
) using a TCP connect scan.
Exercise 2: SYN Scan on a Remote Machine
- Perform a SYN scan on a remote machine within your network.
- Document the open ports and the services identified.
Solution:
- This command performs a SYN scan on the remote machine with IP
192.168.1.10
.
Exercise 3: Comprehensive Scan
- Perform a comprehensive scan (both TCP and UDP) on a target machine.
- Analyze the results and identify any potential vulnerabilities.
Solution:
- This command performs a comprehensive scan on the target machine with IP
192.168.1.10
.
Common Mistakes and Tips
- Firewall Interference: Firewalls can block or filter scan attempts. Use different scan techniques to bypass them.
- Scan Speed: High-speed scans can overwhelm the network. Use the
-T
option in Nmap to adjust the timing template. - Service Version Detection: Use the
-sV
option in Nmap to detect service versions for better vulnerability assessment.
Summary
Port scanning is an essential technique in penetration testing to identify open ports and services on a target system. Understanding the different types of scans and using tools like Nmap effectively can provide valuable insights into the security posture of the target. By practicing various scanning techniques and analyzing the results, pentesters can uncover potential vulnerabilities and plan further exploitation steps.
Pentesting Course: Penetration Testing Techniques
Module 1: Introduction to Pentesting
Module 2: Reconnaissance and Information Gathering
Module 3: Scanning and Enumeration
Module 4: Exploitation of Vulnerabilities
- Introduction to Exploitation
- Exploitation of Web Vulnerabilities
- Exploitation of Network Vulnerabilities
- Exploitation of System Vulnerabilities