(
self, ref: MSFModuleRef, target: str, port: int, extra: dict
)
| 193 | async def _ensure_connected(self) -> bool: |
| 194 | if not self._connected: |
| 195 | self._connected = await self._msf.connect() |
| 196 | return self._connected |
| 197 | |
| 198 | async def _run_check( |
| 199 | self, ref: MSFModuleRef, target: str, port: int, extra: dict |
| 200 | ) -> ExploitResult: |
| 201 | try: |
| 202 | if not await self._ensure_connected(): |
| 203 | return ExploitResult( |
| 204 | cve_id=ref.cve_id, target=target, port=port, |
| 205 | module_path=ref.module_path, status="ERROR", |
| 206 | error="Cannot connect to Metasploit RPC. Is msfrpcd running?", |
| 207 | ) |
| 208 | |
| 209 | options = {**ref.default_options, "RHOSTS": target, "RPORT": port, **extra} |
| 210 | logger.info(f"[CHECK] {ref.module_path} → {target}:{port} (CVE: {ref.cve_id})") |
| 211 | |
| 212 | if ref.module_type == "exploit": |
| 213 | # Exploit modules: use module.check (runs check() without payload) |
| 214 | raw = await self._msf._call( |
| 215 | "module.check", [ref.module_type, ref.module_path, options] |
| 216 | ) |
| 217 | status = self._parse_check_result(raw) |
| 218 | else: |
| 219 | # Auxiliary modules: use module.execute + direct socket probe fallback |
| 220 | # module.check does not apply to auxiliary scanners. |
| 221 | # We run execute and then probe the service ourselves to confirm exposure. |
| 222 | status = await self._probe_service(target, port, ref) |
| 223 | |
| 224 | logger.info(f"[CHECK RESULT] {ref.cve_id} @ {target}:{port} → {status}") |
| 225 | |
| 226 | from modules.mitre.mapper import MITREMapper # noqa: PLC0415 |
| 227 | tags = MITREMapper.tag_finding( |
| 228 | ref.description, "", cve_ids=[ref.cve_id], port=port |
| 229 | ) |
| 230 | return ExploitResult( |
| 231 | cve_id=ref.cve_id, target=target, port=port, |
| 232 | module_path=ref.module_path, status=status, |
| 233 | attack_tags=[t.to_dict() for t in tags], |
| 234 | ) |
| 235 | |
| 236 | except Exception as exc: |
| 237 | logger.error(f"[CHECK ERROR] {ref.cve_id} @ {target}: {exc}") |
| 238 | return ExploitResult( |
| 239 | cve_id=ref.cve_id, target=target, port=port, |
| 240 | module_path=ref.module_path, status="ERROR", error=str(exc), |
| 241 | ) |
no test coverage detected