Coder Social home page Coder Social logo

node-bash-obfuscate's Introduction

node-bash-obfuscate

npm npm

A Node.js CLI tool and library to heavily obfuscate bash scripts.

Installation

$ npm install -g bash-obfuscate
$ bash-obfuscate script.sh -o output.sh

Usage

Usage: bash-obfuscate <inputFilename> [options]

Options:
  -o, --out                       Output file
  -c, --chunk-size, --chunk-size  Chunk size (for variables in obfuscated code)
                                                                    [default: 4]
  -r, --randomize                 Randomize variable order
                                                       [boolean] [default: true]

Example

Input

#!/usr/bin/env bash

USR_VAR='I like Node.js!'

echo $USR_VAR
for (( i = 0; i < 10; i++ )); do
    echo $i
done
echo "It works!"

Output

z="
";Hz='echo';Gz=''\''';Lz='for ';Qz='; i+';Ez='Node';Cz=''\''I l';Uz='done';Jz='R_VA';Az='USR_';Fz='.js!';Nz=' = 0';Bz='VAR=';Kz='R';Rz='+ ))';Wz=' wor';Iz=' $US';Vz=' "It';Oz='; i ';Sz='; do';Mz='(( i';Tz=' $i';Xz='ks!"';Pz='< 10';Dz='ike ';
eval "$Az$Bz$Cz$Dz$Ez$Fz$Gz$z$Hz$Iz$Jz$Kz$z$Lz$Mz$Nz$Oz$Pz$Qz$Rz$Sz$z$Hz$Tz$z$Uz$z$Hz$Vz$Wz$Xz"

FAQ

How does it work?

This tool divides the bash script into chunks (size specified by the -c flag). It then assigns a variable name to each chunk (with the same variable name for identical chunks) and replaces the original script with variable references, essentially scrambling the original script.

How do I deobfuscate a script?

Although this does not provide a method of automatically deobfuscating a script, it can be fairly easily done manually. To deobfuscate a bash script, you just have to have the script print out the contents of the deobfuscated script instead of having the script execute it.

No detailed instructions will be provided because the exact details will vary as new obfuscation stages are added to the script.

What's the point? I can deobfuscate it so easily...

The idea is not to provide absolute or even robust protection for your code against someone with a good understanding of bash. Its main purpose is to discourage tampering from someone with little/no understanding of bash.

The main problem with bash obfuscation is that the code can always be printed out when it is about to be executed, which is also when the code is deobfuscated.

node-bash-obfuscate's People

Contributors

willshiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-bash-obfuscate's Issues

Don't work at all

birkhoff at Birkhoff-MBPR in ~/dev/tesasd
$ bash-obfuscate
env: node\r: No such file or directory
$ bash-obfuscate 123.sh -o 321.sh
env: node\r: No such file or directory

slightly better obfs

not sure how much better this is but if you change the ouput from eval to heredoc it doesn't spit out the whole script during tracing at least on first approach, like this:

set +x ### I am annoyng
z="varsblabla"
exec bash <<< "$varsblabla"

Add ability to base64-encode strings

The obfuscator should allow users to further obfuscate their scripts by base64 encoding each chunk. This has the effect of making each chunk less human-readable.

Chunk replace should move before this line

if(chunk in table) return '$' + table[chunk];

In case single quote exist in chunk, original chunk will be changed. Table mapping is based changed chunk content. While in beginning, still use original chunk to check if chunk already exist in table.
Eg. Chunk is ', after replace, chunk is ''. In mapping table, id = ''. In case next chunk still is ', it can't be found in table and will be mapping to another id, original id will lost.
Solution is move line 51 before line 49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.