989.index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. "use strict";
  2. exports.id = 989;
  3. exports.ids = [989];
  4. exports.modules = {
  5. /***/ 60959:
  6. /***/ ((__unused_webpack_module, exports) => {
  7. /**
  8. * The content of this file is generated by a tool.
  9. * Don't edit it manually!
  10. * */
  11. Object.defineProperty(exports, "__esModule", ({ value: true }));
  12. exports.vulnerableSignatures = void 0;
  13. exports.vulnerableSignatures = {
  14. IfBVtiwVRT8NeXCp2ZTKtw: {
  15. filename: 'JndiManager.class',
  16. versions: ['2.13.2', '2.13.1', '2.13.0', '2.13.3'],
  17. },
  18. CsWz5uabp3ZWg3mOZpowsg: {
  19. filename: 'log4j-core-2.13.2.jar',
  20. versions: ['2.13.2'],
  21. },
  22. '8MQ62soq/HHGzID4UbOIGA': {
  23. filename: 'log4j-core-2.4.1.jar',
  24. versions: ['2.4.1'],
  25. },
  26. RyyOH7qg5hUg4CXCVbXRaA: {
  27. filename: 'log4j-core-2.6.2.jar',
  28. versions: ['2.6.2'],
  29. },
  30. '7Q4xglxv2kNCP7ODV6QrPQ': {
  31. filename: 'MessagePatternConverter.class',
  32. versions: ['2.16.0'],
  33. },
  34. geBDOuAGAsDk0AQk0hOwqw: {
  35. filename: 'log4j-core-2.15.0.jar',
  36. versions: ['2.15.0'],
  37. },
  38. 'miPB9v/sgl70HMwQVBogkA': {
  39. filename: 'JndiManager.java',
  40. versions: ['2.8.2-sources', '2.8-sources', '2.7-sources', '2.8.1-sources'],
  41. },
  42. WCRxHWxoFi61NcxNv3SF0w: {
  43. filename: 'JndiManager.class',
  44. versions: ['2.12.1', '2.12.0'],
  45. },
  46. 'xtIzvI6c/l2mkAWdJ9n4jw': {
  47. filename: 'log4j-core-2.8.jar',
  48. versions: ['2.8'],
  49. },
  50. zH1V7WnMX9NANbFcbt95oA: {
  51. filename: 'log4j-core-2.13.3.jar',
  52. versions: ['2.13.3'],
  53. },
  54. 'EQqz4+TzeAkh6O5d3jNzrQ': {
  55. filename: 'log4j-core-2.3.jar',
  56. versions: ['2.3'],
  57. },
  58. 'VSPxRPrvK/ygijyosr7Nag': {
  59. filename: 'log4j-core-2.6.jar',
  60. versions: ['2.6'],
  61. },
  62. 'C1fpJhCjMxrxWn6Q+LNTnQ': {
  63. filename: 'Interpolator.class',
  64. versions: ['2.16.0'],
  65. },
  66. 'QVwT58hQX7BW1UDqwpty+g': {
  67. filename: 'JndiManager.class',
  68. versions: ['2.7', '2.8.1', '2.8'],
  69. },
  70. zXChiI7N0xHBmQ54SGfOHg: {
  71. filename: 'log4j-core-2.0.jar',
  72. versions: ['2.0'],
  73. },
  74. 'txoT/V3yUWlPyhFiQAA7Ig': {
  75. filename: 'log4j-core-2.13.0.jar',
  76. versions: ['2.13.0'],
  77. },
  78. VHuz7S3rhW0OO713wnuWJQ: {
  79. filename: 'log4j-core-2.8.1.jar',
  80. versions: ['2.8.1'],
  81. },
  82. SlF3oXJ2S9pvRHK5S6F8yw: {
  83. filename: 'log4j-core-2.8.2.jar',
  84. versions: ['2.8.2'],
  85. },
  86. ToAy4jACKoyI3X1SbwtnCw: {
  87. filename: 'JndiManager.java',
  88. versions: [
  89. '2.9.0-sources',
  90. '2.9.1-sources',
  91. '2.10.0-sources',
  92. '2.11.0-sources',
  93. '2.11.1-sources',
  94. ],
  95. },
  96. 'oZNwOQSj8Y+zyQqHfrXIpw': {
  97. filename: 'JndiManager.class',
  98. versions: ['2.8.2'],
  99. },
  100. '+/pfM6tLKab91SRz7nuDTQ': {
  101. filename: 'log4j-core-2.0.1.jar',
  102. versions: ['2.0.1'],
  103. },
  104. 'Kr7CzmZeDVKaPyj/+7st0w': {
  105. filename: 'log4j-core-2.11.0.jar',
  106. versions: ['2.11.0'],
  107. },
  108. 'AHnJByMGWZaPD8DkGmq8+Q': {
  109. filename: 'log4j-core-2.4.jar',
  110. versions: ['2.4'],
  111. },
  112. '3o0BzBX9DHT+qLu2aOKJ9Q': {
  113. filename: 'log4j-core-2.0-rc2.jar',
  114. versions: ['2.0-rc2.jar'],
  115. },
  116. 'siQt4Gd75lFdbO+/SOfl1Q': {
  117. filename: 'log4j-core-2.11.1.jar',
  118. versions: ['2.11.1'],
  119. },
  120. jTMVRLLnsgrRZt68olUNcw: {
  121. filename: 'log4j-core-2.1.jar',
  122. versions: ['2.1'],
  123. },
  124. '3Q4+C0BAg+xpYYqrtQuKwA': {
  125. filename: 'log4j-core-2.5.jar',
  126. versions: ['2.5'],
  127. },
  128. BP3XAYCdF0ZcF8fmA7GyAg: {
  129. filename: 'JndiManager.class',
  130. versions: ['2.11.1', '2.9.1', '2.11.0', '2.11.2', '2.10.0', '2.9.0'],
  131. },
  132. FS7LPOCUrFvJ6jnWEi4oFA: {
  133. filename: 'log4j-core-2.0-beta9.jar',
  134. versions: ['2.0-beta9.jar'],
  135. },
  136. 'SPfzzaUwMKh+jDh9jR5CZQ': {
  137. filename: 'log4j-core-2.6.1.jar',
  138. versions: ['2.6.1'],
  139. },
  140. 'axX0LDM6w5q6z+7rGIUqRA': {
  141. filename: 'JndiManager.class',
  142. versions: ['2.1', '2.2', '2.3'],
  143. },
  144. 'XkvKXtILlKsZu2WDbak/lg': {
  145. filename: 'log4j-core-2.2.jar',
  146. versions: ['2.2'],
  147. },
  148. lI3aeHWTNAp68aGOMot7fw: {
  149. filename: 'log4j-core-2.14.1.jar',
  150. versions: ['2.14.1'],
  151. },
  152. 'K2Pg5QY/2sz2aaHiY4Tz/Q': {
  153. filename: 'log4j-core-2.7.jar',
  154. versions: ['2.7'],
  155. },
  156. 'iyJgsczmQUT2MQh2+UsWOA': {
  157. filename: 'JndiManager.class',
  158. versions: ['2.4', '2.4.1', '2.5'],
  159. },
  160. 'CI3xE60kmrcr8Zt/ALhj1Q': {
  161. filename: 'log4j-core-2.0-rc1.jar',
  162. versions: ['2.0-rc1.jar'],
  163. },
  164. '3JkBHwR+Y9zHQbWraNEW2w': {
  165. filename: 'log4j-core-2.10.0.jar',
  166. versions: ['2.10.0'],
  167. },
  168. 'XFJ4IdEISn7z4D1AFE/1Mg': {
  169. filename: 'log4j-core-2.12.0.jar',
  170. versions: ['2.12.0'],
  171. },
  172. n0GSikGCAN4iMt0yblIsxw: {
  173. filename: 'log4j-core-2.16.0.jar',
  174. versions: ['2.16.0'],
  175. },
  176. 'XSU+U/qZPhIv8BIiGqSeww': {
  177. filename: 'JndiManager.class',
  178. versions: ['2.15.0'],
  179. },
  180. 'NbG1m0kl+RbQmdW4+7nykQ': {
  181. filename: 'JndiManager.java',
  182. versions: [
  183. '2.11.2-sources',
  184. '2.12.1-sources',
  185. '2.13.0-sources',
  186. '2.13.1-sources',
  187. '2.13.2-sources',
  188. '2.14.1-sources',
  189. '2.12.0-sources',
  190. '2.13.3-sources',
  191. '2.14.0-sources',
  192. ],
  193. },
  194. 'Kn94Du0/K5zJ8p4blmlGjw': {
  195. filename: 'JndiManager.java',
  196. versions: [
  197. '2.4-sources',
  198. '2.2-sources',
  199. '2.3-sources',
  200. '2.5-sources',
  201. '2.6.1-sources',
  202. '2.6.2-sources',
  203. '2.6-sources',
  204. '2.1-sources',
  205. '2.4.1-sources',
  206. ],
  207. },
  208. '02XkgiFBT5P+7wk6G/YH7w': {
  209. filename: 'log4j-core-2.13.1.jar',
  210. versions: ['2.13.1'],
  211. },
  212. '+rZGJX+UWwsqfOPhw+POXw': {
  213. filename: 'log4j-core-2.9.0.jar',
  214. versions: ['2.9.0'],
  215. },
  216. 'lC9Cnqy4AV4Y2PWZls++5g': {
  217. filename: 'log4j-core-2.9.1.jar',
  218. versions: ['2.9.1'],
  219. },
  220. 'yL2LXFqqoHo9y/V94BySZg': {
  221. filename: 'log4j-core-2.11.2.jar',
  222. versions: ['2.11.2'],
  223. },
  224. ATi6HBkdXHVP0OPDphwDBw: {
  225. filename: 'log4j-core-2.12.1.jar',
  226. versions: ['2.12.1'],
  227. },
  228. 'hiwAsuhU+cDx6NhAnSPYmQ': {
  229. filename: 'log4j-core-2.14.0.jar',
  230. versions: ['2.14.0'],
  231. },
  232. 'uhz4+B57MccJdoVhuoq1WA': {
  233. filename: 'JndiManager.class',
  234. versions: ['2.16.0'],
  235. },
  236. 'O9n0G4nOT+jMv3PkMZWlzg': {
  237. filename: 'JndiManager.class',
  238. versions: ['2.6.1', '2.6', '2.6.2'],
  239. },
  240. '8dYwxIkoCWpITkuVzLFioA': {
  241. filename: 'JndiManager.class',
  242. versions: ['2.14.0', '2.14.1'],
  243. },
  244. jAzz6wRxVKT44W2vWiCTGQ: {
  245. filename: 'log4j-core-2.0.2.jar',
  246. versions: ['2.0.2'],
  247. },
  248. };
  249. /***/ }),
  250. /***/ 86989:
  251. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  252. Object.defineProperty(exports, "__esModule", ({ value: true }));
  253. const fs_1 = __webpack_require__(35747);
  254. const crypto = __webpack_require__(76417);
  255. const AdmZip = __webpack_require__(55285);
  256. const ora = __webpack_require__(63395);
  257. const semver = __webpack_require__(36625);
  258. const log4shell_hashes_1 = __webpack_require__(60959);
  259. const readFile = fs_1.promises.readFile;
  260. const readDir = fs_1.promises.readdir;
  261. const stat = fs_1.promises.stat;
  262. const MAX_FILE_SIZE = 2 * 1024 * 1024 * 1024 - 1;
  263. class Paths {
  264. constructor(paths) {
  265. this.paths = paths;
  266. }
  267. static empty() {
  268. return new Paths([]);
  269. }
  270. static fromZip(content, path) {
  271. try {
  272. const unzippedEntries = new AdmZip(content).getEntries();
  273. const entries = unzippedEntries.map((entry) => {
  274. return {
  275. path: path + '/' + entry.entryName,
  276. content: async () => entry.getData(),
  277. };
  278. });
  279. return new Paths(entries);
  280. }
  281. catch (error) {
  282. errors.push(error);
  283. return this.empty();
  284. }
  285. }
  286. static async fromDisk(paths) {
  287. try {
  288. const entries = paths.map((path) => {
  289. return {
  290. path,
  291. content: async () => await readFile(path),
  292. };
  293. });
  294. return new Paths(entries);
  295. }
  296. catch (error) {
  297. errors.push(error);
  298. return this.empty();
  299. }
  300. }
  301. }
  302. const errors = [];
  303. async function startSpinner() {
  304. const spinner = ora({ isSilent: false, stream: process.stdout });
  305. spinner.text = `Looking for Log4Shell...`;
  306. spinner.start();
  307. return spinner;
  308. }
  309. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  310. async function log4shell(...args) {
  311. console.log('Please note this command is for already built artifacts. To test source code please use `snyk test`.');
  312. const signatures = new Array();
  313. const spinner = await startSpinner();
  314. const paths = await find('.');
  315. await parsePaths(await Paths.fromDisk(paths), signatures);
  316. spinner.stop();
  317. console.log('\nResults:');
  318. const issues = filterJndi(signatures);
  319. if (issues.length == 0) {
  320. console.log('No known vulnerable version of Log4J was detected');
  321. return;
  322. }
  323. const rceIssues = [];
  324. const dosIssues = [];
  325. issues.forEach((issue) => {
  326. issue.path = issue.path.replace(/(.*org\/apache\/logging\/log4j\/core).*/, '$1');
  327. if (issue.exploitType === 'Log4Shell') {
  328. rceIssues.push(issue);
  329. }
  330. if (issue.exploitType === 'DoS') {
  331. dosIssues.push(issue);
  332. }
  333. });
  334. if (rceIssues.length > 0) {
  335. displayIssues('A version of Log4J that is vulnerable to Log4Shell was detected:', rceIssues);
  336. displayRemediation('Log4Shell');
  337. }
  338. if (dosIssues.length > 0) {
  339. displayIssues('A version of Log4J that is vulnerable to CVE-2021-45105 (Denial of Service) was detected:', dosIssues);
  340. displayRemediation('DoS');
  341. }
  342. exitWithError();
  343. }
  344. exports.default = log4shell;
  345. async function parsePaths(ctx, accumulator) {
  346. for (const { path, content } of ctx.paths) {
  347. if (!isArchiveOrJndi(path)) {
  348. continue;
  349. }
  350. const signature = await computeSignature(await content());
  351. const isVulnerable = signature in log4shell_hashes_1.vulnerableSignatures;
  352. if (isVulnerable || path.includes('JndiLookup')) {
  353. await append(path, signature, accumulator);
  354. continue;
  355. }
  356. if (!isVulnerable && isJavaArchive(path)) {
  357. await parsePaths(Paths.fromZip(await content(), path), accumulator);
  358. }
  359. }
  360. }
  361. async function computeSignature(content) {
  362. return crypto
  363. .createHash('md5')
  364. .update(content)
  365. .digest('base64')
  366. .replace(/=/g, '');
  367. }
  368. async function find(path) {
  369. const result = [];
  370. await traverse(path, (filePath, stats) => {
  371. if (!stats.isFile() || stats.size > MAX_FILE_SIZE) {
  372. return;
  373. }
  374. result.push(filePath);
  375. });
  376. return result;
  377. }
  378. async function traverse(path, handle) {
  379. try {
  380. const stats = await stat(path);
  381. if (!stats.isDirectory()) {
  382. handle(path, stats);
  383. return;
  384. }
  385. const entries = await readDir(path);
  386. for (const entry of entries) {
  387. const absolute = path + '/' + entry;
  388. await traverse(absolute, handle);
  389. }
  390. }
  391. catch (error) {
  392. errors.push(error);
  393. }
  394. }
  395. async function computeExploitType(signatureDetails) {
  396. for (const version of signatureDetails.versions) {
  397. const coercedVersion = semver.coerce(version);
  398. if (coercedVersion === null) {
  399. continue;
  400. }
  401. if (semver.lt(coercedVersion, '2.16.0')) {
  402. return 'Log4Shell';
  403. }
  404. if (semver.satisfies(coercedVersion, '2.16.x')) {
  405. return 'DoS';
  406. }
  407. }
  408. return 'Unknown';
  409. }
  410. function displayIssues(message, signatures) {
  411. console.log(message);
  412. signatures.forEach((signature) => {
  413. console.log(`\t${signature.path}`);
  414. });
  415. }
  416. function displayRemediation(exploitType) {
  417. switch (exploitType) {
  418. case 'Log4Shell':
  419. console.log(`\nWe highly recommend fixing this vulnerability. If it cannot be fixed by upgrading, see mitigation information here:
  420. \t- https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720
  421. \t- https://snyk.io/blog/log4shell-remediation-cheat-sheet/\n`);
  422. break;
  423. case 'DoS':
  424. console.log(`\nWe recommend fixing this vulnerability by upgrading to a later version. To learn more about this vulnerability, see:
  425. \t- https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2321524\n`);
  426. break;
  427. default:
  428. break;
  429. }
  430. }
  431. function isJavaArchive(path) {
  432. return path.endsWith('.jar') || path.endsWith('.war') || path.endsWith('ear');
  433. }
  434. function isArchiveOrJndi(path) {
  435. return (isJavaArchive(path) ||
  436. path.includes('JndiManager') ||
  437. path.includes('JndiLookup'));
  438. }
  439. async function append(path, signature, accumulator) {
  440. const exploitType = log4shell_hashes_1.vulnerableSignatures[signature]
  441. ? await computeExploitType(log4shell_hashes_1.vulnerableSignatures[signature])
  442. : 'Unknown';
  443. accumulator.push({
  444. value: signature,
  445. path,
  446. exploitType,
  447. });
  448. }
  449. function filterJndi(signatures) {
  450. return signatures.filter((signature) => {
  451. if (isJavaArchive(signature.path)) {
  452. return true;
  453. }
  454. if (signature.path.includes('JndiManager')) {
  455. const jndiManagerPathIndex = signature.path.indexOf('/net/JndiManager.class');
  456. const jndiLookupPath = signature.path.substr(0, jndiManagerPathIndex) + '/lookup/JndiLookup';
  457. const isJndiLookupPresent = signatures.find((element) => element.path.includes(jndiLookupPath));
  458. return !!isJndiLookupPresent;
  459. }
  460. return false;
  461. });
  462. }
  463. function exitWithError() {
  464. const err = new Error();
  465. err.code = 'VULNS';
  466. throw err;
  467. }
  468. /***/ })
  469. };
  470. ;
  471. //# sourceMappingURL=989.index.js.map