Metasploit Framework: A Practical Penetration Testing Guide
1. Stages of Penetration Testing
A penetration test typically involves the following steps:- Scope Definition
- Reconnaissance
- Discovery
- Exploitation
- Social Engineering
- Control Acquisition
- Pivoting
- Evidence Collection
- Reporting
- Remediation
Scope Definition
The first step in a penetration test is to determine which systems will be tested. In this stage, the boundaries of the target system, critical data, and which services need protection should be clarified. For example, it is essential to identify which systems are critical for protecting customer data in a financial institution.Example Scenario: An IT manager at a bank requests that only the server containing customer databases be tested for an external penetration test. In this case, the scope of the test should be clearly defined and limited.Reconnaissance
In this phase, as much information as possible about the target is gathered. Details such as IP addresses, employee information, and operating systems are collected.Example Scenario: A penetration tester reviews employee profiles on LinkedIn to gather information about the company structure. Additionally, they may learn the names of executives from the company’s "About Us" page on its website.Discovery
During this phase, open ports and services on the target network are scanned. Tools like Nmap are used to identify devices on the network and their open ports.Example Command:This command scans devices within the specified IP range and lists open ports. The scan results can be used to determine which services are running and identify potential vulnerabilities.
2. Exploitation
After the discovery phase, appropriate exploits are selected to take advantage of identified vulnerabilities. Exploit modules available in Metasploit are utilized to attack target systems.Example Scenario: Creating a Windows Backdoor
- Use
msfvenom
in the terminal to create a Windows backdoor:This command creates a payload that will establish a reverse connection to the target system. - Next, start the Metasploit console:
- Configure settings to listen for the payload:
- When the backdoor is executed on the target, a reverse connection will be established to the attacker's system.
3. Social Engineering
Social engineering techniques can be employed to bypass security measures of a target. For instance, phishing emails can be sent to trick users into revealing their credentials.Example Scenario: A penetration tester sends a fake email requesting employees to update their passwords. To make it appear trustworthy, they use the bank's logo and direct users to a fraudulent website.Phishing Email Example
4. Control Acquisition
Once access to the target system is obtained, various commands can be used to gain control over it. When a Meterpreter session is opened, actions can be performed on the system.Example Commands:The
sysinfo
command retrieves information about the target system, while hashdump
can extract user passwords.5. Pivoting
Using acquired access, pivoting techniques can be employed to move into other segments of the network, allowing access to additional systems.Proxy Pivot Example
- Create a proxy pivot through a compromised host:
- Establish connections to other systems through this proxy:
6. Evidence Collection
During penetration testing, data and evidence obtained must be collected. This evidence is crucial for documenting test results.Example: Meterpreter commands can be used to take screenshots or download files:The data obtained with these commands will be utilized during reporting.
7. Reporting and Remediation
Finally, the results of the penetration test should be presented in a detailed report format. The report should include identified vulnerabilities along with recommended remediations.Report Content:- Scope and methods of testing.
- Findings obtained.
- Severity of vulnerabilities.
- Remediation recommendations.