obfuscation-detector
Advanced tools
Comparing version 1.1.7 to 2.0.0
#!/usr/bin/env node | ||
const fs = require('node:fs'); | ||
const detectObfuscation = require(__dirname + '/../src'); | ||
import fs from 'node:fs'; | ||
import {fileURLToPath} from 'node:url'; | ||
import {detectObfuscation} from './../src/index.js'; | ||
if (require.main === module) { | ||
if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
try { | ||
@@ -7,0 +8,0 @@ const args = process.argv.slice(2); |
{ | ||
"name": "obfuscation-detector", | ||
"version": "1.1.7", | ||
"version": "2.0.0", | ||
"description": "Javascript obfuscation detector", | ||
"main": "src/index.js", | ||
"type": "module", | ||
"directories": { | ||
"prepare": "husky install", | ||
"prepare": "husky", | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"test": "node tests/testDetectors.js" | ||
"lint": "eslint .", | ||
"test": "node --test", | ||
"test:coverage": "node --trace-warnings --test --experimental-test-coverage" | ||
}, | ||
@@ -27,3 +30,3 @@ "bin": { | ||
], | ||
"author": "ben.baryo@perimeterx.com", | ||
"author": "Ben Baryo (ben.baryo@humansecurity.com)", | ||
"license": "MIT", | ||
@@ -35,8 +38,8 @@ "bugs": { | ||
"devDependencies": { | ||
"eslint": "^8.49.0", | ||
"husky": "^8.0.1" | ||
"eslint": "^9.12.0", | ||
"husky": "^9.1.6" | ||
}, | ||
"dependencies": { | ||
"flast": "^1.6.0" | ||
"flast": "^2.0.0" | ||
} | ||
} |
@@ -13,8 +13,8 @@ # Obfuscation Detector | ||
```javascript | ||
const fs = require('fs'); | ||
const detectObfuscation = require('obfuscation-detector'); | ||
import fs from 'node:fs'; | ||
import detectObfuscation from 'obfuscation-detector'; | ||
const code = fs.readFileSync('obfuscated.js', 'utf-8'); | ||
const most_likely_obfuscation_type = detectObfuscation(code); | ||
// const all_matching_obfuscation_types = detectObfuscation(code, false); | ||
const most_likely_obfuscation_type = detectObfuscation(code); | ||
console.log(`Obfuscation type is probably ${most_likely_obfuscation_type}`); | ||
@@ -21,0 +21,0 @@ ``` |
@@ -1,5 +0,2 @@ | ||
const { | ||
findArrayDeclarationCandidates, | ||
functionHasMinimumRequiredReferences, | ||
} = require(__dirname + '/sharedDetectionMethods'); | ||
import {findArrayDeclarationCandidates, functionHasMinimumRequiredReferences} from './sharedDetectionMethods.js'; | ||
@@ -31,2 +28,2 @@ const obfuscationName = 'array_function_replacements'; | ||
module.exports = detectArrayFunctionReplacements; | ||
export {detectArrayFunctionReplacements}; |
@@ -1,5 +0,2 @@ | ||
const { | ||
arrayHasMinimumRequiredReferences, | ||
findArrayDeclarationCandidates, | ||
} = require(__dirname + '/sharedDetectionMethods'); | ||
import {arrayHasMinimumRequiredReferences, findArrayDeclarationCandidates} from './sharedDetectionMethods.js'; | ||
@@ -26,2 +23,2 @@ const obfuscationName = 'array_replacements'; | ||
module.exports = detectArrayReplacements; | ||
export {detectArrayReplacements}; |
@@ -1,6 +0,2 @@ | ||
const { | ||
arrayIsProvidedAsArgumentToIIFE, | ||
findArrayDeclarationCandidates, | ||
functionHasMinimumRequiredReferences, | ||
} = require(__dirname + '/sharedDetectionMethods'); | ||
import {arrayIsProvidedAsArgumentToIIFE, findArrayDeclarationCandidates, functionHasMinimumRequiredReferences} from './sharedDetectionMethods.js'; | ||
@@ -30,2 +26,2 @@ const obfuscationName = 'augmented_array_function_replacements'; | ||
module.exports = detectAugmentedArrayFunctionReplacements; | ||
export {detectAugmentedArrayFunctionReplacements}; |
@@ -1,6 +0,2 @@ | ||
const { | ||
arrayHasMinimumRequiredReferences, | ||
arrayIsProvidedAsArgumentToIIFE, | ||
findArrayDeclarationCandidates, | ||
} = require(__dirname + '/sharedDetectionMethods'); | ||
import {arrayHasMinimumRequiredReferences, arrayIsProvidedAsArgumentToIIFE, findArrayDeclarationCandidates} from './sharedDetectionMethods.js'; | ||
@@ -28,2 +24,2 @@ const obfuscationName = 'augmented_array_replacements'; | ||
module.exports = detectAugmentedArrayReplacements; | ||
export {detectAugmentedArrayReplacements}; |
@@ -41,2 +41,2 @@ const obfuscationName = 'augmented_proxied_array_function_replacements'; | ||
module.exports = detectAugmentedProxiedArrayFunctionReplacements; | ||
export {detectAugmentedProxiedArrayFunctionReplacements}; |
@@ -54,2 +54,2 @@ const obfuscationName = 'caesar_plus'; | ||
module.exports = detectCaesarPlus; | ||
export {detectCaesarPlus}; |
@@ -21,2 +21,2 @@ const obfuscationName = 'function_to_array_replacements'; | ||
module.exports = detectFunctionToArrayReplacemets; | ||
export {detectFunctionToArrayReplacemets}; |
@@ -56,2 +56,2 @@ const obfuscationName = 'obfuscator.io'; | ||
module.exports = detectObfuscatorIo; | ||
export {detectObfuscatorIo}; |
@@ -77,3 +77,3 @@ /** | ||
module.exports = { | ||
export { | ||
arrayHasMinimumRequiredReferences, | ||
@@ -80,0 +80,0 @@ arrayIsProvidedAsArgumentToIIFE, |
@@ -1,16 +0,5 @@ | ||
const {generateFlatAST} = require('flast'); | ||
import {generateFlatAST, utils} from 'flast'; | ||
import * as detectors from './detectors/index.js'; | ||
const {logger} = utils; | ||
const availableDetectors = []; | ||
// Lazily import available detectors | ||
[ | ||
'arrayReplacements', | ||
'functionToArrayReplacements', | ||
'augmentedArrayReplacements', | ||
'arrayFunctionReplacements', | ||
'augmentedArrayFunctionReplacements', | ||
'obfuscator-io', | ||
'caesarp', | ||
'augmentedProxiedArrayFunctionReplacements', | ||
].forEach(detName => availableDetectors.push(__dirname + `/detectors/${detName}`)); | ||
/** | ||
@@ -26,6 +15,5 @@ * @param {string} code | ||
const tree = generateFlatAST(code); | ||
for (let i = 0; i < availableDetectors.length; i++) { | ||
const detector = require(availableDetectors[i]); | ||
for (const detectorName in detectors) { | ||
try { | ||
const detectionType = detector(tree, detectedObfuscations); | ||
const detectionType = detectors[detectorName](tree, detectedObfuscations); | ||
if (detectionType) { | ||
@@ -36,7 +24,7 @@ detectedObfuscations.push(detectionType); | ||
} catch (e) { | ||
// console.log(`Error while running ${detector?.name}: ${e.message}`); // Keep for debugging | ||
logger.debug(`Error while running ${detectorName}: ${e.message}`); // Keep for debugging | ||
} | ||
} | ||
} catch (e) { | ||
// console.log(e.message); // Keep for debugging | ||
logger.debug(e.message); // Keep for debugging | ||
} | ||
@@ -46,2 +34,2 @@ return detectedObfuscations; | ||
module.exports = detectObfuscation; | ||
export {detectObfuscation}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
922362
30
0
Yes
16165
+ Added@javascript-obfuscator/escodegen@2.3.0(transitive)
+ Added@javascript-obfuscator/estraverse@5.4.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedflast@2.1.0(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
- Removedescodegen@2.1.0(transitive)
- Removedflast@1.7.1(transitive)
Updatedflast@^2.0.0