|
| 1 | +Description: ExploitDB in Python |
| 2 | + |
| 3 | + |
| 4 | +Installation: |
| 5 | +Python |
| 6 | +Must Have Python |
| 7 | +pip3 install pyExploitDb |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +# Import the PyExploitDb class |
| 18 | +from pyExploitDb import PyExploitDb |
| 19 | + |
| 20 | +# Create an instance of the class |
| 21 | +pEdb = PyExploitDb() |
| 22 | + |
| 23 | +# (Optional) Enable debug output to see what's happening |
| 24 | +pEdb.debug = True |
| 25 | + |
| 26 | +# Open the local Exploit-DB files (this will download them if they don't exist |
| 27 | +# or update them if they are outdated. This can take some time on first run.) |
| 28 | +print("Opening Exploit-DB files and updating if necessary...") |
| 29 | +pEdb.openFile() |
| 30 | +print("Exploit-DB files loaded.") |
| 31 | + |
| 32 | +# --- Now you can perform searches --- |
| 33 | + |
| 34 | +# Example 1: Search for an exploit by CVE ID |
| 35 | +cve_id = "CVE-2023-2825" # Example CVE (replace with one you're interested in) |
| 36 | +print(f"\nSearching for exploits related to CVE: {cve_id}") |
| 37 | +results_cve = pEdb.searchCve(cve_id) |
| 38 | +if results_cve: |
| 39 | + for result in results_cve: |
| 40 | + print(f" - Exploit-DB ID: {result.get('edbid')}") |
| 41 | + print(f" File: {result.get('exploit')}") |
| 42 | + print(f" Date: {result.get('date')}") |
| 43 | + print(f" Author: {result.get('author')}") |
| 44 | + print(f" Platform: {result.get('platform')}") |
| 45 | + print(f" Type: {result.get('type')}") |
| 46 | +else: |
| 47 | + print(f" No exploits found for CVE: {cve_id}") |
| 48 | + |
| 49 | +# Example 2: Search for a CVE ID by Exploit-DB ID |
| 50 | +edb_id = "51743" # Example EDB ID (replace with one you're interested in) |
| 51 | +print(f"\nSearching for CVEs related to Exploit-DB ID: {edb_id}") |
| 52 | +results_edb = pEdb.searchEdbid(edb_id) |
| 53 | +if results_edb: |
| 54 | + for result in results_edb: |
| 55 | + print(f" - CVE: {result.get('cve')}") |
| 56 | + print(f" Title: {result.get('description')}") |
| 57 | +else: |
| 58 | + print(f" No CVEs found for Exploit-DB ID: {edb_id}") |
| 59 | + |
| 60 | +# Example 3: Search for exploits by keyword |
| 61 | +keyword = "webmin" |
| 62 | +print(f"\nSearching for exploits with keyword: '{keyword}'") |
| 63 | +results_keyword = pEdb.searchAll(keyword) |
| 64 | +if results_keyword: |
| 65 | + for result in results_keyword: |
| 66 | + print(f" - Exploit-DB ID: {result.get('edbid')}, CVE: {result.get('cve', 'N/A')}, Description: {result.get('description', 'N/A')}") |
| 67 | +else: |
| 68 | + print(f" No exploits found for keyword: '{keyword}'") |
| 69 | + |
| 70 | +# Example 4: Get details of a specific exploit file (requires the exploit-database to be cloned) |
| 71 | +# The `openFile()` method by default clones the full Exploit-DB repo into a local path. |
| 72 | +# You can then construct the path to the exploit file and read it. |
| 73 | +# This part assumes you have the full Exploit-DB cloned locally. |
| 74 | +# The `exploit` key in the search result gives you the path relative to the exploit-database clone. |
| 75 | + |
| 76 | +# For example, if you found EDBID 45447 (from the GitHub README example) |
| 77 | +# exploit_path_relative = "./exploit-database/exploits/php/webapps/45447.txt" |
| 78 | +# This path is relative to the `pyExploitDb` data directory where it clones exploit-database. |
| 79 | +# You'd need to know where pyExploitDb stores its data to access the raw file. |
| 80 | +# pEdb.exploitdb_path will give you the root of the cloned Exploit-DB repository. |
| 81 | +# You would then join it with the `exploit` value from a search result. |
| 82 | + |
| 83 | +# Example: |
| 84 | +# results_cve_specific = pEdb.searchCve("CVE-2018-14592") |
| 85 | +# if results_cve_specific: |
| 86 | +# first_exploit = results_cve_specific[0] |
| 87 | +# full_exploit_path = os.path.join(pEdb.exploitdb_path, first_exploit.get('exploit')) |
| 88 | +# print(f"\nAttempting to read exploit file: {full_exploit_path}") |
| 89 | +# try: |
| 90 | +# with open(full_exploit_path, 'r') as f: |
| 91 | +# print(f.read()[:500] + "...") # Print first 500 chars |
| 92 | +# except FileNotFoundError: |
| 93 | +# print("Exploit file not found locally. Ensure exploit-database is fully cloned.") |
0 commit comments