UNPKG

web-vuln-scanner

Version:

Advanced, lightweight web vulnerability scanner with smart detection and easy-to-use interface

81 lines (63 loc) 2.48 kB
const fs = require('fs'); const path = require('path'); function generateMarkdown(results) { const { target, targetUrl, summary, vulnerabilities } = results; const timestamp = new Date().toLocaleString(); // Use target or targetUrl, whichever is available const scanTarget = target || targetUrl || 'Unknown'; // Calculate actual counts from vulnerabilities if summary is incomplete const severityCounts = { high: 0, medium: 0, low: 0, info: 0 }; vulnerabilities.forEach(v => { const severity = (v.severity || 'info').toLowerCase(); if (severityCounts[severity] !== undefined) { severityCounts[severity]++; } }); let md = `# Web Vulnerability Scan Report **Target:** ${scanTarget} **Scan Date:** ${timestamp} --- ## Summary - 🔴 **High:** ${summary?.high || severityCounts.high || 0} - 🟠 **Medium:** ${summary?.medium || severityCounts.medium || 0} - 🔵 **Low:** ${summary?.low || severityCounts.low || 0} - ⚪ **Info:** ${summary?.info || severityCounts.info || 0} --- ## Vulnerabilities `; // Group by type const grouped = {}; vulnerabilities.forEach((v) => { if (!grouped[v.type]) grouped[v.type] = []; grouped[v.type].push(v); }); let count = 1; for (const [type, list] of Object.entries(grouped)) { md += `### 🔹 ${type.toUpperCase()}\n\n`; list.forEach((v) => { const url = v.url || scanTarget || 'Target'; const severity = (v.severity || 'info').toUpperCase(); const riskLevel = v.riskLevel || v.severity || 'low'; const description = v.description || 'No description available'; const recommendation = v.recommendation || v.remediation || 'Review security configuration'; const evidence = typeof v.evidence === 'string' ? v.evidence : v.evidence ? JSON.stringify(v.evidence, null, 2) : 'No evidence available'; md += `#### ${count++}. ${severity}${url}\n`; md += `- **Risk Level:** ${riskLevel}\n`; md += `- **Description:** ${description}\n`; md += `- **Recommendation:** ${recommendation}\n`; md += `- **Evidence:**\n\`\`\`\n${evidence}\n\`\`\`\n\n`; }); md += '---\n'; } return md; } function saveMarkdownReport(filePath, results) { const content = generateMarkdown(results); fs.writeFileSync(path.resolve(filePath), content, 'utf-8'); console.log(`Markdown report saved at: ${filePath}`); } module.exports = { generateMarkdown, saveMarkdownReport };