Detecting Obfuscated Javascripts from Known and Unknown Obfuscators Using Machine Learning

Detecting Obfuscated Javascripts from Known and Unknown Obfuscators Using Machine Learning

International Journal on Advances in Security, vol 9 no 3 & 4, year 2016, http://www.iariajournals.org/security/ 196 Detecting Obfuscated JavaScripts from Known and Unknown Obfuscators using Machine Learning Bernhard Tellenbach Sergio Paganoni Marc Rennhard Zurich University of Applied Sciences SecureSafe / DSwiss AG Zurich University of Applied Sciences Switzerland Zurich, Switzerland Switzerland Email: [email protected] Email: [email protected] Email: [email protected] Abstract—JavaScript is a common attack vector to probe for On the other hand, the only legitimate reason to obfuscate known vulnerabilities to select a fitting exploit or to manipulate a script is to protect intellectual property. Our evaluation of the Document Object Model (DOM) of a web page in a harmful the prevalence of such scripts on the Alexa top 5000 home way. The JavaScripts used in such attacks are often obfuscated to make them hard to detect using signature-based approaches. pages suggests that this is fairly uncommon. One reason for On the other hand, since the only legitimate reason to obfuscate this might be that a lot of JavaScript code on these pages is a script is to protect intellectual property, there are not many code from JavaScript libraries that are available to the public scripts that are both benign and obfuscated. A detector that anyway. If it is indeed the case that there are not too many can reliably detect obfuscated JavaScripts would therefore be a scripts that are both benign and obfuscated, it should be easy valuable tool in fighting JavaScript based attacks. In this paper, we compare the performance of nine different classifiers with to capture these with a whitelist. A detector that can reliably respect to correctly classifying obfuscated and non-obfuscated detect obfuscated JavaScript code would then be a valuable scripts. For our experiments, we use a data set of regular, tool in fighting malicious JavaScript based attacks. But even minified, and obfuscated samples from jsDeliver and the Alexa if there would be a lot of obfuscated benign JavaScript code, a top 5000 websites and a set of malicious samples from MELANI. detector could play an important role in that it helps to filtering We find that the best of these classifiers, the boosted decision tree classifier, performs very well to correctly classify obfuscated and such scripts and feed them to a component that performs a non-obfuscated scripts with precision and recall rates of around more in-depth analysis. 99 percent. The boosted decision tree classifier is then used to assess how well this approach can cope with scripts obfuscated The most common method to address the problem of by an obfuscator not present in our training set. The results malicious JavaScripts is having malware analysts write rules show that while it may work for some obfuscators, it is still for anti-malware or intrusion detection systems that identify critical to have as many different obfuscators in the training set common patterns in obfuscated (or non-obfuscated) malicious as possible. Finally, we describe the results from experiments to scripts. While signature-based detection is good at detecting classify malicious obfuscated scripts when no such scripts are included in the training set. Depending on the set of features known malware, it often fails to detect it when obfuscation used, it is possible to detect about half of those scripts, even is used to alter the features captured by the signature. Fur- though those samples do not seem to use any of the obfuscators thermore, keeping up with the attackers and their obfuscation used in our training set. techniques is a time consuming task. This is why a lot of re- Index Terms—Machine learning; Classification algorithms; search effort is put into alternative solutions to identify/classify JavaScript; Obfuscated; Malicious malicious JavaScripts. See Section V for details. I. INTRODUCTION In this paper, we analyze and extend our approach to automatically detect obfuscated JavaScripts using machine JavaScript is omnipresent on the web. Almost all websites learning presented in [1]. Our paper makes the following three make use of it and there are a lot of other applications, contributions. First, we make use of the cloud based Microsoft such as Portable Document Format (PDF) forms or HyperText Azure Machine Learning Studio [2] to quickly create, train, Markup Language (HTML) e-mails, where JavaScript plays evaluate and deploy predictive models of nine different clas- an important role. This strong dependence creates attack sifiers and to do an analysis of what the most descriptive opportunities for individuals by using malicious JavaScripts, features are. The top performing one, the boosted decision which may provide them with an entry point into a victim’s tree classifier, was not among the three classifiers tested in [1]. system. The main functionalities of a malicious JavaScript Second, using the boosted decision tree classifier we perform are reconnaissance, exploitation, and cross-site scripting (XSS) a comprehensive analysis of how well this approach can cope vulnerabilities in web applications. with scripts obfuscated by an obfuscator not present in our The JavaScripts used in such attacks are often obfuscated to training set. As pointed out in [1], such an analysis would be make them hard to detect using signature-based approaches. quite desirable since malicious JavaScripts are likely to make 2016, © Copyright by authors, Published under agreement with IARIA - www.iaria.org International Journal on Advances in Security, vol 9 no 3 & 4, year 2016, http://www.iariajournals.org/security/ 197 use of a custom obfuscation approaches. Finally, we describe var a="ale"; the results from experiments to classify malicious obfuscated a +="rt("; a +="’hello’"; scripts when no such scripts are included in the training set. a +=");"; For our experiments, we use the same data set as in [1] with eval(a); two important modifications. First, we use the scripts from the Listing 1. A simple example of code unfolding Alexa top 5000 instead of the top 500 websites and second, we perform a rigorous preprocessing to get rid of scripts that Note that the obfuscated files can also be considered are identical or almost the same as other scripts in the data minified. The obfuscators remove whitespaces and make the set (see Section III). Not doing this could produce results that scripts more compact. Scripts that are first minified and then are better than they should be if there are scripts that appear obfuscated look similar or are the same as when only obfus- on almost all of the pages (e.g., Google Analytics scripts). cation is applied. Applying obfuscation and then minification The rest of the paper is organized as follows. Section II might lead to partial de-obfuscation (e.g., decoding of encoded briefly explains the different JavaScript classes that we dis- strings) and is therefore unlikely to be used in practice. tinguish in this work. In Section III, we discuss our data set, D. Malicious JavaScripts the preprocessing steps performed, feature selection and the machine learning methodology and tools. Section IV presents Whether or not a JavaScript is malicious is a question of its our results, followed by a discussion of results IV. Section V semantics and not of its syntax. Hence, a malicious JavaScript discusses related works and Section VI concludes the paper. could be a regular, minified or obfuscated one. Previous work sometimes conflates obfuscation with maliciousness. In this II. SYNTACTIC AND FUNCTIONAL VARIETIES OF work and in prior art (see [4]), it is explicitly stated that JAVASCRIPT neither is all obfuscated code malicious nor is all malicious code obfuscated. However, in practice, it appears that at least Client-side JavaScript for JavaScript-enabled applications for now, most malicious scripts are indeed obfuscated, as all can be attributed to one of the following four classes: regular, of the recent malicious JavaScripts samples we collected in minified, obfuscated, and malicious. Note that only regular, the wild were obfuscated. minified, and obfuscated are disjoint classes and that we distinguish only obfuscated, non-obfuscated, and malicious III. MACHINE LEARNING APPROACH TO JAVASCRIPT JavaScripts in the reminder of this paper. CLASSIFICATION A. Regular JavaScripts In order to evaluate the feasibility and accuracy of dis- tinguishing between different classes of JavaScript code, we The regular class contains the scripts as they have been adopted a classic machine learning approach. We collected a written by their developers. These scripts are typically easy to data set containing a number of JavaScripts representing each read and understand by human beings. of the classes of interest, i.e., non-obfuscated, obfuscated and B. Minified JavaScripts malicious. For each of the samples in the data set we extracted a set of discriminatory features, which we list in Table III be- Minified scripts are more compact versions of the regular low. The extracted features form fixed-length feature vectors, scripts. To achieve this, minifiers such as the YUI Compres- which in turn are used for training and evaluation of classifiers. sor [3] remove space and new line characters that only exist to make the code easier to read for humans. Some of the minifiers A. Data Set do also rename functions and variables to get rid of long Our data set consists of data from three different sources: function or variable names. While this makes the scripts harder (1) the complete list of JavaScripts available from the jsDelivr to read and understand for a human, the program flow stays content delivery network, (2) the Alexa Top 5000 websites the same. Minification main purpose is to reduce bandwidth and (3) a set of malicious JavaScript samples from the Swiss usage when loading JavaScripts. Reporting and Analysis Centre for Information Assurance MELANI. C. Obfuscated JavaScripts Obfuscation tools keep the original functionality of the code jsDeliver: contains a large number of JavaScript libraries and but modify the program flow with the goal to make it hard to files in both regular and minified form.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us