xploitscan-shared-rules 2.4.17 → 2.4.19
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/dist/index.cjs +392 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +392 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -162,7 +162,7 @@ __export(index_exports, {
|
|
|
162
162
|
module.exports = __toCommonJS(index_exports);
|
|
163
163
|
|
|
164
164
|
// src/version.ts
|
|
165
|
-
var SCANNER_VERSION = "2.4.
|
|
165
|
+
var SCANNER_VERSION = "2.4.19";
|
|
166
166
|
|
|
167
167
|
// src/snippet.ts
|
|
168
168
|
var cacheContent = null;
|
|
@@ -5256,7 +5256,219 @@ var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|
|
|
|
5256
5256
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
5257
5257
|
var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
|
|
5258
5258
|
var VERIFICATION_KEY_NAMES = /^(?:google|yandex|yahoo|bing|me|other|["']?(?:google-site-verification|facebook-domain-verification|msvalidate\.01|norton-safeweb-site-verification|ahrefs-site-verification|p:domain_verify|wot-verification)["']?)$/i;
|
|
5259
|
-
|
|
5259
|
+
function isWsCode(code) {
|
|
5260
|
+
if (code <= 32) return code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 32;
|
|
5261
|
+
if (code < 160) return false;
|
|
5262
|
+
if (code === 160 || code === 5760 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279) return true;
|
|
5263
|
+
return code >= 8192 && code <= 8202;
|
|
5264
|
+
}
|
|
5265
|
+
function isWordCode(code) {
|
|
5266
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 95;
|
|
5267
|
+
}
|
|
5268
|
+
function isWs(c) {
|
|
5269
|
+
return c !== void 0 && isWsCode(c.charCodeAt(0));
|
|
5270
|
+
}
|
|
5271
|
+
function isLineTerminator2(c) {
|
|
5272
|
+
return c === "\n" || c === "\r" || c === "\u2028" || c === "\u2029";
|
|
5273
|
+
}
|
|
5274
|
+
function isAsciiLetter(c) {
|
|
5275
|
+
if (c === void 0) return false;
|
|
5276
|
+
const a = c.charCodeAt(0);
|
|
5277
|
+
return a >= 65 && a <= 90 || a >= 97 && a <= 122;
|
|
5278
|
+
}
|
|
5279
|
+
function isKeyChar(c) {
|
|
5280
|
+
if (c === void 0) return false;
|
|
5281
|
+
const a = c.charCodeAt(0);
|
|
5282
|
+
return a >= 48 && a <= 57 || a >= 65 && a <= 90 || a >= 97 && a <= 122 || a === 95 || a === 46 || a === 45;
|
|
5283
|
+
}
|
|
5284
|
+
function ciAt(line, p, word) {
|
|
5285
|
+
if (p < 0 || p + word.length > line.length) return false;
|
|
5286
|
+
for (let k = 0; k < word.length; k++) {
|
|
5287
|
+
const a = line.charCodeAt(p + k);
|
|
5288
|
+
const b = word.charCodeAt(k);
|
|
5289
|
+
if (a !== b && !(a >= 65 && a <= 90 && a + 32 === b)) return false;
|
|
5290
|
+
}
|
|
5291
|
+
return true;
|
|
5292
|
+
}
|
|
5293
|
+
function matchConfigAssign(line) {
|
|
5294
|
+
const n = line.length;
|
|
5295
|
+
let i = 0;
|
|
5296
|
+
while (i < n && isWs(line[i])) i++;
|
|
5297
|
+
if (!isAsciiLetter(line[i])) return null;
|
|
5298
|
+
const keyStart = i;
|
|
5299
|
+
i++;
|
|
5300
|
+
let extra = 0;
|
|
5301
|
+
while (i < n && extra < 120 && isKeyChar(line[i])) {
|
|
5302
|
+
i++;
|
|
5303
|
+
extra++;
|
|
5304
|
+
}
|
|
5305
|
+
if (extra < 1) return null;
|
|
5306
|
+
if (isKeyChar(line[i])) return null;
|
|
5307
|
+
while (i < n && isWs(line[i])) i++;
|
|
5308
|
+
if (line[i] !== ":" && line[i] !== "=") return null;
|
|
5309
|
+
const valueFrom = i + 1;
|
|
5310
|
+
let j = valueFrom;
|
|
5311
|
+
while (j < n && isWs(line[j])) j++;
|
|
5312
|
+
let end = n;
|
|
5313
|
+
while (end > j && isWs(line[end - 1])) end--;
|
|
5314
|
+
let vs;
|
|
5315
|
+
let ve;
|
|
5316
|
+
if (end > j) {
|
|
5317
|
+
for (let k = j; k < end; k++) if (isLineTerminator2(line[k])) return null;
|
|
5318
|
+
vs = j;
|
|
5319
|
+
ve = end;
|
|
5320
|
+
} else {
|
|
5321
|
+
let k = n - 1;
|
|
5322
|
+
while (k >= valueFrom && isLineTerminator2(line[k])) k--;
|
|
5323
|
+
if (k < valueFrom) return null;
|
|
5324
|
+
vs = k;
|
|
5325
|
+
ve = k + 1;
|
|
5326
|
+
}
|
|
5327
|
+
const out = [line, line.slice(keyStart, keyStart + 1 + extra), line.slice(vs, ve)];
|
|
5328
|
+
out.index = 0;
|
|
5329
|
+
return out;
|
|
5330
|
+
}
|
|
5331
|
+
function isQuote(c) {
|
|
5332
|
+
return c === '"' || c === "'";
|
|
5333
|
+
}
|
|
5334
|
+
function eqQuote(line, p) {
|
|
5335
|
+
const n = line.length;
|
|
5336
|
+
while (p < n && isWs(line[p])) p++;
|
|
5337
|
+
if (line[p] !== "=") return -1;
|
|
5338
|
+
p++;
|
|
5339
|
+
while (p < n && isWs(line[p])) p++;
|
|
5340
|
+
if (!isQuote(line[p])) return -1;
|
|
5341
|
+
return p + 1;
|
|
5342
|
+
}
|
|
5343
|
+
function litAt(line, p, min, max) {
|
|
5344
|
+
let k = p;
|
|
5345
|
+
const lim = Math.min(line.length, p + max + 1);
|
|
5346
|
+
while (k < lim && !isQuote(line[k])) k++;
|
|
5347
|
+
if (k >= line.length || !isQuote(line[k])) return -1;
|
|
5348
|
+
const len = k - p;
|
|
5349
|
+
if (len < min || len > max) return -1;
|
|
5350
|
+
return k;
|
|
5351
|
+
}
|
|
5352
|
+
function rightmostIn(arr, lo, hi) {
|
|
5353
|
+
let a = 0;
|
|
5354
|
+
let b = arr.length - 1;
|
|
5355
|
+
let best = null;
|
|
5356
|
+
while (a <= b) {
|
|
5357
|
+
const mid = a + b >> 1;
|
|
5358
|
+
if (arr[mid][0] <= hi) {
|
|
5359
|
+
if (arr[mid][0] >= lo) best = arr[mid];
|
|
5360
|
+
a = mid + 1;
|
|
5361
|
+
} else b = mid - 1;
|
|
5362
|
+
}
|
|
5363
|
+
return best;
|
|
5364
|
+
}
|
|
5365
|
+
function gtOffsets(line) {
|
|
5366
|
+
const out = [];
|
|
5367
|
+
let from = 0;
|
|
5368
|
+
while (from < line.length) {
|
|
5369
|
+
const g = line.indexOf(">", from);
|
|
5370
|
+
if (g < 0) break;
|
|
5371
|
+
out.push(g);
|
|
5372
|
+
from = g + 1;
|
|
5373
|
+
}
|
|
5374
|
+
return out;
|
|
5375
|
+
}
|
|
5376
|
+
function firstGtAt(offsets, lineLength, from) {
|
|
5377
|
+
let lo = 0;
|
|
5378
|
+
let hi = offsets.length;
|
|
5379
|
+
while (lo < hi) {
|
|
5380
|
+
const mid = lo + hi >> 1;
|
|
5381
|
+
if (offsets[mid] < from) lo = mid + 1;
|
|
5382
|
+
else hi = mid;
|
|
5383
|
+
}
|
|
5384
|
+
return lo < offsets.length ? offsets[lo] : lineLength;
|
|
5385
|
+
}
|
|
5386
|
+
function attrStart(kind, code) {
|
|
5387
|
+
if (kind === "key") return code === 75 || code === 107 || code === 78 || code === 110;
|
|
5388
|
+
return code === 86 || code === 118;
|
|
5389
|
+
}
|
|
5390
|
+
function matchInto(line, p, kind, buf) {
|
|
5391
|
+
if (p > 0 && isWordCode(line.charCodeAt(p - 1))) return false;
|
|
5392
|
+
let w = 0;
|
|
5393
|
+
if (kind === "key") {
|
|
5394
|
+
w = ciAt(line, p, "key") ? 3 : ciAt(line, p, "name") ? 4 : 0;
|
|
5395
|
+
} else if (ciAt(line, p, "value")) {
|
|
5396
|
+
w = 5;
|
|
5397
|
+
}
|
|
5398
|
+
if (!w) return false;
|
|
5399
|
+
const q = eqQuote(line, p + w);
|
|
5400
|
+
if (q < 0) return false;
|
|
5401
|
+
const e = litAt(line, q, kind === "key" ? 1 : 20, kind === "key" ? Number.POSITIVE_INFINITY : 256);
|
|
5402
|
+
if (e < 0) return false;
|
|
5403
|
+
buf[0] = p;
|
|
5404
|
+
buf[1] = q;
|
|
5405
|
+
buf[2] = e;
|
|
5406
|
+
buf[3] = e + 1;
|
|
5407
|
+
return true;
|
|
5408
|
+
}
|
|
5409
|
+
function collectAttr(line, kind) {
|
|
5410
|
+
const buf = [0, 0, 0, 0];
|
|
5411
|
+
const out = [];
|
|
5412
|
+
for (let p = 0; p < line.length; p++) {
|
|
5413
|
+
if (!attrStart(kind, line.charCodeAt(p))) continue;
|
|
5414
|
+
if (!matchInto(line, p, kind, buf)) continue;
|
|
5415
|
+
out.push([buf[0], buf[1], buf[2], buf[3]]);
|
|
5416
|
+
}
|
|
5417
|
+
return out;
|
|
5418
|
+
}
|
|
5419
|
+
function pairScan(line, first, second) {
|
|
5420
|
+
const seconds = collectAttr(line, second);
|
|
5421
|
+
if (seconds.length === 0) return null;
|
|
5422
|
+
const gts = gtOffsets(line);
|
|
5423
|
+
const buf = [0, 0, 0, 0];
|
|
5424
|
+
const n = line.length;
|
|
5425
|
+
for (let p = 0; p < n; p++) {
|
|
5426
|
+
if (!attrStart(first, line.charCodeAt(p))) continue;
|
|
5427
|
+
if (!matchInto(line, p, first, buf)) continue;
|
|
5428
|
+
const s2 = rightmostIn(seconds, buf[3], firstGtAt(gts, n, buf[3]));
|
|
5429
|
+
if (!s2) continue;
|
|
5430
|
+
const out = [line.slice(buf[0], s2[3]), line.slice(buf[1], buf[2]), line.slice(s2[1], s2[2])];
|
|
5431
|
+
out.index = buf[0];
|
|
5432
|
+
return out;
|
|
5433
|
+
}
|
|
5434
|
+
return null;
|
|
5435
|
+
}
|
|
5436
|
+
function matchXmlAttr(line) {
|
|
5437
|
+
return pairScan(line, "key", "value");
|
|
5438
|
+
}
|
|
5439
|
+
function matchXmlElement(line) {
|
|
5440
|
+
return pairScan(line, "value", "key");
|
|
5441
|
+
}
|
|
5442
|
+
var VERIFICATION_META_KEYWORDS = ["site-verification", "domain-verification", "msvalidate", "domain_verify"];
|
|
5443
|
+
function ciIncludes(hay, word) {
|
|
5444
|
+
for (let p = 0; p + word.length <= hay.length; p++) if (ciAt(hay, p, word)) return true;
|
|
5445
|
+
return false;
|
|
5446
|
+
}
|
|
5447
|
+
function matchVerificationMeta(line) {
|
|
5448
|
+
const good = [];
|
|
5449
|
+
for (let p = 0; p < line.length; p++) {
|
|
5450
|
+
if (!ciAt(line, p, "name")) continue;
|
|
5451
|
+
const q = eqQuote(line, p + 4);
|
|
5452
|
+
if (q < 0) continue;
|
|
5453
|
+
const e = litAt(line, q, 0, Number.POSITIVE_INFINITY);
|
|
5454
|
+
if (e < 0) continue;
|
|
5455
|
+
const lit = line.slice(q, e);
|
|
5456
|
+
if (VERIFICATION_META_KEYWORDS.some((w) => ciIncludes(lit, w))) good.push([p]);
|
|
5457
|
+
}
|
|
5458
|
+
if (good.length === 0) return false;
|
|
5459
|
+
const gts = gtOffsets(line);
|
|
5460
|
+
for (let s = 0; s < line.length; s++) {
|
|
5461
|
+
if (!ciAt(line, s, "<meta")) continue;
|
|
5462
|
+
if (rightmostIn(good, s + 6, firstGtAt(gts, line.length, s + 5))) return true;
|
|
5463
|
+
}
|
|
5464
|
+
return false;
|
|
5465
|
+
}
|
|
5466
|
+
var entropyLineMatchers = {
|
|
5467
|
+
configAssign: matchConfigAssign,
|
|
5468
|
+
xmlAttr: matchXmlAttr,
|
|
5469
|
+
xmlElement: matchXmlElement,
|
|
5470
|
+
verificationMeta: matchVerificationMeta
|
|
5471
|
+
};
|
|
5260
5472
|
var SECRET_VAR_NAMES = /(?:^|[^a-z])(?:key|secret|token|password|passwd|pwd|api[_-]?key|auth|credential|private|signing|bearer|access[_-]?token|refresh[_-]?token|session[_-]?id)(?:$|[^a-z])/i;
|
|
5261
5473
|
var CAMEL_SECRET_VAR_NAMES = /(?:Key|Secret|Token|Password|Passwd|Credential|Private|Signing|Bearer|Auth)$/;
|
|
5262
5474
|
var HUMAN_READABLE_ENV_REFERENCE_RE = /^(?:[a-z][a-z'-]*\s+){1,6}[A-Z][A-Z0-9_]{2,}$/;
|
|
@@ -5347,7 +5559,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5347
5559
|
}
|
|
5348
5560
|
} else {
|
|
5349
5561
|
if (KEY_VALUE_CONFIG_RE.test(filePath)) {
|
|
5350
|
-
const configAssign =
|
|
5562
|
+
const configAssign = entropyLineMatchers.configAssign(line);
|
|
5351
5563
|
if (configAssign && isSecretVariableName(configAssign[1])) {
|
|
5352
5564
|
const value = dotenvValue(configAssign[2]);
|
|
5353
5565
|
if (value.length >= 20 && value.length <= MAX_DOTENV_VALUE) {
|
|
@@ -5360,7 +5572,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5360
5572
|
}
|
|
5361
5573
|
}
|
|
5362
5574
|
if (XML_CONFIG_RE.test(filePath)) {
|
|
5363
|
-
const xmlPair =
|
|
5575
|
+
const xmlPair = entropyLineMatchers.xmlAttr(line) || entropyLineMatchers.xmlElement(line);
|
|
5364
5576
|
if (xmlPair) {
|
|
5365
5577
|
const valueFirst = /^\s*<[^>]*\bvalue\s*=/i.test(line);
|
|
5366
5578
|
const variableName = valueFirst ? xmlPair[2] : xmlPair[1];
|
|
@@ -5452,7 +5664,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5452
5664
|
continue;
|
|
5453
5665
|
}
|
|
5454
5666
|
if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
|
|
5455
|
-
if (verificationMeta === void 0) verificationMeta =
|
|
5667
|
+
if (verificationMeta === void 0) verificationMeta = entropyLineMatchers.verificationMeta(line);
|
|
5456
5668
|
if (verificationMeta) continue;
|
|
5457
5669
|
if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
|
|
5458
5670
|
if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;
|
|
@@ -6479,8 +6691,183 @@ var CONFIG_CHECKS = [
|
|
|
6479
6691
|
}
|
|
6480
6692
|
return null;
|
|
6481
6693
|
}
|
|
6694
|
+
},
|
|
6695
|
+
{
|
|
6696
|
+
id: "CFG013",
|
|
6697
|
+
title: "PHP base image affected by CVE-2026-109618 and CVE-2026-109619",
|
|
6698
|
+
severity: "critical",
|
|
6699
|
+
category: "Dependencies",
|
|
6700
|
+
description: "This Dockerfile builds on an official php image whose PHP version is affected by CVE-2026-109618 and CVE-2026-109619 (publicly known as PHP2Shell), memory-safety flaws reachable from unauthenticated HTTP requests to mod_php (-apache) and PHP-FPM (-fpm). Affected: 8.2.0-8.2.34, 8.3.0-8.3.35, 8.4.0-8.4.26, 8.5.0-8.5.11, and all end-of-life releases (8.1 and older), which have no fixed official release. Advisories: https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w and https://github.com/php/php-src/security/advisories/GHSA-6wmf-4rv5-p3rp",
|
|
6701
|
+
fix: "Rebuild on php 8.2.35, 8.3.36, 8.4.27 or 8.5.12 or later, keeping the same variant (for example php:8.3.36-apache). End-of-life branches (8.1 and older) have no fixed release: move to a supported branch. Until you can rebuild, setting session.upload_progress.enabled=0, a low post_max_size and, on 8.5, fatal_error_backtraces=0 reduces but does not remove exposure.",
|
|
6702
|
+
owasp: "A06:2021",
|
|
6703
|
+
cwe: "CWE-1395",
|
|
6704
|
+
filePattern: /Dockerfile$/i,
|
|
6705
|
+
check(content) {
|
|
6706
|
+
const line = php2shellLines(content).cfg013Line;
|
|
6707
|
+
if (line === null) return null;
|
|
6708
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
6709
|
+
}
|
|
6710
|
+
},
|
|
6711
|
+
{
|
|
6712
|
+
id: "CFG014",
|
|
6713
|
+
title: "PHP base image (non-web variant) at a version affected by CVE-2026-109618 and CVE-2026-109619",
|
|
6714
|
+
severity: "info",
|
|
6715
|
+
category: "Dependencies",
|
|
6716
|
+
description: "The final stage uses an official php image without the -apache or -fpm variant at an affected PHP version (8.2.0-8.2.34, 8.3.0-8.3.35, 8.4.0-8.4.26, 8.5.0-8.5.11, or 8.1 and older). The PHP advisories scope the risk to PHP serving web requests (mod_php, PHP-FPM, php-cgi, FrankenPHP, LiteSpeed); the official cli and zts images include php-cgi. Advisories: https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w and https://github.com/php/php-src/security/advisories/GHSA-6wmf-4rv5-p3rp",
|
|
6717
|
+
fix: "Pin a fixed version (8.2.35, 8.3.36, 8.4.27, 8.5.12 or later). If this image never serves web requests, upgrade on your normal schedule.",
|
|
6718
|
+
owasp: "A06:2021",
|
|
6719
|
+
cwe: "CWE-1395",
|
|
6720
|
+
filePattern: /Dockerfile$/i,
|
|
6721
|
+
check(content) {
|
|
6722
|
+
const line = php2shellLines(content).cfg014Line;
|
|
6723
|
+
if (line === null) return null;
|
|
6724
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
6725
|
+
}
|
|
6482
6726
|
}
|
|
6483
6727
|
];
|
|
6728
|
+
var PHP2SHELL_LINE_LIMIT = 4096;
|
|
6729
|
+
var PHP2SHELL_FROM_CAP = 256;
|
|
6730
|
+
var PHP2SHELL_FROM_MARK = /^[ \t\uFEFF]{0,4096}FROM[ \t]/i;
|
|
6731
|
+
var PHP2SHELL_FROM = /^[ \t\uFEFF]{0,4096}FROM[ \t]{1,4096}(?:--[^ \t]{1,256}[ \t]{1,4096}){0,4}([^ \t]{1,512})(?:[ \t]{1,4096}AS[ \t]{1,4096}([^ \t]{1,128}))?[ \t]{0,4096}$/i;
|
|
6732
|
+
var PHP2SHELL_ARG = /^[ \t\uFEFF]{0,4096}ARG[ \t]{1,4096}([A-Za-z_][A-Za-z0-9_]{0,63})=(?:"([^"\s$]{1,64})"|'([^'\s$]{1,64})'|([^\s"'$]{1,64}))[ \t]{0,4096}$/i;
|
|
6733
|
+
var PHP2SHELL_VAR = /\$(?:\{([A-Za-z_][A-Za-z0-9_]{0,63})\}|([A-Za-z_][A-Za-z0-9_]{0,63}))/g;
|
|
6734
|
+
var PHP2SHELL_IMAGE = /^(?:(?:docker\.io|registry-1\.docker\.io|index\.docker\.io|mirror\.gcr\.io|public\.ecr\.aws\/docker)\/)?(?:library\/)?php(?::([A-Za-z0-9_][A-Za-z0-9_.-]{0,127}))?(?:@sha256:[a-f0-9]{64})?$/;
|
|
6735
|
+
var PHP2SHELL_TAG = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,3}))?(?:-([a-z0-9][a-z0-9.-]{0,63}))?$/;
|
|
6736
|
+
var PHP2SHELL_FIXED_PATCH = [
|
|
6737
|
+
[8, 2, 35],
|
|
6738
|
+
[8, 3, 36],
|
|
6739
|
+
[8, 4, 27],
|
|
6740
|
+
[8, 5, 12]
|
|
6741
|
+
];
|
|
6742
|
+
function php2shellDigits(value) {
|
|
6743
|
+
let n = 0;
|
|
6744
|
+
for (let i = 0; i < value.length; i++) n = n * 10 + (value.charCodeAt(i) - 48);
|
|
6745
|
+
return n;
|
|
6746
|
+
}
|
|
6747
|
+
function php2shellFixedPatch(major, minor) {
|
|
6748
|
+
for (let i = 0; i < PHP2SHELL_FIXED_PATCH.length; i++) {
|
|
6749
|
+
const row = PHP2SHELL_FIXED_PATCH[i];
|
|
6750
|
+
if (row[0] === major && row[1] === minor) return row[2];
|
|
6751
|
+
}
|
|
6752
|
+
return null;
|
|
6753
|
+
}
|
|
6754
|
+
function php2shellAffected(major, minor, patch) {
|
|
6755
|
+
if (major < 8) return true;
|
|
6756
|
+
if (major === 8 && minor !== null && minor <= 1) return true;
|
|
6757
|
+
if (minor === null || patch === null) return false;
|
|
6758
|
+
const fixed = php2shellFixedPatch(major, minor);
|
|
6759
|
+
return fixed !== null && patch < fixed;
|
|
6760
|
+
}
|
|
6761
|
+
function php2shellWebSapi(suffix) {
|
|
6762
|
+
if (!suffix) return false;
|
|
6763
|
+
let start = 0;
|
|
6764
|
+
for (let i = 0; i <= suffix.length; i++) {
|
|
6765
|
+
if (i === suffix.length || suffix.charCodeAt(i) === 45) {
|
|
6766
|
+
const token = suffix.slice(start, i);
|
|
6767
|
+
if (token === "apache" || token === "fpm") return true;
|
|
6768
|
+
start = i + 1;
|
|
6769
|
+
}
|
|
6770
|
+
}
|
|
6771
|
+
return false;
|
|
6772
|
+
}
|
|
6773
|
+
function php2shellComment(line) {
|
|
6774
|
+
let i = 0;
|
|
6775
|
+
while (i < line.length) {
|
|
6776
|
+
const c = line.charCodeAt(i);
|
|
6777
|
+
if (c !== 32 && c !== 9) break;
|
|
6778
|
+
i += 1;
|
|
6779
|
+
}
|
|
6780
|
+
return i < line.length && line.charCodeAt(i) === 35;
|
|
6781
|
+
}
|
|
6782
|
+
function php2shellNormalize(raw, index) {
|
|
6783
|
+
let line = raw;
|
|
6784
|
+
if (index === 0 && line.charCodeAt(0) === 65279) line = line.slice(1);
|
|
6785
|
+
if (line.length > 0 && line.charCodeAt(line.length - 1) === 13) line = line.slice(0, -1);
|
|
6786
|
+
return line;
|
|
6787
|
+
}
|
|
6788
|
+
function php2shellSubstitute(ref, args) {
|
|
6789
|
+
PHP2SHELL_VAR.lastIndex = 0;
|
|
6790
|
+
let unknown = false;
|
|
6791
|
+
const out = ref.replace(PHP2SHELL_VAR, (match, braced, bare) => {
|
|
6792
|
+
const name = braced ?? bare;
|
|
6793
|
+
const value = name ? args.get(name) : void 0;
|
|
6794
|
+
if (value === void 0) {
|
|
6795
|
+
unknown = true;
|
|
6796
|
+
return match;
|
|
6797
|
+
}
|
|
6798
|
+
return value;
|
|
6799
|
+
});
|
|
6800
|
+
if (unknown || out.includes("$")) return null;
|
|
6801
|
+
return out;
|
|
6802
|
+
}
|
|
6803
|
+
function php2shellLines(content) {
|
|
6804
|
+
const args = /* @__PURE__ */ new Map();
|
|
6805
|
+
const stages = /* @__PURE__ */ new Set();
|
|
6806
|
+
let seenFrom = false;
|
|
6807
|
+
let fromCount = 0;
|
|
6808
|
+
let capped = false;
|
|
6809
|
+
let cfg013Line = null;
|
|
6810
|
+
let lastLine = 0;
|
|
6811
|
+
let lastAffectedNonWeb = false;
|
|
6812
|
+
const lines = content.split("\n");
|
|
6813
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6814
|
+
const line = php2shellNormalize(lines[i] ?? "", i);
|
|
6815
|
+
if (line.length > PHP2SHELL_LINE_LIMIT) continue;
|
|
6816
|
+
if (php2shellComment(line)) continue;
|
|
6817
|
+
if (!seenFrom) {
|
|
6818
|
+
const arg = PHP2SHELL_ARG.exec(line);
|
|
6819
|
+
if (arg?.[1]) {
|
|
6820
|
+
const value = arg[2] ?? arg[3] ?? arg[4];
|
|
6821
|
+
if (value !== void 0) {
|
|
6822
|
+
args.set(arg[1], value);
|
|
6823
|
+
continue;
|
|
6824
|
+
}
|
|
6825
|
+
}
|
|
6826
|
+
}
|
|
6827
|
+
if (!PHP2SHELL_FROM_MARK.test(line)) continue;
|
|
6828
|
+
fromCount += 1;
|
|
6829
|
+
if (fromCount > PHP2SHELL_FROM_CAP) {
|
|
6830
|
+
capped = true;
|
|
6831
|
+
break;
|
|
6832
|
+
}
|
|
6833
|
+
seenFrom = true;
|
|
6834
|
+
const lineNo = i + 1;
|
|
6835
|
+
lastLine = lineNo;
|
|
6836
|
+
lastAffectedNonWeb = false;
|
|
6837
|
+
const from = PHP2SHELL_FROM.exec(line);
|
|
6838
|
+
const rawRef = from?.[1];
|
|
6839
|
+
if (!rawRef) continue;
|
|
6840
|
+
const ref = php2shellSubstitute(rawRef, args);
|
|
6841
|
+
if (ref === null) continue;
|
|
6842
|
+
const asName = from?.[2];
|
|
6843
|
+
const refLower = ref.toLowerCase();
|
|
6844
|
+
if (stages.has(refLower)) {
|
|
6845
|
+
if (asName) stages.add(asName.toLowerCase());
|
|
6846
|
+
continue;
|
|
6847
|
+
}
|
|
6848
|
+
if (asName) stages.add(asName.toLowerCase());
|
|
6849
|
+
if (ref === "scratch") continue;
|
|
6850
|
+
const image = PHP2SHELL_IMAGE.exec(ref);
|
|
6851
|
+
const tag = image?.[1];
|
|
6852
|
+
if (!image || tag === void 0 || tag === "latest") continue;
|
|
6853
|
+
const parsed = PHP2SHELL_TAG.exec(tag);
|
|
6854
|
+
const majorText = parsed?.[1];
|
|
6855
|
+
if (!parsed || majorText === void 0) continue;
|
|
6856
|
+
const major = php2shellDigits(majorText);
|
|
6857
|
+
const minor = parsed[2] !== void 0 ? php2shellDigits(parsed[2]) : null;
|
|
6858
|
+
const patch = parsed[3] !== void 0 ? php2shellDigits(parsed[3]) : null;
|
|
6859
|
+
if (!php2shellAffected(major, minor, patch)) continue;
|
|
6860
|
+
if (php2shellWebSapi(parsed[4])) {
|
|
6861
|
+
if (cfg013Line === null) cfg013Line = lineNo;
|
|
6862
|
+
} else {
|
|
6863
|
+
lastAffectedNonWeb = true;
|
|
6864
|
+
}
|
|
6865
|
+
}
|
|
6866
|
+
return {
|
|
6867
|
+
cfg013Line,
|
|
6868
|
+
cfg014Line: !capped && cfg013Line === null && lastAffectedNonWeb ? lastLine : null
|
|
6869
|
+
};
|
|
6870
|
+
}
|
|
6484
6871
|
function scanConfigs(files) {
|
|
6485
6872
|
const findings = [];
|
|
6486
6873
|
for (const { path: filePath, content } of files) {
|