vigievuln 1.3.1 → 1.3.3
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 +15 -0
- package/README.md +1 -1
- package/data/fingerprints/index.js +80 -0
- package/data/fingerprints/interpreters/javascript/bun.json +23 -0
- package/data/fingerprints/interpreters/javascript/deno.json +10 -0
- package/data/fingerprints/interpreters/javascript/electron.json +20 -0
- package/data/fingerprints/interpreters/javascript/gjs.json +8 -0
- package/data/fingerprints/interpreters/javascript/javascriptcore.json +14 -0
- package/data/fingerprints/interpreters/javascript/jscgtk.json +10 -0
- package/data/fingerprints/interpreters/javascript/node.json +26 -0
- package/data/fingerprints/interpreters/javascript/nwjs.json +8 -0
- package/data/fingerprints/interpreters/javascript/webkitgtk.json +10 -0
- package/data/fingerprints/interpreters/javascript/wpewebkit.json +10 -0
- package/data/fingerprints/interpreters/languages/dotnet.json +8 -0
- package/data/fingerprints/interpreters/languages/erlang.json +9 -0
- package/data/fingerprints/interpreters/languages/gawk.json +10 -0
- package/data/fingerprints/interpreters/languages/guile.json +9 -0
- package/data/fingerprints/interpreters/languages/java.json +8 -0
- package/data/fingerprints/interpreters/languages/julia.json +9 -0
- package/data/fingerprints/interpreters/languages/lua.json +11 -0
- package/data/fingerprints/interpreters/languages/luajit.json +10 -0
- package/data/fingerprints/interpreters/languages/perl.json +11 -0
- package/data/fingerprints/interpreters/languages/php.json +22 -0
- package/data/fingerprints/interpreters/languages/powershell.json +17 -0
- package/data/fingerprints/interpreters/languages/pypy.json +8 -0
- package/data/fingerprints/interpreters/languages/python.json +24 -0
- package/data/fingerprints/interpreters/languages/r.json +9 -0
- package/data/fingerprints/interpreters/languages/racket.json +9 -0
- package/data/fingerprints/interpreters/languages/raku.json +8 -0
- package/data/fingerprints/interpreters/languages/ruby.json +21 -0
- package/data/fingerprints/interpreters/languages/tcl.json +9 -0
- package/data/fingerprints/interpreters/shells/bash.json +10 -0
- package/data/fingerprints/interpreters/shells/dash.json +8 -0
- package/data/fingerprints/interpreters/shells/fish.json +9 -0
- package/data/fingerprints/interpreters/shells/ksh.json +8 -0
- package/data/fingerprints/interpreters/shells/zsh.json +9 -0
- package/data/fingerprints/services/databases/clickhouse.json +8 -0
- package/data/fingerprints/services/databases/elasticsearch.json +8 -0
- package/data/fingerprints/services/databases/etcd.json +9 -0
- package/data/fingerprints/services/databases/mariadb.json +9 -0
- package/data/fingerprints/services/databases/memcached.json +9 -0
- package/data/fingerprints/services/databases/mongo.json +8 -0
- package/data/fingerprints/services/databases/mysql.json +9 -0
- package/data/fingerprints/services/databases/opensearch.json +8 -0
- package/data/fingerprints/services/databases/postgres.json +18 -0
- package/data/fingerprints/services/databases/redis.json +9 -0
- package/data/fingerprints/services/databases/valkey.json +8 -0
- package/data/fingerprints/services/dns-directory/bind.json +8 -0
- package/data/fingerprints/services/dns-directory/dnsmasq.json +8 -0
- package/data/fingerprints/services/dns-directory/slapd.json +8 -0
- package/data/fingerprints/services/dns-directory/unbound.json +8 -0
- package/data/fingerprints/services/mail/cyrus.json +8 -0
- package/data/fingerprints/services/mail/dovecot.json +8 -0
- package/data/fingerprints/services/mail/exim.json +9 -0
- package/data/fingerprints/services/mail/opendkim.json +8 -0
- package/data/fingerprints/services/mail/opensmtpd.json +8 -0
- package/data/fingerprints/services/mail/postfix.json +8 -0
- package/data/fingerprints/services/mail/rspamd.json +8 -0
- package/data/fingerprints/services/mail/sendmail.json +8 -0
- package/data/fingerprints/services/messaging/kafka.json +8 -0
- package/data/fingerprints/services/messaging/mosquitto.json +8 -0
- package/data/fingerprints/services/messaging/nats.json +9 -0
- package/data/fingerprints/services/messaging/rabbitmq.json +8 -0
- package/data/fingerprints/services/remote-access/dropbear.json +8 -0
- package/data/fingerprints/services/remote-access/openssh.json +10 -0
- package/data/fingerprints/services/remote-access/proftpd.json +8 -0
- package/data/fingerprints/services/remote-access/samba.json +8 -0
- package/data/fingerprints/services/remote-access/vsftpd.json +8 -0
- package/data/fingerprints/services/web-proxies/apache.json +18 -0
- package/data/fingerprints/services/web-proxies/caddy.json +9 -0
- package/data/fingerprints/services/web-proxies/envoy.json +8 -0
- package/data/fingerprints/services/web-proxies/haproxy.json +10 -0
- package/data/fingerprints/services/web-proxies/lighttpd.json +8 -0
- package/data/fingerprints/services/web-proxies/nginx.json +14 -0
- package/data/fingerprints/services/web-proxies/squid.json +8 -0
- package/data/fingerprints/services/web-proxies/tomcat.json +8 -0
- package/data/fingerprints/services/web-proxies/traefik.json +9 -0
- package/data/fingerprints/services/web-proxies/varnish.json +8 -0
- package/lib/artifacts/component-scope.js +26 -3
- package/lib/artifacts/elf-product.js +215 -0
- package/lib/artifacts/image-products.js +180 -0
- package/lib/artifacts/install-version.js +44 -0
- package/lib/artifacts/inventory-scope.js +2 -1
- package/lib/artifacts/pe-product.js +28 -0
- package/lib/artifacts/product-advisories.js +207 -0
- package/lib/artifacts/product-catalog.js +62 -0
- package/lib/artifacts/report-inventory.js +7 -1
- package/lib/artifacts/report.js +42 -7
- package/lib/artifacts/retire.js +80 -0
- package/lib/artifacts/scan.js +40 -13
- package/lib/cli-image.js +6 -1
- package/lib/codecs/binary/elf-metadata.js +6 -0
- package/lib/codecs/binary/metadata.js +1 -1
- package/lib/codecs/binary/pe-metadata.js +47 -11
- package/lib/codecs/binary/scan.js +1 -1
- package/lib/cve-report.js +26 -3
- package/lib/i18n.js +2 -0
- package/lib/image-references.js +21 -1
- package/lib/json-export.js +2 -2
- package/lib/providers/nvd.js +16 -2
- package/lib/report-notices.js +1 -1
- package/lib/resource-cache/engine.js +3 -2
- package/lib/resource-cache/validate.js +1 -0
- package/lib/retire.js +12 -10
- package/lib/source-image-scan.js +1 -0
- package/lib/system-inventory/collect.js +1 -1
- package/lib/system-inventory/distribution-sources.js +1 -1
- package/lib/system-inventory/nginx-advisories.js +26 -8
- package/package.json +1 -1
- package/vigievuln.js +3 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "postgres",
|
|
4
|
+
"label": "PostgreSQL",
|
|
5
|
+
"category": "service",
|
|
6
|
+
"executable": "^postgres$",
|
|
7
|
+
"osPackage": "^postgresql(?:-?\\d+)?(?:-server)?$",
|
|
8
|
+
"cpe": "postgresql:postgresql",
|
|
9
|
+
"peVersionInfo": {
|
|
10
|
+
"names": [
|
|
11
|
+
"PostgreSQL"
|
|
12
|
+
],
|
|
13
|
+
"originals": [
|
|
14
|
+
"postgres.exe"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"elfBanner": "\\x00postgres \\(PostgreSQL\\) (\\d+\\.\\d+(?:\\.\\d+)?)\\x00"
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "apache",
|
|
4
|
+
"label": "Apache HTTP Server",
|
|
5
|
+
"category": "service",
|
|
6
|
+
"executable": "^(?:apache2|httpd)$",
|
|
7
|
+
"osPackage": "^(?:apache2(?:-bin)?|httpd(?:-core)?)$",
|
|
8
|
+
"cpe": "apache:http_server",
|
|
9
|
+
"elfBanner": "\\0Apache\\/(\\d+\\.\\d+\\.\\d+)(?=\\0)",
|
|
10
|
+
"peVersionInfo": {
|
|
11
|
+
"names": [
|
|
12
|
+
"Apache HTTP Server"
|
|
13
|
+
],
|
|
14
|
+
"originals": [
|
|
15
|
+
"httpd.exe"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "nginx",
|
|
4
|
+
"label": "NGINX",
|
|
5
|
+
"category": "service",
|
|
6
|
+
"executable": "^nginx$",
|
|
7
|
+
"osPackage": "^nginx(?:-(?:core|full|light|extras))?$",
|
|
8
|
+
"cpe": "f5:nginx",
|
|
9
|
+
"elfBanner": "\\0nginx\\/(\\d+\\.\\d+\\.\\d+)(?=\\0)",
|
|
10
|
+
"cpeAliases": [
|
|
11
|
+
"nginx:nginx",
|
|
12
|
+
"igor_sysoev:nginx"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const IMAGE_COMPONENT_SCOPE='image-components/
|
|
3
|
+
const IMAGE_COMPONENT_SCOPE='image-components/2';
|
|
4
4
|
const parts=value=>String(value||'').replace(/\\/g,'/').split('/').filter(Boolean);
|
|
5
5
|
const stores=new Set(['node_modules','vendor','site-packages','dist-packages','specifications','__pypackages__','.cache','.npm','.yarn','.m2','.gradle','.nuget']);
|
|
6
6
|
// Installed metadata is authoritative inside package stores; source manifests
|
|
@@ -19,13 +19,36 @@ function isNpmPackageDescriptor(value) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function imageComponentRole(dep={}) {
|
|
22
|
+
if(imageComponentSource(dep).category==='global')return 'direct';
|
|
22
23
|
if(dep.ecosystem==='system' || dep.ecosystem==='binary')return 'direct';
|
|
23
24
|
const source=dep.installEvidence?.source;
|
|
24
|
-
if(['pypi','composer','composer-php','ruby','nuget'].includes(source))return 'transitive';
|
|
25
|
+
if(['pypi','composer','composer-php','ruby','nuget','retire'].includes(source))return 'transitive';
|
|
25
26
|
if(dep.provenance==='binary-module')return dep.binaryEvidence?.original?.kind==='mod'?'direct':'transitive';
|
|
26
27
|
const paths=[dep.artifactPath,dep.installEvidence?.path,...(dep.manifestPaths||[])].filter(Boolean);
|
|
27
28
|
if(paths.some(p=>String(p).includes('!/') || parts(p).some(n=>stores.has(n)) || String(p).replace(/\\/g,'/').includes('usr/share/nodejs/')))return 'transitive';
|
|
28
29
|
return 'direct';
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
// Paths here are relative to the image, never the temporary extraction directory.
|
|
33
|
+
// A package store is not evidence of a global install unless its prefix is known.
|
|
34
|
+
function imageComponentSource(dep={}) {
|
|
35
|
+
const p=String(dep.artifactPath || dep.installEvidence?.path || dep.manifestPaths?.[0] || '').replace(/\\/g,'/').replace(/^\/+/, '');
|
|
36
|
+
const source=dep.installEvidence?.source;
|
|
37
|
+
const os=dep.ecosystem==='system' ? dep : dep.osPackageOwners?.[0];
|
|
38
|
+
if(os)return {category:'system',manager:os.manager || os.packageType || 'system'};
|
|
39
|
+
if(source==='retire' || dep.ecosystemType==='retire')return {category:'vendored',manager:'retirejs'};
|
|
40
|
+
const npm=/^((?:(?:usr(?:\/local)?|opt\/[^/]+)\/lib|(?:root|home\/[^/]+)\/(?:\.npm-global\/lib|\.nvm\/versions\/node\/[^/]+\/lib))\/node_modules)\/(?:@[^/]+\/)?[^/]+\/package\.json$/.exec(p);
|
|
41
|
+
if(dep.ecosystem==='npm' && npm)return {category:'global',manager:'npm',root:npm[1]};
|
|
42
|
+
const python=/^((?:usr(?:\/local)?\/lib(?:64)?\/python[^/]+|(?:root|home\/[^/]+)\/\.local\/lib\/python[^/]+)\/(?:site|dist)-packages)\//.exec(p);
|
|
43
|
+
if(dep.ecosystem==='pypi' && python)return {category:'global',manager:'python',root:python[1]};
|
|
44
|
+
const ruby=/^((?:usr(?:\/local)?\/(?:lib\/ruby\/gems|share\/gems)|var\/lib\/gems|(?:root|home\/[^/]+)\/\.gem\/ruby)(?:\/[^/]+)?)\/specifications\//.exec(p);
|
|
45
|
+
if(dep.ecosystem==='ruby' && ruby)return {category:'global',manager:'ruby',root:ruby[1]};
|
|
46
|
+
const composer=/^((?:root|home\/[^/]+)\/(?:\.composer|\.config\/composer))\/vendor\/composer\/installed\.(?:json|php)$/.exec(p);
|
|
47
|
+
if(dep.ecosystem==='composer' && composer)return {category:'global',manager:'composer',root:composer[1]};
|
|
48
|
+
if(p && !p.includes('!/') && isProjectDescriptor(p) && !p.startsWith('usr/share/nodejs/') &&
|
|
49
|
+
(['composer-project','pypi-project','maven-project'].includes(source) || dep.ecosystem==='npm' && /(?:^|\/)package\.json$/.test(p)))
|
|
50
|
+
return {category:'project',manager:dep.ecosystem,root:p.includes('/')?p.slice(0,p.lastIndexOf('/')):'.'};
|
|
51
|
+
return {category:'other',manager:dep.ecosystem || 'unknown'};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports={IMAGE_COMPONENT_SCOPE,isNpmPackageDescriptor,isProjectDescriptor,imageComponentRole,imageComponentSource};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { catalog, binaryProduct } = require('./product-catalog');
|
|
4
|
+
const codecs = new Map(
|
|
5
|
+
[...catalog.values()].filter((product) => product.elfCodec).map((product) => [product.elfCodec, product])
|
|
6
|
+
);
|
|
7
|
+
const libraries = [...catalog.values()].filter((product) => product.library);
|
|
8
|
+
function libraryProduct(name) {
|
|
9
|
+
return libraries.find((product) => product.library.test(name));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function sectionsOf({ read, header, bits, word, u16, u32, max }) {
|
|
13
|
+
const wide = bits === 64,
|
|
14
|
+
stride = u16(header, wide ? 58 : 46),
|
|
15
|
+
count = u16(header, wide ? 60 : 48);
|
|
16
|
+
if (!count || count > 4096 || stride < (wide ? 64 : 40) || stride * count > max) return [];
|
|
17
|
+
const table = read(word(header, wide ? 40 : 32), stride * count);
|
|
18
|
+
return Array.from({ length: count }, (_, i) => {
|
|
19
|
+
const p = i * stride;
|
|
20
|
+
return {
|
|
21
|
+
name: u32(table, p),
|
|
22
|
+
type: u32(table, p + 4),
|
|
23
|
+
offset: word(table, p + (wide ? 24 : 16)),
|
|
24
|
+
size: word(table, p + (wide ? 32 : 20)),
|
|
25
|
+
link: u32(table, p + (wide ? 40 : 24)),
|
|
26
|
+
entry: word(table, p + (wide ? 56 : 36))
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function bunGraph(elf, sections) {
|
|
32
|
+
const trailer = Buffer.from('\n---- Bun! ----\n');
|
|
33
|
+
if (elf.size >= 24) {
|
|
34
|
+
const end = elf.read(elf.size - 24, 24);
|
|
35
|
+
if (end.subarray(0, 16).equals(trailer) && end.readBigUInt64LE(16) === BigInt(elf.size)) return true;
|
|
36
|
+
}
|
|
37
|
+
const names = sections[elf.u16(elf.header, elf.bits === 64 ? 62 : 50)];
|
|
38
|
+
if (!names || names.size > 65536) return false;
|
|
39
|
+
const strings = elf.read(names.offset, names.size);
|
|
40
|
+
for (const section of sections) {
|
|
41
|
+
if (
|
|
42
|
+
section.type !== 1 ||
|
|
43
|
+
strings.toString('latin1', section.name, section.name + 5) !== '.bun\0' ||
|
|
44
|
+
section.size < 32
|
|
45
|
+
)
|
|
46
|
+
continue;
|
|
47
|
+
const len = elf.read(section.offset, 8).readBigUInt64LE();
|
|
48
|
+
if (
|
|
49
|
+
len >= 24n &&
|
|
50
|
+
len <= BigInt(section.size - 8) &&
|
|
51
|
+
elf.read(section.offset + 8 + Number(len) - 16, 16).equals(trailer)
|
|
52
|
+
)
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function symbolBytes(elf, sections, wanted) {
|
|
59
|
+
const wide = elf.bits === 64,
|
|
60
|
+
result = new Map();
|
|
61
|
+
for (const section of sections) {
|
|
62
|
+
if (section.type !== 11) continue;
|
|
63
|
+
const strings = sections[section.link];
|
|
64
|
+
if (
|
|
65
|
+
strings?.type !== 3 ||
|
|
66
|
+
section.entry !== (wide ? 24 : 16) ||
|
|
67
|
+
section.size % section.entry ||
|
|
68
|
+
Math.max(section.size, strings.size) > elf.max
|
|
69
|
+
)
|
|
70
|
+
continue;
|
|
71
|
+
const names = elf.read(strings.offset, strings.size);
|
|
72
|
+
if (!wanted.every((name) => names.includes(name + '\0'))) continue;
|
|
73
|
+
const symbols = elf.read(section.offset, section.size);
|
|
74
|
+
for (let j = 0; j < symbols.length; j += section.entry) {
|
|
75
|
+
const start = elf.u32(symbols, j);
|
|
76
|
+
const end = names.subarray(start, start + 49).indexOf(0) + start;
|
|
77
|
+
if (end < start || end - start > 48) continue;
|
|
78
|
+
const name = names.toString('latin1', start, end);
|
|
79
|
+
if (!wanted.includes(name) || !elf.u16(symbols, j + (wide ? 6 : 14))) continue;
|
|
80
|
+
const type = symbols[j + (wide ? 4 : 12)];
|
|
81
|
+
if (!(type >> 4) || (type & 15) !== (name === 'Py_Version' ? 1 : 2)) continue;
|
|
82
|
+
const length = elf.word(symbols, j + (wide ? 16 : 8));
|
|
83
|
+
if (length < 1 || length > 32) continue;
|
|
84
|
+
result.set(name, elf.read(elf.mapped(elf.word(symbols, j + (wide ? 8 : 4)), length), length));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function constantReturn(bytes, machine) {
|
|
91
|
+
if (!bytes) return;
|
|
92
|
+
// Entire leaf function must be a literal return. No machine code is run.
|
|
93
|
+
if (machine === 62 || machine === 3) {
|
|
94
|
+
if (bytes.subarray(0, 4).equals(Buffer.from([0xf3, 0x0f, 0x1e, machine === 62 ? 0xfa : 0xfb])))
|
|
95
|
+
bytes = bytes.subarray(4);
|
|
96
|
+
if (bytes.equals(Buffer.from([0x31, 0xc0, 0xc3]))) return 0;
|
|
97
|
+
if (bytes.length === 6 && bytes[0] === 0xb8 && bytes[5] === 0xc3) return bytes.readUInt32LE(1);
|
|
98
|
+
}
|
|
99
|
+
if (machine === 183 && bytes.length === 8 && bytes.readUInt32LE(4) === 0xd65f03c0) {
|
|
100
|
+
const mov = bytes.readUInt32LE(0);
|
|
101
|
+
if ((mov & 0xffe0001f) >>> 0 === 0x52800000) return (mov >>> 5) & 0xffff;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function exportedVersion(product, elf, sections) {
|
|
106
|
+
if (product.elfCodec === 'py-version') {
|
|
107
|
+
const bytes = symbolBytes(elf, sections, ['Py_Version']).get('Py_Version');
|
|
108
|
+
if (!bytes || ![4, 8].includes(bytes.length)) return;
|
|
109
|
+
const hex = bytes.length === 4 ? elf.u32(bytes, 0) : elf.word(bytes, 0);
|
|
110
|
+
if (hex <= 0xffffffff && hex >>> 24 === 3 && (hex & 255) === 0xf0)
|
|
111
|
+
return {
|
|
112
|
+
id: product.id,
|
|
113
|
+
version: [hex >>> 24, (hex >>> 16) & 255, (hex >>> 8) & 255].join('.'),
|
|
114
|
+
source: 'Py_Version'
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (['webkit-version', 'jsc-version'].includes(product.elfCodec)) {
|
|
118
|
+
const prefix = product.elfCodec === 'jsc-version' ? 'jsc' : 'webkit';
|
|
119
|
+
const names = ['major', 'minor', 'micro'].map((part) => prefix + '_get_' + part + '_version');
|
|
120
|
+
const symbols = symbolBytes(elf, sections, names);
|
|
121
|
+
const parts = names.map((name) => constantReturn(symbols.get(name), elf.machine));
|
|
122
|
+
if (parts.every((n) => Number.isInteger(n) && n <= 65535) && parts[0] > 0)
|
|
123
|
+
return { id: product.id, version: parts.join('.'), source: prefix + ' version API' };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// For renamed/embedded Node, bind the inspector version to the release archive
|
|
128
|
+
// compiled into Node. Compatibility strings in another JS engine do not suffice.
|
|
129
|
+
function embeddedEngines(elf, product) {
|
|
130
|
+
const tags = new Set(),
|
|
131
|
+
releases = new Set();
|
|
132
|
+
const jsc = codecs.get('jsc-build');
|
|
133
|
+
const markers = new Set(jsc.elfBuildMarkers);
|
|
134
|
+
const checkNode = !['node-release', 'bun-standalone'].includes(product?.elfCodec);
|
|
135
|
+
const checkJsc = !['jsc-version', 'webkit-version'].includes(product?.elfCodec);
|
|
136
|
+
let registered = false;
|
|
137
|
+
if (!checkNode && !checkJsc) return [];
|
|
138
|
+
for (const chunk of readonlyChunks(elf)) {
|
|
139
|
+
if (checkJsc) for (const marker of markers) if (chunk.includes(marker)) markers.delete(marker);
|
|
140
|
+
if (!checkNode) {
|
|
141
|
+
if (!markers.size) break;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (chunk.includes('node_module_register\0')) registered = true;
|
|
145
|
+
if (tags.size <= 1 && chunk.includes('node.js/v'))
|
|
146
|
+
for (const m of chunk.matchAll(/\0node\.js\/v(\d+\.\d+\.\d+)(?=\0)/g)) {
|
|
147
|
+
tags.add(m[1]);
|
|
148
|
+
if (tags.size > 1) break;
|
|
149
|
+
}
|
|
150
|
+
if (releases.size <= 1 && chunk.includes('nodejs.org/download/release/'))
|
|
151
|
+
for (const m of chunk.matchAll(
|
|
152
|
+
/https:\/\/nodejs\.org\/download\/release\/v(\d+\.\d+\.\d+)\/node-v\1\.tar\.gz\0/g
|
|
153
|
+
)) {
|
|
154
|
+
releases.add(m[1]);
|
|
155
|
+
if (releases.size > 1) break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const products = [],
|
|
159
|
+
[version] = tags;
|
|
160
|
+
if (registered && tags.size === 1 && releases.size === 1 && releases.has(version))
|
|
161
|
+
products.push({ id: codecs.get('node-release').id, version, source: 'node-release-and-inspector' });
|
|
162
|
+
if (checkJsc && !markers.size) products.push({ id: jsc.id, version: null, source: 'jsc-build-markers' });
|
|
163
|
+
return products;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function* readonlyChunks(elf) {
|
|
167
|
+
let remaining = elf.size;
|
|
168
|
+
for (const segment of elf.segments.filter((s) => s.type === 1 && !(s.flags & 2))) {
|
|
169
|
+
if (segment.filesz > remaining) throw Error('overlapping ELF load segments');
|
|
170
|
+
remaining -= segment.filesz;
|
|
171
|
+
let tail = '';
|
|
172
|
+
const step = Math.min(256 * 1024, elf.max);
|
|
173
|
+
for (let pos = 0; pos < segment.filesz; pos += step) {
|
|
174
|
+
const data =
|
|
175
|
+
tail + elf.read(segment.offset + pos, Math.min(step, segment.filesz - pos)).toString('latin1');
|
|
176
|
+
yield data;
|
|
177
|
+
tail = data.slice(-160);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function embeddedProducts(name, elf) {
|
|
183
|
+
const sections = sectionsOf(elf);
|
|
184
|
+
const bundled = bunGraph(elf, sections);
|
|
185
|
+
const product = bundled
|
|
186
|
+
? codecs.get('bun-standalone')
|
|
187
|
+
: binaryProduct(name) ||
|
|
188
|
+
libraryProduct(name) ||
|
|
189
|
+
binaryProduct(elf.soname) ||
|
|
190
|
+
libraryProduct(elf.soname || '');
|
|
191
|
+
const products = elf.size >= 1024 * 1024 ? embeddedEngines(elf, product) : [];
|
|
192
|
+
if (!product) return products;
|
|
193
|
+
const exported = exportedVersion(product, elf, sections);
|
|
194
|
+
if (exported) products.push(exported);
|
|
195
|
+
if (!product.banner) return products;
|
|
196
|
+
// Read only mapped, read-only data. Small overlapping chunks also handle
|
|
197
|
+
// signatures spanning a read boundary without loading an entire executable.
|
|
198
|
+
const versions = new Set();
|
|
199
|
+
for (const data of readonlyChunks(elf)) {
|
|
200
|
+
for (const match of data.matchAll(product.banner)) {
|
|
201
|
+
const version = match.slice(1).join('.');
|
|
202
|
+
if (version.length <= 40) versions.add(version);
|
|
203
|
+
if (versions.size > 1) return products;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (versions.size)
|
|
207
|
+
products.push({
|
|
208
|
+
id: product.id,
|
|
209
|
+
version: [...versions][0],
|
|
210
|
+
source: bundled ? 'bun-module-graph' : 'embedded-version-banner'
|
|
211
|
+
});
|
|
212
|
+
else if (bundled) products.push({ id: 'bun', version: null, source: 'bun-module-graph' });
|
|
213
|
+
return products;
|
|
214
|
+
}
|
|
215
|
+
module.exports = { embeddedProducts, libraryProduct };
|