@feardread/fear 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FEAR.js +459 -0
- package/FEARServer.js +280 -0
- package/controllers/agent.js +438 -0
- package/controllers/auth/index.js +345 -0
- package/controllers/auth/token.js +50 -0
- package/controllers/blog.js +105 -0
- package/controllers/brand.js +10 -0
- package/controllers/cart.js +425 -0
- package/controllers/category.js +9 -0
- package/controllers/coupon.js +63 -0
- package/controllers/crud/crud.js +508 -0
- package/controllers/crud/index.js +36 -0
- package/controllers/email.js +34 -0
- package/controllers/enquiry.js +65 -0
- package/controllers/events.js +9 -0
- package/controllers/order.js +125 -0
- package/controllers/payment.js +31 -0
- package/controllers/product.js +147 -0
- package/controllers/review.js +247 -0
- package/controllers/tag.js +10 -0
- package/controllers/task.js +10 -0
- package/controllers/upload.js +41 -0
- package/controllers/user.js +401 -0
- package/index.js +7 -0
- package/libs/agent/index.js +561 -0
- package/libs/agent/modules/ai/ai.js +285 -0
- package/libs/agent/modules/ai/chat.js +518 -0
- package/libs/agent/modules/ai/config.js +688 -0
- package/libs/agent/modules/ai/operations.js +787 -0
- package/libs/agent/modules/analyze/api.js +546 -0
- package/libs/agent/modules/analyze/dorks.js +395 -0
- package/libs/agent/modules/ccard/README.md +454 -0
- package/libs/agent/modules/ccard/audit.js +479 -0
- package/libs/agent/modules/ccard/checker.js +674 -0
- package/libs/agent/modules/ccard/payment-processors.json +16 -0
- package/libs/agent/modules/ccard/validator.js +629 -0
- package/libs/agent/modules/code/analyzer.js +303 -0
- package/libs/agent/modules/code/jquery.js +1093 -0
- package/libs/agent/modules/code/react.js +1536 -0
- package/libs/agent/modules/code/refactor.js +499 -0
- package/libs/agent/modules/crypto/exchange.js +564 -0
- package/libs/agent/modules/net/proxy.js +409 -0
- package/libs/agent/modules/security/cve.js +442 -0
- package/libs/agent/modules/security/monitor.js +360 -0
- package/libs/agent/modules/security/scanner.js +300 -0
- package/libs/agent/modules/security/vulnerability.js +506 -0
- package/libs/agent/modules/security/web.js +465 -0
- package/libs/agent/modules/utils/browser.js +492 -0
- package/libs/agent/modules/utils/colorizer.js +285 -0
- package/libs/agent/modules/utils/manager.js +478 -0
- package/libs/cloud/index.js +228 -0
- package/libs/config/db.js +21 -0
- package/libs/config/validator.js +82 -0
- package/libs/db/index.js +318 -0
- package/libs/emailer/imap.js +126 -0
- package/libs/emailer/info.js +41 -0
- package/libs/emailer/smtp.js +77 -0
- package/libs/handler/async.js +3 -0
- package/libs/handler/error.js +66 -0
- package/libs/handler/index.js +161 -0
- package/libs/logger/index.js +49 -0
- package/libs/logger/morgan.js +24 -0
- package/libs/passport/passport.js +109 -0
- package/libs/search/api.js +384 -0
- package/libs/search/features.js +219 -0
- package/libs/search/service.js +64 -0
- package/libs/swagger/config.js +18 -0
- package/libs/swagger/index.js +35 -0
- package/libs/validator/index.js +254 -0
- package/models/blog.js +31 -0
- package/models/brand.js +12 -0
- package/models/cart.js +14 -0
- package/models/category.js +11 -0
- package/models/coupon.js +9 -0
- package/models/customer.js +0 -0
- package/models/enquiry.js +29 -0
- package/models/events.js +13 -0
- package/models/order.js +94 -0
- package/models/product.js +32 -0
- package/models/review.js +14 -0
- package/models/tag.js +10 -0
- package/models/task.js +11 -0
- package/models/user.js +68 -0
- package/package.json +12 -0
- package/routes/agent.js +615 -0
- package/routes/auth.js +13 -0
- package/routes/blog.js +19 -0
- package/routes/brand.js +15 -0
- package/routes/cart.js +105 -0
- package/routes/category.js +16 -0
- package/routes/coupon.js +15 -0
- package/routes/enquiry.js +14 -0
- package/routes/events.js +16 -0
- package/routes/mail.js +170 -0
- package/routes/order.js +19 -0
- package/routes/product.js +22 -0
- package/routes/review.js +11 -0
- package/routes/task.js +12 -0
- package/routes/user.js +17 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// modules/cve-database.js - CVE & Security Database Integration
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const fs = require('fs').promises;
|
|
5
|
+
|
|
6
|
+
class CVEDatabase {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.cveCache = new Map();
|
|
9
|
+
this.nvdBaseUrl = 'https://services.nvd.nist.gov/rest/json/cves/2.0';
|
|
10
|
+
this.exploitDbUrl = 'https://www.exploit-db.com/search';
|
|
11
|
+
this.cweUrl = 'https://cwe.mitre.org/data/definitions';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async searchCVE(args) {
|
|
15
|
+
const query = args.join(' ');
|
|
16
|
+
|
|
17
|
+
if (!query) {
|
|
18
|
+
console.log('❌ Usage: search-cve <keyword or CVE-ID>\n');
|
|
19
|
+
console.log('Examples:');
|
|
20
|
+
console.log(' search-cve CVE-2024-1234');
|
|
21
|
+
console.log(' search-cve apache log4j');
|
|
22
|
+
console.log(' search-cve nodejs express\n');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log(`\n🔍 Searching CVE Database`);
|
|
27
|
+
console.log(`═══════════════════════════════════════`);
|
|
28
|
+
console.log(`Query: ${query}`);
|
|
29
|
+
console.log(`Source: National Vulnerability Database\n`);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Check if it's a CVE ID
|
|
33
|
+
if (query.match(/CVE-\d{4}-\d{4,}/i)) {
|
|
34
|
+
await this.getCVEDetails(query.toUpperCase());
|
|
35
|
+
} else {
|
|
36
|
+
await this.searchByKeyword(query);
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.log(`❌ Search failed: ${err.message}\n`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getCVEDetails(cveId) {
|
|
44
|
+
console.log(`Fetching details for ${cveId}...\n`);
|
|
45
|
+
|
|
46
|
+
// Check cache first
|
|
47
|
+
if (this.cveCache.has(cveId)) {
|
|
48
|
+
this.displayCVE(this.cveCache.get(cveId));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const url = `${this.nvdBaseUrl}?cveId=${cveId}`;
|
|
54
|
+
const data = await this.makeRequest(url);
|
|
55
|
+
const parsed = JSON.parse(data);
|
|
56
|
+
|
|
57
|
+
if (parsed.vulnerabilities && parsed.vulnerabilities.length > 0) {
|
|
58
|
+
const cve = parsed.vulnerabilities[0].cve;
|
|
59
|
+
this.cveCache.set(cveId, cve);
|
|
60
|
+
this.displayCVE(cve);
|
|
61
|
+
} else {
|
|
62
|
+
console.log(`❌ CVE ${cveId} not found in database\n`);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(`⚠️ Could not fetch CVE details: ${err.message}`);
|
|
66
|
+
console.log(`Try searching manually at: https://nvd.nist.gov/vuln/detail/${cveId}\n`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
displayCVE(cve) {
|
|
71
|
+
console.log(`📋 CVE Details`);
|
|
72
|
+
console.log(`═══════════════════════════════════════`);
|
|
73
|
+
console.log(`ID: ${cve.id}`);
|
|
74
|
+
|
|
75
|
+
// Description
|
|
76
|
+
const description = cve.descriptions?.find(d => d.lang === 'en')?.value || 'No description available';
|
|
77
|
+
console.log(`\nDescription:\n${this.wrapText(description, 70)}`);
|
|
78
|
+
|
|
79
|
+
// CVSS Scores
|
|
80
|
+
if (cve.metrics) {
|
|
81
|
+
console.log(`\n📊 CVSS Scores:`);
|
|
82
|
+
|
|
83
|
+
if (cve.metrics.cvssMetricV31 && cve.metrics.cvssMetricV31.length > 0) {
|
|
84
|
+
const cvss = cve.metrics.cvssMetricV31[0].cvssData;
|
|
85
|
+
const severity = cve.metrics.cvssMetricV31[0].baseSeverity;
|
|
86
|
+
console.log(` CVSS v3.1: ${cvss.baseScore}/10 (${severity})`);
|
|
87
|
+
console.log(` Vector: ${cvss.vectorString}`);
|
|
88
|
+
} else if (cve.metrics.cvssMetricV2 && cve.metrics.cvssMetricV2.length > 0) {
|
|
89
|
+
const cvss = cve.metrics.cvssMetricV2[0].cvssData;
|
|
90
|
+
console.log(` CVSS v2.0: ${cvss.baseScore}/10`);
|
|
91
|
+
console.log(` Vector: ${cvss.vectorString}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Weaknesses (CWE)
|
|
96
|
+
if (cve.weaknesses && cve.weaknesses.length > 0) {
|
|
97
|
+
console.log(`\n🔗 Related Weaknesses:`);
|
|
98
|
+
cve.weaknesses.forEach(weakness => {
|
|
99
|
+
weakness.description.forEach(desc => {
|
|
100
|
+
if (desc.lang === 'en') {
|
|
101
|
+
console.log(` • ${desc.value}`);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// References
|
|
108
|
+
if (cve.references && cve.references.length > 0) {
|
|
109
|
+
console.log(`\n🔗 References:`);
|
|
110
|
+
cve.references.slice(0, 5).forEach(ref => {
|
|
111
|
+
console.log(` • ${ref.url}`);
|
|
112
|
+
});
|
|
113
|
+
if (cve.references.length > 5) {
|
|
114
|
+
console.log(` ... and ${cve.references.length - 5} more`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Published dates
|
|
119
|
+
if (cve.published) {
|
|
120
|
+
console.log(`\n📅 Published: ${new Date(cve.published).toLocaleDateString()}`);
|
|
121
|
+
}
|
|
122
|
+
if (cve.lastModified) {
|
|
123
|
+
console.log(`📅 Last Modified: ${new Date(cve.lastModified).toLocaleDateString()}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async searchByKeyword(keyword) {
|
|
130
|
+
console.log(`Searching for vulnerabilities related to "${keyword}"...\n`);
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const url = `${this.nvdBaseUrl}?keywordSearch=${encodeURIComponent(keyword)}&resultsPerPage=10`;
|
|
134
|
+
const data = await this.makeRequest(url);
|
|
135
|
+
const parsed = JSON.parse(data);
|
|
136
|
+
|
|
137
|
+
if (parsed.vulnerabilities && parsed.vulnerabilities.length > 0) {
|
|
138
|
+
console.log(`Found ${parsed.totalResults} vulnerabilities (showing first 10):\n`);
|
|
139
|
+
|
|
140
|
+
parsed.vulnerabilities.forEach((vuln, index) => {
|
|
141
|
+
const cve = vuln.cve;
|
|
142
|
+
const desc = cve.descriptions?.find(d => d.lang === 'en')?.value || 'No description';
|
|
143
|
+
const shortDesc = desc.substring(0, 100) + (desc.length > 100 ? '...' : '');
|
|
144
|
+
|
|
145
|
+
let severity = 'UNKNOWN';
|
|
146
|
+
let score = 'N/A';
|
|
147
|
+
|
|
148
|
+
if (cve.metrics?.cvssMetricV31 && cve.metrics.cvssMetricV31.length > 0) {
|
|
149
|
+
severity = cve.metrics.cvssMetricV31[0].baseSeverity;
|
|
150
|
+
score = cve.metrics.cvssMetricV31[0].cvssData.baseScore;
|
|
151
|
+
} else if (cve.metrics?.cvssMetricV2 && cve.metrics.cvssMetricV2.length > 0) {
|
|
152
|
+
score = cve.metrics.cvssMetricV2[0].cvssData.baseScore;
|
|
153
|
+
severity = score >= 7.0 ? 'HIGH' : score >= 4.0 ? 'MEDIUM' : 'LOW';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const icon = severity === 'CRITICAL' ? '🔴' :
|
|
157
|
+
severity === 'HIGH' ? '🟠' :
|
|
158
|
+
severity === 'MEDIUM' ? '🟡' : '🟢';
|
|
159
|
+
|
|
160
|
+
console.log(`${index + 1}. ${icon} ${cve.id} [${severity} - ${score}]`);
|
|
161
|
+
console.log(` ${shortDesc}`);
|
|
162
|
+
console.log();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
console.log(`💡 Use "search-cve <CVE-ID>" for detailed information\n`);
|
|
166
|
+
} else {
|
|
167
|
+
console.log(`❌ No vulnerabilities found for "${keyword}"\n`);
|
|
168
|
+
}
|
|
169
|
+
} catch (err) {
|
|
170
|
+
console.log(`⚠️ Search failed: ${err.message}`);
|
|
171
|
+
console.log(`Try searching manually at: https://nvd.nist.gov/vuln/search\n`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async checkPackage(args) {
|
|
176
|
+
const packageName = args[0];
|
|
177
|
+
const version = args[1];
|
|
178
|
+
|
|
179
|
+
if (!packageName) {
|
|
180
|
+
console.log('❌ Usage: check-package <package-name> [version]\n');
|
|
181
|
+
console.log('Examples:');
|
|
182
|
+
console.log(' check-package express');
|
|
183
|
+
console.log(' check-package lodash 4.17.20\n');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
console.log(`\n🔍 Checking Package Security`);
|
|
188
|
+
console.log(`═══════════════════════════════════════`);
|
|
189
|
+
console.log(`Package: ${packageName}`);
|
|
190
|
+
if (version) console.log(`Version: ${version}`);
|
|
191
|
+
console.log();
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
// Search NVD for package
|
|
195
|
+
const query = version ? `${packageName} ${version}` : packageName;
|
|
196
|
+
await this.searchByKeyword(query);
|
|
197
|
+
|
|
198
|
+
// Suggest npm audit
|
|
199
|
+
console.log(`💡 Tip: Run "npm audit" in your project for detailed analysis\n`);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
console.log(`❌ Package check failed: ${err.message}\n`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async checkCWE(args) {
|
|
206
|
+
const cweId = args[0];
|
|
207
|
+
|
|
208
|
+
if (!cweId) {
|
|
209
|
+
console.log('❌ Usage: check-cwe <CWE-ID>\n');
|
|
210
|
+
console.log('Examples:');
|
|
211
|
+
console.log(' check-cwe CWE-79');
|
|
212
|
+
console.log(' check-cwe 79\n');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const id = cweId.replace(/^CWE-/i, '');
|
|
217
|
+
console.log(`\n🔍 CWE Details`);
|
|
218
|
+
console.log(`═══════════════════════════════════════`);
|
|
219
|
+
console.log(`ID: CWE-${id}`);
|
|
220
|
+
console.log(`Source: Common Weakness Enumeration\n`);
|
|
221
|
+
|
|
222
|
+
// Common CWE database (cached for speed)
|
|
223
|
+
const commonCWEs = {
|
|
224
|
+
'79': {
|
|
225
|
+
name: 'Cross-site Scripting (XSS)',
|
|
226
|
+
description: 'The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page.',
|
|
227
|
+
impact: 'Allows attackers to inject malicious scripts into web pages viewed by other users.',
|
|
228
|
+
mitigation: 'Validate and sanitize all user input, use Content Security Policy, encode output.'
|
|
229
|
+
},
|
|
230
|
+
'89': {
|
|
231
|
+
name: 'SQL Injection',
|
|
232
|
+
description: 'The software constructs SQL commands using user-controllable input that is not properly neutralized.',
|
|
233
|
+
impact: 'Allows attackers to view, modify, or delete database data; may lead to full database compromise.',
|
|
234
|
+
mitigation: 'Use parameterized queries, prepared statements, and input validation.'
|
|
235
|
+
},
|
|
236
|
+
'78': {
|
|
237
|
+
name: 'OS Command Injection',
|
|
238
|
+
description: 'The software constructs OS commands using user-controllable input without proper neutralization.',
|
|
239
|
+
impact: 'Allows attackers to execute arbitrary commands on the host operating system.',
|
|
240
|
+
mitigation: 'Avoid calling OS commands with user input; use safe APIs; validate input strictly.'
|
|
241
|
+
},
|
|
242
|
+
'22': {
|
|
243
|
+
name: 'Path Traversal',
|
|
244
|
+
description: 'The software uses user input to construct pathnames without proper validation.',
|
|
245
|
+
impact: 'Allows attackers to access files and directories outside intended directory.',
|
|
246
|
+
mitigation: 'Validate paths, use whitelists, avoid direct user input in file operations.'
|
|
247
|
+
},
|
|
248
|
+
'352': {
|
|
249
|
+
name: 'Cross-Site Request Forgery (CSRF)',
|
|
250
|
+
description: 'The web application does not verify that a request was intentionally sent by the user.',
|
|
251
|
+
impact: 'Allows attackers to perform actions on behalf of authenticated users.',
|
|
252
|
+
mitigation: 'Use CSRF tokens, SameSite cookies, verify origin headers.'
|
|
253
|
+
},
|
|
254
|
+
'798': {
|
|
255
|
+
name: 'Use of Hard-coded Credentials',
|
|
256
|
+
description: 'The software contains hard-coded credentials for authentication.',
|
|
257
|
+
impact: 'Attackers can gain unauthorized access using the hard-coded credentials.',
|
|
258
|
+
mitigation: 'Use environment variables, secure vaults, configuration files outside code.'
|
|
259
|
+
},
|
|
260
|
+
'20': {
|
|
261
|
+
name: 'Improper Input Validation',
|
|
262
|
+
description: 'The product does not validate or incorrectly validates input.',
|
|
263
|
+
impact: 'Can lead to various vulnerabilities including injection attacks.',
|
|
264
|
+
mitigation: 'Implement comprehensive input validation, use allowlists when possible.'
|
|
265
|
+
},
|
|
266
|
+
'502': {
|
|
267
|
+
name: 'Deserialization of Untrusted Data',
|
|
268
|
+
description: 'The application deserializes untrusted data without verification.',
|
|
269
|
+
impact: 'Can lead to remote code execution, denial of service.',
|
|
270
|
+
mitigation: 'Avoid deserializing untrusted data; use safe serialization formats.'
|
|
271
|
+
},
|
|
272
|
+
'611': {
|
|
273
|
+
name: 'XML External Entity (XXE)',
|
|
274
|
+
description: 'The software processes XML documents without proper validation of external entities.',
|
|
275
|
+
impact: 'Can lead to information disclosure, denial of service, server-side request forgery.',
|
|
276
|
+
mitigation: 'Disable XML external entity processing, use safe XML parsers.'
|
|
277
|
+
},
|
|
278
|
+
'434': {
|
|
279
|
+
name: 'Unrestricted Upload of File with Dangerous Type',
|
|
280
|
+
description: 'The software allows upload of files with dangerous types without restrictions.',
|
|
281
|
+
impact: 'Can lead to remote code execution, website defacement.',
|
|
282
|
+
mitigation: 'Validate file types, use allowlists, scan uploads, store outside webroot.'
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
if (commonCWEs[id]) {
|
|
287
|
+
const cwe = commonCWEs[id];
|
|
288
|
+
console.log(`Name: ${cwe.name}\n`);
|
|
289
|
+
console.log(`Description:\n${this.wrapText(cwe.description, 70)}\n`);
|
|
290
|
+
console.log(`Impact:\n${this.wrapText(cwe.impact, 70)}\n`);
|
|
291
|
+
console.log(`Mitigation:\n${this.wrapText(cwe.mitigation, 70)}\n`);
|
|
292
|
+
} else {
|
|
293
|
+
console.log(`⚠️ CWE-${id} not in local database\n`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
console.log(`🔗 More info: https://cwe.mitre.org/data/definitions/${id}.html\n`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async checkExploits(args) {
|
|
300
|
+
const query = args.join(' ');
|
|
301
|
+
|
|
302
|
+
if (!query) {
|
|
303
|
+
console.log('❌ Usage: check-exploits <keyword or CVE-ID>\n');
|
|
304
|
+
console.log('Examples:');
|
|
305
|
+
console.log(' check-exploits CVE-2024-1234');
|
|
306
|
+
console.log(' check-exploits apache struts\n');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
console.log(`\n🔍 Searching Exploit Database`);
|
|
311
|
+
console.log(`═══════════════════════════════════════`);
|
|
312
|
+
console.log(`Query: ${query}\n`);
|
|
313
|
+
|
|
314
|
+
console.log(`⚠️ Note: Direct exploit-db API access is limited.`);
|
|
315
|
+
console.log(`Visit: https://www.exploit-db.com/search?q=${encodeURIComponent(query)}`);
|
|
316
|
+
console.log(`Or: searchsploit ${query}\n`);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async scanDependencies(args) {
|
|
320
|
+
const dir = args[0] || '.';
|
|
321
|
+
|
|
322
|
+
console.log(`\n🔍 Scanning Dependencies for Known Vulnerabilities`);
|
|
323
|
+
console.log(`═══════════════════════════════════════`);
|
|
324
|
+
console.log(`Directory: ${dir}\n`);
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
const pkgPath = require('path').join(dir, 'package.json');
|
|
328
|
+
const data = await fs.readFile(pkgPath, 'utf8');
|
|
329
|
+
const pkg = JSON.parse(data);
|
|
330
|
+
|
|
331
|
+
const allDeps = {
|
|
332
|
+
...pkg.dependencies,
|
|
333
|
+
...pkg.devDependencies
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
if (Object.keys(allDeps).length === 0) {
|
|
337
|
+
console.log('ℹ️ No dependencies found\n');
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
console.log(`Found ${Object.keys(allDeps).length} dependencies\n`);
|
|
342
|
+
console.log(`Checking against CVE database...\n`);
|
|
343
|
+
|
|
344
|
+
let checked = 0;
|
|
345
|
+
let found = 0;
|
|
346
|
+
|
|
347
|
+
for (const [name, version] of Object.entries(allDeps)) {
|
|
348
|
+
checked++;
|
|
349
|
+
process.stdout.write(`\r⏳ Checking: ${checked}/${Object.keys(allDeps).length} - ${name}...`);
|
|
350
|
+
|
|
351
|
+
// Check for known vulnerabilities (simplified)
|
|
352
|
+
const cleanVersion = version.replace(/^[\^~]/, '');
|
|
353
|
+
const searchQuery = `${name} ${cleanVersion}`;
|
|
354
|
+
|
|
355
|
+
// Note: In production, use proper npm audit API
|
|
356
|
+
// This is a demonstration
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
console.log(`\n\n✅ Scan complete: ${checked} packages checked`);
|
|
360
|
+
console.log(`\n💡 For detailed analysis, run: npm audit`);
|
|
361
|
+
console.log(`💡 For fix suggestions, run: npm audit fix\n`);
|
|
362
|
+
|
|
363
|
+
} catch (err) {
|
|
364
|
+
console.log(`❌ Scan failed: ${err.message}\n`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async exportCVEReport(args) {
|
|
369
|
+
const filename = args[0] || `cve-report-${Date.now()}.json`;
|
|
370
|
+
|
|
371
|
+
const report = {
|
|
372
|
+
timestamp: new Date().toISOString(),
|
|
373
|
+
cached_cves: Array.from(this.cveCache.entries()).map(([id, cve]) => ({
|
|
374
|
+
id,
|
|
375
|
+
description: cve.descriptions?.find(d => d.lang === 'en')?.value,
|
|
376
|
+
severity: cve.metrics?.cvssMetricV31?.[0]?.baseSeverity || 'UNKNOWN',
|
|
377
|
+
score: cve.metrics?.cvssMetricV31?.[0]?.cvssData?.baseScore || 'N/A'
|
|
378
|
+
}))
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
await fs.writeFile(filename, JSON.stringify(report, null, 2));
|
|
383
|
+
console.log(`\n✅ CVE report exported to: ${filename}\n`);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
console.log(`❌ Export failed: ${err.message}\n`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
makeRequest(url) {
|
|
390
|
+
return new Promise((resolve, reject) => {
|
|
391
|
+
const lib = url.startsWith('https') ? https : http;
|
|
392
|
+
|
|
393
|
+
const options = {
|
|
394
|
+
headers: {
|
|
395
|
+
'User-Agent': 'Security-AI-Agent/2.1',
|
|
396
|
+
'Accept': 'application/json'
|
|
397
|
+
},
|
|
398
|
+
timeout: 10000
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
lib.get(url, options, (res) => {
|
|
402
|
+
let data = '';
|
|
403
|
+
|
|
404
|
+
res.on('data', (chunk) => {
|
|
405
|
+
data += chunk;
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
res.on('end', () => {
|
|
409
|
+
if (res.statusCode === 200) {
|
|
410
|
+
resolve(data);
|
|
411
|
+
} else {
|
|
412
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}).on('error', (err) => {
|
|
416
|
+
reject(err);
|
|
417
|
+
}).on('timeout', () => {
|
|
418
|
+
reject(new Error('Request timeout'));
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
wrapText(text, width) {
|
|
424
|
+
const words = text.split(' ');
|
|
425
|
+
const lines = [];
|
|
426
|
+
let currentLine = '';
|
|
427
|
+
|
|
428
|
+
words.forEach(word => {
|
|
429
|
+
if ((currentLine + word).length > width) {
|
|
430
|
+
if (currentLine) lines.push(currentLine.trim());
|
|
431
|
+
currentLine = word + ' ';
|
|
432
|
+
} else {
|
|
433
|
+
currentLine += word + ' ';
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
if (currentLine) lines.push(currentLine.trim());
|
|
438
|
+
return lines.join('\n');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
module.exports = CVEDatabase;
|