Network Penetration Testing
Network Penetration Testing
ICTP DP – 001
Network scanning and enumeration are foundational steps in penetration testing, where the goal is
to discover and map out the structure, devices, and services running within a target network. Nmap,
a powerful network scanner, is a critical tool used for these tasks. This module provides detailed
content on techniques for network discovery and scanning using Nmap, along with advanced
scanning techniques.
Introduction to Nmap
Nmap (Network Mapper) is an open-source tool used for network discovery and security auditing.
It is widely recognized for its ability to quickly and efficiently scan large networks, identify hosts,
open ports, running services, and the operating systems in use.
• Service and version detection: Identifying services running on open ports and their
versions.
o A ping scan is used to identify live hosts on a network without performing a full
port scan. It sends ICMP Echo requests to determine if the host is up.
- A ping scan is used to identify live hosts on a network without performing a full port scan. It
sends ICMP Echo requests to determine if the host is up.
- This command scans the entire subnet `192.168.1.0/24` to identify live hosts.
2. Port Scanning:
- TCP Connect Scan (-sT): Establishes a full TCP connection (3-way handshake) with each target
port. It is the most reliable but easily detectable.
- SYN Scan (-sS): Also known as a half-open scan, it sends a SYN packet to initiate a connection,
but does not complete it. This is faster and stealthier.
- UDP Scan (-sU): Used to identify open UDP ports. It is slower and less reliable than TCP scans
due to the stateless nature of UDP.
- Nmap can detect the versions of services running on open ports. This is crucial for identifying
vulnerable software versions.
4. OS Detection:
- OS detection relies on analyzing the responses of various probes sent by Nmap. It helps in
identifying the operating system running on a target host.
nmap -O 192.168.1.10
1. Stealth Scans:
- Fragmentation Scan (-f): Breaks the scan packets into smaller fragments to avoid detection by
some firewalls and intrusion detection systems (IDS).
nmap -f 192.168.1.10
- Idle Scan (-sI): Uses a third-party host as a zombie to send packets, making it difficult to trace
the scan back to the attacker.
- Timing Templates (-T): Nmap allows adjusting the speed of scans with templates ranging from
`T0` (paranoid) to `T5` (insane). This is useful for balancing stealth and speed.
- Parallel Scanning: Adjust the number of hosts and ports Nmap scans simultaneously using the
`--min-parallelism` and `--max-parallelism` options to optimize performance.
3. Evasion Techniques:
- Decoy Scan (-D): Sends scan packets from multiple IP addresses (decoys) to confuse the
target’s logging and make it difficult to identify the real attacker.
```
- Introduction to NSE: The Nmap Scripting Engine allows users to write and execute custom
scripts to automate a wide range of tasks, such as vulnerability detection, network inventory, and
more.
-Example Scripts:
- Vulnerability Scanning:
- Custom Scripts: Users can write custom NSE scripts in Lua to perform specific tasks tailored
to their penetration Testing needs.
Practical Applications
1. Live Host Discovery: Ethical hackers can use Nmap to map out active hosts within a target
network before conducting more detailed scans. This helps in planning attacks and identifying
potential entry points.
2. Service and Vulnerability Detection: Nmap’s version detection and NSE scripts enable ethical
hackers to identify outdated and vulnerable services running on target machines, making it easier
to prioritize attack vectors.
4. Bypassing Security Measures: Advanced Nmap techniques like decoy scans and MAC address
spoofing help ethical hackers bypass firewalls, IDS, and other security mechanisms, allowing for
deeper penetration into the network.
Identifying live hosts and open ports is a crucial step in network penetration testing. This process
allows ethical hackers to discover which devices are active within a target network and what
services they are running, thereby helping to identify potential vulnerabilities. Various techniques
and tools can be employed to achieve this, with Nmap being one of the most widely used tools for
this purpose.
Host Discovery involves detecting active devices (hosts) within a network. Once these hosts are
identified, **Port Scanning** is used to determine which network services (ports) are open and
listening on these devices.
- The simplest method to identify live hosts is by sending an ICMP Echo Request (ping) to the
target. If the target responds with an Echo Reply, it indicates that the host is alive.
- This command sends a ping to all IP addresses in the `192.168.1.0/24` subnet, identifying any
active hosts.
- An ARP (Address Resolution Protocol) scan is used on local networks to identify active hosts
by sending ARP requests to all IP addresses in the subnet.
- This method is highly reliable within a local network, as ARP requests do not rely on ICMP,
which might be blocked by firewalls.
- A TCP SYN ping scan sends a SYN packet to a target port (commonly port 80) to check if the
port is open. If the target responds with a SYN/ACK packet, the host is considered alive.
- This technique is effective when ICMP is blocked but TCP connections are allowed.
4. UDP Ping:
- A UDP ping scan sends a UDP packet to a specified port (often port 53, used by DNS) to check
for a response, indicating an active host.
- UDP ping is useful in networks where ICMP and TCP are restricted but UDP traffic is
permitted.
- A comprehensive ping sweep involves using multiple methods (ICMP, ARP, TCP, UDP)
simultaneously to increase the likelihood of discovering live hosts.
- This command uses ICMP Echo, TCP SYN on port 80, and TCP ACK on port 443 to discover
hosts.
- This scan attempts to establish a full TCP connection with each target port by completing the
3-way handshake. It is reliable but can be easily detected by firewalls and intrusion detection
systems (IDS).
nmap -sT 192.168.1.10 - This scan will list all open ports on the target host `192.168.1.10`.
- A SYN scan is faster and stealthier than a TCP Connect scan. It sends a SYN packet and waits
for a SYN/ACK response to identify open ports without completing the TCP handshake, making
it less likely to be logged.
- A UDP scan checks for open UDP ports by sending a UDP packet to each port and waiting for
a response. Since UDP is stateless, open ports often don’t respond, making this scan slower and
more challenging to interpret.
- An ACK scan is used to map out firewall rules by sending an ACK packet to a target port. Based
on the response, it can determine whether the port is filtered (by a firewall) or unfiltered.
- This scan helps in understanding firewall configurations without necessarily identifying open
ports.
- These scans can reveal open ports on systems where standard scanning techniques might be
blocked.
Practical Applications
1. Reconnaissance: By identifying live hosts and open ports, ethical hackers can gather critical
information about the network's structure and the services running on it. This is often the first step
in a penetration test, setting the stage for further investigation and exploitation.
2. Target Identification: Open port information helps in pinpointing specific services that might be
vulnerable to attacks. For example, if a web server is identified with an open port 80, it can be
targeted with web application penetration testing techniques.
3. Firewall Evasion: Understanding which ports are open and how they are filtered enables ethical
hackers to craft strategies to bypass firewalls and other security mechanisms, gaining deeper access
to the network.
4. Vulnerability Assessment: Once live hosts and open ports are identified, ethical hackers can use
this information to run targeted vulnerability assessments, identifying weaknesses in the network
that could be exploited.
Network mapping is a critical step in the process of network penetration testing, where ethical
hackers create visual representations of a network's structure. These maps help in identifying the
relationships between devices, the flow of data, and potential vulnerabilities within the network.
By understanding the layout of the network, ethical hackers can more effectively plan their attacks
and identify key targets that may be susceptible to exploitation.
Network Mapping involves gathering data about the network’s devices, connections, and services,
then using this data to create a visual map that represents the network’s infrastructure. This map is
a valuable tool for both defenders and attackers, as it provides a clear overview of how the network
is structured and where its weak points may lie.
- Nmap is widely used for network discovery, but it can also be used to create basic network
maps. **Zenmap** is the graphical interface for Nmap, allowing for easy visualization of network
topologies.
This command performs an aggressive scan on the network range `192.168.1.0/24`, gathering
detailed information about hosts, open ports, running services, and operating systems, which can
be used to build a network map.
- Zenmap: After performing a scan, Zenmap provides a topology view that displays the
network structure, including devices and connections.
- Microsoft Visio:
- SolarWinds offers a dedicated tool for network mapping that automatically discovers network
devices and creates visual maps. It’s particularly useful for larger networks where manual mapping
would be time-consuming.
- Ethical hackers often gather data from multiple sources (e.g., Nmap, Wireshark, ARP scans)
and manually piece together a network map. This method allows for greater control over the level
of detail and accuracy of the map.
- Example Workflow:
1. Nmap is used to scan the network for live hosts and open ports.
2. Wireshark captures network traffic to identify communication patterns and hidden devices.
3. ARP Scans provide information on the relationships between IP addresses and MAC
addresses.
4. Visi or similar tools are used to draw the network map based on the collected data.
- Initial scans (like those performed with Nmap) identify live hosts, open ports, and services.
This data forms the foundation of the network map.
-Topology Detection:
- Advanced Nmap scans (using options like `-A` for aggressive scanning or `-O` for OS
detection) provide information on the network’s topology, identifying how devices are connected
and the pathways data travels through.
4.Traceroute Analysis:
- Traceroute:
- Traceroute is a tool used to map the route that packets take from the source to the destination.
This helps in understanding the network’s topology by identifying the sequence of hops and the
devices involved in routing traffic.
traceroute 192.168.1.10
This command reveals the path taken to reach the target IP `192.168.1.10`, which can be used
to infer network structure.
- Nmap Traceroute:
- Nmap includes a built-in traceroute feature that can be combined with other scan data to map
out the network’s topology.
1. Data Collection:
- Begin by conducting comprehensive scans using tools like Nmap, which provide data on live
hosts, open ports, services, and the devices' operating systems.
2. Organizing Data:
- Compile the scan data into a coherent structure. Group devices based on their roles (e.g.,
servers, workstations, routers) and physical or logical locations within the network.
- Identify connections between devices, including which ports and services facilitate these
connections.
- Use tools like Zenmap, Visio, or SolarWinds to create a visual representation of the network.
Begin with the core infrastructure (e.g., routers, switches) and branch out to individual hosts and
devices.
- Highlight critical assets, such as servers or sensitive data repositories, and mark potential
vulnerabilities, such as open ports or outdated services.
- Once the network map is created, analyze it to identify potential vulnerabilities. Look for
unpatched devices, open ports that could be exploited, and weak points in the network’s defenses.
- Use the map to plan penetration tests, focusing on areas where an attacker could gain access to
critical systems or data.
Network vulnerabilities are weaknesses or flaws in a system that can be exploited by attackers to
gain unauthorized access, disrupt services, or steal sensitive information. These vulnerabilities can
exist in various components of the network, such as hardware, software, configurations, and
protocols.
1. Configuration Vulnerabilities:
o Default Configurations:
▪ Many network devices and software come with default settings that include
default passwords, open ports, and enabled services that are not required.
Attackers often exploit these defaults to gain unauthorized access.
o Unnecessary Services:
2. Software Vulnerabilities:
o Unpatched Software:
o Buffer Overflows:
o Weak Encryption:
3. Protocol Vulnerabilities:
o Insecure Protocols:
▪ Protocols like FTP, Telnet, and HTTP transmit data in plaintext, making it
easy for attackers to intercept and read the data. These protocols should be
replaced with secure alternatives like SFTP, SSH, and HTTPS.
o Weak Passwords:
▪ Internet of Things (IoT) devices often have minimal security features and
are susceptible to attacks. Vulnerabilities in IoT devices can be exploited to
gain access to the broader network.
1. CVE-2017-0144 (EternalBlue):
o Description:
o Impact:
2. CVE-2014-0160 (Heartbleed):
o Description:
o Impact:
o Description:
o Impact:
1. Vulnerability Scanning:
o Ensure that all software, operating systems, and firmware are regularly updated
with the latest patches. This practice helps to close known vulnerabilities before
they can be exploited by attackers.
o Implement secure configuration baselines for all network devices, ensuring that
default settings are replaced with secure alternatives. Regularly review and update
these configurations to address new security challenges.
5. Network Segmentation:
o Segment the network into smaller, isolated sections to limit the spread of an attack.
Sensitive systems should be placed in isolated segments with strict access controls.
o Deploy IDPS solutions to monitor network traffic for suspicious activity and
respond to potential threats in real time. These systems can detect and block many
types of network-based attacks.
Practical Applications
1. Risk Assessment:
2. Penetration Testing:
o Educating users and administrators about common vulnerabilities and how to avoid
them is a critical component of a comprehensive security strategy. Awareness
programs can reduce the likelihood of human error leading to a security breach.
Vulnerability scanning is an essential part of network security, involving the use of automated tools
to identify potential weaknesses in systems, networks, and applications. Tools like Nessus and
OpenVAS are widely used by security professionals to perform these scans, providing detailed
reports on vulnerabilities that can be exploited by attackers. These tools streamline the process of
vulnerability management, enabling organizations to proactively address security risks.
Overview of Nessus
What is Nessus?
o Nessus can scan for vulnerabilities across multiple platforms, including operating
systems, databases, applications, and network devices. It checks for common
vulnerabilities such as missing patches, misconfigurations, and known exploits.
2. Plugin Architecture:
3. Policy Compliance:
4. Detailed Reporting:
5. Integration Capabilities:
o Nessus integrates with various security information and event management (SIEM)
systems, as well as other tools in the Tenable ecosystem, allowing for a more
comprehensive security management approach.
Overview of OpenVAS
What is OpenVAS?
o OpenVAS includes a large vulnerability database, regularly updated with the latest
security checks. This database covers a broad spectrum of vulnerabilities across
different platforms and technologies.
o Users can customize scan configurations and policies to suit specific needs, such as
targeting particular hosts, services, or compliance standards. This flexibility makes
OpenVAS suitable for various types of assessments.
o OpenVAS can be integrated with other tools within the Greenbone Security
Manager (GSM) framework, as well as external systems, to enhance vulnerability
management processes.
Installing Nessus
2. Licensing:
o Nessus offers a free version (Nessus Essentials) for personal use, as well as
professional versions (Nessus Professional) with more advanced features and
support. Users need to register for a license key to activate the software.
3. Initial Configuration:
o After installation, users access Nessus through a web interface to complete the
initial setup. This includes creating an admin account, updating plugins, and
configuring scanning policies.
o Ensure that Nessus has the necessary network access to perform scans. This may
involve configuring firewalls, opening specific ports, or setting up credentials for
authenticated scans.
Installing OpenVAS
2. Setting Up GVM:
3. Initial Configuration:
o After installation, users configure scan settings, including defining scan targets,
selecting scan profiles, and updating the vulnerability database.
4. Network Configuration:
o In Nessus, scan policies define how a scan is conducted. Users can create custom
policies based on their specific needs, such as targeting specific vulnerabilities,
services, or compliance requirements.
o Once the policy is defined, users can launch a scan by selecting the target network
or hosts. Nessus performs the scan and identifies vulnerabilities, misconfigurations,
and other issues.
o Nessus categorizes vulnerabilities by severity (e.g., critical, high, medium, low) and
provides detailed information on each finding, including a description, potential
impact, and recommended remediation.
4. Generating Reports:
o After the scan is complete, Nessus allows users to generate reports in various
formats (PDF, HTML, CSV). These reports can be tailored to different audiences,
highlighting the most critical issues and suggesting remediation steps.
o In OpenVAS, users create scan tasks that define what to scan and how to scan it.
Tasks include selecting target hosts, choosing scan profiles, and configuring scan
parameters.
o Users can launch scans directly from the GSA web interface. OpenVAS provides
real-time feedback on scan progress, including logs and status updates.
1. Regular Scanning:
o Perform regular vulnerability scans to ensure that new vulnerabilities are identified
and addressed promptly. Automated scans can be scheduled to run at regular
intervals.
2. Authenticated Scans:
o Use authenticated scans whenever possible, as they provide deeper insights into
system vulnerabilities compared to unauthenticated scans. This requires
configuring credentials for the scanning tools.
3. Prioritizing Vulnerabilities:
4. Continuous Monitoring:
5. Regular Updates:
o Keep the vulnerability scanners and their databases updated to ensure that they can
detect the latest vulnerabilities and exploits.
1. Command-Line Tools:
▪ Manually interact with services using these protocols to check for default
credentials, weak authentication mechanisms, or exposed administrative
interfaces.
▪ Use these tools for manual testing of web applications, focusing on areas
where automated tools may not fully probe, such as multi-step forms, API
endpoints, and AJAX calls.
o Fiddler, Postman:
▪ Manually test API endpoints and HTTP requests to check for improper input
validation, insecure methods, and authentication flaws.
o Static Analysis:
▪ If access to the source code is available, manually review the code for
security issues such as hardcoded credentials, insecure functions, or
improper error handling.
o Dynamic Analysis:
4. Custom Scripting:
5. Reverse Engineering:
o Binary Analysis:
▪ For applications or services where source code is not available, use reverse
engineering techniques to understand how binaries function and identify
potential vulnerabilities.
Exploiting network services is a core component of penetration testing, where the goal is to identify
and exploit vulnerabilities within services running on networked systems. Network services, such
as web servers, databases, file sharing, and more, often present attack surfaces that, if inadequately
secured, can be leveraged to gain unauthorized access, escalate privileges, or disrupt services.
Understanding how to exploit these vulnerabilities is essential for both offensive and defensive
security operations.
o Web Servers: HTTP/HTTPS services, often running on ports 80/443, serve web
pages and APIs.
o File Sharing Services: SMB, FTP, NFS, and other protocols used for sharing files
across networks.
o Databases: Services like MySQL, MSSQL, and PostgreSQL, which store and
manage data.
o Remote Access Services: SSH, Telnet, RDP, and similar services used for remote
system management.
2. Vulnerability Types:
o Banner Grabbing: Use tools like Netcat or Telnet to connect to a service and
extract version information from banners.
o Nmap Service Detection: Employ Nmap's service detection (-sV) to identify the
running services and their versions.
o Manual Inspection: Analyze the output from service scans to manually verify the
software versions and configurations.
o CVE Exploitation:
o Metasploit Framework:
o Custom Exploits:
▪ When a specific exploit does not exist, create custom scripts or modify
existing ones to exploit the vulnerability, particularly for zero-day
vulnerabilities or lesser-known bugs.
o Password Cracking:
o Credential Harvesting:
4. Service-Specific Exploitation:
o Database Exploits:
5. Post-Exploitation Activities:
o Maintaining Access:
o Privilege Escalation:
o Lateral Movement:
1. Exploitation Frameworks:
o Core Impact: A commercial penetration testing tool that offers automated and
manual exploitation capabilities.
2. Custom Scripting:
3. Manual Techniques:
o Netcat for Manual Exploits: Use Netcat to create manual connections and exploit
vulnerabilities by sending crafted requests.
Real-World Examples
o Gaining shell access by exploiting weak SSH configurations or using exploits for
specific SSH vulnerabilities.
A Man-in-the-Middle (MITM) attack is a type of cyber attack where an attacker secretly intercepts
and potentially alters the communication between two parties who believe they are directly
communicating with each other. This type of attack is particularly dangerous because it can be
used to steal sensitive information, inject malicious content, or manipulate communications
without the knowledge of the communicating parties.
1. Basic Concept:
o In a MITM attack, the attacker positions themselves between the victim and the
intended communication partner, either by redirecting traffic or by exploiting
vulnerabilities in the communication channel. The attacker can then monitor,
capture, or alter the data being transmitted.
o Unsecured Wi-Fi Networks: Public Wi-Fi networks are often targets for MITM
attacks because the traffic is usually unencrypted, making it easier for attackers to
intercept communications.
o Passive MITM: The attacker simply monitors and records the communication
between two parties without altering it. This is often used for eavesdropping.
o Active MITM: The attacker not only intercepts but also modifies the
communication. This can include injecting malicious code, altering messages, or
redirecting traffic to malicious sites.
1. Preparation:
o Tools: Familiarize yourself with the tools commonly used for MITM attacks, such
as Wireshark for packet capturing, Ettercap for ARP poisoning, and SSLstrip for
intercepting HTTPS traffic.
o Execution:
3. DNS Spoofing:
o Concept: DNS spoofing involves altering the DNS responses to redirect the
victim’s traffic to a different IP address, usually to a malicious server controlled by
the attacker.
o Execution:
▪ Use tools like dnsspoof or manually inject forged DNS responses into the
network to redirect traffic.
▪ When the victim attempts to access a legitimate website, they are instead
directed to a malicious site without their knowledge.
4. SSL/TLS Stripping:
o Execution:
▪ Monitor the victim's traffic and capture sensitive data that would normally
be encrypted.
5. Packet Sniffing:
o Concept: Packet sniffing involves capturing network traffic to analyze the data
being transmitted over the network. In the context of a MITM attack, packet
sniffing allows the attacker to capture sensitive information such as usernames,
passwords, and other private communications.
o Execution:
▪ Focus on protocols that transmit data in plaintext, such as HTTP, FTP, and
SMTP, to extract valuable information.
1. Encryption:
o Always use encrypted connections (e.g., HTTPS, SSH) to ensure that even if traffic
is intercepted, it cannot be easily read or modified by the attacker.
o Use a VPN to create a secure tunnel for your data, making it much harder for
attackers to perform a successful MITM attack.
3. Strong Authentication:
o Secure your network by configuring proper ARP defenses, such as using static ARP
entries or implementing dynamic ARP inspection (DAI) on your switches.
o Regularly monitor your network for unusual ARP activity, DNS anomalies, and
other signs of a MITM attack.
1. Ettercap:
2. Wireshark:
o A powerful network protocol analyzer that captures and displays data traveling back
and forth on a network in real-time.
o A tool that intercepts and silently downgrades HTTPS to HTTP, capturing data that
would normally be protected by SSL/TLS encryption.
o A Windows-based tool that can be used for password recovery and MITM attacks.
It can perform ARP poisoning, sniffing, and other forms of network analysis.
Real-World Examples
o An attacker sets up a rogue Wi-Fi access point in a public area and entices users to
connect to it. Once connected, the attacker can intercept all of the victim's internet
traffic, potentially capturing sensitive information.
Exploit development is the process of creating code or techniques that leverage vulnerabilities in
software or network services to achieve unauthorized actions. This could involve gaining remote
access, escalating privileges, or extracting sensitive information from a target system.
Understanding the fundamentals of exploit development is crucial for ethical hackers and
penetration testers to simulate real-world attacks and assess the security posture of networks and
systems.
Understanding Vulnerabilities
1. What is a Vulnerability?
2. Types of Vulnerabilities:
o Buffer Overflows: Occur when more data is written to a buffer than it can hold,
causing data to overwrite adjacent memory, potentially allowing arbitrary code
execution.
o SQL Injection: Involves injecting malicious SQL queries through user input fields
to manipulate a database.
o Analyze the target system or service to identify the operating system, architecture,
and software version. This information is critical for tailoring an exploit to the
specific environment.
1. Analyzing a Vulnerability:
o Understanding the Root Cause: Break down the vulnerability to understand how
it occurs, what conditions trigger it, and what the impact is.
o Payload Design: The payload is the code that executes once the vulnerability is
exploited. This could be a reverse shell, a bind shell, or any custom code that
achieves the desired outcome.
o Constructing the Exploit: Write the code that will trigger the vulnerability,
incorporating the payload and ensuring it will execute as intended. This often
involves manipulating inputs or constructing data structures that overflow buffers
or corrupt memory.
o Troubleshooting: If the exploit fails, analyze the output and logs to determine
where the issue lies. It might involve adjusting offsets, modifying payloads, or
rethinking the attack vector.
4. Bypassing Protections:
o Data Execution Prevention (DEP): DEP prevents the execution of code in certain
regions of memory. To bypass DEP, attackers often use techniques like code reuse
attacks (e.g., ROP).
o Stack Canaries: Stack canaries are values placed on the stack to detect buffer
overflows. Exploit developers need to understand how to bypass or disable these
protections.
o Identifying the Attack Surface: Focus on network services that listen on open
ports, such as web servers, FTP servers, or custom applications. Use network
scanning tools like Nmap to identify these services.
o Handling Network Protocols: Ensure that your exploit handles the network
protocol correctly, maintaining the necessary handshake or session to execute the
attack successfully.
o This vulnerability in the Windows Server service allowed remote code execution
by sending a specially crafted RPC request. Exploit developers crafted payloads
that exploited this vulnerability to execute arbitrary code on vulnerable Windows
machines.
2. Heartbleed (CVE-2014-0160):
3. EternalBlue (CVE-2017-0144):
Ethical Considerations
1. Responsible Disclosure:
2. Legal Compliance:
o Ensure that your exploit development activities comply with local and international
laws. Unauthorized exploitation of vulnerabilities can lead to legal consequences,
even if done with good intentions.