Skip to content

Commit

Permalink
Add CLI Support (#8)
Browse files Browse the repository at this point in the history
* Add simple CLI support

* Update eslint

* 1.1.5
  • Loading branch information
BenBaryoPX committed Aug 1, 2023
1 parent bca267a commit f655457
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 43 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Detect different types of JS obfuscation by their AST structure.
`npm install obfuscation-detector`

## Usage
### Module
```javascript
const fs = require('fs');
const detectObfuscation = require('obfuscation-detector');
Expand All @@ -18,6 +19,19 @@ const most_likely_obfuscation_type = detectObfuscation(code);
console.log(`Obfuscation type is probably ${most_likely_obfuscation_type}`);
```

### CLI
> obfuscation-detector /path/to/obfuscated.js [stopAfterFirst]
Getting all matching obfuscation types for a file:
> $ obfuscation-detector /path/to/obfuscated.js
> [+] function_to_array_replacements, augmented_proxied_array_function_replacements
Getting just the first match:
> $ obfuscation-detector /path/to/obfuscated.js stop
> [+] function_to_array_replacements
The `stopAfterFirst` arguments doesn't have to be any specific string, it just needs not to be empty.

## Supported Obfuscation Types
You can find descriptions of the different types in the code itself, and more info [here](src/detectors/README.md).
- [Array Replacements](src/detectors/arrayReplacements.js)
Expand Down
18 changes: 18 additions & 0 deletions bin/obfuscation-detector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
const fs = require('node:fs');
const detectObfuscation = require(__dirname + '/../src');

if (require.main === module) {
try {
const args = process.argv.slice(2);
if (args.length) {
let content = fs.readFileSync(args[0], 'utf-8');
const stopAfterFirst = !!args[1];
const obfuscationType = detectObfuscation(content, stopAfterFirst);
if (obfuscationType.length) console.log('[+] ' + obfuscationType.join(', '));
else console.log('[-] No obfuscation detected / unknown obfuscation');
} else console.log('Usage: obfuscation-detector /path/to/obfuscated.js [stopAfterFirst]');
} catch (e) {
console.error(`[X] Critical Error: ${e.message}`);
}
}
92 changes: 51 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obfuscation-detector",
"version": "1.1.4",
"version": "1.1.5",
"description": "Javascript obfuscation detector",
"main": "src/index.js",
"directories": {
Expand All @@ -10,6 +10,9 @@
"scripts": {
"test": "node tests/testDetectors.js"
},
"bin": {
"obfuscation-detector": "./bin/obfuscation-detector.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/PerimeterX/obfuscation-detector.git"
Expand All @@ -28,7 +31,7 @@
},
"homepage": "https://github.com/PerimeterX/obfuscation-detector#readme",
"devDependencies": {
"eslint": "^8.43.0",
"eslint": "^8.45.0",
"husky": "^8.0.1"
},
"dependencies": {
Expand Down

0 comments on commit f655457

Please sign in to comment.