Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 29, 2015 03:58
Show Gist options
  • Save JavaScript-Packer/0ac9254197d10e6b9b33 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/0ac9254197d10e6b9b33 to your computer and use it in GitHub Desktop.
Watch me do (step by step) a basic manual obfuscation of basic JavaScript source code
//using encoder online tools @ http://www.scriptcompress.com/30-encoders-in-1.htm
function hex(Δ){return Δ.replace(/./g,function(Δ){return'\\x'+Δ.charCodeAt(0).toString(16)})};
alert(hex('ScripCompress.com'));
//lets bracket notation stuff
function hex(Δ){return Δ['replace'](/./g,function(Δ){return'\\x'+Δ['charCodeAt'](0)['toString'](16)})};
alert(hex('ScripCompress.com'));
//lets encode stuff between brackets using hexidecimal/hex
function hex(Δ){return Δ['\x72\x65\x70\x6c\x61\x63\x65'](/./g,function(Δ){return'\\x'+Δ['\x63\x68\x61\x72\x43\x6f\x64\x65\x41\x74'](0)['\x74\x6f\x53\x74\x72\x69\x6e\x67'](16)})};
alert(hex('\x53\x63\x72\x69\x70\x43\x6f\x6d\x70\x72\x65\x73\x73\x2e\x63\x6f\x6d'));
//lets encode variable and function names in unicode
function \u0068\u0065\u0078(\u0394){return \u0394['\x72\x65\x70\x6c\x61\x63\x65'](/./g,function(\u0394){return'\\x'+\u0394['\x63\x68\x61\x72\x43\x6f\x64\x65\x41\x74'](0)['\x74\x6f\x53\x74\x72\x69\x6e\x67'](16)})};
\u0061\u006c\u0065\u0072\u0074(\u0068\u0065\u0078('\x53\x63\x72\x69\x70\x43\x6f\x6d\x70\x72\x65\x73\x73\x2e\x63\x6f\x6d'));
//lets make it a dataURI and embed in an embeded embedded file
document['write']('<script src="data:,function%20%5Cu0068%5Cu0065%5Cu0078(%5Cu0394)%7Breturn%20%5Cu0394%5B%27%5Cx72%5Cx65%5Cx70%5Cx6c%5Cx61%5Cx63%5Cx65%27%5D(%2F.%2Fg,function(%5Cu0394)%7Breturn%27%5C%5Cx%27+%5Cu0394%5B%27%5Cx63%5Cx68%5Cx61%5Cx72%5Cx43%5Cx6f%5Cx64%5Cx65%5Cx41%5Cx74%27%5D(0)%5B%27%5Cx74%5Cx6f%5Cx53%5Cx74%5Cx72%5Cx69%5Cx6e%5Cx67%27%5D(16)%7D)%7D;%0D%0A%5Cu0061%5Cu006c%5Cu0065%5Cu0072%5Cu0074(%5Cu0068%5Cu0065%5Cu0078(%27%5Cx53%5Cx63%5Cx72%5Cx69%5Cx70%5Cx43%5Cx6f%5Cx6d%5Cx70%5Cx72%5Cx65%5Cx73%5Cx73%5Cx2e%5Cx63%5Cx6f%5Cx6d%27));"><\/script>');
//because the script source is theoretically HTML in a href link type environment, we can encode some HTML entities
this['document']['write']('<script src="&#100;&#97;&#116;&#97;&#58;&#44;&#102;&#117;&#110;&#99;&#116;&#105;&#111;&#110;&#32;&#92;&#117;&#48;&#48;&#54;&#56;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#56;&#40;&#92;&#117;&#48;&#51;&#57;&#52;&#41;&#123;&#114;&#101;&#116;&#117;&#114;&#110;&#32;&#92;&#117;&#48;&#51;&#57;&#52;&#91;&#39;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#53;&#92;&#120;&#55;&#48;&#92;&#120;&#54;&#99;&#92;&#120;&#54;&#49;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#53;&#39;&#93;&#40;&#47;&#46;&#47;&#103;&#44;&#102;&#117;&#110;&#99;&#116;&#105;&#111;&#110;&#40;&#92;&#117;&#48;&#51;&#57;&#52;&#41;&#123;&#114;&#101;&#116;&#117;&#114;&#110;&#39;&#92;&#92;&#120;&#39;&#43;&#92;&#117;&#48;&#51;&#57;&#52;&#91;&#39;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#56;&#92;&#120;&#54;&#49;&#92;&#120;&#55;&#50;&#92;&#120;&#52;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#52;&#92;&#120;&#54;&#53;&#92;&#120;&#52;&#49;&#92;&#120;&#55;&#52;&#39;&#93;&#40;&#48;&#41;&#91;&#39;&#92;&#120;&#55;&#52;&#92;&#120;&#54;&#102;&#92;&#120;&#53;&#51;&#92;&#120;&#55;&#52;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#57;&#92;&#120;&#54;&#101;&#92;&#120;&#54;&#55;&#39;&#93;&#40;&#49;&#54;&#41;&#125;&#41;&#125;&#59;&#10;&#92;&#117;&#48;&#48;&#54;&#49;&#92;&#117;&#48;&#48;&#54;&#99;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#50;&#92;&#117;&#48;&#48;&#55;&#52;&#40;&#92;&#117;&#48;&#48;&#54;&#56;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#56;&#40;&#39;&#92;&#120;&#53;&#51;&#92;&#120;&#54;&#51;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#57;&#92;&#120;&#55;&#48;&#92;&#120;&#52;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#100;&#92;&#120;&#55;&#48;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#53;&#92;&#120;&#55;&#51;&#92;&#120;&#55;&#51;&#92;&#120;&#50;&#101;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#100;&#39;&#41;&#41;&#59;"><\/script>');
//now lets encode again between brackets using octal this time and then encode this in unicode
\u0074\u0068\u0069\u0073['\144\157\143\165\155\145\156\164']['\167\162\151\164\145']('\74\163\143\162\151\160\164\40\163\162\143\75\42&#100;&#97;&#116;&#97;&#58;&#44;&#102;&#117;&#110;&#99;&#116;&#105;&#111;&#110;&#32;&#92;&#117;&#48;&#48;&#54;&#56;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#56;&#40;&#92;&#117;&#48;&#51;&#57;&#52;&#41;&#123;&#114;&#101;&#116;&#117;&#114;&#110;&#32;&#92;&#117;&#48;&#51;&#57;&#52;&#91;&#39;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#53;&#92;&#120;&#55;&#48;&#92;&#120;&#54;&#99;&#92;&#120;&#54;&#49;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#53;&#39;&#93;&#40;&#47;&#46;&#47;&#103;&#44;&#102;&#117;&#110;&#99;&#116;&#105;&#111;&#110;&#40;&#92;&#117;&#48;&#51;&#57;&#52;&#41;&#123;&#114;&#101;&#116;&#117;&#114;&#110;&#39;&#92;&#92;&#120;&#39;&#43;&#92;&#117;&#48;&#51;&#57;&#52;&#91;&#39;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#56;&#92;&#120;&#54;&#49;&#92;&#120;&#55;&#50;&#92;&#120;&#52;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#52;&#92;&#120;&#54;&#53;&#92;&#120;&#52;&#49;&#92;&#120;&#55;&#52;&#39;&#93;&#40;&#48;&#41;&#91;&#39;&#92;&#120;&#55;&#52;&#92;&#120;&#54;&#102;&#92;&#120;&#53;&#51;&#92;&#120;&#55;&#52;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#57;&#92;&#120;&#54;&#101;&#92;&#120;&#54;&#55;&#39;&#93;&#40;&#49;&#54;&#41;&#125;&#41;&#125;&#59;&#10;&#92;&#117;&#48;&#48;&#54;&#49;&#92;&#117;&#48;&#48;&#54;&#99;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#50;&#92;&#117;&#48;&#48;&#55;&#52;&#40;&#92;&#117;&#48;&#48;&#54;&#56;&#92;&#117;&#48;&#48;&#54;&#53;&#92;&#117;&#48;&#48;&#55;&#56;&#40;&#39;&#92;&#120;&#53;&#51;&#92;&#120;&#54;&#51;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#57;&#92;&#120;&#55;&#48;&#92;&#120;&#52;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#100;&#92;&#120;&#55;&#48;&#92;&#120;&#55;&#50;&#92;&#120;&#54;&#53;&#92;&#120;&#55;&#51;&#92;&#120;&#55;&#51;&#92;&#120;&#50;&#101;&#92;&#120;&#54;&#51;&#92;&#120;&#54;&#102;&#92;&#120;&#54;&#100;&#39;&#41;&#41;&#59;\42\76\74\/\163\143\162\151\160\164\76');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment