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.d.cts
CHANGED
|
@@ -165,7 +165,7 @@ interface CustomRule {
|
|
|
165
165
|
* before a scan can be saved without enough provenance to explain a changed
|
|
166
166
|
* grade.
|
|
167
167
|
*/
|
|
168
|
-
declare const SCANNER_VERSION = "2.4.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.19";
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
package/dist/index.d.ts
CHANGED
|
@@ -165,7 +165,7 @@ interface CustomRule {
|
|
|
165
165
|
* before a scan can be saved without enough provenance to explain a changed
|
|
166
166
|
* grade.
|
|
167
167
|
*/
|
|
168
|
-
declare const SCANNER_VERSION = "2.4.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.19";
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SCANNER_VERSION = "2.4.
|
|
2
|
+
var SCANNER_VERSION = "2.4.19";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -5093,7 +5093,219 @@ var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|
|
|
|
5093
5093
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
5094
5094
|
var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
|
|
5095
5095
|
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;
|
|
5096
|
-
|
|
5096
|
+
function isWsCode(code) {
|
|
5097
|
+
if (code <= 32) return code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 32;
|
|
5098
|
+
if (code < 160) return false;
|
|
5099
|
+
if (code === 160 || code === 5760 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279) return true;
|
|
5100
|
+
return code >= 8192 && code <= 8202;
|
|
5101
|
+
}
|
|
5102
|
+
function isWordCode(code) {
|
|
5103
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 95;
|
|
5104
|
+
}
|
|
5105
|
+
function isWs(c) {
|
|
5106
|
+
return c !== void 0 && isWsCode(c.charCodeAt(0));
|
|
5107
|
+
}
|
|
5108
|
+
function isLineTerminator2(c) {
|
|
5109
|
+
return c === "\n" || c === "\r" || c === "\u2028" || c === "\u2029";
|
|
5110
|
+
}
|
|
5111
|
+
function isAsciiLetter(c) {
|
|
5112
|
+
if (c === void 0) return false;
|
|
5113
|
+
const a = c.charCodeAt(0);
|
|
5114
|
+
return a >= 65 && a <= 90 || a >= 97 && a <= 122;
|
|
5115
|
+
}
|
|
5116
|
+
function isKeyChar(c) {
|
|
5117
|
+
if (c === void 0) return false;
|
|
5118
|
+
const a = c.charCodeAt(0);
|
|
5119
|
+
return a >= 48 && a <= 57 || a >= 65 && a <= 90 || a >= 97 && a <= 122 || a === 95 || a === 46 || a === 45;
|
|
5120
|
+
}
|
|
5121
|
+
function ciAt(line, p, word) {
|
|
5122
|
+
if (p < 0 || p + word.length > line.length) return false;
|
|
5123
|
+
for (let k = 0; k < word.length; k++) {
|
|
5124
|
+
const a = line.charCodeAt(p + k);
|
|
5125
|
+
const b = word.charCodeAt(k);
|
|
5126
|
+
if (a !== b && !(a >= 65 && a <= 90 && a + 32 === b)) return false;
|
|
5127
|
+
}
|
|
5128
|
+
return true;
|
|
5129
|
+
}
|
|
5130
|
+
function matchConfigAssign(line) {
|
|
5131
|
+
const n = line.length;
|
|
5132
|
+
let i = 0;
|
|
5133
|
+
while (i < n && isWs(line[i])) i++;
|
|
5134
|
+
if (!isAsciiLetter(line[i])) return null;
|
|
5135
|
+
const keyStart = i;
|
|
5136
|
+
i++;
|
|
5137
|
+
let extra = 0;
|
|
5138
|
+
while (i < n && extra < 120 && isKeyChar(line[i])) {
|
|
5139
|
+
i++;
|
|
5140
|
+
extra++;
|
|
5141
|
+
}
|
|
5142
|
+
if (extra < 1) return null;
|
|
5143
|
+
if (isKeyChar(line[i])) return null;
|
|
5144
|
+
while (i < n && isWs(line[i])) i++;
|
|
5145
|
+
if (line[i] !== ":" && line[i] !== "=") return null;
|
|
5146
|
+
const valueFrom = i + 1;
|
|
5147
|
+
let j = valueFrom;
|
|
5148
|
+
while (j < n && isWs(line[j])) j++;
|
|
5149
|
+
let end = n;
|
|
5150
|
+
while (end > j && isWs(line[end - 1])) end--;
|
|
5151
|
+
let vs;
|
|
5152
|
+
let ve;
|
|
5153
|
+
if (end > j) {
|
|
5154
|
+
for (let k = j; k < end; k++) if (isLineTerminator2(line[k])) return null;
|
|
5155
|
+
vs = j;
|
|
5156
|
+
ve = end;
|
|
5157
|
+
} else {
|
|
5158
|
+
let k = n - 1;
|
|
5159
|
+
while (k >= valueFrom && isLineTerminator2(line[k])) k--;
|
|
5160
|
+
if (k < valueFrom) return null;
|
|
5161
|
+
vs = k;
|
|
5162
|
+
ve = k + 1;
|
|
5163
|
+
}
|
|
5164
|
+
const out = [line, line.slice(keyStart, keyStart + 1 + extra), line.slice(vs, ve)];
|
|
5165
|
+
out.index = 0;
|
|
5166
|
+
return out;
|
|
5167
|
+
}
|
|
5168
|
+
function isQuote(c) {
|
|
5169
|
+
return c === '"' || c === "'";
|
|
5170
|
+
}
|
|
5171
|
+
function eqQuote(line, p) {
|
|
5172
|
+
const n = line.length;
|
|
5173
|
+
while (p < n && isWs(line[p])) p++;
|
|
5174
|
+
if (line[p] !== "=") return -1;
|
|
5175
|
+
p++;
|
|
5176
|
+
while (p < n && isWs(line[p])) p++;
|
|
5177
|
+
if (!isQuote(line[p])) return -1;
|
|
5178
|
+
return p + 1;
|
|
5179
|
+
}
|
|
5180
|
+
function litAt(line, p, min, max) {
|
|
5181
|
+
let k = p;
|
|
5182
|
+
const lim = Math.min(line.length, p + max + 1);
|
|
5183
|
+
while (k < lim && !isQuote(line[k])) k++;
|
|
5184
|
+
if (k >= line.length || !isQuote(line[k])) return -1;
|
|
5185
|
+
const len = k - p;
|
|
5186
|
+
if (len < min || len > max) return -1;
|
|
5187
|
+
return k;
|
|
5188
|
+
}
|
|
5189
|
+
function rightmostIn(arr, lo, hi) {
|
|
5190
|
+
let a = 0;
|
|
5191
|
+
let b = arr.length - 1;
|
|
5192
|
+
let best = null;
|
|
5193
|
+
while (a <= b) {
|
|
5194
|
+
const mid = a + b >> 1;
|
|
5195
|
+
if (arr[mid][0] <= hi) {
|
|
5196
|
+
if (arr[mid][0] >= lo) best = arr[mid];
|
|
5197
|
+
a = mid + 1;
|
|
5198
|
+
} else b = mid - 1;
|
|
5199
|
+
}
|
|
5200
|
+
return best;
|
|
5201
|
+
}
|
|
5202
|
+
function gtOffsets(line) {
|
|
5203
|
+
const out = [];
|
|
5204
|
+
let from = 0;
|
|
5205
|
+
while (from < line.length) {
|
|
5206
|
+
const g = line.indexOf(">", from);
|
|
5207
|
+
if (g < 0) break;
|
|
5208
|
+
out.push(g);
|
|
5209
|
+
from = g + 1;
|
|
5210
|
+
}
|
|
5211
|
+
return out;
|
|
5212
|
+
}
|
|
5213
|
+
function firstGtAt(offsets, lineLength, from) {
|
|
5214
|
+
let lo = 0;
|
|
5215
|
+
let hi = offsets.length;
|
|
5216
|
+
while (lo < hi) {
|
|
5217
|
+
const mid = lo + hi >> 1;
|
|
5218
|
+
if (offsets[mid] < from) lo = mid + 1;
|
|
5219
|
+
else hi = mid;
|
|
5220
|
+
}
|
|
5221
|
+
return lo < offsets.length ? offsets[lo] : lineLength;
|
|
5222
|
+
}
|
|
5223
|
+
function attrStart(kind, code) {
|
|
5224
|
+
if (kind === "key") return code === 75 || code === 107 || code === 78 || code === 110;
|
|
5225
|
+
return code === 86 || code === 118;
|
|
5226
|
+
}
|
|
5227
|
+
function matchInto(line, p, kind, buf) {
|
|
5228
|
+
if (p > 0 && isWordCode(line.charCodeAt(p - 1))) return false;
|
|
5229
|
+
let w = 0;
|
|
5230
|
+
if (kind === "key") {
|
|
5231
|
+
w = ciAt(line, p, "key") ? 3 : ciAt(line, p, "name") ? 4 : 0;
|
|
5232
|
+
} else if (ciAt(line, p, "value")) {
|
|
5233
|
+
w = 5;
|
|
5234
|
+
}
|
|
5235
|
+
if (!w) return false;
|
|
5236
|
+
const q = eqQuote(line, p + w);
|
|
5237
|
+
if (q < 0) return false;
|
|
5238
|
+
const e = litAt(line, q, kind === "key" ? 1 : 20, kind === "key" ? Number.POSITIVE_INFINITY : 256);
|
|
5239
|
+
if (e < 0) return false;
|
|
5240
|
+
buf[0] = p;
|
|
5241
|
+
buf[1] = q;
|
|
5242
|
+
buf[2] = e;
|
|
5243
|
+
buf[3] = e + 1;
|
|
5244
|
+
return true;
|
|
5245
|
+
}
|
|
5246
|
+
function collectAttr(line, kind) {
|
|
5247
|
+
const buf = [0, 0, 0, 0];
|
|
5248
|
+
const out = [];
|
|
5249
|
+
for (let p = 0; p < line.length; p++) {
|
|
5250
|
+
if (!attrStart(kind, line.charCodeAt(p))) continue;
|
|
5251
|
+
if (!matchInto(line, p, kind, buf)) continue;
|
|
5252
|
+
out.push([buf[0], buf[1], buf[2], buf[3]]);
|
|
5253
|
+
}
|
|
5254
|
+
return out;
|
|
5255
|
+
}
|
|
5256
|
+
function pairScan(line, first, second) {
|
|
5257
|
+
const seconds = collectAttr(line, second);
|
|
5258
|
+
if (seconds.length === 0) return null;
|
|
5259
|
+
const gts = gtOffsets(line);
|
|
5260
|
+
const buf = [0, 0, 0, 0];
|
|
5261
|
+
const n = line.length;
|
|
5262
|
+
for (let p = 0; p < n; p++) {
|
|
5263
|
+
if (!attrStart(first, line.charCodeAt(p))) continue;
|
|
5264
|
+
if (!matchInto(line, p, first, buf)) continue;
|
|
5265
|
+
const s2 = rightmostIn(seconds, buf[3], firstGtAt(gts, n, buf[3]));
|
|
5266
|
+
if (!s2) continue;
|
|
5267
|
+
const out = [line.slice(buf[0], s2[3]), line.slice(buf[1], buf[2]), line.slice(s2[1], s2[2])];
|
|
5268
|
+
out.index = buf[0];
|
|
5269
|
+
return out;
|
|
5270
|
+
}
|
|
5271
|
+
return null;
|
|
5272
|
+
}
|
|
5273
|
+
function matchXmlAttr(line) {
|
|
5274
|
+
return pairScan(line, "key", "value");
|
|
5275
|
+
}
|
|
5276
|
+
function matchXmlElement(line) {
|
|
5277
|
+
return pairScan(line, "value", "key");
|
|
5278
|
+
}
|
|
5279
|
+
var VERIFICATION_META_KEYWORDS = ["site-verification", "domain-verification", "msvalidate", "domain_verify"];
|
|
5280
|
+
function ciIncludes(hay, word) {
|
|
5281
|
+
for (let p = 0; p + word.length <= hay.length; p++) if (ciAt(hay, p, word)) return true;
|
|
5282
|
+
return false;
|
|
5283
|
+
}
|
|
5284
|
+
function matchVerificationMeta(line) {
|
|
5285
|
+
const good = [];
|
|
5286
|
+
for (let p = 0; p < line.length; p++) {
|
|
5287
|
+
if (!ciAt(line, p, "name")) continue;
|
|
5288
|
+
const q = eqQuote(line, p + 4);
|
|
5289
|
+
if (q < 0) continue;
|
|
5290
|
+
const e = litAt(line, q, 0, Number.POSITIVE_INFINITY);
|
|
5291
|
+
if (e < 0) continue;
|
|
5292
|
+
const lit = line.slice(q, e);
|
|
5293
|
+
if (VERIFICATION_META_KEYWORDS.some((w) => ciIncludes(lit, w))) good.push([p]);
|
|
5294
|
+
}
|
|
5295
|
+
if (good.length === 0) return false;
|
|
5296
|
+
const gts = gtOffsets(line);
|
|
5297
|
+
for (let s = 0; s < line.length; s++) {
|
|
5298
|
+
if (!ciAt(line, s, "<meta")) continue;
|
|
5299
|
+
if (rightmostIn(good, s + 6, firstGtAt(gts, line.length, s + 5))) return true;
|
|
5300
|
+
}
|
|
5301
|
+
return false;
|
|
5302
|
+
}
|
|
5303
|
+
var entropyLineMatchers = {
|
|
5304
|
+
configAssign: matchConfigAssign,
|
|
5305
|
+
xmlAttr: matchXmlAttr,
|
|
5306
|
+
xmlElement: matchXmlElement,
|
|
5307
|
+
verificationMeta: matchVerificationMeta
|
|
5308
|
+
};
|
|
5097
5309
|
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;
|
|
5098
5310
|
var CAMEL_SECRET_VAR_NAMES = /(?:Key|Secret|Token|Password|Passwd|Credential|Private|Signing|Bearer|Auth)$/;
|
|
5099
5311
|
var HUMAN_READABLE_ENV_REFERENCE_RE = /^(?:[a-z][a-z'-]*\s+){1,6}[A-Z][A-Z0-9_]{2,}$/;
|
|
@@ -5184,7 +5396,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5184
5396
|
}
|
|
5185
5397
|
} else {
|
|
5186
5398
|
if (KEY_VALUE_CONFIG_RE.test(filePath)) {
|
|
5187
|
-
const configAssign =
|
|
5399
|
+
const configAssign = entropyLineMatchers.configAssign(line);
|
|
5188
5400
|
if (configAssign && isSecretVariableName(configAssign[1])) {
|
|
5189
5401
|
const value = dotenvValue(configAssign[2]);
|
|
5190
5402
|
if (value.length >= 20 && value.length <= MAX_DOTENV_VALUE) {
|
|
@@ -5197,7 +5409,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5197
5409
|
}
|
|
5198
5410
|
}
|
|
5199
5411
|
if (XML_CONFIG_RE.test(filePath)) {
|
|
5200
|
-
const xmlPair =
|
|
5412
|
+
const xmlPair = entropyLineMatchers.xmlAttr(line) || entropyLineMatchers.xmlElement(line);
|
|
5201
5413
|
if (xmlPair) {
|
|
5202
5414
|
const valueFirst = /^\s*<[^>]*\bvalue\s*=/i.test(line);
|
|
5203
5415
|
const variableName = valueFirst ? xmlPair[2] : xmlPair[1];
|
|
@@ -5289,7 +5501,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5289
5501
|
continue;
|
|
5290
5502
|
}
|
|
5291
5503
|
if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
|
|
5292
|
-
if (verificationMeta === void 0) verificationMeta =
|
|
5504
|
+
if (verificationMeta === void 0) verificationMeta = entropyLineMatchers.verificationMeta(line);
|
|
5293
5505
|
if (verificationMeta) continue;
|
|
5294
5506
|
if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
|
|
5295
5507
|
if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;
|
|
@@ -6316,8 +6528,183 @@ var CONFIG_CHECKS = [
|
|
|
6316
6528
|
}
|
|
6317
6529
|
return null;
|
|
6318
6530
|
}
|
|
6531
|
+
},
|
|
6532
|
+
{
|
|
6533
|
+
id: "CFG013",
|
|
6534
|
+
title: "PHP base image affected by CVE-2026-109618 and CVE-2026-109619",
|
|
6535
|
+
severity: "critical",
|
|
6536
|
+
category: "Dependencies",
|
|
6537
|
+
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",
|
|
6538
|
+
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.",
|
|
6539
|
+
owasp: "A06:2021",
|
|
6540
|
+
cwe: "CWE-1395",
|
|
6541
|
+
filePattern: /Dockerfile$/i,
|
|
6542
|
+
check(content) {
|
|
6543
|
+
const line = php2shellLines(content).cfg013Line;
|
|
6544
|
+
if (line === null) return null;
|
|
6545
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
6546
|
+
}
|
|
6547
|
+
},
|
|
6548
|
+
{
|
|
6549
|
+
id: "CFG014",
|
|
6550
|
+
title: "PHP base image (non-web variant) at a version affected by CVE-2026-109618 and CVE-2026-109619",
|
|
6551
|
+
severity: "info",
|
|
6552
|
+
category: "Dependencies",
|
|
6553
|
+
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",
|
|
6554
|
+
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.",
|
|
6555
|
+
owasp: "A06:2021",
|
|
6556
|
+
cwe: "CWE-1395",
|
|
6557
|
+
filePattern: /Dockerfile$/i,
|
|
6558
|
+
check(content) {
|
|
6559
|
+
const line = php2shellLines(content).cfg014Line;
|
|
6560
|
+
if (line === null) return null;
|
|
6561
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
6562
|
+
}
|
|
6319
6563
|
}
|
|
6320
6564
|
];
|
|
6565
|
+
var PHP2SHELL_LINE_LIMIT = 4096;
|
|
6566
|
+
var PHP2SHELL_FROM_CAP = 256;
|
|
6567
|
+
var PHP2SHELL_FROM_MARK = /^[ \t\uFEFF]{0,4096}FROM[ \t]/i;
|
|
6568
|
+
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;
|
|
6569
|
+
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;
|
|
6570
|
+
var PHP2SHELL_VAR = /\$(?:\{([A-Za-z_][A-Za-z0-9_]{0,63})\}|([A-Za-z_][A-Za-z0-9_]{0,63}))/g;
|
|
6571
|
+
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})?$/;
|
|
6572
|
+
var PHP2SHELL_TAG = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,3}))?(?:-([a-z0-9][a-z0-9.-]{0,63}))?$/;
|
|
6573
|
+
var PHP2SHELL_FIXED_PATCH = [
|
|
6574
|
+
[8, 2, 35],
|
|
6575
|
+
[8, 3, 36],
|
|
6576
|
+
[8, 4, 27],
|
|
6577
|
+
[8, 5, 12]
|
|
6578
|
+
];
|
|
6579
|
+
function php2shellDigits(value) {
|
|
6580
|
+
let n = 0;
|
|
6581
|
+
for (let i = 0; i < value.length; i++) n = n * 10 + (value.charCodeAt(i) - 48);
|
|
6582
|
+
return n;
|
|
6583
|
+
}
|
|
6584
|
+
function php2shellFixedPatch(major, minor) {
|
|
6585
|
+
for (let i = 0; i < PHP2SHELL_FIXED_PATCH.length; i++) {
|
|
6586
|
+
const row = PHP2SHELL_FIXED_PATCH[i];
|
|
6587
|
+
if (row[0] === major && row[1] === minor) return row[2];
|
|
6588
|
+
}
|
|
6589
|
+
return null;
|
|
6590
|
+
}
|
|
6591
|
+
function php2shellAffected(major, minor, patch) {
|
|
6592
|
+
if (major < 8) return true;
|
|
6593
|
+
if (major === 8 && minor !== null && minor <= 1) return true;
|
|
6594
|
+
if (minor === null || patch === null) return false;
|
|
6595
|
+
const fixed = php2shellFixedPatch(major, minor);
|
|
6596
|
+
return fixed !== null && patch < fixed;
|
|
6597
|
+
}
|
|
6598
|
+
function php2shellWebSapi(suffix) {
|
|
6599
|
+
if (!suffix) return false;
|
|
6600
|
+
let start = 0;
|
|
6601
|
+
for (let i = 0; i <= suffix.length; i++) {
|
|
6602
|
+
if (i === suffix.length || suffix.charCodeAt(i) === 45) {
|
|
6603
|
+
const token = suffix.slice(start, i);
|
|
6604
|
+
if (token === "apache" || token === "fpm") return true;
|
|
6605
|
+
start = i + 1;
|
|
6606
|
+
}
|
|
6607
|
+
}
|
|
6608
|
+
return false;
|
|
6609
|
+
}
|
|
6610
|
+
function php2shellComment(line) {
|
|
6611
|
+
let i = 0;
|
|
6612
|
+
while (i < line.length) {
|
|
6613
|
+
const c = line.charCodeAt(i);
|
|
6614
|
+
if (c !== 32 && c !== 9) break;
|
|
6615
|
+
i += 1;
|
|
6616
|
+
}
|
|
6617
|
+
return i < line.length && line.charCodeAt(i) === 35;
|
|
6618
|
+
}
|
|
6619
|
+
function php2shellNormalize(raw, index) {
|
|
6620
|
+
let line = raw;
|
|
6621
|
+
if (index === 0 && line.charCodeAt(0) === 65279) line = line.slice(1);
|
|
6622
|
+
if (line.length > 0 && line.charCodeAt(line.length - 1) === 13) line = line.slice(0, -1);
|
|
6623
|
+
return line;
|
|
6624
|
+
}
|
|
6625
|
+
function php2shellSubstitute(ref, args) {
|
|
6626
|
+
PHP2SHELL_VAR.lastIndex = 0;
|
|
6627
|
+
let unknown = false;
|
|
6628
|
+
const out = ref.replace(PHP2SHELL_VAR, (match, braced, bare) => {
|
|
6629
|
+
const name = braced ?? bare;
|
|
6630
|
+
const value = name ? args.get(name) : void 0;
|
|
6631
|
+
if (value === void 0) {
|
|
6632
|
+
unknown = true;
|
|
6633
|
+
return match;
|
|
6634
|
+
}
|
|
6635
|
+
return value;
|
|
6636
|
+
});
|
|
6637
|
+
if (unknown || out.includes("$")) return null;
|
|
6638
|
+
return out;
|
|
6639
|
+
}
|
|
6640
|
+
function php2shellLines(content) {
|
|
6641
|
+
const args = /* @__PURE__ */ new Map();
|
|
6642
|
+
const stages = /* @__PURE__ */ new Set();
|
|
6643
|
+
let seenFrom = false;
|
|
6644
|
+
let fromCount = 0;
|
|
6645
|
+
let capped = false;
|
|
6646
|
+
let cfg013Line = null;
|
|
6647
|
+
let lastLine = 0;
|
|
6648
|
+
let lastAffectedNonWeb = false;
|
|
6649
|
+
const lines = content.split("\n");
|
|
6650
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6651
|
+
const line = php2shellNormalize(lines[i] ?? "", i);
|
|
6652
|
+
if (line.length > PHP2SHELL_LINE_LIMIT) continue;
|
|
6653
|
+
if (php2shellComment(line)) continue;
|
|
6654
|
+
if (!seenFrom) {
|
|
6655
|
+
const arg = PHP2SHELL_ARG.exec(line);
|
|
6656
|
+
if (arg?.[1]) {
|
|
6657
|
+
const value = arg[2] ?? arg[3] ?? arg[4];
|
|
6658
|
+
if (value !== void 0) {
|
|
6659
|
+
args.set(arg[1], value);
|
|
6660
|
+
continue;
|
|
6661
|
+
}
|
|
6662
|
+
}
|
|
6663
|
+
}
|
|
6664
|
+
if (!PHP2SHELL_FROM_MARK.test(line)) continue;
|
|
6665
|
+
fromCount += 1;
|
|
6666
|
+
if (fromCount > PHP2SHELL_FROM_CAP) {
|
|
6667
|
+
capped = true;
|
|
6668
|
+
break;
|
|
6669
|
+
}
|
|
6670
|
+
seenFrom = true;
|
|
6671
|
+
const lineNo = i + 1;
|
|
6672
|
+
lastLine = lineNo;
|
|
6673
|
+
lastAffectedNonWeb = false;
|
|
6674
|
+
const from = PHP2SHELL_FROM.exec(line);
|
|
6675
|
+
const rawRef = from?.[1];
|
|
6676
|
+
if (!rawRef) continue;
|
|
6677
|
+
const ref = php2shellSubstitute(rawRef, args);
|
|
6678
|
+
if (ref === null) continue;
|
|
6679
|
+
const asName = from?.[2];
|
|
6680
|
+
const refLower = ref.toLowerCase();
|
|
6681
|
+
if (stages.has(refLower)) {
|
|
6682
|
+
if (asName) stages.add(asName.toLowerCase());
|
|
6683
|
+
continue;
|
|
6684
|
+
}
|
|
6685
|
+
if (asName) stages.add(asName.toLowerCase());
|
|
6686
|
+
if (ref === "scratch") continue;
|
|
6687
|
+
const image = PHP2SHELL_IMAGE.exec(ref);
|
|
6688
|
+
const tag = image?.[1];
|
|
6689
|
+
if (!image || tag === void 0 || tag === "latest") continue;
|
|
6690
|
+
const parsed = PHP2SHELL_TAG.exec(tag);
|
|
6691
|
+
const majorText = parsed?.[1];
|
|
6692
|
+
if (!parsed || majorText === void 0) continue;
|
|
6693
|
+
const major = php2shellDigits(majorText);
|
|
6694
|
+
const minor = parsed[2] !== void 0 ? php2shellDigits(parsed[2]) : null;
|
|
6695
|
+
const patch = parsed[3] !== void 0 ? php2shellDigits(parsed[3]) : null;
|
|
6696
|
+
if (!php2shellAffected(major, minor, patch)) continue;
|
|
6697
|
+
if (php2shellWebSapi(parsed[4])) {
|
|
6698
|
+
if (cfg013Line === null) cfg013Line = lineNo;
|
|
6699
|
+
} else {
|
|
6700
|
+
lastAffectedNonWeb = true;
|
|
6701
|
+
}
|
|
6702
|
+
}
|
|
6703
|
+
return {
|
|
6704
|
+
cfg013Line,
|
|
6705
|
+
cfg014Line: !capped && cfg013Line === null && lastAffectedNonWeb ? lastLine : null
|
|
6706
|
+
};
|
|
6707
|
+
}
|
|
6321
6708
|
function scanConfigs(files) {
|
|
6322
6709
|
const findings = [];
|
|
6323
6710
|
for (const { path: filePath, content } of files) {
|