@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.
Files changed (99) hide show
  1. package/FEAR.js +459 -0
  2. package/FEARServer.js +280 -0
  3. package/controllers/agent.js +438 -0
  4. package/controllers/auth/index.js +345 -0
  5. package/controllers/auth/token.js +50 -0
  6. package/controllers/blog.js +105 -0
  7. package/controllers/brand.js +10 -0
  8. package/controllers/cart.js +425 -0
  9. package/controllers/category.js +9 -0
  10. package/controllers/coupon.js +63 -0
  11. package/controllers/crud/crud.js +508 -0
  12. package/controllers/crud/index.js +36 -0
  13. package/controllers/email.js +34 -0
  14. package/controllers/enquiry.js +65 -0
  15. package/controllers/events.js +9 -0
  16. package/controllers/order.js +125 -0
  17. package/controllers/payment.js +31 -0
  18. package/controllers/product.js +147 -0
  19. package/controllers/review.js +247 -0
  20. package/controllers/tag.js +10 -0
  21. package/controllers/task.js +10 -0
  22. package/controllers/upload.js +41 -0
  23. package/controllers/user.js +401 -0
  24. package/index.js +7 -0
  25. package/libs/agent/index.js +561 -0
  26. package/libs/agent/modules/ai/ai.js +285 -0
  27. package/libs/agent/modules/ai/chat.js +518 -0
  28. package/libs/agent/modules/ai/config.js +688 -0
  29. package/libs/agent/modules/ai/operations.js +787 -0
  30. package/libs/agent/modules/analyze/api.js +546 -0
  31. package/libs/agent/modules/analyze/dorks.js +395 -0
  32. package/libs/agent/modules/ccard/README.md +454 -0
  33. package/libs/agent/modules/ccard/audit.js +479 -0
  34. package/libs/agent/modules/ccard/checker.js +674 -0
  35. package/libs/agent/modules/ccard/payment-processors.json +16 -0
  36. package/libs/agent/modules/ccard/validator.js +629 -0
  37. package/libs/agent/modules/code/analyzer.js +303 -0
  38. package/libs/agent/modules/code/jquery.js +1093 -0
  39. package/libs/agent/modules/code/react.js +1536 -0
  40. package/libs/agent/modules/code/refactor.js +499 -0
  41. package/libs/agent/modules/crypto/exchange.js +564 -0
  42. package/libs/agent/modules/net/proxy.js +409 -0
  43. package/libs/agent/modules/security/cve.js +442 -0
  44. package/libs/agent/modules/security/monitor.js +360 -0
  45. package/libs/agent/modules/security/scanner.js +300 -0
  46. package/libs/agent/modules/security/vulnerability.js +506 -0
  47. package/libs/agent/modules/security/web.js +465 -0
  48. package/libs/agent/modules/utils/browser.js +492 -0
  49. package/libs/agent/modules/utils/colorizer.js +285 -0
  50. package/libs/agent/modules/utils/manager.js +478 -0
  51. package/libs/cloud/index.js +228 -0
  52. package/libs/config/db.js +21 -0
  53. package/libs/config/validator.js +82 -0
  54. package/libs/db/index.js +318 -0
  55. package/libs/emailer/imap.js +126 -0
  56. package/libs/emailer/info.js +41 -0
  57. package/libs/emailer/smtp.js +77 -0
  58. package/libs/handler/async.js +3 -0
  59. package/libs/handler/error.js +66 -0
  60. package/libs/handler/index.js +161 -0
  61. package/libs/logger/index.js +49 -0
  62. package/libs/logger/morgan.js +24 -0
  63. package/libs/passport/passport.js +109 -0
  64. package/libs/search/api.js +384 -0
  65. package/libs/search/features.js +219 -0
  66. package/libs/search/service.js +64 -0
  67. package/libs/swagger/config.js +18 -0
  68. package/libs/swagger/index.js +35 -0
  69. package/libs/validator/index.js +254 -0
  70. package/models/blog.js +31 -0
  71. package/models/brand.js +12 -0
  72. package/models/cart.js +14 -0
  73. package/models/category.js +11 -0
  74. package/models/coupon.js +9 -0
  75. package/models/customer.js +0 -0
  76. package/models/enquiry.js +29 -0
  77. package/models/events.js +13 -0
  78. package/models/order.js +94 -0
  79. package/models/product.js +32 -0
  80. package/models/review.js +14 -0
  81. package/models/tag.js +10 -0
  82. package/models/task.js +11 -0
  83. package/models/user.js +68 -0
  84. package/package.json +12 -0
  85. package/routes/agent.js +615 -0
  86. package/routes/auth.js +13 -0
  87. package/routes/blog.js +19 -0
  88. package/routes/brand.js +15 -0
  89. package/routes/cart.js +105 -0
  90. package/routes/category.js +16 -0
  91. package/routes/coupon.js +15 -0
  92. package/routes/enquiry.js +14 -0
  93. package/routes/events.js +16 -0
  94. package/routes/mail.js +170 -0
  95. package/routes/order.js +19 -0
  96. package/routes/product.js +22 -0
  97. package/routes/review.js +11 -0
  98. package/routes/task.js +12 -0
  99. package/routes/user.js +17 -0
@@ -0,0 +1,506 @@
1
+ // modules/vulnerability-assessment.js - Vulnerability Assessment & Testing
2
+ const https = require('https');
3
+ const http = require('http');
4
+ const { URL } = require('url');
5
+ const fs = require('fs').promises;
6
+ const net = require('net');
7
+ const colorizer = require('../utils/colorizer');
8
+
9
+ const VulnerabilityAssessment = function() {}
10
+
11
+ VulnerabilityAssessment.prototype = {
12
+
13
+ assess(args) {
14
+ const url = args[0];
15
+ const testType = args[1] || 'all';
16
+
17
+ if (!url) {
18
+ console.log(colorizer.error('Usage: vuln-assess <url> [test-type]'));
19
+ console.log(colorizer.info('Available tests:'));
20
+ console.log(colorizer.dim(' sql-injection - Test for SQL injection'));
21
+ console.log(colorizer.dim(' xss - Test for Cross-Site Scripting'));
22
+ console.log(colorizer.dim(' directory-traversal - Test for path traversal'));
23
+ console.log(colorizer.dim(' command-injection - Test for OS command injection'));
24
+ console.log(colorizer.dim(' xxe - Test for XML External Entity'));
25
+ console.log(colorizer.dim(' ssrf - Test for Server-Side Request Forgery'));
26
+ console.log(colorizer.dim(' open-redirect - Test for open redirect'));
27
+ console.log(colorizer.dim(' csrf - Test for CSRF vulnerabilities'));
28
+ console.log(colorizer.dim(' all - Run all tests (default)'));
29
+ console.log(colorizer.warning('WARNING: Only test systems you own or have permission to test!\n'));
30
+ return Promise.resolve();
31
+ }
32
+
33
+ console.log(colorizer.header('Vulnerability Assessment'));
34
+ console.log(colorizer.separator());
35
+ console.log(colorizer.cyan('Target: ') + colorizer.bright(url));
36
+ console.log(colorizer.cyan('Test Type: ') + colorizer.yellow(testType));
37
+ console.log(colorizer.warning('Only testing systems with authorization!'));
38
+ console.log();
39
+
40
+ this.results = [];
41
+ const testFunc = this.vulnerabilityTests[testType];
42
+
43
+ if (!testFunc) {
44
+ console.log(colorizer.error('Unknown test type: ' + testType + '\n'));
45
+ return Promise.resolve();
46
+ }
47
+
48
+ return testFunc(url)
49
+ .then(() => {
50
+ this.displayResults();
51
+ })
52
+ .catch(err => {
53
+ console.log(colorizer.error('Assessment failed: ' + err.message + '\n'));
54
+ });
55
+ },
56
+
57
+ testSQLInjection(url) {
58
+ console.log(colorizer.section('Testing for SQL Injection'));
59
+
60
+ const payloads = [
61
+ "' OR '1'='1",
62
+ "1' OR '1'='1' --",
63
+ "admin'--",
64
+ "' UNION SELECT NULL--",
65
+ "1' AND 1=1--",
66
+ "1' AND 1=2--"
67
+ ];
68
+
69
+ const promises = payloads.map(payload => {
70
+ const testUrl = this.appendParam(url, 'id', payload);
71
+ return this.makeRequest(testUrl)
72
+ .then(response => {
73
+ const indicators = [
74
+ 'SQL syntax',
75
+ 'mysql_fetch',
76
+ 'ORA-',
77
+ 'PostgreSQL',
78
+ 'SQLite',
79
+ 'Microsoft SQL',
80
+ 'syntax error'
81
+ ];
82
+
83
+ const vulnerable = indicators.some(indicator =>
84
+ response.body && response.body.toLowerCase().includes(indicator.toLowerCase())
85
+ );
86
+
87
+ if (vulnerable) {
88
+ this.addResult('SQL Injection', 'CRITICAL', 'Vulnerable',
89
+ 'SQL error messages detected in response', testUrl);
90
+ console.log(colorizer.critical('VULNERABLE - SQL error detected with payload: ' + payload));
91
+ } else if (response.statusCode >= 500) {
92
+ this.addResult('SQL Injection', 'HIGH', 'Possible',
93
+ 'Server error (500) with SQL payload', testUrl);
94
+ console.log(colorizer.high('POSSIBLE - Server error with payload: ' + payload));
95
+ }
96
+ })
97
+ .catch(() => {
98
+ // Connection errors are expected with some payloads
99
+ });
100
+ });
101
+
102
+ return Promise.all(promises)
103
+ .then(() => {
104
+ console.log(colorizer.success('SQL Injection test complete'));
105
+ });
106
+ },
107
+
108
+ testXSS(url) {
109
+ console.log(colorizer.section('Testing for Cross-Site Scripting (XSS)'));
110
+
111
+ const payloads = [
112
+ '<script>alert(1)</script>',
113
+ '"><script>alert(1)</script>',
114
+ '<img src=x onerror=alert(1)>',
115
+ '<svg onload=alert(1)>',
116
+ 'javascript:alert(1)'
117
+ ];
118
+
119
+ const promises = payloads.map(payload => {
120
+ const testUrl = this.appendParam(url, 'q', payload);
121
+ return this.makeRequest(testUrl)
122
+ .then(response => {
123
+ if (response.body && response.body.includes(payload)) {
124
+ this.addResult('XSS', 'HIGH', 'Vulnerable',
125
+ 'Unescaped payload reflected in response', testUrl);
126
+ console.log(colorizer.high('VULNERABLE - Payload reflected: ' + payload.substring(0, 50)));
127
+ }
128
+ })
129
+ .catch(() => {});
130
+ });
131
+
132
+ return Promise.all(promises)
133
+ .then(() => {
134
+ console.log(colorizer.success('XSS test complete'));
135
+ });
136
+ },
137
+
138
+ testDirectoryTraversal(url) {
139
+ console.log(colorizer.section('Testing for Directory Traversal'));
140
+
141
+ const payloads = [
142
+ '../../../etc/passwd',
143
+ '..\\..\\..\\windows\\system.ini',
144
+ '....//....//....//etc/passwd',
145
+ '%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'
146
+ ];
147
+
148
+ const promises = payloads.map(payload => {
149
+ const testUrl = this.appendParam(url, 'file', payload);
150
+ return this.makeRequest(testUrl)
151
+ .then(response => {
152
+ const indicators = [
153
+ 'root:',
154
+ '[extensions]',
155
+ 'for 16-bit app support'
156
+ ];
157
+
158
+ const vulnerable = indicators.some(indicator =>
159
+ response.body && response.body.includes(indicator)
160
+ );
161
+
162
+ if (vulnerable) {
163
+ this.addResult('Directory Traversal', 'CRITICAL', 'Vulnerable',
164
+ 'System file contents detected in response', testUrl);
165
+ console.log(colorizer.critical('VULNERABLE - System file accessed with: ' + payload));
166
+ }
167
+ })
168
+ .catch(() => {});
169
+ });
170
+
171
+ return Promise.all(promises)
172
+ .then(() => {
173
+ console.log(colorizer.success('Directory Traversal test complete'));
174
+ });
175
+ },
176
+
177
+ testCommandInjection(url) {
178
+ console.log(colorizer.section('Testing for Command Injection'));
179
+
180
+ const payloads = [
181
+ '; ls -la',
182
+ '| whoami',
183
+ '`whoami`',
184
+ '$(whoami)',
185
+ '& dir'
186
+ ];
187
+
188
+ const promises = payloads.map(payload => {
189
+ const testUrl = this.appendParam(url, 'cmd', payload);
190
+ return this.makeRequest(testUrl)
191
+ .then(response => {
192
+ const indicators = [
193
+ 'total ',
194
+ 'drwx',
195
+ 'Directory of',
196
+ 'Volume Serial Number'
197
+ ];
198
+
199
+ const vulnerable = indicators.some(indicator =>
200
+ response.body && response.body.includes(indicator)
201
+ );
202
+
203
+ if (vulnerable) {
204
+ this.addResult('Command Injection', 'CRITICAL', 'Vulnerable',
205
+ 'Command output detected in response', testUrl);
206
+ console.log(colorizer.critical('VULNERABLE - Command executed: ' + payload));
207
+ }
208
+ })
209
+ .catch(() => {});
210
+ });
211
+
212
+ return Promise.all(promises)
213
+ .then(() => {
214
+ console.log(colorizer.success('Command Injection test complete'));
215
+ });
216
+ },
217
+
218
+ testXXE(url) {
219
+ console.log(colorizer.section('Testing for XML External Entity (XXE)'));
220
+
221
+ const payload = '<?xml version="1.0"?><!DOCTYPE root [<!ENTITY test SYSTEM "file:///etc/passwd">]><root>&test;</root>';
222
+
223
+ return this.makeRequest(url, 'POST', payload, {
224
+ 'Content-Type': 'application/xml'
225
+ })
226
+ .then(response => {
227
+ if (response.body && response.body.includes('root:')) {
228
+ this.addResult('XXE', 'CRITICAL', 'Vulnerable',
229
+ 'External entity processed and file contents returned', url);
230
+ console.log(colorizer.critical('VULNERABLE - XXE injection successful'));
231
+ } else {
232
+ console.log(colorizer.success('No XXE vulnerability detected'));
233
+ }
234
+ })
235
+ .catch(() => {
236
+ console.log(colorizer.info('XXE test completed (endpoint may not accept XML)'));
237
+ });
238
+ },
239
+
240
+ testSSRF(url) {
241
+ console.log(colorizer.section('Testing for Server-Side Request Forgery (SSRF)'));
242
+
243
+ const payloads = [
244
+ 'http://localhost:8080',
245
+ 'http://127.0.0.1:22',
246
+ 'http://169.254.169.254/latest/meta-data/',
247
+ 'file:///etc/passwd'
248
+ ];
249
+
250
+ const promises = payloads.map(payload => {
251
+ const testUrl = this.appendParam(url, 'url', payload);
252
+ return this.makeRequest(testUrl)
253
+ .then(response => {
254
+ if (response.statusCode === 200 && response.body && response.body.length > 100) {
255
+ this.addResult('SSRF', 'HIGH', 'Possible',
256
+ 'Server made request to internal resource', testUrl);
257
+ console.log(colorizer.high('POSSIBLE - Internal request to: ' + payload));
258
+ }
259
+ })
260
+ .catch(() => {});
261
+ });
262
+
263
+ return Promise.all(promises)
264
+ .then(() => {
265
+ console.log(colorizer.success('SSRF test complete'));
266
+ });
267
+ },
268
+
269
+ testOpenRedirect(url) {
270
+ console.log(colorizer.section('Testing for Open Redirect'));
271
+
272
+ const payloads = [
273
+ 'https://evil.com',
274
+ '//evil.com',
275
+ '/\\evil.com',
276
+ 'https://example.com@evil.com'
277
+ ];
278
+
279
+ const promises = payloads.map(payload => {
280
+ const testUrl = this.appendParam(url, 'redirect', payload);
281
+ return this.makeRequest(testUrl)
282
+ .then(response => {
283
+ if (response.statusCode >= 300 && response.statusCode < 400) {
284
+ const location = response.headers.location || '';
285
+ if (location.includes('evil.com')) {
286
+ this.addResult('Open Redirect', 'MEDIUM', 'Vulnerable',
287
+ 'Redirects to attacker-controlled domain', testUrl);
288
+ console.log(colorizer.medium('VULNERABLE - Redirects to: ' + location));
289
+ }
290
+ }
291
+ })
292
+ .catch(() => {});
293
+ });
294
+
295
+ return Promise.all(promises)
296
+ .then(() => {
297
+ console.log(colorizer.success('Open Redirect test complete'));
298
+ });
299
+ },
300
+
301
+ testCSRF(url) {
302
+ console.log(colorizer.section('Testing for CSRF Protection'));
303
+
304
+ return this.makeRequest(url)
305
+ .then(response => {
306
+ const hasCSRFToken = response.body && (
307
+ response.body.includes('csrf') ||
308
+ response.body.includes('_token') ||
309
+ response.body.includes('authenticity_token')
310
+ );
311
+
312
+ const hasSameSite = response.headers['set-cookie'] &&
313
+ response.headers['set-cookie'].some(cookie =>
314
+ cookie.toLowerCase().includes('samesite')
315
+ );
316
+
317
+ if (!hasCSRFToken && !hasSameSite) {
318
+ this.addResult('CSRF', 'MEDIUM', 'Vulnerable',
319
+ 'No CSRF tokens or SameSite cookies detected', url);
320
+ console.log(colorizer.medium('VULNERABLE - No CSRF protection detected'));
321
+ } else {
322
+ console.log(colorizer.success('CSRF protection appears to be in place'));
323
+ }
324
+ })
325
+ .catch(() => {
326
+ console.log(colorizer.info('CSRF test completed'));
327
+ });
328
+ },
329
+
330
+ runAllTests(url) {
331
+ console.log(colorizer.bright('Running comprehensive vulnerability assessment...\n'));
332
+
333
+ return this.testSQLInjection(url)
334
+ .then(() => this.testXSS(url))
335
+ .then(() => this.testDirectoryTraversal(url))
336
+ .then(() => this.testCommandInjection(url))
337
+ .then(() => this.testXXE(url))
338
+ .then(() => this.testSSRF(url))
339
+ .then(() => this.testOpenRedirect(url))
340
+ .then(() => this.testCSRF(url));
341
+ },
342
+
343
+ makeRequest(url, method = 'GET', body = null, customHeaders = {}) {
344
+ return new Promise((resolve, reject) => {
345
+ const parsedUrl = new URL(url);
346
+ const lib = parsedUrl.protocol === 'https:' ? https : http;
347
+
348
+ const options = {
349
+ hostname: parsedUrl.hostname,
350
+ port: parsedUrl.port,
351
+ path: parsedUrl.pathname + parsedUrl.search,
352
+ method: method,
353
+ headers: {
354
+ 'User-Agent': 'Security-Assessment-Tool/2.3',
355
+ 'Accept': '*/*',
356
+ ...customHeaders
357
+ },
358
+ timeout: 5000,
359
+ rejectUnauthorized: false
360
+ };
361
+
362
+ if (body) {
363
+ options.headers['Content-Length'] = Buffer.byteLength(body);
364
+ }
365
+
366
+ const req = lib.request(options, res => {
367
+ let data = '';
368
+
369
+ res.on('data', chunk => {
370
+ data += chunk.toString();
371
+ });
372
+
373
+ res.on('end', () => {
374
+ resolve({
375
+ statusCode: res.statusCode,
376
+ headers: res.headers,
377
+ body: data
378
+ });
379
+ });
380
+ });
381
+
382
+ req.on('error', err => {
383
+ reject(err);
384
+ });
385
+
386
+ req.on('timeout', () => {
387
+ req.destroy();
388
+ reject(new Error('Timeout'));
389
+ });
390
+
391
+ if (body) {
392
+ req.write(body);
393
+ }
394
+
395
+ req.end();
396
+ });
397
+ },
398
+
399
+ appendParam(url, key, value) {
400
+ const separator = url.includes('?') ? '&' : '?';
401
+ return url + separator + key + '=' + encodeURIComponent(value);
402
+ },
403
+
404
+ addResult(vulnerability, severity, status, description, url) {
405
+ this.results.push({
406
+ vulnerability,
407
+ severity,
408
+ status,
409
+ description,
410
+ url,
411
+ timestamp: new Date().toISOString()
412
+ });
413
+ },
414
+
415
+ displayResults() {
416
+ console.log(colorizer.header('Assessment Results'));
417
+ console.log(colorizer.separator());
418
+
419
+ if (this.results.length === 0) {
420
+ console.log(colorizer.success('No vulnerabilities detected!\n'));
421
+ return;
422
+ }
423
+
424
+ const critical = this.results.filter(r => r.severity === 'CRITICAL');
425
+ const high = this.results.filter(r => r.severity === 'HIGH');
426
+ const medium = this.results.filter(r => r.severity === 'MEDIUM');
427
+ const low = this.results.filter(r => r.severity === 'LOW');
428
+
429
+ if (critical.length > 0) {
430
+ console.log(colorizer.section('CRITICAL Vulnerabilities'));
431
+ critical.forEach(r => {
432
+ console.log(colorizer.critical(r.vulnerability + ' - ' + r.status));
433
+ console.log(colorizer.dim(' ' + r.description));
434
+ console.log(colorizer.dim(' URL: ' + r.url.substring(0, 80)));
435
+ });
436
+ }
437
+
438
+ if (high.length > 0) {
439
+ console.log(colorizer.section('HIGH Vulnerabilities'));
440
+ high.forEach(r => {
441
+ console.log(colorizer.high(r.vulnerability + ' - ' + r.status));
442
+ console.log(colorizer.dim(' ' + r.description));
443
+ console.log(colorizer.dim(' URL: ' + r.url.substring(0, 80)));
444
+ });
445
+ }
446
+
447
+ if (medium.length > 0) {
448
+ console.log(colorizer.section('MEDIUM Vulnerabilities'));
449
+ medium.forEach(r => {
450
+ console.log(colorizer.medium(r.vulnerability + ' - ' + r.status));
451
+ console.log(colorizer.dim(' ' + r.description));
452
+ console.log(colorizer.dim(' URL: ' + r.url.substring(0, 80)));
453
+ });
454
+ }
455
+
456
+ console.log(colorizer.section('Summary'));
457
+ console.log(colorizer.dim(' Total Vulnerabilities: ' + this.results.length));
458
+ console.log(colorizer.critical(' Critical: ' + critical.length));
459
+ console.log(colorizer.high(' High: ' + high.length));
460
+ console.log(colorizer.medium(' Medium: ' + medium.length));
461
+ console.log(colorizer.low(' Low: ' + low.length));
462
+
463
+ const score = this.calculateRiskScore(critical.length, high.length, medium.length, low.length);
464
+ console.log(colorizer.section('Risk Score: ' +
465
+ (score >= 80 ? colorizer.red(score) :
466
+ score >= 50 ? colorizer.yellow(score) :
467
+ colorizer.green(score)) + '/100'));
468
+ console.log();
469
+ },
470
+
471
+ calculateRiskScore(critical, high, medium, low) {
472
+ return Math.min(100, (critical * 30) + (high * 20) + (medium * 10) + (low * 5));
473
+ },
474
+
475
+ exportResults(args) {
476
+ const filename = args[0] || 'vulnerability-assessment-' + Date.now() + '.json';
477
+
478
+ const report = {
479
+ timestamp: new Date().toISOString(),
480
+ results: this.results,
481
+ summary: {
482
+ total: this.results.length,
483
+ critical: this.results.filter(r => r.severity === 'CRITICAL').length,
484
+ high: this.results.filter(r => r.severity === 'HIGH').length,
485
+ medium: this.results.filter(r => r.severity === 'MEDIUM').length,
486
+ low: this.results.filter(r => r.severity === 'LOW').length
487
+ },
488
+ riskScore: this.calculateRiskScore(
489
+ this.results.filter(r => r.severity === 'CRITICAL').length,
490
+ this.results.filter(r => r.severity === 'HIGH').length,
491
+ this.results.filter(r => r.severity === 'MEDIUM').length,
492
+ this.results.filter(r => r.severity === 'LOW').length
493
+ )
494
+ };
495
+
496
+ return fs.writeFile(filename, JSON.stringify(report, null, 2))
497
+ .then(() => {
498
+ console.log(colorizer.success('Assessment report exported to: ' + filename + '\n'));
499
+ })
500
+ .catch(err => {
501
+ console.log(colorizer.error('Export failed: ' + err.message + '\n'));
502
+ });
503
+ }
504
+ };
505
+
506
+ module.exports = VulnerabilityAssessment;