Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
JavaScript-Packer / obfuscation.js
Created April 29, 2015 03:58
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'));
@JavaScript-Packer
JavaScript-Packer / code_runner.js
Created April 29, 2015 04:50
Pass a command to function that can be easily obfuscated
var code = " alert( 'ScriptCompress.com' ); ";
var command="eval"; //command="\x65val";
function runner( Δ, ǃ ) { \u0065v\u0061l( ǃ )( Δ ) };
runner( code, command );
@JavaScript-Packer
JavaScript-Packer / wtf.js
Created April 29, 2015 05:56
WTF? How does this JavaScript even work?
Δ=~[],Δ={ǃǃǃ:++Δ,ππππ:(!1+"")[Δ],ǃǃπ:++Δ,πǃπǃ:(!1+"")[Δ],ǃπǃ:++Δ,πǃππ:({}+"")[Δ],ππǃπ:(Δ[Δ]+"")[Δ],
ǃππ:++Δ,πππǃ:(!0+"")[Δ],πǃǃ:++Δ,πǃπ:++Δ,ππǃǃ:({}+"")[Δ],
ππǃ:++Δ,πππ:++Δ,πǃǃǃ:++Δ,πǃǃπ:++Δ},
Δ.πǃ=(Δ.πǃ=Δ+"")[Δ.πǃπ]+(Δ.ǃπ=Δ.πǃ[Δ.ǃǃπ])+(Δ.ππ=(Δ.π+"")[Δ.ǃǃπ])+(!Δ+"")[Δ.ǃππ]+(Δ.ǃǃ=Δ.πǃ[Δ.ππǃ])+(Δ.π=(!0+"")[Δ.ǃǃπ])+(Δ.ǃ=(!0+"")[Δ.ǃπǃ])+Δ.πǃ[Δ.πǃπ]+Δ.ǃǃ+Δ.ǃπ+Δ.π,Δ.ππ=Δ.π+(!0+"")[Δ.ǃππ]+Δ.ǃǃ+Δ.ǃ+Δ.π+Δ.ππ,Δ.π=Δ.ǃǃǃ[Δ.πǃ][Δ.πǃ],
Δ.π(Δ.π(Δ.ππ+'"'+Δ.ππππ+Δ.ǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+Δ.ππǃǃ+Δ.ǃǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ǃǃπ+Δ.ǃπ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+"\\"+Δ.πǃǃ+Δ.ǃǃǃ+Δ.ππǃǃ+Δ.ǃπ+Δ.ππǃπ+Δ.πππǃ+"\\"+Δ.ǃǃπ+Δ.ǃπǃ+Δ.ǃπǃ+Δ.ǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+Δ.πππǃ+"\\"+Δ.ǃǃπ+Δ.ππǃ+Δ.ǃπǃ+"("+Δ.ππǃǃ+Δ.ǃπ+Δ.ππǃπ+Δ.πππǃ+","+Δ.ππǃǃ+Δ.ǃπ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.πǃπ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.πǃπ+Δ.πǃπǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+Δ.ππǃπ+"){"+Δ.πππǃ+"\\"+Δ.ǃǃπ+Δ.ππǃ+Δ.ππǃ+Δ.πǃπǃ+(!1+"")[Δ.ǃπǃ]+"("+Δ.ππǃǃ+Δ.ǃπ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.πǃπ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.πǃπ+Δ.πǃπǃ+"\\"+Δ.ǃǃπ+Δ.πǃπ+Δ.ππǃ+Δ.ππǃπ+")("+Δ.ππǃǃ+Δ.ǃπ+Δ.ππǃπ+Δ.πππǃ+")}\\"+Δ.ǃǃπ+Δ.ππǃ+Δ.
@JavaScript-Packer
JavaScript-Packer / WTF.js
Created April 29, 2015 06:52
WTF? How does this JavaScript even work? 20 obfuscated snippets from 1 script
//eample of weird and crazy obfuscation on http://www.whak.ca/ (whak-a-script)
var W,H,A,K,com;for(W='€̷̛͇̟̎̎̎ͅ€̷̷̷̷̧̛̛̛̛͕̰̗͎͇͕̗̖͇͕͔͎̎̍̍̇̍̍̇͛̎̚̕҉̷̷͕̎̍̍̎̓͛̎͛̚ͅ\n€̷̛͇͕͕̟̎ͨͅ€͔͛ͅ\n̷̷̛̥͎̰͇͇̟͉ͣͨͨ̎ͣͨͨ҉̷̵͇̟͇͕͕̟̣̘̎ͫ̎ͨ̎̓̎̎ͣ͊͊̋€̵̴̘͔ͣ͊͊҉͇͕͕̟̎ͨ̎̓҉̷͇̟̎̎̓̎͛\n̷̷̛͇̟͉ͣͨͨ҉̷͇̟͇͕͕̟̎ͫ̎ͨ̎̓͛',K='',com=31;127>com;com++)K+=String.fromCharCode(com);K=K.split(''),A='̫̎̉̔̊̇ͅ҉̴̧̖̼̙̩̘̺̝̭͙̓̀̿ͫͬ͊̋́͛̃͗͌ͭͦ̐͆̈́͘͡͝͏̶̵̷̡̛͉̪̤̟̥̰̱͔͕͇̗͎͂̂ͪ̄ͯ̾̑̽ͨ̌̍ͣ̕̚͢͜͠€‚̻̨̢̣̞͍̦̬̜͈̳͓̹̲̆ͮ̈̓ͩ͐͑ͤͧ̀̏̅̒͟ƒ̸̠̮̯͖͚͒͋ͥ́͞'.split('');for(var S in A)W=W.split(A[S]).join(K[S]);this['eval'](W);
//this was our original JavaScript source code:
var code = " alert( 'ScriptCompress.com' ); ";
var command="eval"; //command="\x65val";
function runner( Δ, ǃ ) { \u0065v\u0061l( ǃ )( Δ ) };
runner( code, command );
//ALL BELOW SAMPLES ARE ACTUAL WORKING JAVASCRIPT
@JavaScript-Packer
JavaScript-Packer / hashish.js
Created April 30, 2015 13:16
Get complete hash of URL without substring, split/join or indexof
if(window.location.hash) {
alert(window.location.hash.replace("#",""));
//above we simply get rid of the first occurance of #, without global set, only first match dealt with
} else {
alert('no hash for you');
}
//this is a WHAK.com script :)
@JavaScript-Packer
JavaScript-Packer / base64-compression.js
Created April 30, 2015 14:19
Sick of Base64 encoding making everything bigger? We have come up with a free tool on www.scriptcompress.com to help compress and pack to a self extracting/running JavaScript. We originally made the tool for compressing DNA code sequences, but discovered it works well with many types of encrypted and encoded type stuff :)
// Base64 encoing sucks, it makes everything 33% bigger. But, we are going to make it smaller using
// tools on http://www.scriptcompress.com/DNA-Packer.htm
//demo script using 5.5KB Base64 encoding of 4KB of HTML code
pack='PGgyPkZyZWUgVG9vbHMgRm9yIFByb2dyYW1tZXJzOjwvaDI+CjxoND48YSBocmVmPSJodHRwO\
i8vd3d3LnNjcmlwdGNvbXByZXNzLmNvbS9KYXZhU2NyaXB0LVBhY2tlcnMuaHRtIj4yMCBQYWNrZXJz\
IEluIDEgQXBwPC9hPjwvaDQ+CjxoND48YSBocmVmPSJodHRwOi8vd3d3LnNjcmlwdGNvbXByZXNzLmN\
vbS9QSFAtUGFja2VyLmh0bSI+UEhQIFNvdXJjZSBDb2RlIFBhY2tlcnM8L2E+PC9oND4KPGg0PjxhIG\
hyZWY9Imh0dHA6Ly93d3cuc2NyaXB0Y29tcHJlc3MuY29tL1RleHQtVG8tSmF2YVNjcmlwdC5odG0iP\
lRleHQgUGFja2VyPC9hPjwvaDQ+CjxoND48YSBocmVmPSJodHRwOi8vd3d3LnNjcmlwdGNvbXByZXNz\
@JavaScript-Packer
JavaScript-Packer / bracket-notation.js
Created April 30, 2015 16:06
JavaScript simple golf coding example taking advantage of Bracket Notation using online golfing tool http://www.scriptcompress.com/golf.htm
//BEFORE: below is 394 byte sample that we want to make smaller with one simple technique
/*
var r={d4:function(){return Math.floor(4*Math.random())+1},
d6:function(){return Math.floor(6*Math.random())+1},d8:function(){return Math.floor(8*Math.random())+1},
d10:function(){return Math.floor(10*Math.random())+1},d12:function(){return Math.floor(12*Math.random())+1},
d20:function(){return Math.floor(20*Math.random())+1}};alert("rolling D4 : "+r.d4()),alert("rolling D20 : "+r.d20());
*/
//AFTER: 340 bytes, over 50 bytes saved
@JavaScript-Packer
JavaScript-Packer / download-blob.js
Last active August 29, 2015 14:20
Turn a string into a downloadable blob link to click on for download.
//create blob link for downloading data
var name = "YourFile.txt", data = "THIS IS JUST A TEST", d = "download", $ = "setAttribute", _ = document, r = new Blob([ data ], {
"type": "text/plain;charset=utf8;"
}), e = _.createElement("a");
void 0 !== e[d] ? (e[$]("href", window.URL.createObjectURL(r)), e[$](d, name)) : e[$]("href", "http://www.whak.com"),
e.innerHTML = "Download", _.body.appendChild(e);
@JavaScript-Packer
JavaScript-Packer / blobify.js
Created April 30, 2015 18:45
Make a JavaScript source code into a download link using blobs. Click link to download.
//make a javascript source code downloadable by blob
var name="script.js",data="alert('THIS IS A TEST');",d="download",$="setAttribute",_=document,
r=new Blob([data],{type:"text/plain;charset=utf8;"}),e=_.createElement("a");
void 0!==e[d]?(e[$]("href",window.URL.createObjectURL(r)),
e[$](d,name)):e[$]("href","http://www.whak.com"),e.innerHTML="Download",_.body.appendChild(e);
@JavaScript-Packer
JavaScript-Packer / blobity.js
Created April 30, 2015 18:51
Automatic downloading JavaScript source code with blobs
// click on generated href link dynamically created and attached to page
var Δ="script.js",data="alert('THIS IS A TEST');",d="download",$="setAttribute",_=document,
r=new Blob([data],{type:"text/plain;charset=utf8;"}),e=_.createElement("a");
void 0!==e[d]?(e[$]("href",window.URL.createObjectURL(r)),e[$](d,Δ)):e[$]("href","http://www.whak.com"),
e.click(),_.body.appendChild(e);
//automatic downloader, download pops up right after page load