MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / save_scan_finding

Method save_scan_finding

db_manager.py:2135–2204  ·  view source on GitHub ↗

Save a vulnerability finding to the database. Args: finding_id: Unique finding identifier scan_id: Parent scan ID scanner: Scanner that found it (nuclei, zap, nikto, etc.) host: Target host port: Target port (optional)

(self, finding_id: str, scan_id: str, scanner: str, host: str,
                          port: int = None, severity: str = 'info', title: str = '',
                          description: str = '', cve_ids: List[str] = None,
                          cwe_ids: List[str] = None, cvss_score: float = None,
                          evidence: str = '', remediation: str = '',
                          references: List[str] = None, tags: List[str] = None,
                          matched_at: str = '', template_id: str = '',
                          raw_output: str = '', details: dict = None)

Source from the content-addressed store, hash-verified

2133 cursor = conn.cursor()
2134 cursor.execute("DELETE FROM scan_jobs WHERE scan_id = ?", (scan_id,))
2135 conn.commit()
2136 return True
2137 except Exception as e:
2138 logger.error(f"Failed to delete scan job {scan_id}: {e}")
2139 return False
2140
2141 def all_scan_db_paths(self) -> List[str]:
2142 """
2143 Every SQLite file that may hold scan_jobs/scan_findings rows: the
2144 current db_path plus each per-network DB under <datadir>/networks/*/db/.
2145
2146 Scans are persisted to whichever network DB was active when they ran,
2147 so any scan-level delete/cleanup must consider all of them — deleting
2148 from only the current db_path silently misses rows (and leftover
2149 status='running' rows get resurrected into active_scans at every boot).
2150 """
2151 paths = [self.db_path]
2152 try:
2153 import glob as _glob
2154 current = os.path.abspath(self.db_path)
2155 for p in _glob.glob(os.path.join(self.datadir, 'networks', '*', 'db', '*.db')):
2156 if os.path.abspath(p) != current:
2157 paths.append(p)
2158 except Exception as e:
2159 logger.debug(f"Could not enumerate network DBs under {self.datadir}: {e}")
2160 return paths
2161
2162 def delete_scan_everywhere(self, scan_id: str) -> int:
2163 """
2164 Delete a scan job (and its findings) from every known DB: the current
2165 db_path and all per-network DBs.
2166
2167 Args:
2168 scan_id: Scan ID to delete
2169
2170 Returns:
2171 int: total scan_jobs rows removed (0 if the scan was unknown)
2172 """
2173 import sqlite3 as _sqlite3
2174 removed = 0
2175 for path in self.all_scan_db_paths():
2176 try:
2177 with _sqlite3.connect(path, timeout=30) as conn:
2178 n = conn.execute(
2179 "DELETE FROM scan_jobs WHERE scan_id = ?", (scan_id,)).rowcount
2180 f = conn.execute(
2181 "DELETE FROM scan_findings WHERE scan_id = ?", (scan_id,)).rowcount
2182 conn.commit()
2183 removed += n
2184 if n or f:
2185 logger.info(f"Deleted scan {scan_id} rows from {path} "
2186 f"(jobs={n}, findings={f})")
2187 except Exception as e:
2188 # A network DB without the scan tables is fine — it just holds
2189 # nothing for this scan.
2190 logger.debug(f"delete_scan_everywhere skipped {path}: {e}")
2191 return removed
2192

Callers 1

_save_finding_to_dbMethod · 0.80

Calls 5

get_connectionMethod · 0.95
cursorMethod · 0.80
commitMethod · 0.80
errorMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected