SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Creating, obfuscating and
            analyzing malware JavaScript



                     Krzysztof Kotowicz
                     PHP Developer

                     http://web.eskot.pl
OWASP                Medycyna Praktyczna
                     krzysztof@kotowicz.net
June 2010

                Copyright © The OWASP Foundation
                Permission is granted to copy, distribute and/or modify this document
                under the terms of the OWASP License.




                The OWASP Foundation
                http://www.owasp.org
Plan

 Theory - Obfuscation and analysis
  in general
  in JavaScript
 Practice - evading automatic code analyzers
  jsunpack
  JavaScript unpacker
  Capture-HPC


                                      OWASP     2
Theory



         OWASP
Obfuscation
        Goal - make analysis harder




                                      OWASP   4
Obfuscation

 There is no perfect obfuscation                [cs.princeton.edu]

 Analysis as debugging

Debugging is twice as hard as
writing a program in the first
place. So if you're as clever as
you can be when you write it,
how will you ever debug it?
Brian Kernighan, The Elements of Programming Style
                                                       OWASP          5
Obfuscation methods

   for     while + if
   Iteration   recursion
   Complex logical tests
   Dummy code branches
   Quasitautologies [blog.didierstevens.com]
   Enigmatic variable names




                                                OWASP   6
Obfuscation methods in JS

JavaScript is a dynamic and functional language
 Code created at runtime – eval
 String.fromCharCode, unescape
 Regular expressions - String.replace
     Packers, e.g.
     [dean.edwards.name]
     [developer.yahoo.com]
     [malwareguru.org]
     [closure-compiler.appspot.com]

     Others - e.g. WhiteSpace Obfuscation   [ktcorpsecurity.com]




                                                      OWASP         7
Active defense against analysis

    Function.toString /
     arguments.callee.toString               [isc.sans.org]

    autoencryption [isc.sans.org]
    browser detection
     DOM
     window, navigator
     timings
     cookies
     mouse position, screen resolution
    Malware served only once per IP      [research.zscaler.com]

                                                   OWASP           8
Active defense - know thy language


function is_even(n) {
    var parameter_is_even =
      (n % 2) == 0 ? true : false;

     return
       parameter_is_even;
}

alert(is_even(16));


                                     OWASP   9
Result




         OWASP   10
How to analyze malware JavaScript?

 Know JavaScript!
 Run the code & observe effects in a
  controlled environment
 Overload functions
    eval
    String.fromCharCode
 Deobfuscate parts of code
 Be patient and creative

                                        OWASP   11
JavaScript analysis...

   Is rather heuristics than algorithm
   Is rather manual than automatic
   Human is required
   Tools help greatly, but they're not perfect




                                         OWASP    12
Practice



      OWASP
jsunpack

 Runs JS inside SpiderMonkey      [mozilla.org]
   JS fetched from URL, PCAP, JS/HTML file…
 SM is modified to include:
   DOM emulation
   browser objects emulation
   onload() event
 monitors eval(), setTimeout() and
  others
 scans the code using signatures file

                                                   OWASP   14
jsunpack - weak points

 Emulates browser
 Code that won't run (dead
  branches) will be checked with
  signatures only




                               OWASP   15
Evading detection


 if (fake_browser) {
   do_no_harm();
 } else {
   redirect_to_malicious_website();
   // or obfuscate an exploit
 }


 We need to detect being run in jsunpack

                                     OWASP   16
How to detect jsunpack?

Many, many ways:
 Bad implementation of
   window.location
  fake_browser = window.location.host.match('/'); pliku
  window.location.host = ścieżka do


 It adds its own global variables
  fake_browser = (typeof my_location != "undefined");
  // my_navigator, my_activex, my_element,
  // the_activex, app, ...


                                                OWASP     17
How to detect jsunpack?

 It overloads some functions
fake_browser = (window.open.toString().match(/print/));
fake_browser = (alert.toString().match(/{s*}/));


 Objects emulation has missing spots

 fake_browser = (typeof
     PluginArray.prototype.refresh == "undefined");

 fake_browser = (document.title == 'My Title');




                                                  OWASP   18
Jsunpack - bonus

 jsunpack runs not only JavaScript

<script type="text/dummy">
  // good enough for jsunpack
</script>

 Code will be run in jsunpack, but not in
  browsers


                                      OWASP   19
Note to online viewers:
 Demos require checking and running the files locally - see attached docs



         DEMO 1
index.php / js.js - sandbox detection
(modify js.js to test different techniques)

jekyll2.html - Dr Jekyll attack

js.js - HTML hack
(shortest jsunpack disabler)




 github.com/koto/owasp-malicious-javascript/
                                                                     OWASP   20
jsunpack - summary

 You could easily detect being run in
  jsunpack sandbox
 When detected, you just skip doing bad
  stuff
 If malware code is obfuscated, it will not
  be detected with signatures

You go under the radar of jsunpack analysis

                                     OWASP     21
Dean Edwards' Unpacker

A JavaScript Decompressor [dean.edwards.name]
 Reverses Dean Edward's packer
 Packer works like this:
eval(function(p,a,c,k,e,r){/*code*/}(para,
meters))

/* which is the same as */
var packer = function(p,a,c,k,e,r) {/**/};
var s = packer(para,meters);
eval(s);


                                          OWASP   22
Unpacker - step 1

 Replace eval() with string assignment

    // packed code is in input
    var input="eval(function(p,a,c,k....";

    eval("var value=String" +
    input.slice(4)); // cut "eval"

    // executed code will be:
    var value=String(function(p,a,c,k..);

 value holds decompressed code

                                          OWASP   23
Unpacker - step 1

 Replace eval() with string assignment
     // packed code is in input
     var input="eval(function(p,a,c,k....";

     eval("var value=String" +
     input.slice(4)); // cut "eval"

     // executed code will be:
     var value=String(function(p,a,c,k..);

 value holds decompressed code
 But! we're blindly executing cut&pasted code!
                                           OWASP   24
Unpacker - step 2

 Use Function.toString() to display the code

     eval(
     "var unpacked = function() {"
     + value + "}"
     );
     alert(unpacked.toString());


 Unpacked code WILL NOT RUN, it wil just print!
   Disclaimer - the real code is a bit different, but the concept is the
    same

                                                             OWASP          25
Dean Edwards Unpacker - weak points

 Concatenating strings and executing the
  resulting code (injection, anyone?)
 Using a constant - we cut first 4 characters
  without looking at them
 eval() without any validation
 Depends on Function.toString() to
  print the code




                                          OWASP   26
Dean Edwards Unpacker - disarming

 eval() uses a single parameter
 String() uses a single parameter
 ...but you could give more :)
 eval("code");
 eval("code", "ignored");
 eval("code", malicious());
 String("code", malicious());

 Arbitrary code execution without changing
  p,a,c,k,e,r function!

                                       OWASP   27
Dean Edwards Unpacker - disarming

 eval(function(p,a,c,k,e,r){...}(para,mete
 rs),malicious());

 var
 value=String(function(p,a,c,k,e,r){...}(p
 ara,meters),malicious());

 malicious() will execute in packed code
  and in unpacker




                                    OWASP    28
Dean Edwards Unpacker - disarming

What can we do in malicious()?
 Unpacker uses Function.toString()
 Let's override it!
 malicious() is e.g. obfuscated:

Function.prototype.toString = function()
{
  return 'harmless code';
}


                                    OWASP   29
DEMO 2

demo2/evil.packed.js




github.com/koto/owasp-malicious-javascript/
                                    OWASP     30
Dean Edwards Unpacker - point of concept




                                   OWASP   31
High interaction client honeypots

Capture-HPC     [projects.honeynet.org]   as an example
 Code is run in real browser in a virtual machine
 Server serves URL list to visit
 Client starts browsers and waits…
 Code side-effects are monitored
  Filesystem
  Registry
  Processes
 If anything suspicious happens with the system, URL
  is reported to server as a malware

                                                      OWASP   32
High interaction client honeypots

 Runtime environment is the same
 There is no emulation

       Could we detect we're traced?




                                       OWASP   33
Weak point




             OWASP   34
High interaction client honeypots - robot

                      Doesn't move mouse
                      Doesn't click
                      Doesn't drag
                      Doesn't navigate
                      Is "stupid"




                                      OWASP   35
High interaction client honeypots - user

                      Moves mouse
                      Clicks
                      Drags
                      Navigates
                      Is stupid




                                      OWASP   36
Honeypots – social engineering




                                 OWASP   37
Honeypots – social engineering




                                 OWASP   38
Honeypots - summary

 No emulation layer to detect
 Code is run in real browser
 Weakest point is the lack of human
  element
 Just run the code after detecting an
  interaction with the page




                                    OWASP   39
Summary

    Obfuscation can only make analysis slower
    Code can actively defend against analysis
    Human is required to do a complete analysis
    Analysis requires strong skills
    Automatic tools can be fooled
     detect emulation differences
     errors
     lack of full interaction with a webpage


                                          OWASP    40
Links
Demo source: github.com/koto/owasp-malicious-javascript
Tools
       jsunpack.blogspot.com
       dean.edwards.name/unpacker/
       projects.honeynet.org/capture-hpc
       malzilla.sourceforge.net
Obfuscation and analysis
       isc.sans.org/diary.html
       www.malwareguru.org
       delicious.com/koto/obfuscation
       closure-compiler.appspot.com
JavaScript
       www.slideshare.net/ferrantes/just-advanced-javascript
       jsninja.com


krzysztof@kotowicz.net             http://blog.kotowicz.net
                                                                OWASP   41

Contenu connexe

Tendances

Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfacesjuanvazquezslides
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Christian Schneider
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codeAndrey Karpov
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistAnton Arhipov
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers ViewpointSource Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers ViewpointTyler Shields
 
A Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL ProjectA Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL ProjectAndrey Karpov
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...joaomatosf_
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)CODE WHITE GmbH
 
Deserialization vulnerabilities
Deserialization vulnerabilitiesDeserialization vulnerabilities
Deserialization vulnerabilitiesGreenD0g
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Christian Schneider
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistAnton Arhipov
 
10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems10 Typical Enterprise Java Problems
10 Typical Enterprise Java ProblemsEberhard Wolff
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)CODE WHITE GmbH
 
Discussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source ComponentsDiscussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source ComponentsPVS-Studio
 
Black Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized CommunicationBlack Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized Communicationmsaindane
 

Tendances (20)

Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers ViewpointSource Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
 
A Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL ProjectA Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL Project
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
 
Deserialization vulnerabilities
Deserialization vulnerabilitiesDeserialization vulnerabilities
Deserialization vulnerabilities
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
 
Discussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source ComponentsDiscussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source Components
 
Black Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized CommunicationBlack Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized Communication
 
Shark
Shark Shark
Shark
 

En vedette

Malware classification
Malware classificationMalware classification
Malware classificationzynamics GmbH
 
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download DetectionDrivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download DetectionWayne Huang
 
NoSQL, no SQL injections?
NoSQL, no SQL injections?NoSQL, no SQL injections?
NoSQL, no SQL injections?Wayne Huang
 
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...Wayne Huang
 
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case Studies
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case StudiesRSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case Studies
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case StudiesWayne Huang
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23DefconRussia
 

En vedette (6)

Malware classification
Malware classificationMalware classification
Malware classification
 
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download DetectionDrivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
 
NoSQL, no SQL injections?
NoSQL, no SQL injections?NoSQL, no SQL injections?
NoSQL, no SQL injections?
 
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...
0box Analyzer--Afterdark Runtime Forensics for Automated Malware Analysis and...
 
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case Studies
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case StudiesRSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case Studies
RSA 2015 Bitcoin's Future Threats: Expert's Roundtable based on 150 Case Studies
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
 

Similaire à Creating, obfuscating and analyzing malware JavaScript

exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportPVS-Studio
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiasanjeeviniindia1186
 
Gauntlt Rugged By Example
Gauntlt Rugged By Example Gauntlt Rugged By Example
Gauntlt Rugged By Example James Wickett
 
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ -  Automated Malware AnalysisIstSec'14 - İbrahim BALİÇ -  Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ - Automated Malware AnalysisBGA Cyber Security
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of JavascriptSamuel Abraham
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopPVS-Studio
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypalLenny Markus
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisRuslan Shevchenko
 
How to find 56 potential vulnerabilities in FreeBSD code in one evening
How to find 56 potential vulnerabilities in FreeBSD code in one eveningHow to find 56 potential vulnerabilities in FreeBSD code in one evening
How to find 56 potential vulnerabilities in FreeBSD code in one eveningPVS-Studio
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testingPeter Edwards
 
How Scala code is expressed in the JVM
How Scala code is expressed in the JVMHow Scala code is expressed in the JVM
How Scala code is expressed in the JVMKoichi Sakata
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applicationshubx
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...Christoph Matthies
 
JavaScript development methodology
JavaScript development methodologyJavaScript development methodology
JavaScript development methodologyAleksander Fabijan
 
How to really obfuscate your pdf malware
How to really obfuscate   your pdf malwareHow to really obfuscate   your pdf malware
How to really obfuscate your pdf malwarezynamics GmbH
 

Similaire à Creating, obfuscating and analyzing malware JavaScript (20)

Web Application Defences
Web Application DefencesWeb Application Defences
Web Application Defences
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large report
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Gauntlt Rugged By Example
Gauntlt Rugged By Example Gauntlt Rugged By Example
Gauntlt Rugged By Example
 
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ -  Automated Malware AnalysisIstSec'14 - İbrahim BALİÇ -  Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelop
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypal
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
How to find 56 potential vulnerabilities in FreeBSD code in one evening
How to find 56 potential vulnerabilities in FreeBSD code in one eveningHow to find 56 potential vulnerabilities in FreeBSD code in one evening
How to find 56 potential vulnerabilities in FreeBSD code in one evening
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testing
 
Play framework
Play frameworkPlay framework
Play framework
 
How Scala code is expressed in the JVM
How Scala code is expressed in the JVMHow Scala code is expressed in the JVM
How Scala code is expressed in the JVM
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
 
JavaScript development methodology
JavaScript development methodologyJavaScript development methodology
JavaScript development methodology
 
How to really obfuscate your pdf malware
How to really obfuscate   your pdf malwareHow to really obfuscate   your pdf malware
How to really obfuscate your pdf malware
 

Plus de Krzysztof Kotowicz

Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)
Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)
Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)Krzysztof Kotowicz
 
Trusted Types and the end of DOM XSS
Trusted Types and the end of DOM XSSTrusted Types and the end of DOM XSS
Trusted Types and the end of DOM XSSKrzysztof Kotowicz
 
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Krzysztof Kotowicz
 
Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Krzysztof Kotowicz
 
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsI'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsKrzysztof Kotowicz
 
I'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffI'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffKrzysztof Kotowicz
 
Advanced Chrome extension exploitation
Advanced Chrome extension exploitationAdvanced Chrome extension exploitation
Advanced Chrome extension exploitationKrzysztof Kotowicz
 
Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Krzysztof Kotowicz
 
Something wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceSomething wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceKrzysztof Kotowicz
 
Html5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraHtml5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraKrzysztof Kotowicz
 
Html5: something wicked this way comes
Html5: something wicked this way comesHtml5: something wicked this way comes
Html5: something wicked this way comesKrzysztof Kotowicz
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptKrzysztof Kotowicz
 
Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Krzysztof Kotowicz
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersKrzysztof Kotowicz
 
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Krzysztof Kotowicz
 

Plus de Krzysztof Kotowicz (17)

Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)
Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)
Trusted Types - Securing the DOM from the bottom up (JSNation Amsterdam)
 
Trusted Types @ W3C TPAC 2018
Trusted Types @ W3C TPAC 2018Trusted Types @ W3C TPAC 2018
Trusted Types @ W3C TPAC 2018
 
Trusted Types and the end of DOM XSS
Trusted Types and the end of DOM XSSTrusted Types and the end of DOM XSS
Trusted Types and the end of DOM XSS
 
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
 
Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)
 
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsI'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
 
HTML5: Atak i obrona
HTML5: Atak i obronaHTML5: Atak i obrona
HTML5: Atak i obrona
 
I'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffI'm in your browser, pwning your stuff
I'm in your browser, pwning your stuff
 
Advanced Chrome extension exploitation
Advanced Chrome extension exploitationAdvanced Chrome extension exploitation
Advanced Chrome extension exploitation
 
Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)
 
Something wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceSomething wicked this way comes - CONFidence
Something wicked this way comes - CONFidence
 
Html5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraHtml5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPra
 
Html5: something wicked this way comes
Html5: something wicked this way comesHtml5: something wicked this way comes
Html5: something wicked this way comes
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
 
Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developers
 
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
 

Dernier

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Dernier (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Creating, obfuscating and analyzing malware JavaScript

  • 1. Creating, obfuscating and analyzing malware JavaScript Krzysztof Kotowicz PHP Developer http://web.eskot.pl OWASP Medycyna Praktyczna krzysztof@kotowicz.net June 2010 Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation http://www.owasp.org
  • 2. Plan  Theory - Obfuscation and analysis  in general  in JavaScript  Practice - evading automatic code analyzers  jsunpack  JavaScript unpacker  Capture-HPC OWASP 2
  • 3. Theory OWASP
  • 4. Obfuscation Goal - make analysis harder OWASP 4
  • 5. Obfuscation  There is no perfect obfuscation [cs.princeton.edu]  Analysis as debugging Debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? Brian Kernighan, The Elements of Programming Style OWASP 5
  • 6. Obfuscation methods  for while + if  Iteration recursion  Complex logical tests  Dummy code branches  Quasitautologies [blog.didierstevens.com]  Enigmatic variable names OWASP 6
  • 7. Obfuscation methods in JS JavaScript is a dynamic and functional language  Code created at runtime – eval  String.fromCharCode, unescape  Regular expressions - String.replace  Packers, e.g.  [dean.edwards.name]  [developer.yahoo.com]  [malwareguru.org]  [closure-compiler.appspot.com]  Others - e.g. WhiteSpace Obfuscation [ktcorpsecurity.com] OWASP 7
  • 8. Active defense against analysis  Function.toString / arguments.callee.toString [isc.sans.org]  autoencryption [isc.sans.org]  browser detection  DOM  window, navigator  timings  cookies  mouse position, screen resolution  Malware served only once per IP [research.zscaler.com] OWASP 8
  • 9. Active defense - know thy language function is_even(n) { var parameter_is_even = (n % 2) == 0 ? true : false; return parameter_is_even; } alert(is_even(16)); OWASP 9
  • 10. Result OWASP 10
  • 11. How to analyze malware JavaScript?  Know JavaScript!  Run the code & observe effects in a controlled environment Overload functions  eval  String.fromCharCode  Deobfuscate parts of code  Be patient and creative OWASP 11
  • 12. JavaScript analysis...  Is rather heuristics than algorithm  Is rather manual than automatic  Human is required  Tools help greatly, but they're not perfect OWASP 12
  • 13. Practice OWASP
  • 14. jsunpack  Runs JS inside SpiderMonkey [mozilla.org]  JS fetched from URL, PCAP, JS/HTML file…  SM is modified to include:  DOM emulation  browser objects emulation  onload() event  monitors eval(), setTimeout() and others  scans the code using signatures file OWASP 14
  • 15. jsunpack - weak points  Emulates browser  Code that won't run (dead branches) will be checked with signatures only OWASP 15
  • 16. Evading detection if (fake_browser) { do_no_harm(); } else { redirect_to_malicious_website(); // or obfuscate an exploit }  We need to detect being run in jsunpack OWASP 16
  • 17. How to detect jsunpack? Many, many ways:  Bad implementation of window.location fake_browser = window.location.host.match('/'); pliku window.location.host = ścieżka do  It adds its own global variables fake_browser = (typeof my_location != "undefined"); // my_navigator, my_activex, my_element, // the_activex, app, ... OWASP 17
  • 18. How to detect jsunpack?  It overloads some functions fake_browser = (window.open.toString().match(/print/)); fake_browser = (alert.toString().match(/{s*}/));  Objects emulation has missing spots fake_browser = (typeof PluginArray.prototype.refresh == "undefined"); fake_browser = (document.title == 'My Title'); OWASP 18
  • 19. Jsunpack - bonus  jsunpack runs not only JavaScript <script type="text/dummy"> // good enough for jsunpack </script>  Code will be run in jsunpack, but not in browsers OWASP 19
  • 20. Note to online viewers: Demos require checking and running the files locally - see attached docs DEMO 1 index.php / js.js - sandbox detection (modify js.js to test different techniques) jekyll2.html - Dr Jekyll attack js.js - HTML hack (shortest jsunpack disabler) github.com/koto/owasp-malicious-javascript/ OWASP 20
  • 21. jsunpack - summary  You could easily detect being run in jsunpack sandbox  When detected, you just skip doing bad stuff  If malware code is obfuscated, it will not be detected with signatures You go under the radar of jsunpack analysis OWASP 21
  • 22. Dean Edwards' Unpacker A JavaScript Decompressor [dean.edwards.name]  Reverses Dean Edward's packer  Packer works like this: eval(function(p,a,c,k,e,r){/*code*/}(para, meters)) /* which is the same as */ var packer = function(p,a,c,k,e,r) {/**/}; var s = packer(para,meters); eval(s); OWASP 22
  • 23. Unpacker - step 1  Replace eval() with string assignment // packed code is in input var input="eval(function(p,a,c,k...."; eval("var value=String" + input.slice(4)); // cut "eval" // executed code will be: var value=String(function(p,a,c,k..);  value holds decompressed code OWASP 23
  • 24. Unpacker - step 1  Replace eval() with string assignment // packed code is in input var input="eval(function(p,a,c,k...."; eval("var value=String" + input.slice(4)); // cut "eval" // executed code will be: var value=String(function(p,a,c,k..);  value holds decompressed code  But! we're blindly executing cut&pasted code! OWASP 24
  • 25. Unpacker - step 2  Use Function.toString() to display the code eval( "var unpacked = function() {" + value + "}" ); alert(unpacked.toString());  Unpacked code WILL NOT RUN, it wil just print!  Disclaimer - the real code is a bit different, but the concept is the same OWASP 25
  • 26. Dean Edwards Unpacker - weak points  Concatenating strings and executing the resulting code (injection, anyone?)  Using a constant - we cut first 4 characters without looking at them  eval() without any validation  Depends on Function.toString() to print the code OWASP 26
  • 27. Dean Edwards Unpacker - disarming  eval() uses a single parameter  String() uses a single parameter  ...but you could give more :) eval("code"); eval("code", "ignored"); eval("code", malicious()); String("code", malicious());  Arbitrary code execution without changing p,a,c,k,e,r function! OWASP 27
  • 28. Dean Edwards Unpacker - disarming eval(function(p,a,c,k,e,r){...}(para,mete rs),malicious()); var value=String(function(p,a,c,k,e,r){...}(p ara,meters),malicious());  malicious() will execute in packed code and in unpacker OWASP 28
  • 29. Dean Edwards Unpacker - disarming What can we do in malicious()?  Unpacker uses Function.toString()  Let's override it!  malicious() is e.g. obfuscated: Function.prototype.toString = function() { return 'harmless code'; } OWASP 29
  • 31. Dean Edwards Unpacker - point of concept OWASP 31
  • 32. High interaction client honeypots Capture-HPC [projects.honeynet.org] as an example  Code is run in real browser in a virtual machine  Server serves URL list to visit  Client starts browsers and waits…  Code side-effects are monitored  Filesystem  Registry  Processes  If anything suspicious happens with the system, URL is reported to server as a malware OWASP 32
  • 33. High interaction client honeypots  Runtime environment is the same  There is no emulation Could we detect we're traced? OWASP 33
  • 34. Weak point OWASP 34
  • 35. High interaction client honeypots - robot  Doesn't move mouse  Doesn't click  Doesn't drag  Doesn't navigate  Is "stupid" OWASP 35
  • 36. High interaction client honeypots - user  Moves mouse  Clicks  Drags  Navigates  Is stupid OWASP 36
  • 37. Honeypots – social engineering OWASP 37
  • 38. Honeypots – social engineering OWASP 38
  • 39. Honeypots - summary  No emulation layer to detect  Code is run in real browser  Weakest point is the lack of human element  Just run the code after detecting an interaction with the page OWASP 39
  • 40. Summary  Obfuscation can only make analysis slower  Code can actively defend against analysis  Human is required to do a complete analysis  Analysis requires strong skills  Automatic tools can be fooled  detect emulation differences  errors  lack of full interaction with a webpage OWASP 40
  • 41. Links Demo source: github.com/koto/owasp-malicious-javascript Tools  jsunpack.blogspot.com  dean.edwards.name/unpacker/  projects.honeynet.org/capture-hpc  malzilla.sourceforge.net Obfuscation and analysis  isc.sans.org/diary.html  www.malwareguru.org  delicious.com/koto/obfuscation  closure-compiler.appspot.com JavaScript  www.slideshare.net/ferrantes/just-advanced-javascript  jsninja.com krzysztof@kotowicz.net http://blog.kotowicz.net OWASP 41