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

  1. 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).
  2. 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.
  3. 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

nmap -sT <target-ip>
  • -sT: Specifies a TCP connect scan.
  • <target-ip>: The IP address of the target system.

SYN Scan

nmap -sS <target-ip>
  • -sS: Specifies a SYN scan.

UDP Scan

nmap -sU <target-ip>
  • -sU: Specifies a UDP scan.

Comprehensive Scan

nmap -sS -sU -p- <target-ip>
  • -p-: Scans all 65535 ports.

Example Explanation

nmap -sS -sU -p- 192.168.1.1
  • 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

  1. Perform a TCP connect scan on a local machine.
  2. Identify the open ports and the services running on them.

Solution:

nmap -sT 127.0.0.1
  • This command scans the local machine (127.0.0.1) using a TCP connect scan.

Exercise 2: SYN Scan on a Remote Machine

  1. Perform a SYN scan on a remote machine within your network.
  2. Document the open ports and the services identified.

Solution:

nmap -sS 192.168.1.10
  • This command performs a SYN scan on the remote machine with IP 192.168.1.10.

Exercise 3: Comprehensive Scan

  1. Perform a comprehensive scan (both TCP and UDP) on a target machine.
  2. Analyze the results and identify any potential vulnerabilities.

Solution:

nmap -sS -sU -p- 192.168.1.10
  • 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.

© Copyright 2024. All rights reserved