# Exploit Discovery

In this chapter, we’ll dive into how to identify the correct exploit for a vulnerability using resources like SearchSploit, MITRE ATT\&CK, and NIST’s National Vulnerability Database (NVD). This process involves pinpointing vulnerabilities, understanding exploitability, and selecting appropriate tools and methods. We’ll walk through three in-depth case studies that illustrate different scenarios in network, web application, and system exploitation, showing how these frameworks can streamline the process of locating and selecting the right exploit.

***

#### Key Frameworks for Exploit Discovery

1. **SearchSploit**: An offline tool included in Exploit-DB that lets you search through available exploits directly from your terminal. Useful for finding pre-written exploits for known vulnerabilities.
2. **MITRE ATT\&CK**: A comprehensive knowledge base that categorizes tactics and techniques used by cyber adversaries, linked to real-world observations. Helps in mapping out stages of an attack and finding corresponding methods and tools.
3. **NIST National Vulnerability Database (NVD)**: Contains standardized data on software vulnerabilities (CVEs). Each entry includes information about the severity, impact, and possible mitigations, making it a valuable resource for identifying risks and finding mitigations.

***

#### Case Study 1: Web Application Exploitation – SQL Injection Vulnerability

**Scenario**

A cybersecurity assessment has identified a web application with an SQL injection vulnerability in the login form. The web app uses a poorly coded SQL query that is susceptible to injection attacks.

**Steps to Identify and Use the Exploit**

1. **SearchSploit**:
   * **Query**: Using `searchsploit "SQL injection" web application` on the terminal yields several potential scripts, payloads, and methods for exploiting SQL injection.
   * **Exploit Selection**: Narrow down based on the web app’s technology stack (e.g., PHP or ASP).
   * **Example Exploit**: `SQL Injection Exploit - PHP (Login Bypass).` Download the exploit and review its contents to ensure it aligns with the application environment.
2. **MITRE ATT\&CK**:
   * **Mapping Technique**: Using the MITRE ATT\&CK framework, SQL Injection falls under the `T1190 - Exploit Public-Facing Application` technique, which is part of the “Initial Access” tactic.
   * **Further Analysis**: Mapping the technique helps identify related methods attackers may use in conjunction with SQL Injection (e.g., credential dumping after a successful login bypass).
3. **NVD**:
   * **Vulnerability Lookup**: Check the NVD database for similar SQL injection vulnerabilities (e.g., CVE-2020-12084). This entry might include severity, associated risk, and potential mitigation or remediation suggestions.
   * **Severity and Relevance**: The CVSS score on NVD helps prioritize if this is a critical vulnerability, which aids in justifying the exploit’s importance.

**Execution**

Once the vulnerability is verified, a crafted SQL payload (like `admin'--`) can bypass login. Further, tools like SQLmap automate the attack and extract sensitive information from the database once initial access is gained.

***

#### Case Study 2: Network Exploitation – SMB Vulnerability

**Scenario**

During a network audit, an SMB service on a Windows server (version 2003) was identified as vulnerable. A quick scan suggests this service may be susceptible to an exploit for the MS08-067 vulnerability, a critical buffer overflow in Microsoft’s SMB protocol.

**Steps to Identify and Use the Exploit**

1. **SearchSploit**:
   * **Query**: Execute `searchsploit MS08-067` to locate relevant exploits for this known vulnerability. This command reveals multiple options, including Python scripts and Metasploit modules.
   * **Exploit Selection**: Choose an exploit such as `Microsoft Windows Server Service - Remote Buffer Overflow (MS08-067)`, compatible with Metasploit and non-Metasploit options.
   * **Verification**: Run a test payload in a controlled environment to confirm exploit functionality.
2. **MITRE ATT\&CK**:
   * **Mapping Technique**: The MS08-067 exploit maps to the `T1210 - Exploitation of Remote Services` technique, useful in lateral movement within a network.
   * **Tactical Relevance**: The tactic helps reveal related techniques that may support post-exploitation (e.g., privilege escalation using stolen credentials after initial access).
3. **NVD**:
   * **Vulnerability Check**: Search for `CVE-2008-4250` in the NVD for details on MS08-067. This vulnerability has a high CVSS score due to its critical impact on unpatched systems, reinforcing its exploit’s necessity.

**Execution**

Use Metasploit with the `ms08_067_netapi` module to initiate the exploit on the target IP. If successful, it opens a reverse shell, granting remote command execution. Further privilege escalation techniques can be employed to gain system-level access.

***

#### Case Study 3: Credential Harvesting and Privilege Escalation on Linux

**Scenario**

In a penetration test against a Linux-based web server, weak or reused passwords are suspected. After performing network reconnaissance, SSH is open on a non-standard port, indicating it might be accessible with credential-based attacks.

**Steps to Identify and Use the Exploit**

1. **SearchSploit**:
   * **Query**: Run `searchsploit SSH brute-force` to find scripts and tools that perform brute-force or dictionary-based SSH attacks.
   * **Exploit Selection**: Choose a brute-forcing tool, such as Hydra or Medusa, along with common password lists.
   * **Auxiliary Tools**: Consider using tools like John the Ripper or Hashcat if credential hashes are captured during the test.
2. **MITRE ATT\&CK**:
   * **Mapping Technique**: This type of attack maps to `T1110 - Brute Force`, under “Credential Access.” The tool choice aligns with real-world tactics where attackers systematically attempt to gain SSH access through brute-force.
   * **Linked Techniques**: This approach may also involve `T1078 - Valid Accounts`, emphasizing post-compromise activities once access is gained.
3. **NVD**:
   * **Vulnerability Reference**: NVD may not have a direct CVE entry for brute-forcing, as this is a general approach rather than a specific flaw. However, searching for default credential vulnerabilities or known weak password lists in services (e.g., `CVE-2020-7460` for SSH with default credentials) can inform the risk level.

**Execution**

Using Hydra: `hydra -l root -P passwords.txt ssh://<target_IP>:<port>`. If credentials are cracked, a shell can be accessed, followed by privilege escalation attempts (e.g., checking for `sudo` rights or SUID binaries).

Tools like `LinPEAS` and `Linux Exploit Suggester` can be run for potential privilege escalation techniques, further mapping out exploitable paths on the server.

***

#### Additional Resources

* **Exploit-DB**: Searchable database of exploits, includes SearchSploit for terminal-based access.
* **MITRE ATT\&CK Navigator**: Interactive tool for mapping out tactics and techniques by stages of an attack.
* **National Vulnerability Database (NVD)**: Tracks all known CVEs, their severity scores, and contextual information.

Each case demonstrates the synergy between these frameworks, from identifying vulnerabilities to selecting the right exploits and post-exploitation activities. Following this structured approach helps ensure systematic exploitation while considering each vulnerability's context and overall attack chain possibilities.

Here’s an extensive listing some common vulnerabilities, corresponding MITRE ATT\&CK techniques, and description. Each vulnerability type is associated with its relevant MITRE ATT\&CK technique ID (when applicable).

<table data-view="cards"><thead><tr><th>Vulnerability</th><th>MITRE ATT&#x26;CK Technique</th><th>Description</th></tr></thead><tbody><tr><td>SQL Injection</td><td>T1190 - Exploit Public-Facing Application</td><td>An attacker injects malicious SQL queries into input fields to manipulate database queries and access unauthorized data.</td></tr><tr><td>Command Injection</td><td>T1059 - Command and Scripting Interpreter</td><td>Exploits allow attackers to execute arbitrary commands on a host, often used to gain control or retrieve sensitive data.</td></tr><tr><td>Cross-Site Scripting (XSS)</td><td>T1059.007 - Cross-Site Scripting</td><td>Malicious scripts are injected into trusted websites, leading to session hijacking or data theft.</td></tr><tr><td>Cross-Site Request Forgery (CSRF)</td><td>T1056 - Input Capture</td><td>Exploits user sessions by tricking them into making unwanted actions on a trusted application.</td></tr><tr><td>Path Traversal</td><td>T1104 - Directory Traversal</td><td>Attackers manipulate URL paths to access files and directories outside the web root.</td></tr><tr><td>Local File Inclusion (LFI)</td><td>T1211 - Exploitation for Privilege Escalation</td><td>Allows attackers to include files from the local server, potentially exposing sensitive info.</td></tr><tr><td>Remote File Inclusion (RFI)</td><td>T1190 - Exploit Public-Facing Application</td><td>Attackers remotely include files, often malicious, from a server they control to compromise a host.</td></tr><tr><td>Buffer Overflow</td><td>T1203 - Exploitation for Client Execution</td><td>Overflowing a buffer with excessive data to manipulate the memory, often allowing code execution.</td></tr><tr><td>XML External Entity Injection (XXE)</td><td>T1190 - Exploit Public-Facing Application</td><td>Attackers exploit XML parsers to access system files or initiate network requests.</td></tr><tr><td>Insecure Deserialization</td><td>T1574.002 - Dylib Hijacking</td><td>Exploits unsafe handling of serialized data, leading to remote code execution or data manipulation.</td></tr><tr><td>Server-Side Request Forgery (SSRF)</td><td>T1071.001 - Application Layer Protocol</td><td>An attacker tricks a server into making requests to unauthorized locations on its behalf.</td></tr><tr><td>Unrestricted File Upload</td><td>T1190 - Exploit Public-Facing Application</td><td>Attackers upload malicious files, which can then be executed on the server.</td></tr><tr><td>Improper Authentication</td><td>T1078 - Valid Accounts</td><td>Weak authentication practices allow unauthorized access to system resources.</td></tr><tr><td>Hardcoded Credentials</td><td>T1110.001 - Credential Dumping</td><td>Developers leave credentials within code, making them vulnerable to discovery and misuse.</td></tr><tr><td>Insecure Direct Object References (IDOR)</td><td>T1530 - Data from Local System</td><td>Exposes data by failing to properly authorize access to internal objects.</td></tr><tr><td>Improper Session Handling</td><td>T1525 - Implant Container Image</td><td>Weak session management allows attackers to hijack or manipulate sessions.</td></tr><tr><td>Weak Password Policies</td><td>T1110 - Brute Force</td><td>Weak or unenforced password rules make accounts more susceptible to brute-force attacks.</td></tr><tr><td>API Key Leakage</td><td>T1552 - Unsecured Credentials</td><td>Exposed API keys allow unauthorized access to application functionality or data.</td></tr><tr><td>Improper Error Handling</td><td>T1047 - Exfiltration Over Unencrypted/Obfuscated Channel</td><td>Error messages reveal sensitive data or give attackers clues to exploit vulnerabilities.</td></tr><tr><td>Race Condition</td><td>T1069.001 - Permissions, User, Group</td><td>Exploits delays between processes to manipulate resource access or obtain privileged information.</td></tr><tr><td>JSON Web Token (JWT) Flaws</td><td>T1556.003 - Network Service Scanning</td><td>Weak JWT validation or improper handling of token expiration allows privilege escalation.</td></tr><tr><td>Command Injection in IoT Devices</td><td>T1071 - Application Layer Protocol</td><td>Command injection exploits can compromise IoT devices, leading to unauthorized access or control.</td></tr><tr><td>LDAP Injection</td><td>T1220 - Compromise Application Access Token</td><td>Malformed LDAP queries can reveal sensitive directory information or allow unauthorized access.</td></tr><tr><td>Weak TLS/SSL Configuration</td><td>T1573 - Encrypted Channel</td><td>Misconfigured SSL/TLS allows attackers to intercept, alter, or decrypt sensitive data in transit.</td></tr><tr><td>Improper Access Control</td><td>T1078 - Valid Accounts</td><td>Weak or missing access controls allow unauthorized users to gain elevated permissions.</td></tr><tr><td>Plaintext Storage of Sensitive Data</td><td>T1003 - Credential Dumping</td><td>Storing sensitive data in plaintext exposes it to unauthorized access and misuse.</td></tr><tr><td>Log Forging and Injection</td><td>T1059 - Command and Scripting Interpreter</td><td>Manipulating logs to hide malicious activity or create false records, often to evade detection.</td></tr><tr><td>DNS Hijacking</td><td>T1596.002 - Active Scanning</td><td>Attackers alter DNS settings to redirect users to malicious sites or intercept sensitive data.</td></tr><tr><td>Shell Injection</td><td>T1059 - Command and Scripting Interpreter</td><td>Enables remote command execution through shell interfaces, compromising system integrity.</td></tr><tr><td>Eavesdropping</td><td>T1071.001 - Application Layer Protocol</td><td>Intercepting network communications to capture sensitive information.</td></tr><tr><td>Cache Poisoning</td><td>T1557 - Man in the Middle</td><td>Manipulates cache entries to serve malicious responses, often redirecting users or delivering malware.</td></tr><tr><td>Password Spraying</td><td>T1110.001 - Password Guessing</td><td>Attempting commonly used passwords across many accounts to gain access.</td></tr><tr><td>Man-in-the-Middle (MitM) Attack</td><td>T1557 - Man in the Middle</td><td>Intercepting and potentially altering communication between two parties without their knowledge.</td></tr><tr><td>BlueKeep (RDP Vulnerability)</td><td>T1210 - Exploitation of Remote Services</td><td>A vulnerability in RDP allowing remote code execution, critical for Windows systems.</td></tr><tr><td>Weak HTTP Headers</td><td>T1190 - Exploit Public-Facing Application</td><td>Insecure HTTP headers weaken browser protection against common attacks.</td></tr><tr><td>Remote Code Execution (RCE)</td><td>T1203 - Exploitation for Client Execution</td><td>Allows an attacker to execute arbitrary code remotely, compromising the system.</td></tr><tr><td>Default Credentials in IoT Devices</td><td>T1078 - Valid Accounts</td><td>Use of default credentials makes IoT devices susceptible to unauthorized access.</td></tr><tr><td>Typo-Squatting</td><td>T1539 - Steal Application Access Token</td><td>Registering domains with similar names to trick users into accessing malicious sites.</td></tr><tr><td>Sensitive Data Exposure</td><td>T1114.002 - Data Encoding</td><td>Poor data handling exposes sensitive information to unauthorized parties.</td></tr><tr><td>Log Injection</td><td>T1070.004 - Event Triggered Execution</td><td>Exploits injection flaws in log generation, enabling attackers to obfuscate their tracks.</td></tr><tr><td>Ransomware Exploits</td><td>T1486 - Data Encrypted for Impact</td><td>Encrypts files to demand a ransom for data decryption, causing severe operational disruptions.</td></tr><tr><td>Fileless Malware</td><td>T1055.013 - Process Injection</td><td>Malware that operates in-memory only, evading traditional detection methods.</td></tr><tr><td>Memory Corruption</td><td>T1068 - Exploitation for Privilege Escalation</td><td>Exploits memory flaws to manipulate application behavior or escalate privileges.</td></tr><tr><td>Reverse Shell</td><td>T1219 - Remote Access Software</td><td>Allows attackers to execute commands on a remote machine through a shell interface.</td></tr><tr><td>Credential Reuse</td><td>T1078 - Valid Accounts</td><td>Using stolen credentials from one service to access another, often leading to data breaches.</td></tr><tr><td>Cross-Site WebSocket Hijacking</td><td>T1071.001 - Application Layer Protocol</td><td>Exploits improper validation in WebSocket connections to gain unauthorized access.</td></tr><tr><td>Improper Validation of Integrity Checks</td><td>T1589 - Gather Victim Identity Information</td><td>Failing to verify data integrity allows attackers to manipulate system behavior.</td></tr><tr><td>Integer Overflow</td><td>T1203 - Exploitation for Client Execution</td><td>Exploits integer value overflow to manipulate program execution, often for privilege escalation.</td></tr></tbody></table>

This table covers a wide array of common vulnerabilities with brief descriptions and MITRE ATT\&CK references for context. Let me know if you'd like additional details for any of these vulnerabilities or further examples!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ghostpatch.gitbook.io/hexdefender/penetration-testing/exploitation-techniques/exploit-discovery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
