• Stars
    star
    309
  • Rank 135,306 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Javascript Deobfuscator

Restringer

Node.js CI Downloads

Deobfuscate Javascript and reconstruct strings. Simplify cumbersome logic where possible while adhering to scope limitations.

Try it online @ restringer.tech.

For comments and suggestions feel free to open an issue or find me on Twitter - @ctrl__esc

Table of Contents


Installation

npm

npm install restringer

Clone The Repo

Requires Node 16 or newer.

git clone [email protected]:PerimeterX/restringer.git
cd restringer
npm install

Usage

The restringer.js uses generic deobfuscation methods that reconstruct and restore obfuscated strings and simplifies redundant logic meant only to encumber. REstringer employs the Obfuscation Detector to identify specific types of obfuscation for which there's a need to apply specific deobfuscation methods in order to circumvent anti-debugging mechanisms or other code traps preventing the script from being deobfuscated.

Command-Line Usage

Usage: restringer input_filename [-h] [-c] [-q | -v] [-m M] [-o [output_filename]]

positional arguments:
	input_filename                  The obfuscated JS file

optional arguments:
	-h, --help                      Show this help message and exit.
	-c, --clean                     Remove dead nodes from script after deobfuscation is complete (unsafe).
	-q, --quiet                     Suppress output to stdout. Output result only to stdout if the -o option is not set.
																	Does not go with the -v option.
	-m, --max-iterations M          Run at most M iterations
	-v, --verbose                   Show more debug messages while deobfuscating. Does not go with the -q option.
	-o, --output [output_filename]  Write deobfuscated script to output_filename. 
																	Use <input_filename>-deob.js if no filename is provided.

Use as a Module

const {REstringer} = require('restringer');

const restringer = new REstringer('"RE" + "stringer"');
if (restringer.deobfuscate()) {
  console.log(restringer.script);
} else {
  console.log('Nothing was deobfuscated :/');
}
// Output: 'REstringer';

Create Custom Deobfuscators

REstringer is highly modularized. It exposes modules that allow creating custom deobfuscators that can solve specific problems.

The basic structure of such a deobfuscator would be an array of deobfuscation modules (either safe or unsafe), run via the runLoop util function.

Unsafe modules run code through eval (using vm2 to be on the safe side) while safe modules do not.

const {
  safe: {normalizeComputed},
  unsafe: {resolveDefiniteBinaryExpressions, resolveLocalCalls}
} = require('restringer').modules;
let script = 'obfuscated JS here';
const deobModules = [
  resolveDefiniteBinaryExpressions,
  resolveLocalCalls,
  normalizeComputed,
];
script = runLoop(script, deobModules);
console.log(script); // Deobfuscated script

With the additional candidateFilter function argument, it's possible to narrow down the targeted nodes:

const {unsafe: {resolveLocalCalls}} = require('restringer').modules;
let script = 'obfuscated JS here';

// It's better to define a function with a name that can show up in the log (otherwise you'll get 'undefined')
function resolveLocalCallsInGlobalScope(arb) {
  return resolveLocalCalls(arb, n => n.parentNode?.type === 'Program');
}
script = runLoop(script, [resolveLocalCallsInGlobalScope]);
console.log(script); // Deobfuscated script

Read More

More Repositories

1

marshmallow

Marshmallow provides a flexible and performant JSON unmarshalling in Go. It specializes in dealing with unstructured struct - when some fields are known and some aren't, with zero performance overhead nor extra coding needed.
Go
372
star
2

go-project-structure

149
star
3

obfuscation-detector

Detect different types of JS obfuscation by their AST structure
JavaScript
50
star
4

perimeterx-nginx-plugin

PerimeterX NGINX Lua Middleware
Lua
42
star
5

CVE-2020-6519

JavaScript
26
star
6

ok-lets-go

Three Approaches to Structuring Go Code
Go
25
star
7

perimeterx-node-express

PerimeterX Express.js middleware to monitor and block traffic according to PerimeterX risk score
JavaScript
25
star
8

bot-tools

HTML
22
star
9

map-events

events mapped out completely cross browsers
JavaScript
20
star
10

flast

Provides a flat Abstract Syntax Tree and an Arborist to trim and modify the tree
JavaScript
19
star
11

px-iOS-Framework

HUMAN iOS framework
Objective-C
17
star
12

perimeterx-java-sdk

PerimeterX JAVA SDK
Java
16
star
13

perimeterx-php-sdk

PerimeterX PHP SDK
PHP
16
star
14

perimeterx-python-wsgi

PerimeterX WSGI Middleware
Python
15
star
15

gitapp_alert_on_public

A service for finding and alerting on newly created public repositories for GitHub users who are part of a GitHub organization.
Python
14
star
16

CVE-2019-18426

10
star
17

node-http2-server-push

HTML
8
star
18

perimeterx-kong-plugin

PerimeterX Kong plugin
Lua
7
star
19

web-security-analysis-toolkit-workshop

Sample code and examples for the Web Security Analysis Toolkit workshop.
6
star
20

rpc-protocol-benchmark

Go
5
star
21

perimeterx-node-core

JavaScript
5
star
22

perimeterx-asp-net

C#
4
star
23

perimeterx-abr-samples

Samples for the Advanced Blocking Response feature
HTML
4
star
24

map-events-website

a website for https://github.com/perimeterx/event-handlers project
JavaScript
3
star
25

perimeterx-public-devtools

JavaScript
3
star
26

envite

A framework to manage development and testing environments
Go
3
star
27

px-mobile-sdk-demo-app

PerimeterX Mobile SDK - Demo App
C++
2
star
28

perimeterx-ruby-sdk

perimeterx ruby sdk
Ruby
2
star
29

Data-Defender

A tool to help organizations improve efficiency and saving cost of BigQuery data
Python
2
star
30

perimeterx-python-3-wsgi

PerimeterX WSGI Middleware for Python 3
Python
2
star
31

eslint-config-perimeterx

JavaScript
1
star
32

ip-clipboard

macOS Automator workflow to copy your external ip address to clipboard
1
star