Search for exploits matching query.
(
self,
query: str,
exact_match: bool = False,
exclude_dos: bool = True,
)
| 17 | |
| 18 | async def search( |
| 19 | self, |
| 20 | query: str, |
| 21 | exact_match: bool = False, |
| 22 | exclude_dos: bool = True, |
| 23 | ) -> list[dict]: |
| 24 | """Search for exploits matching query.""" |
| 25 | if not self.searchsploit_available: |
| 26 | self.logger.warning("searchsploit not found. Install exploitdb package.") |
| 27 | return [] |
| 28 | |
| 29 | cmd = ["searchsploit", "--json"] |
| 30 | |
| 31 | if exact_match: |
| 32 | cmd.append("--exact") |
| 33 | |
| 34 | if exclude_dos: |
| 35 | cmd.append("--exclude=dos") |
| 36 | |
| 37 | cmd.append(query) |
| 38 | |
| 39 | try: |
| 40 | proc = await asyncio.create_subprocess_exec( |
| 41 | *cmd, |
| 42 | stdout=asyncio.subprocess.PIPE, |
| 43 | stderr=asyncio.subprocess.PIPE, |
| 44 | ) |
| 45 | |
| 46 | stdout, stderr = await proc.communicate() |
| 47 | |
| 48 | if stdout: |
| 49 | data = json.loads(stdout.decode()) |
| 50 | return data.get("RESULTS_EXPLOIT", []) |
| 51 | |
| 52 | except json.JSONDecodeError: |
| 53 | self.logger.error("Failed to parse searchsploit output") |
| 54 | except Exception as e: |
| 55 | self.logger.error(f"searchsploit failed: {e}") |
| 56 | |
| 57 | return [] |
| 58 | |
| 59 | async def search_for_service( |
| 60 | self, |
| 61 | service: str, |