Intro to Pentesting

Penetration testing, often referred to as “pen testing” or “ethical hacking,” is a crucial practice in the field of cybersecurity. It involves the deliberate and authorized simulation of cyberattacks on computer systems, networks, or web applications to identify security vulnerabilities that could be exploited by malicious hackers. Penetration testing helps organizations assess the robustness of their defenses, strengthen their security posture, and ensure that their systems are resistant to real-world cyber threats.

1. Purpose of Penetration Testing

The primary goal of penetration testing is to identify and address security weaknesses before they can be exploited by attackers. By mimicking the tactics, techniques, and procedures of cybercriminals, penetration testers (also known as “ethical hackers”) can find vulnerabilities in systems and provide actionable recommendations for remediation.

2. Key Objectives

Penetration testing helps organizations achieve several key objectives:

  • Identifying Vulnerabilities: Pen testers discover weaknesses that could be exploited in various systems, including networks, applications, databases, and devices.
  • Evaluating Security Controls: The effectiveness of existing security controls, such as firewalls, intrusion detection systems, and encryption, is assessed.
  • Testing Incident Response: The exercise helps evaluate how well an organization responds to a security breach, from detection to containment.
  • Improving Risk Management: By identifying vulnerabilities, pen testing helps organizations prioritize security risks and implement effective risk mitigation strategies.

3. Types of Penetration Testing

Penetration testing can be performed in several ways, depending on the scope, objectives, and level of access provided to the tester:

  • Black Box Testing: The tester has no prior knowledge of the target system. This type of test simulates the actions of an external attacker with no inside information.
  • White Box Testing: The tester is given full knowledge of the system, including source code, architecture, and network diagrams. This test simulates the actions of an insider or highly skilled attacker.
  • Gray Box Testing: The tester has limited knowledge of the system, often providing a combination of internal and external perspectives. This test simulates an attacker with partial information, such as a disgruntled employee or a hacker with some level of access.

4. Penetration Testing Methodology

Penetration testing generally follows a structured methodology that includes several key phases:

  1. Reconnaissance: The initial phase where the tester gathers information about the target system, such as IP addresses, domain names, open ports, and services running on the network. This can involve passive techniques, like searching public databases, or active techniques, like scanning the network.
  2. Scanning and Enumeration: In this phase, the tester uses tools to identify potential vulnerabilities and misconfigurations in the system. They look for weaknesses such as unpatched software, open ports, and misconfigured services.
  3. Exploitation: After vulnerabilities are identified, the tester attempts to exploit them to gain unauthorized access to the system. The goal is to simulate a real-world attack and determine the extent of damage that can be caused.
  4. Post-Exploitation: This phase involves maintaining access to the compromised system, escalating privileges, and exploring the system further to identify additional vulnerabilities or sensitive data that could be exploited.
  5. Reporting: After the penetration test, the tester prepares a detailed report outlining the vulnerabilities discovered, the steps taken during the test, and recommendations for remediation. This report is typically provided to the organization’s security team for further action.

5. Tools Used in Penetration Testing

Penetration testers rely on a wide range of tools to assist in various phases of the testing process. Some commonly used tools include:

  • Nmap: A network scanning tool used to discover devices, services, and open ports on a network.
  • Metasploit: A framework for exploiting vulnerabilities and testing the effectiveness of security controls.
  • Wireshark: A network protocol analyzer used to capture and analyze network traffic.
  • Burp Suite: A set of tools used for web application security testing, including vulnerability scanning and exploit development.
  • John the Ripper: A password-cracking tool used to identify weak passwords in systems and applications.

6. Benefits of Penetration Testing

Penetration testing offers several benefits to organizations:

  • Risk Mitigation: By identifying vulnerabilities, penetration testing helps reduce the risk of cyberattacks by allowing organizations to fix flaws before they are exploited.
  • Compliance: Many industries and regulations require penetration testing as part of their compliance standards. Pen tests help organizations meet requirements such as PCI DSS, HIPAA, and GDPR.
  • Improved Security Posture: Pen testing provides organizations with valuable insights into their security strengths and weaknesses, leading to improved overall protection.
  • Real-World Attack Simulation: Penetration testing provides a practical, hands-on approach to understanding how an attacker might exploit weaknesses, allowing organizations to implement targeted defenses.

7. Challenges and Considerations

While penetration testing is essential for improving cybersecurity, it also comes with certain challenges:

  • Scope Limitations: Penetration testing may not cover every possible attack vector, particularly in complex or rapidly evolving systems. It is essential to define a clear scope to ensure that critical areas are tested.
  • Time and Resources: Penetration testing can be time-consuming, especially for large organizations with complex networks. It requires skilled testers and significant resources to conduct a thorough assessment.
  • False Positives and False Negatives: Penetration testing tools may produce false positives (incorrectly identifying a vulnerability) or false negatives (failing to identify an existing vulnerability). Manual verification and thorough testing are required to ensure accurate results.

8. Penetration Testing vs. Vulnerability Scanning

While penetration testing and vulnerability scanning both aim to identify security weaknesses, they differ in their approaches:

  • Vulnerability Scanning: Automated tools scan systems for known vulnerabilities and generate reports, but they do not actively attempt to exploit vulnerabilities.
  • Penetration Testing: This is a more thorough and manual process where testers exploit vulnerabilities to understand the full impact and assess the effectiveness of existing security measures.

9. Conclusion

Penetration testing is a vital aspect of cybersecurity, helping organizations identify and address vulnerabilities before they can be exploited by malicious attackers. By simulating real-world cyberattacks, penetration testers provide valuable insights into an organization’s security posture and help improve overall defenses. While challenges exist in ensuring comprehensive coverage and minimizing false positives, the benefits of penetration testing far outweigh the risks, making it an essential practice for organizations seeking to protect sensitive data and maintain trust with clients and stakeholders.

VPN Router (Road Warrior)

A machine in the middle between a VPN server and a Local Network, acting as a client for the VPN server (on the external interface) and as a Router for the Local Network (on the internal interface) is known as “Road Warrior”.

The overall goal is to provide clients on the Local Network transparent communication (plug and play) to the internet obtaining the VPN Server IP and a secure encrypted connection.

Research

This solution can be achieved with professional dedicated firewall software such i.e Pfsense or with dedicated hardware. The first option can be complicated to implement and the second expensive for a small environment.

Here below a third option realized with opensource OS and Software that is a the same time cheap and easy to configure.

Requirements

  • OpenVPN software
  • Linux servers OS
  • VMs (local or on the cloud) / Physical Servers

Design

Implementation

Any Linux distribution will work with minor changes, for the specific implementation below Linux Ubuntu 18 LTS has been used.

Linux Remote Server

The Linux Remote Server can be any linux distro with an OpenVPN Server installed on top

  1. Install the OpenVPN Server
  2. Generate a Client certificate
  3. Test the connectivity with a client either Windows or Linux checking ports and communication is working properly and the VPN tunnel can be established with no issues.

Linux Local Server

New external interface for VPN connection tun0

  • Install the server certificate in a folder on the client i.e. the /home/user
  • Install the OpenVPN client

Code:

sudo apt update
sudo apt install openvpn

Run the

Code:

sudo apt openvpn certificate.ovpn 

Typing the command “ip a” a new interface called tun0 should be shown, this is the vpn tunnel established with typically 10.8.0.2 ip address (10.8.0.1 should be remote server).

Internal Interface DHCP Server

  • Install dhcp server on the Linux Local Server internal interface in this example ens37

Code:

sudo apt install isc-dhcp-server

Next edit the configuration file:

sudo nano /etc/default/isc-dhcp-server

Find the line INTERFACES=”ens37″ and add the value for the internal nic ens37. Save and exit.

Next edit the config file of the dhcp server

sudo nano /etc/dhcp/dhcpd.conf

Remove defaults and paste the below syntax, adjusting DNS IPs and range with personal config.

option domain-name-servers 8.8.8.8, 8.8.4.4;

option subnet-mask 255.255.255.0;
option broadcast-address 192.168.100.255;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.100;
option routers 192.168.100.1;
}

Save and restart the dhcp server

Code:

sudo service isc-dhcp-server restart

*Please note the internal interface needs to be setup as gateway and given an IP, for this configuration ens37 interface needs to be setup with 192.168.100.1/24

Enable Routing for IPv4

Edit this file with nano: /etc/sysctl.conf and uncomment to enable routing ipv4

net.ipv4.ip_forward=1
save the file and exit

enable the changes with

Code:

sudo sysctl -p /etc/sysctl.conf

NAT Config

Network address translation needs to be enabled on the internal interface with the following commands:

Code:

sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A FORWARD -i tun0 -o ens37 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i ens37 -o tun0 -j ACCEPT

The changes need to be persisted on the iptables otherwise at the reboot they will be lost.

Code:

sudo apt-get install iptables-persistent

Test

At this stage any client connected on the Linux Local Server internal interface should be able to navigate using the Public IP address of the Remote Linux Server.

How to enable ssh root access in Ubuntu

This is not recommended for security reasons but in some cases can be useful to temporarily enable it

Edit the file /etc/ssh/sshd_config

Command:

nano /etc/ssh/sshd_config

add the line:

Code:

PermitRootLogin yes

reboot the system or type the command below

Command:

systemctl restart sshd.service

*Note: When root ssh access is not needed anymore remember to comment the added line with a # at the beginning