All Projects → jwillbold → rusty-jsyc

jwillbold / rusty-jsyc

Licence: LGPL-3.0 license
JavaScript-To-Bytecode compiler written in Rust

Programming Languages

rust
11053 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to rusty-jsyc

bpre
bot protection reverse engineering
Stars: ✭ 181 (+66.06%)
Mutual labels:  obfuscation
Berserker
Obfuscate your Python scripts better, faster.
Stars: ✭ 81 (-25.69%)
Mutual labels:  obfuscation
nand nor
C++ Compile time NAND/NOR obfuscation
Stars: ✭ 32 (-70.64%)
Mutual labels:  obfuscation
ColonialObfuscator
Java Obfuscator in Beta
Stars: ✭ 23 (-78.9%)
Mutual labels:  obfuscation
code-obfuscation
一款iOS代码混淆工具(A code obfuscation tool for iOS.)
Stars: ✭ 32 (-70.64%)
Mutual labels:  obfuscation
folm
Folm
Stars: ✭ 16 (-85.32%)
Mutual labels:  obfuscation
PPiOS-Rename
Symbol obfuscator for iOS apps
Stars: ✭ 350 (+221.1%)
Mutual labels:  obfuscation
LLVM-Obfuscator
LLVM Obfuscator
Stars: ✭ 44 (-59.63%)
Mutual labels:  obfuscation
Jawbreaker
A Python obfuscator using HTTP Requests and Hastebin.
Stars: ✭ 50 (-54.13%)
Mutual labels:  obfuscation
VisualBasicObfuscator
Visual Basic Code universal Obfuscator intended to be used during penetration testing assignments.
Stars: ✭ 115 (+5.5%)
Mutual labels:  obfuscation
kiteshield
Packer/Protector for x86-64 ELF binaries on Linux
Stars: ✭ 71 (-34.86%)
Mutual labels:  obfuscation
TrezorSymmetricFileEncryption
🔒 Use your Trezor device to symmetrically encrypt and decrypt files
Stars: ✭ 16 (-85.32%)
Mutual labels:  obfuscation
react-obfuscate
An intelligent React component to obfuscate any contact link!
Stars: ✭ 87 (-20.18%)
Mutual labels:  obfuscation
Forsaken
One of the best Python3.9 obfuscators.
Stars: ✭ 94 (-13.76%)
Mutual labels:  obfuscation
chameleon
PowerShell Script Obfuscator
Stars: ✭ 319 (+192.66%)
Mutual labels:  obfuscation
Lua-Obfuscator
A Lua Obfuscator made for Roblox, but should work on most Lua applications
Stars: ✭ 84 (-22.94%)
Mutual labels:  obfuscation
dumb-obfuscator
Tutorial on how to write the dumbest obfuscator I could think of.
Stars: ✭ 147 (+34.86%)
Mutual labels:  obfuscation
Powershell-Obfuscator
Powerful script for logical obfuscation of powershell scripts
Stars: ✭ 27 (-75.23%)
Mutual labels:  obfuscation
gnirts
Obfuscate string literals in JavaScript code.
Stars: ✭ 65 (-40.37%)
Mutual labels:  obfuscation
vm-obfuscator
simple virtualization obfuscator
Stars: ✭ 25 (-77.06%)
Mutual labels:  virtualization-based-security

Build Status codecov

Rusty-JSYC

Rusty-JSYC (JavaScript bYtecode Compiler) is a JavaScript-To-Bytecode compiler written in Rust. The bytecode is meant to be used in conjunction with the provided virtual machine written in JavaScript. In combination they form the components for a virtualization obfuscation.

There is also a blogpost explaining this project and virtualization obfuscation in general.

How to use this

You must first compile the given JavaScript code. After that you can execute it with the provided virtual machine.

Compile your JavaScript code

You can either use the provided command line tool:

cargo run </path/to/javascript.js> </path/to/vm-template.js> </output/dir> -d

or use the compiler as a library and call it from your own rust code:

extern crate jsyc_compiler;

use jsyc_compiler::{JSSourceCode, BytecodeCompiler};

fn main() {
  let js_code = JSSourceCode::new("console.log('Hello World');".into());
  let mut compiler = BytecodeCompiler::new();

  let bytecode = compiler.compile(&js_code).expect("Failed to compile code");
  println!("Bytecode: {}", bytecode);

  let depedencies = compiler.decl_dependencies();
  println!("Depedencies: {:?}", depedencies);

  let base64_bytecode = bytecode.encode_base64();
  println!("Base64-encoded bytecode: {}", base64_bytecode);
}

In your Cargo.Toml:

[dependencies]
jsyc_compiler = "~0.1"

Run the virtual machine

// include vm.js
// ...
var vm = new VM();
vm.init(Base64EncodedBytecode);
requestIdleCallback(() => vm.run());
// ...

Replace Base64EncodedBytecode with the actual base64 encoded bytecode.

Playground example

An example demonstrating both the compiler and the virtual machine can be found in playground/snake. It features a small Snake game (snake.js). You can compile this with:

cargo run "playground/snake/unobfuscated/snake.js" "vm/vm.js" "playground/snake/obfuscated" "playground/snake/unobfuscated/index.html"

After compilation, open the index.html file in your browser.

/path/to/rusty-jsyc/playground/snake/obfuscated/index.html

This was tested in Chrome 74 and Firefox 67. However, any ES6 capable browser should be compatible.

Virtualization Obfuscation

Virtualization obfuscation is a state-of-the-art obfuscation scheme. It obfuscates the code by compiling it into bytecode which is then executed by a virtual machine (VM). Thus, the VM gets distributed along with the compiled bytecode. It is then called with this bytecode and executes it and is thereby executing the actual code.

Since the bytecode is executed instruction by instruction, the original code is never restored anywhere. So, any potential attacker must first reverse engineer the VM, which may be heavily obfuscated. One must then understand the underlying architecture and instruction-set before being able to analyze the actual bytecode. Since any two virtualization obfuscations are potentially different, the use of automated tools is limited.[1][2]

Compatibility

Interactions between the virtual and real JavaScript context

It is possible to provide the functions defined in the virtual JavaScript context to the real JavaScript context.

// Compiled JavaScript
function secret_function(a, b, c) { return a*b+c; }
window.secret_function = secret_function;
// Non-Compiled JavaScript
var secret_function = window.secret_function;
secret_function(10, 20, 1337);

It does not need to be window, any object instance know to both contexts will work. When calling secret_function the virtual machine will start the execution of the corresponding bytecode chunk. Thus, calling a function this way does not reveal any more information on the implementation than just calling it inside the compiled JavaScript.

Current unsound properties

These are the properties that are not reflected by the bytecode as they would be in real JavaScript.

  • the 'this' pointer for external non-member functions is simply 'void 0'
  • Assignment expressions do not return a value, and thus are not really expressions
  • If you declare a variable without assignment it's value will be unknown. Thus it might or might not be undefined (void 0). (It will be undefined but not JavaScript's undefined (void 0))
  • let and const declarations are treated as var declarations

Unsupported JavaScript syntaxes

This compiler currently only supports a subset of JavaScript features. Currently missing are

  • Object related notations ({}, new, this, super, class)
  • for-of and for-in loops
  • async and await keywords
  • with, and switch keywords
  • try and throw structures
  • break, continue, labels
  • function expressions and arrow function (Regular functions are allowed)
  • function expressions and arrow functions can be realized with:
var func_expr = eval("0, function(x) {return x*x;}");

However, they do not support references to variables defined in the compiled JavaScript.

  • tagged template expressions
  • spread, rest and sequence notations

How to run tests

There are several test sets in this project:

  1. Cargo tests: cargo test
  2. Node (mocha) tests:npm install && npm test

1: Rolf Rolles. Unpacking virtualization obfuscators. USENIX Workshop on Offensive Technologies (WOOT), 2009.

2: Johannes Kinder. Towards static analysis of virtualization-obfuscated binaries. Reverse Engineering (WCRE), 2012 19th Working Conference.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].