noctra-scanner 0.0.0-stage โ 1.0.0
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/README.md +157 -2
- package/bin/noctra +2 -0
- package/bin/noctra.mjs +91 -0
- package/lib/cli/commands/scan.mjs +157 -0
- package/lib/cli/parser.mjs +31 -0
- package/lib/formatters/html.mjs +138 -0
- package/package.json +38 -3
- package/tools/docs/generate-engine-docs.mjs +47 -0
- package/tools/inspector/ast-analyzer.mjs +604 -0
- package/tools/inspector/ast-analyzer.mjs.bak-ast-contract-1795242323915 +526 -0
- package/tools/inspector/ast-analyzer.mjs.bak-dynamic-import-1795241721753 +506 -0
- package/tools/inspector/ast-analyzer.mjs.bak-export-fix-1795240953591 +428 -0
- package/tools/inspector/ast-analyzer.mjs.bak-namespace-export-1795241297271 +506 -0
- package/tools/inspector/binding-resolver.mjs +161 -0
- package/tools/inspector/jsx-parser.mjs +8 -0
- package/tools/inspector/module-analyzer.mjs +127 -0
- package/tools/inspector/parser-registry.mjs +64 -0
- package/tools/inspector/project-dependency-graph.mjs +70 -0
- package/tools/inspector/safe-file-reader.mjs +251 -0
- package/tools/inspector/scope-analyzer.mjs +605 -0
- package/tools/inspector/scope-analyzer.mjs.bak-declaration-node-id +542 -0
- package/tools/inspector/scope-analyzer.mjs.bak-function-id-mapping +541 -0
- package/tools/inspector/typescript-analyzer.mjs +204 -0
- package/tools/nea/core/authorization-verifier.mjs +383 -0
- package/tools/nea/core/contracts.mjs +480 -0
- package/tools/nea/core/control-center.mjs +525 -0
- package/tools/nea/core/engine-registry.mjs +184 -0
- package/tools/nea/core/orchestrator.mjs +306 -0
- package/tools/nea/core/recovery-store.mjs +399 -0
- package/tools/nea/core/restore-coordinator.mjs +372 -0
- package/tools/nea/core/task-router.mjs +403 -0
- package/tools/nea/core/verification-pipeline.mjs +34 -0
- package/tools/nea/core/verification.mjs +280 -0
- package/tools/nea/engines/bounty-hunter.mjs +85 -0
- package/tools/nea/engines/dependency-checker.mjs +57 -0
- package/tools/nea/engines/entropy-secret-scanner.mjs +85 -0
- package/tools/nea/engines/iac-scanner.mjs +160 -0
- package/tools/nea/engines/solidity-scanner.mjs +110 -0
- package/tools/nea/engines/taint-analyzer.mjs +148 -0
- package/tools/nea/engines/vulnerability-scanner.mjs +125 -0
package/README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ๐ก๏ธ NOCTRA
|
|
2
|
+
[](https://github.com/0xjenichord-web/noctra/actions/workflows/test.yml)
|
|
3
|
+
[](https://github.com/0xjenichord-web/noctra/actions/workflows/test.yml)
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
> Independent security research and bug bounty intelligence system.
|
|
6
|
+
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](#)
|
|
9
|
+
[](#)
|
|
10
|
+
|
|
11
|
+
Noctra adalah *security scanner* modular berbasis CLI yang dirancang untuk mendeteksi kerentanan keamanan pada kode JavaScript/TypeScript. Berbeda dengan scanner berbasis Regex biasa, Noctra menggunakan **Abstract Syntax Tree (AST) Analysis** untuk memahami struktur kode secara mendalam, mengurangi *false positive* secara drastis.
|
|
12
|
+
|
|
13
|
+
Didukung oleh arsitektur **NEA (Noctra Engine Architecture)**, Noctra memungkinkan eksekusi multi-engine yang terstandarisasi, aman, dan dapat diperluas (*extensible*).
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## โจ Fitur Utama
|
|
18
|
+
|
|
19
|
+
- ๐ง **AST-Based Detection**: Menganalisis struktur kode (bukan sekadar teks) untuk mendeteksi *Prototype Pollution*, *XSS*, *Eval Injection*, dan lainnya dengan akurasi tinggi.
|
|
20
|
+
- โ๏ธ **Web3 & Solidity Support**: Dedicated engine for smart contract auditing, detecting patterns like `tx.origin` auth, unsafe `delegatecall`, and reentrancy risks.
|
|
21
|
+
- ๐๏ธ **NEA Architecture**: Arsitektur modular di mana setiap fitur adalah "Engine" yang berkomunikasi melalui kontrak data yang ketat (*immutable* & *validated*).
|
|
22
|
+
- โก **Multi-Engine Orchestration**: Menjalankan beberapa engine (misal: Vulnerability Scanner + Dependency Checker) secara paralel dalam satu perintah.
|
|
23
|
+
- ๐ก๏ธ **Read-Only by Default**: Dirancang dengan prinsip keamanan maksimal, menolak *path traversal*, *symlinks*, dan eksekusi kode yang tidak sah.
|
|
24
|
+
- ๐งช **Test-Driven**: Dibangun dengan 285+ unit test yang passing, menjamin stabilitas dan mencegah regresi.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## ๐ Quick Start
|
|
29
|
+
|
|
30
|
+
### Prasyarat
|
|
31
|
+
- Node.js v20 atau lebih baru
|
|
32
|
+
|
|
33
|
+
### Instalasi
|
|
34
|
+
```bash
|
|
35
|
+
# 1. Clone atau masuk ke direktori proyek
|
|
36
|
+
cd ~/noctra
|
|
37
|
+
|
|
38
|
+
# 2. Instal dependensi
|
|
39
|
+
npm install
|
|
40
|
+
|
|
41
|
+
# 3. Berikan izin eksekusi pada CLI
|
|
42
|
+
chmod +x bin/noctra.mjs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Penggunaan Dasar
|
|
46
|
+
```bash
|
|
47
|
+
# Lihat bantuan
|
|
48
|
+
./bin/noctra.mjs --help
|
|
49
|
+
|
|
50
|
+
# Scan direktori tertentu
|
|
51
|
+
./bin/noctra.mjs scan ./target-folder
|
|
52
|
+
|
|
53
|
+
# Scan dan simpan hasil ke file JSON
|
|
54
|
+
./bin/noctra.mjs scan ./target-folder --output laporan.json
|
|
55
|
+
|
|
56
|
+
# Scan dengan format output JSON (untuk integrasi CI/CD)
|
|
57
|
+
./bin/noctra.mjs scan ./target-folder --format json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## ๐ Contoh Output
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
Scanning: ./test-project
|
|
66
|
+
Format: text
|
|
67
|
+
|
|
68
|
+
Found 5 target files
|
|
69
|
+
|
|
70
|
+
๐ Initializing Multi-Engine NEA Scan...
|
|
71
|
+
๐ Executing engines in parallel via NEA Contracts...
|
|
72
|
+
|
|
73
|
+
=== ๐ก๏ธ Noctra Multi-Engine Scan Summary ===
|
|
74
|
+
Files scanned: 5
|
|
75
|
+
Total Findings: 7
|
|
76
|
+
Errors: 0
|
|
77
|
+
|
|
78
|
+
๐จ Findings:
|
|
79
|
+
[CRITICAL] PROTOTYPE_POLLUTION_AST in test-project/pollution.js:29
|
|
80
|
+
Message: AST Analysis: Direct access to __proto__ detected. High risk of Prototype Pollution.
|
|
81
|
+
Snippet: testObj.__proto__.isAdmin = true;
|
|
82
|
+
|
|
83
|
+
[HIGH] DANGEROUS_EVAL_AST in test-project/vulnerable.js:3
|
|
84
|
+
Message: AST Analysis: Direct use of eval() detected.
|
|
85
|
+
Snippet: const result = eval(userData);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## ๐๏ธ Arsitektur (NEA)
|
|
91
|
+
|
|
92
|
+
Noctra menggunakan arsitektur berlapis yang memisahkan antarmuka CLI, orkestrasi, dan eksekusi engine:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
96
|
+
โ CLI (bin/noctra.mjs) โ
|
|
97
|
+
โ (Mengumpulkan file, memformat output, menangani argumen) โ
|
|
98
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
99
|
+
โ (NEA Execution Request)
|
|
100
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
101
|
+
โ NEA Core (tools/nea/core/) โ
|
|
102
|
+
โ โข Contracts (Validasi & Immutability) โ
|
|
103
|
+
โ โข Engine Registry (Pendaftaran Engine) โ
|
|
104
|
+
โ โข Orchestrator (Eksekusi & Dependensi) โ
|
|
105
|
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
|
|
106
|
+
โ โ
|
|
107
|
+
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
|
|
108
|
+
โ Vulnerability Scanner โ โ Dependency Checker โ
|
|
109
|
+
โ (AST Parsing + Regex Rules) โ โ (Package.json Analysis) โ
|
|
110
|
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
111
|
+
โ
|
|
112
|
+
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
|
|
113
|
+
โ Inspector (tools/inspector/)โ
|
|
114
|
+
โ (Acorn AST, Scope Analyzer, โ
|
|
115
|
+
โ Binding Resolver, TS/JSX) โ
|
|
116
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## ๐งช Pengujian
|
|
122
|
+
|
|
123
|
+
Proyek ini dikembangkan dengan pendekatan *Test-Driven Development* (TDD). Untuk menjalankan seluruh suite pengujian:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm test
|
|
127
|
+
```
|
|
128
|
+
*(Target: 285+ tests passing)*
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## ๐ ๏ธ Pengembangan Selanjutnya (Roadmap)
|
|
133
|
+
|
|
134
|
+
- [ ] Taint Analysis / Data Flow Tracking (Melacak aliran data dari input ke sink)
|
|
135
|
+
- [ ] SARIF Output Format (Integrasi native dengan GitHub Code Scanning & VS Code)
|
|
136
|
+
- [ ] HTML Report Generation
|
|
137
|
+
- [ ] Custom Rules via `.noctra-config.json`
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## ๐ Lisensi
|
|
142
|
+
|
|
143
|
+
Distributed under the MIT License. Lihat `LICENSE` untuk informasi lebih lanjut.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
*Dibuat dengan โค๏ธ untuk komunitas keamanan siber dan bug bounty hunter.*
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## ๐ฌ Real-World Validation
|
|
151
|
+
|
|
152
|
+
Noctra has been tested against production-ready, popular open-source repositories to ensure high precision and a near-zero false-positive rate.
|
|
153
|
+
|
|
154
|
+
**Test Subject:** [`vercel/ms`](https://github.com/vercel/ms) *(A tiny millisecond parsing utility with millions of weekly downloads)*
|
|
155
|
+
**Result:** โ
**0 Critical/High Vulnerabilities Found**
|
|
156
|
+
**Analysis:** Noctra correctly parsed the AST and identified the project structure without raising false alarms on safe, well-written code. This proves its AST-based analysis is highly accurate and reliable for real-world codebases.
|
|
157
|
+
|
|
158
|
+
*(You can reproduce this test by running: `./bin/noctra.mjs scan /path/to/ms --format sarif`)*
|
package/bin/noctra
ADDED
package/bin/noctra.mjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { scanCommand } from '../lib/cli/commands/scan.mjs';
|
|
4
|
+
import { descriptor as bountyDescriptor, execute as bountyExecute } from '../tools/nea/engines/bounty-hunter.mjs';
|
|
5
|
+
import { createExecutionRequest } from '../tools/nea/core/contracts.mjs';
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const command = args[0];
|
|
9
|
+
|
|
10
|
+
if (!command || command === '--help' || command === '-h') {
|
|
11
|
+
console.log(`
|
|
12
|
+
NOCTRA - Independent Security Research and Bug Bounty Intelligence System
|
|
13
|
+
|
|
14
|
+
USAGE:
|
|
15
|
+
noctra <command> [options]
|
|
16
|
+
|
|
17
|
+
COMMANDS:
|
|
18
|
+
scan <path> Scan project for vulnerabilities (JS, TS, Solidity, IaC)
|
|
19
|
+
hunt <keyword> [min] Search public bug bounty programs (e.g., web3, defi, crypto)
|
|
20
|
+
--help Show this help message
|
|
21
|
+
--version Show version number
|
|
22
|
+
|
|
23
|
+
EXAMPLES:
|
|
24
|
+
noctra scan ./my-project
|
|
25
|
+
noctra scan ./src --format html --output report.html
|
|
26
|
+
noctra hunt web3 10000
|
|
27
|
+
`);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (command === '--version' || command === '-v') {
|
|
32
|
+
const pkg = await import('../package.json', { assert: { type: 'json' } });
|
|
33
|
+
console.log(`Noctra v${pkg.default.version}`);
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (command === 'scan') {
|
|
38
|
+
const targetPath = args[1];
|
|
39
|
+
const format = args.includes('--format') ? args[args.indexOf('--format') + 1] : 'text';
|
|
40
|
+
const output = args.includes('--output') ? args[args.indexOf('--output') + 1] : null;
|
|
41
|
+
|
|
42
|
+
if (!targetPath) {
|
|
43
|
+
console.error('Error: Please provide a target path to scan.');
|
|
44
|
+
console.error('Usage: noctra scan <path> [--format text|json|sarif|html] [--output file]');
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await scanCommand(targetPath, { format, output });
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`Error: Failed to scan ${targetPath}: ${error.message}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
} else if (command === 'hunt') {
|
|
55
|
+
const keyword = args[1] || '';
|
|
56
|
+
const minBounty = parseInt(args[2]) || 0;
|
|
57
|
+
const limit = 10;
|
|
58
|
+
|
|
59
|
+
console.log(`๐ก๏ธ Noctra Bounty Hunter v1.0.0`);
|
|
60
|
+
console.log(`================================`);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const req = createExecutionRequest({
|
|
64
|
+
requestId: `hunt-${Date.now()}`,
|
|
65
|
+
engineId: bountyDescriptor.id,
|
|
66
|
+
operation: 'search',
|
|
67
|
+
input: { keyword, minBounty, limit }
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const result = await bountyExecute(req);
|
|
71
|
+
|
|
72
|
+
console.log(`\n๐ฏ Found ${result.output.findings.length} potential targets:\n`);
|
|
73
|
+
for (const f of result.output.findings) {
|
|
74
|
+
console.log(`โ
${f.message}`);
|
|
75
|
+
console.log(` ๐ URL: ${f.file}`);
|
|
76
|
+
console.log(` ๐ Note: ${f.snippet}\n`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (result.output.errors.length > 0) {
|
|
80
|
+
console.error(`\nโ ๏ธ Errors:`, result.output.errors);
|
|
81
|
+
}
|
|
82
|
+
console.log(`๐ก Tip: Use "noctra scan <cloned-repo-folder>" to scan a target from the list above.`);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`\nโ Hunt failed: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
process.exit(0);
|
|
87
|
+
} else {
|
|
88
|
+
console.error(`Unknown command: ${command}`);
|
|
89
|
+
console.log(`Run "noctra --help" for usage information.`);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createExecutionRequest } from '../../../tools/nea/core/contracts.mjs';
|
|
2
|
+
import { writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { generateHtmlReport } from '../../formatters/html.mjs';
|
|
4
|
+
import { join, extname, basename } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { descriptor as vulnDescriptor, execute as vulnExecute } from '../../../tools/nea/engines/vulnerability-scanner.mjs';
|
|
7
|
+
import { descriptor as taintDescriptor, execute as taintExecute } from '../../../tools/nea/engines/taint-analyzer.mjs';
|
|
8
|
+
import { descriptor as iacDescriptor, execute as iacExecute } from '../../../tools/nea/engines/iac-scanner.mjs';
|
|
9
|
+
import { descriptor as entDescriptor, execute as entExecute } from '../../../tools/nea/engines/entropy-secret-scanner.mjs';
|
|
10
|
+
import { descriptor as solDescriptor, execute as solExecute } from '../../../tools/nea/engines/solidity-scanner.mjs';
|
|
11
|
+
import { descriptor as depDescriptor, execute as depExecute } from '../../../tools/nea/engines/dependency-checker.mjs';
|
|
12
|
+
|
|
13
|
+
function collectTargetFiles(dirPath, files = []) {
|
|
14
|
+
const entries = readdirSync(dirPath);
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
const fullPath = join(dirPath, entry);
|
|
17
|
+
const stat = statSync(fullPath);
|
|
18
|
+
if (stat.isDirectory()) {
|
|
19
|
+
if (entry === 'node_modules' || entry.startsWith('.')) continue;
|
|
20
|
+
collectTargetFiles(fullPath, files);
|
|
21
|
+
} else if (stat.isFile()) {
|
|
22
|
+
const ext = extname(entry);
|
|
23
|
+
if (['.js', '.mjs', '.jsx', '.ts', '.tsx', '.json', '.sol', '.tf', '.yaml', '.yml'].includes(ext) || entry === 'Dockerfile' || entry.startsWith('Dockerfile.') || entry.startsWith('docker-compose') || entry.startsWith('compose.') || entry === 'package.json') {
|
|
24
|
+
files.push(fullPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return files;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function convertToSarif(findings, baseDir) {
|
|
32
|
+
return {
|
|
33
|
+
$schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
|
|
34
|
+
version: "2.1.0",
|
|
35
|
+
runs: [{
|
|
36
|
+
tool: {
|
|
37
|
+
driver: {
|
|
38
|
+
name: "Noctra Security Scanner",
|
|
39
|
+
version: "3.0.0",
|
|
40
|
+
informationUri: "https://github.com/0xjenichord-web/noctra",
|
|
41
|
+
rules: findings.map(f => ({
|
|
42
|
+
id: f.rule,
|
|
43
|
+
shortDescription: { text: f.message },
|
|
44
|
+
defaultConfiguration: { level: f.severity === 'CRITICAL' || f.severity === 'HIGH' ? 'error' : 'warning' }
|
|
45
|
+
}))
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
results: findings.map(f => ({
|
|
49
|
+
ruleId: f.rule,
|
|
50
|
+
level: f.severity === 'CRITICAL' || f.severity === 'HIGH' ? 'error' : 'warning',
|
|
51
|
+
message: { text: f.message },
|
|
52
|
+
locations: [{
|
|
53
|
+
physicalLocation: {
|
|
54
|
+
artifactLocation: { uri: f.file.replace(baseDir + '/', '') },
|
|
55
|
+
region: { startLine: f.line }
|
|
56
|
+
}
|
|
57
|
+
}]
|
|
58
|
+
}))
|
|
59
|
+
}]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const VENDOR_PATTERNS = [
|
|
65
|
+
"node_modules/", "vendor/", "dist/", "build/", ".min.js",
|
|
66
|
+
".bundle.js", ".pack.js", "third_party/", "external/",
|
|
67
|
+
"lib/", "libs/", "assets/js/"
|
|
68
|
+
];
|
|
69
|
+
function isVendorFile(filePath) {
|
|
70
|
+
return VENDOR_PATTERNS.some(p => filePath.includes(p));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function scanCommand(targetPath, flags) {
|
|
74
|
+
if (!targetPath) throw new Error('Please provide a target path to scan');
|
|
75
|
+
const format = flags.format || 'text';
|
|
76
|
+
const outputFile = flags.output;
|
|
77
|
+
|
|
78
|
+
console.log(`Scanning: ${targetPath}`);
|
|
79
|
+
console.log(`Format: ${format}\n`);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const allFiles = collectTargetFiles(targetPath);
|
|
83
|
+
const files = allFiles.filter(f => !isVendorFile(f));
|
|
84
|
+
console.log(` โ๏ธ Filtered out vendor/bundle files. Scanning ${files.length} application files.`);
|
|
85
|
+
console.log(`Found ${files.length} target files\n`);
|
|
86
|
+
|
|
87
|
+
if (files.length === 0) {
|
|
88
|
+
console.log('โ
No files to scan.');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log('๐ Initializing Multi-Engine NEA Scan...');
|
|
93
|
+
const requestId = `noctra-multi-${Date.now()}`;
|
|
94
|
+
|
|
95
|
+
const vulnRequest = createExecutionRequest({ requestId, engineId: vulnDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
96
|
+
const depRequest = createExecutionRequest({ requestId, engineId: depDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
97
|
+
|
|
98
|
+
console.log('๐ Executing engines in parallel via NEA Contracts...\n');
|
|
99
|
+
|
|
100
|
+
const taintRequest = createExecutionRequest({ requestId, engineId: taintDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
101
|
+
const iacRequest = createExecutionRequest({ requestId, engineId: iacDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
102
|
+
const entRequest = createExecutionRequest({ requestId, engineId: entDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
103
|
+
const solRequest = createExecutionRequest({ requestId, engineId: solDescriptor.id, operation: 'scan', input: { targetFiles: files } });
|
|
104
|
+
const results = await Promise.all([vulnExecute(vulnRequest), depExecute(depRequest), solExecute(solRequest), entExecute(entRequest), iacExecute(iacRequest), taintExecute(taintRequest)]);
|
|
105
|
+
|
|
106
|
+
const aggregatedFindings = [];
|
|
107
|
+
const aggregatedErrors = [];
|
|
108
|
+
let totalScanned = 0;
|
|
109
|
+
|
|
110
|
+
for (const result of results) {
|
|
111
|
+
if (result.output) {
|
|
112
|
+
totalScanned = Math.max(totalScanned, result.output.scannedFiles || 0);
|
|
113
|
+
if (result.output.findings) aggregatedFindings.push(...result.output.findings);
|
|
114
|
+
if (result.output.errors) aggregatedErrors.push(...result.output.errors);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const finalOutput = { scannedFiles: totalScanned, findings: aggregatedFindings, errors: aggregatedErrors };
|
|
119
|
+
|
|
120
|
+
if (format === 'sarif') {
|
|
121
|
+
const sarifData = convertToSarif(aggregatedFindings, process.cwd());
|
|
122
|
+
const targetFile = outputFile || 'noctra-report.sarif';
|
|
123
|
+
writeFileSync(targetFile, JSON.stringify(sarifData, null, 2));
|
|
124
|
+
console.log(`โ๏ธ SARIF report saved to: ${targetFile}`);
|
|
125
|
+
} else if (format === 'html') {
|
|
126
|
+
generateHtmlReport(finalOutput, outputFile || 'noctra-report.html');
|
|
127
|
+
} else if (outputFile) {
|
|
128
|
+
writeFileSync(outputFile, JSON.stringify(finalOutput, null, 2));
|
|
129
|
+
console.log(`\nโ๏ธ Report saved to: ${outputFile}`);
|
|
130
|
+
} else if (format === 'json') {
|
|
131
|
+
console.log(JSON.stringify(finalOutput, null, 2));
|
|
132
|
+
} else {
|
|
133
|
+
console.log('=== ๐ก๏ธ Noctra Multi-Engine Scan Summary ===');
|
|
134
|
+
console.log(`Files scanned: ${finalOutput.scannedFiles}`);
|
|
135
|
+
console.log(`Total Findings: ${finalOutput.findings.length}`);
|
|
136
|
+
console.log(`Errors: ${finalOutput.errors.length}\n`);
|
|
137
|
+
|
|
138
|
+
if (finalOutput.findings.length > 0) {
|
|
139
|
+
console.log('๐จ Findings:');
|
|
140
|
+
for (const f of finalOutput.findings) {
|
|
141
|
+
console.log(` [${f.severity}] ${f.rule} in ${f.file}:${f.line}`);
|
|
142
|
+
console.log(` Message: ${f.message}`);
|
|
143
|
+
console.log(` Snippet: ${f.snippet}\n`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (finalOutput.errors.length > 0) {
|
|
147
|
+
console.log('โ ๏ธ Errors:');
|
|
148
|
+
for (const err of finalOutput.errors) console.log(` ${err.file}: ${err.error}`);
|
|
149
|
+
}
|
|
150
|
+
if (finalOutput.findings.length === 0 && finalOutput.errors.length === 0) {
|
|
151
|
+
console.log('โ
No vulnerabilities or errors found!');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new Error(`Failed to scan ${targetPath}: ${error.message}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function parseArgs(args) {
|
|
2
|
+
const result = { command: null, positional: [], flags: {} };
|
|
3
|
+
let i = 0;
|
|
4
|
+
|
|
5
|
+
while (i < args.length && !args[i].startsWith('-')) {
|
|
6
|
+
if (result.command === null) result.command = args[i];
|
|
7
|
+
else result.positional.push(args[i]);
|
|
8
|
+
i++;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
while (i < args.length) {
|
|
12
|
+
const arg = args[i];
|
|
13
|
+
if (arg.startsWith('--')) {
|
|
14
|
+
const flagName = arg.slice(2);
|
|
15
|
+
if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
16
|
+
result.flags[flagName] = args[i + 1];
|
|
17
|
+
i += 2;
|
|
18
|
+
} else {
|
|
19
|
+
result.flags[flagName] = true;
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
} else if (arg.startsWith('-')) {
|
|
23
|
+
result.flags[arg.slice(1)] = true;
|
|
24
|
+
i++;
|
|
25
|
+
} else {
|
|
26
|
+
result.positional.push(arg);
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
export function generateHtmlReport(data, outputPath) {
|
|
4
|
+
const { scannedFiles, findings, errors } = data;
|
|
5
|
+
|
|
6
|
+
// Hitung distribusi severitas untuk Chart
|
|
7
|
+
const severityCounts = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0, INFO: 0 };
|
|
8
|
+
findings.forEach(f => {
|
|
9
|
+
const sev = f.severity.toUpperCase();
|
|
10
|
+
if (severityCounts[sev] !== undefined) severityCounts[sev]++;
|
|
11
|
+
else severityCounts['INFO']++;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Generate baris tabel temuan
|
|
15
|
+
const findingsRows = findings.map(f => {
|
|
16
|
+
const severityColor = {
|
|
17
|
+
'CRITICAL': '#ef4444', // Merah
|
|
18
|
+
'HIGH': '#f97316', // Oranye
|
|
19
|
+
'MEDIUM': '#eab308', // Kuning
|
|
20
|
+
'LOW': '#3b82f6', // Biru
|
|
21
|
+
'INFO': '#6b7280' // Abu-abu
|
|
22
|
+
}[f.severity.toUpperCase()] || '#6b7280';
|
|
23
|
+
|
|
24
|
+
return `
|
|
25
|
+
<tr>
|
|
26
|
+
<td><span style="background:${severityColor}20; color:${severityColor}; padding:4px 8px; border-radius:4px; font-weight:bold; font-size:0.85em;">${f.severity}</span></td>
|
|
27
|
+
<td><code style="background:#1e293b; padding:2px 6px; border-radius:4px;">${f.rule}</code></td>
|
|
28
|
+
<td><code>${f.file}:${f.line}</code></td>
|
|
29
|
+
<td>${f.message}</td>
|
|
30
|
+
<td><pre style="background:#0f172a; padding:8px; border-radius:4px; border-left:3px solid ${severityColor}; margin:0; font-size:0.85em; color:#94a3b8;">${escapeHtml(f.snippet || 'No snippet available')}</pre></td>
|
|
31
|
+
</tr>
|
|
32
|
+
`;
|
|
33
|
+
}).join('');
|
|
34
|
+
|
|
35
|
+
// Generate baris tabel error (jika ada)
|
|
36
|
+
const errorRows = errors.map(e => `
|
|
37
|
+
<tr>
|
|
38
|
+
<td colspan="5" style="color:#ef4444;">โ ๏ธ Error scanning <code>${e.file}</code>: ${escapeHtml(e.error)}</td>
|
|
39
|
+
</tr>
|
|
40
|
+
`).join('');
|
|
41
|
+
|
|
42
|
+
const html = `<!DOCTYPE html>
|
|
43
|
+
<html lang="en">
|
|
44
|
+
<head>
|
|
45
|
+
<meta charset="UTF-8">
|
|
46
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
47
|
+
<title>Noctra Security Report</title>
|
|
48
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
49
|
+
<style>
|
|
50
|
+
:root { --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --text-muted: #94a3b8; --border: #334155; }
|
|
51
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 2rem; line-height: 1.6; }
|
|
52
|
+
.container { max-width: 1200px; margin: 0 auto; }
|
|
53
|
+
header { text-align: center; margin-bottom: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
|
|
54
|
+
header h1 { margin: 0; font-size: 2rem; background: linear-gradient(90deg, #3b82f6, #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
|
55
|
+
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
|
|
56
|
+
.card { background: var(--card); padding: 1.5rem; border-radius: 8px; border: 1px solid var(--border); text-align: center; }
|
|
57
|
+
.card h3 { margin: 0 0 0.5rem 0; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; }
|
|
58
|
+
.card .number { font-size: 2.5rem; font-weight: bold; margin: 0; }
|
|
59
|
+
.chart-container { background: var(--card); padding: 1.5rem; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 2rem; max-width: 500px; margin-left: auto; margin-right: auto; }
|
|
60
|
+
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
|
|
61
|
+
th, td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
|
|
62
|
+
th { background: #0f172a; color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.85rem; }
|
|
63
|
+
tr:last-child td { border-bottom: none; }
|
|
64
|
+
.footer { text-align: center; margin-top: 3rem; color: var(--text-muted); font-size: 0.85rem; }
|
|
65
|
+
</style>
|
|
66
|
+
</head>
|
|
67
|
+
<body>
|
|
68
|
+
<div class="container">
|
|
69
|
+
<header>
|
|
70
|
+
<h1>๐ก๏ธ Noctra Security Intelligence Report</h1>
|
|
71
|
+
<p style="color: var(--text-muted);">Generated on ${new Date().toLocaleString()}</p>
|
|
72
|
+
</header>
|
|
73
|
+
|
|
74
|
+
<div class="summary-grid">
|
|
75
|
+
<div class="card"><h3>Files Scanned</h3><p class="number">${scannedFiles}</p></div>
|
|
76
|
+
<div class="card"><h3>Total Findings</h3><p class="number" style="color: #ef4444;">${findings.length}</p></div>
|
|
77
|
+
<div class="card"><h3>Critical</h3><p class="number" style="color: #ef4444;">${severityCounts.CRITICAL}</p></div>
|
|
78
|
+
<div class="card"><h3>High</h3><p class="number" style="color: #f97316;">${severityCounts.HIGH}</p></div>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<div class="chart-container">
|
|
82
|
+
<canvas id="severityChart"></canvas>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<h2 style="border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;">๐จ Detailed Findings</h2>
|
|
86
|
+
<table>
|
|
87
|
+
<thead>
|
|
88
|
+
<tr>
|
|
89
|
+
<th>Severity</th>
|
|
90
|
+
<th>Rule ID</th>
|
|
91
|
+
<th>Location</th>
|
|
92
|
+
<th>Message</th>
|
|
93
|
+
<th>Code Snippet</th>
|
|
94
|
+
</tr>
|
|
95
|
+
</thead>
|
|
96
|
+
<tbody>
|
|
97
|
+
${findingsRows || '<tr><td colspan="5" style="text-align:center; padding: 2rem;">โ
No vulnerabilities found. Great job!</td></tr>'}
|
|
98
|
+
${errorRows}
|
|
99
|
+
</tbody>
|
|
100
|
+
</table>
|
|
101
|
+
|
|
102
|
+
<div class="footer">
|
|
103
|
+
<p>Powered by <strong>Noctra Security Scanner</strong> | <a href="https://github.com/0xjenichord-web/noctra" style="color: #3b82f6;">github.com/0xjenichord-web/noctra</a></p>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<script>
|
|
108
|
+
const ctx = document.getElementById('severityChart').getContext('2d');
|
|
109
|
+
new Chart(ctx, {
|
|
110
|
+
type: 'doughnut',
|
|
111
|
+
data: {
|
|
112
|
+
labels: ['Critical', 'High', 'Medium', 'Low', 'Info'],
|
|
113
|
+
datasets: [{
|
|
114
|
+
data: [${severityCounts.CRITICAL}, ${severityCounts.HIGH}, ${severityCounts.MEDIUM}, ${severityCounts.LOW}, ${severityCounts.INFO}],
|
|
115
|
+
backgroundColor: ['#ef4444', '#f97316', '#eab308', '#3b82f6', '#6b7280'],
|
|
116
|
+
borderWidth: 0
|
|
117
|
+
}]
|
|
118
|
+
},
|
|
119
|
+
options: {
|
|
120
|
+
responsive: true,
|
|
121
|
+
plugins: {
|
|
122
|
+
legend: { position: 'bottom', labels: { color: '#e2e8f0' } }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
</script>
|
|
127
|
+
</body>
|
|
128
|
+
</html>`;
|
|
129
|
+
|
|
130
|
+
writeFileSync(outputPath, html, 'utf-8');
|
|
131
|
+
console.log(`\n๐จ HTML Dashboard Report saved to: ${outputPath}`);
|
|
132
|
+
console.log(`๐ก Tip: Open this file in your web browser to view the interactive dashboard.`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function escapeHtml(text) {
|
|
136
|
+
if (!text) return '';
|
|
137
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "noctra-scanner",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Noctra: Independent Security Research & Bug Bounty Intelligence System. Multi-engine AST, Solidity, IaC, and Taint Analysis scanner.",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.0.0"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node --test tests/*.test.mjs",
|
|
10
|
+
"docs:generate": "node tools/docs/generate-engine-docs.mjs",
|
|
11
|
+
"prepare": "husky"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@solidity-parser/parser": "^0.20.2",
|
|
15
|
+
"@sveltejs/acorn-typescript": "^1.0.13",
|
|
16
|
+
"acorn": "^8.19.0",
|
|
17
|
+
"acorn-jsx": "^5.3.2"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"bin": {
|
|
21
|
+
"noctra": "./bin/noctra"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"husky": "^9.1.7"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"security",
|
|
28
|
+
"scanner",
|
|
29
|
+
"ast",
|
|
30
|
+
"solidity",
|
|
31
|
+
"web3",
|
|
32
|
+
"devsecops",
|
|
33
|
+
"bug-bounty",
|
|
34
|
+
"iac"
|
|
35
|
+
],
|
|
36
|
+
"files": [
|
|
37
|
+
"bin/",
|
|
38
|
+
"lib/",
|
|
39
|
+
"tools/"
|
|
40
|
+
]
|
|
6
41
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readdirSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
async function generateDocs() {
|
|
7
|
+
const enginesDir = 'tools/nea/engines';
|
|
8
|
+
const docsDir = 'docs';
|
|
9
|
+
|
|
10
|
+
mkdirSync(docsDir, { recursive: true });
|
|
11
|
+
|
|
12
|
+
const files = readdirSync(enginesDir).filter(f => f.endsWith('.mjs'));
|
|
13
|
+
const engines = [];
|
|
14
|
+
|
|
15
|
+
for (const file of files) {
|
|
16
|
+
try {
|
|
17
|
+
const module = await import(pathToFileURL(join(process.cwd(), enginesDir, file)).href);
|
|
18
|
+
if (module.descriptor) {
|
|
19
|
+
engines.push({
|
|
20
|
+
file,
|
|
21
|
+
id: module.descriptor.id,
|
|
22
|
+
name: module.descriptor.name,
|
|
23
|
+
version: module.descriptor.version,
|
|
24
|
+
domain: module.descriptor.domain,
|
|
25
|
+
capabilities: module.descriptor.capabilities
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.warn(`โ ๏ธ Skip ${file}: ${e.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let md = `# ๐ ๏ธ Available Engines\n\n`;
|
|
34
|
+
md += `> Auto-generated documentation. Run \`npm run docs:generate\` to update.\n\n`;
|
|
35
|
+
md += `Total engines: **${engines.length}**\n\n`;
|
|
36
|
+
md += `| ID | Name | Version | Domain | Capabilities |\n`;
|
|
37
|
+
md += `|----|------|---------|--------|---------------|\n`;
|
|
38
|
+
|
|
39
|
+
for (const e of engines) {
|
|
40
|
+
md += `| \`${e.id}\` | ${e.name} | ${e.version} | ${e.domain} | ${e.capabilities.join(', ')} |\n`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
writeFileSync(join(docsDir, 'ENGINES.md'), md);
|
|
44
|
+
console.log(`โ
Generated docs/ENGINES.md with ${engines.length} engines`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
generateDocs().catch(console.error);
|