In this section, we will see how to use machine learning to detect when a JavaScript file is obfuscated. Doing so can serve to create a binary feature, obfuscated or not, to be used in benign/malicious classification, and can serve also as a prerequisite step to deobfuscating the scripts.
Detecting obfuscated JavaScript
Getting ready
Preparation for this recipe involves installing the scikit-learn package in pip. The command is as follows:
pip install sklearn
In addition, obfuscated and non-obfuscated JavaScript files have been provided for you in the repository. Extract JavascriptSamplesNotObfuscated.7z to a folder named JavaScript Samples. Extract JavascriptSamplesObfuscated.7z to a folder named JavaScript Samples...