Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deobfuscator for javascript samples obfuscated by obfuscator.io.

License

NotificationsYou must be signed in to change notification settings

0x1Avram/js-deobfuscator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deobfuscator forTimofey Kachalov'sjavascript-obfuscator - also available atobfuscator.io.

⚠️ !!! WARNING !!!

The code here is not secure. It uses 'eval' for convenience purposes and could easily be exploited by someone with malicious intent. That is why this should only be used in secure and isolated environments. Under no circumstances should anyone run this on a real environment - at least, use a virtual machine or something to protect your system !!!

Setup

  1. Clone this project:
git clone https://github.com/0x1Avram/js-deobfuscator.git
  1. Install node.js (I used version 16.15)
  2. Install dependencies by running this command in the folder root:
npm install
  1. Enjoy

Binaries

I included binaries built for Windows/Linux in the release section (for the windows one, you will need to add the proper '.exe' extension in order to use it). Those binaries where built using pkg and can be run on a system standalone, without the need to install node.js or any other dependencies.Their respective SHA256 hashes can be found in the release section as well.

For those wanting to build this into an executable themselves, installpkg and then run this command in the folder root

pkg index.js

Examples

To showcase the deobfuscator capabilities, I included some sets of original + obfuscated + deobfuscated samples in the 'Examples' folder.Some of those use examples fromjavascript-obfuscator orjavascript-algorithms.Here are their respective copyright licenses:

javascript-obfuscator

Copyright (C) 2016-2022 Timofey Kachalov.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

javascript-algorithms

The MIT License (MIT)Copyright (c) 2018 Oleksii TrekhlebPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

Usage

The "main" script is index.js. Calling it with a '-h' argument should display the command line options.The deobfuscator tries to automatically detect the stringarray related code. If it manages to do so correctly, it can be run by just specifying the input and output path.

node ./index.js -i obfuscated.txt -o deobfuscated.txt

Otherwise, the code for the stringarray needs to be placed in separate files and given as input. Example:

node ./index.js -s stringarray.txt -w stringarraywrappers.txt -n _0x471d,_0x9cad,_0x4cd9 -r stringarrayrotate.txt -i obfuscated.txt -o output.txt

More examples regarding how the stringarray related code looks like along with command lines can be found in the 'Examples' folder.

Detailed information about the command line options:

node .\index.js -hUsage: program [options]Options:      --version                  Show version number                   [boolean]  -i, --inputPath                Path of input (obfuscated) file.                                                 [string] [default: "input.txt"]  -o, --outputPath               Path where the output (deobfuscated) file is                                 stored.        [string] [default: "output.txt"]  -d, --debug                    Display debug log messages (for large input                                 files, debug log might be large).                                                      [boolean] [default: false]  -a, --debugall                 Display all AST operations for debugging. The                                 'debug' option needs to be set for this to                                 work.                [boolean] [default: false]  -l, --separateloggers          Use a separate logger for each deobfuscation                                 stage. This will lead to the creation of a                                 debug log file for each deobfuscation stage (11                                 stages). This is useful so that instead of a                                 single huge debug log file, several smaller                                 ones are created (one per each stage). The                                 'debug' option needs to be set for this to                                 work.                [boolean] [default: false]  -f, --writedifffiles           Write before&after files for each                                 transformation modifying the source code(used                                 for debugging). The files are written in the                                 working directory of the script.                                                      [boolean] [default: false]  -s, --stringarray              [StringArray] The path at which the code for                                 the string array is found(can be just an array                                 or a function containing the array).                                                          [string] [default: ""]  -w, --stringarraywrappers      [StringArray] The path at which the code for                                 the string wrappers is found(there can be                                 multiple wrappers depending on the                                 'string-array-encoding' obfuscation option)                                 (the wrappers can contain the self defending                                 code).                   [string] [default: ""]  -n, --stringarraywrappernames  [StringArray] The names of the string array                                 wrapper functions in a comma separated string                                 without spaces. (these are the functions from                                 the code indicated by the 'stringarraywrappers'                                 path).                   [string] [default: ""]  -r, --stringarrayrotate                                 [string] [default: ""]  -c, --cleanuplog                                    [boolean] [default: false]  -h, --help                     Show help                             [boolean]Examples:  -s stringarray.txt -w stringarraywrappers.txt -n _0x471d,_0x9cad,_0x4cd9 -r  stringarrayrotate.txt -i obfuscated.txt -o output.txt  -i obfuscated.txt -o deobfuscated.txt

Notes

From my testing, this seems to work fine with current versions of the obfuscator.However, older versions of the obfuscator may output a different AST and that might complicate things. If you happen to stumble across a case where this should work but it doesn't, open an issue and I'll look into it.

There are some scenarios where the deobfuscator might crash because an AST cannot be generated from the input. This is a limitation from the esprima parser used by the deobfuscator which does not support all new JavaScript features. If this error is encountered, a message suggesting that the code needs to be transpiled before deobfuscation will be displayed. The transpilation to an older JavaScript version for which esprima correctly parses the script can be done usingBabel and the parsing of the script can be checked with tools such asastexplorer.

Easy transpilation with babel:

  1. Create directory with the file you are trying to deobfuscate inside directory
  2. Initialize node project with default configuration:
npm init -y
  1. Install babel:
npm install --save-dev @babel/core @babel/cli @babel/preset-env
  1. Create '.babelrc' file inside directory with the following content
{  "presets": ["@babel/preset-env"],  "compact": false}
  1. Run babel via CLI for transpilation

Example for transpiling 'a.txt' file to 'output.js' file. ('a.txt' is the input file, not parsed by espirma; 'output.js' is the output file, successfully parsed by esprima):

npx babel a.txt -o output.js

License

The MIT License (MIT)

Copyright (c) 20220x1Avram

Permission is hereby granted, free of charge, to any person obtaining a copy of thissoftware and associated documentation files (the "Software"), to deal in the Softwarewithout restriction, including without limitation the rights to use, copy, modify,merge, publish, distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject to the followingconditions:

The above copyright notice and this permission notice shall be included in all copiesor substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR APARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


[8]ページ先頭

©2009-2025 Movatter.jp