Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

obfuscation-detector

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obfuscation-detector - npm Package Compare versions

Comparing version 1.1.7 to 2.0.0

eslint.config.js

7

bin/obfuscation-detector.js
#!/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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc