scieee AI-readable full text Open interactive document viewer

Ransomware note detection techniques using supervised machine learning

Trujillo, Kim Kip

Abstract

This project is about the detection of ransomware by detecting ransomware notes using supervised machine learning. The goal of the project is to study old ransomnote data to detect notes used in new ransomware campaigns. This is done by extracting the word combinations out of fifty-nine ransom notes and fifty-nine non-ransom notes to define a binary (is or is-not) system of text classification. The hypothesis posed by this project is: A machine learning model trained using ransomnotes from past campaigns will be able to detect notes made in future campaigns. Two machine learning (ML) algorithms are studied; Decision Trees and Support Vector machines (SVM). These ML algorithms were chosen for their ease of implementation and low data requirements. The studied dataset has fewer than sixty raw text documents, therefore models requiring a minimal amount of training data, such as SVM, are prioritized. After training and testing the ML models, the performance of the models is verified using a separate and newer dataset. Most of the project is implemented using Python for application logic and data manipulation while Scikit Learn (sklearn) was used for the training and analysis of the machine learning models. Data is stored using regular files. Incremental comparisons are made using varying levels of data cleaning and feature selection to study which methodologies produce ideal ML models capable of detecting ransomware notes with a low false positive rate. The results of this project are favorable to the goal - it is demonstrated that a single ML model can recognize a ransom note by checking as few as twenty features. Shorter notes tend to have fewer features to check and therefore require an ML model biased towards false positives for reliable detection. It is proposed to combine the output of multiple models in a stacked or "ensemble" configuration [1] to create a system for indicating how confident a positive detection is.

Full text

Ransomware note detection techniques using supervised machine learning. Master’s Thesis submitted to the Faculty of the Escola Tècnica d’Enginyeria de Telecomunicació de Barcelona Universitat Politècnica de Catalunya on September 15, 2022, in partial fulfillment of the requirements for a master’s degree in Cybersecurity Authored by: Kim Kip Trujillo Academic Advisor: René Serral Page 2 of 42 Summary (ISO 214) This project is about the detection of ransomware by detecting ransomware notes using supervised machine learning. The goal of the project is to study old ransomnote data to detect notes used in new ransomware campaigns. This is done by extracting the word combinations out of fifty-nine ransom notes and fifty-nine non-ransom notes to define a binary (is or is-not) system of text classification. The hypothesis posed by this project is: A machine learning model trained using ransomnotes from past campaigns will be able to detect notes made in future campaigns. Two machine learning (ML) algorithms are studied; Decision Trees and Support Vector machines (SVM). These ML algorithms were chosen for their ease of implementation and low data requirements. The studied dataset has fewer than sixty raw text documents, therefore models requiring a minimal amount of training data, such as SVM, are prioritized. After training and testing the ML models, the performance of the models is verified using a separate and newer dataset. Most of the project is implemented using Python for application logic and data manipulation while Scikit Learn (sklearn) was used for the training and analysis of the machine learning models. Data is stored using regular files. Incremental comparisons are made using varying levels of data cleaning and feature selection to study which methodologies produce ideal ML models capable of detecting ransomware notes with a low false positive rate. The results of this project are favorable to the goal – it is demonstrated that a single ML model can recognize a ransom note by checking as few as twenty features. Shorter notes tend to have fewer features to check and therefore require an ML model biased towards false positives for reliable detection. It is proposed to combine the output of multiple models in a stacked or “ensemble” configuration [1] to create a system for indicating how confident a positive detection is. Page 3 of 42 Contents 1 - List of Abbreviations and Symbols ...................................................................................................... 6 2 - Introduction ....................................................................................................................................... 7 2.1 – Motivation .................................................................................................................................. 7 2.2 Background of Toolkits and Technologies used ............................................................................ 8 2.2.1 - Python .................................................................................................................................. 9 2.2.2 – NLTK .................................................................................................................................... 9 2.2.2.1 - Tokens ........................................................................................................................... 9 2.2.3 - Bag of Words Vector Model ................................................................................................. 9 2.2.4 - Corpora ................................................................................................................................ 9 2.2.5 – Scikit-learn ......................................................................................................................... 10 2.2.5.1 - Test train split ............................................................................................................. 10 2.2.5.2 - Decision Trees ............................................................................................................. 10 2.2.5.3 - Support Vector Machines ........................................................................................... 10 3 - Body of Work ................................................................................................................................... 11 3.1 - Program Logic ........................................................................................................................... 12 3.2 - The Data .................................................................................................................................... 13 3.2.1 – The Corpora ....................................................................................................................... 13 3.2.1 - Step 1: Inspect Data ........................................................................................................... 13 3.2.2 - Step 2: Clean Data .............................................................................................................. 13 3.2.3 - Step 3 Feature selection .................................................................................................... 14 3.2.3.1 - Corpus1 Word Frequencies ........................................................................................ 15 3.2.3.2 - Corpus2 Word Frequencies ........................................................................................ 16 3.2.3.3 - Corpus3 Word Frequencies ........................................................................................ 16 3.2.3.4 - Stopword Removal ...................................................................................................... 16 3.2.3.5 - Dictionary Building ...................................................................................................... 17 3.2.3.6 - Vectorization ............................................................................................................... 17 3.2.3.6.1 - Example Vector .................................................................................................... 17 3.2.3.7 - Vector Length .............................................................................................................. 18 3.2.4 - Step 4 Dataset Preparation ................................................................................................ 18 3.2.4.1 - Test / Train Split .......................................................................................................... 18 3.2.4.2 - Correlation Analysis .................................................................................................... 18 3.2.4.3 - Vector size ................................................................................................................... 18 3.3 - Step 5 Machine Learning Training ............................................................................................ 18 3.3.1 - Confusion Matrix ............................................................................................................... 19 3.3.1.1 - Example confusion matrix .......................................................................................... 19 Page 4 of 42 3.3.2 - The Decision Trees ............................................................................................................. 19 3.3.2.1 - Decision tree depth ..................................................................................................... 20 3.3.2.2 - Corpus 1 ...................................................................................................................... 21 3.3.2.3 - Corpus2 ....................................................................................................................... 22 3.3.2.4 - Corpus3 ....................................................................................................................... 23 3.3.2.5 - Conclusions about corpora performance ................................................................... 24 3.3.2.6 - Decision Trees Correlation Tuning .............................................................................. 24 3.3.2.7 - Vector length tuning ................................................................................................... 26 3.3.3 - The Support Vector Machines ........................................................................................... 28 3.3.3.1 - Tunable attributes ...................................................................................................... 28 3.3.3.2 - Hyper-parameter Tuning ............................................................................................ 28 3.3.3.3 - Combined GridSearch and Correlation threshold tuning ........................................... 28 3.3.3.4 - Vector length tuning ................................................................................................... 31 3.3.3.4.1 - Accuracy ............................................................................................................... 31 3.3.3.4.2 - Precision ............................................................................................................... 31 3.3.3.4.3 - Recall .................................................................................................................... 32 3.4 Step 6 - Testing and Validation ................................................................................................... 33 3.4.1 - The validation data ............................................................................................................ 33 3.4.2 - The Validation Parameters ................................................................................................ 33 3.4.3 - Results ................................................................................................................................ 33 3.4.3.1 - Decision Trees ............................................................................................................. 33 3.4.3.1.1 - Accuracy ............................................................................................................... 33 3.4.3.1.2 - Precision ............................................................................................................... 34 3.4.3.1.3 - Recall .................................................................................................................... 34 3.4.3.1.4 - Conclusions about Decision Trees Validation Performance ................................ 34 3.4.3.2 - Support Vector Machines ........................................................................................... 35 3.4.3.2.1 - Accuracy ............................................................................................................... 35 3.4.3.2.2 - Precision ............................................................................................................... 35 3.4.3.2.3 - Recall .................................................................................................................... 36 3.4.3.2.4 - Conclusions about support vector machines validation performance ................ 36 4 - Conclusions ...................................................................................................................................... 37 4.1 - Recommendations for future work .............................................................................................. 37 4.1.1 - Data cleaning ......................................................................................................................... 37 4.1.2 - Stemming and Lemmatization ............................................................................................... 37 4.1.3 - Test file truncation ................................................................................................................. 37 4.1.4 - Language Detection ............................................................................................................... 38 Page 5 of 42 4.1.5 - HTML and RTF ransomnote extraction .................................................................................. 38 5 - Bibliography ..................................................................................................................................... 39 Appendix A – Tools and Libraries used ................................................................................................. 41 Appendix B – Validation data (positive ransomnote samples) ............................................................. 42 Page 6 of 42 1 - List of Abbreviations and Symbols Accuracy - Accuracy classification score. In binary classification, this function is equal to the jaccard_score function. This score is used as a general measure of algorithm performance. AI – Artificial intelligence. A broad term used to describe a machine mimicking human intelligent behavior. Corpus / Corpora – a collection of words/documents/symbols which is to be treated as a data set. Corpora is the plural of the word corpus. Entropy – A measurement of disorder; and also a measure of purity. Entropy is used to determine how uncertain a machine learning model is of a decision. The goal of a machine learning model is to bring entropy down to zero. ML – A subset of artificial intelligence in which a machine can learn from data without being explicitly programmed. Precision - The precision is the ratio tp / (tp + fp) where tp is the number of true positives and fp the number of false positives. The precision is intuitively the ability of the classifier not to label as positive a sample that is negative. Ransomnote – A document used by cyber criminals to communicate to their victims. Ransomware – A generic term used for a type of malware which restricts access to a victims files until a set of demands have been met. Those demands are usually delivered by Ransomnote. Recall - The recall is the ratio tp / (tp + fn) where tp is the number of true positives and fn the number of false negatives. The recall is intuitively the ability of the classifier to find all the positive samples. Stopwords - words which frequently appear in any document and are expected to add minimal information during ML training. (e.g., ‘i', 'me', 'my', 'myself', 'we', 'our', 'ours') Test/Train Splits – How a dataset is divided into testing set and training set. Page 7 of 42 2 - Introduction 2.1 – Motivation The ransomware note is a common variable across all ransomware variants. It is a line of communication between attacker and victim stating all the facts of the situation with strategies designed to collect a payment. The core details of a ransomnote include the demands for payment, explanations about what happened to a victim’s files, contact details and instructions. Notes often end with a threat describing what happens if a victim is thinking about not paying. Every note is unique, yet they are all based on the same motivation and share a common goal. Ransomware threat actors are often reusing parts of ransom notes from prior ransomware campaigns. Darkside and ReVil are suspected of composing their ransomnotes from the same template [2]. When Ryuk disbanded and rebranded to Conti, the link was established through analysis of the ransomnotes the groups were using [3]. Attribution of an attack is often conducted by interpreting details in the ransomnote, though many groups choose to claim the attack to establish a reputation. Specialized services exist to associate a ransom note to its author, such as ID Ransomware 1 . Ransomnote collections like this have a flaw in that they are historical in nature and use signature or pattern-based detection strategies to identify notes. New threat actors (and their uniquely structured ransomnotes) are discovered based on community submissions. There is a gap in capability to detect ransomware notes never seen before. In general, the response to ransom notes is still performed manually. A traditional large enterprise environment typically has at minimum three human exchanges before a response is initiated. 1. User -> service desk analyst 2. Service desk analyst -> ticket 3. Ticket assignment to technician or escalation to a crisis team These handoffs are a risk of misinterpretation and prevent a rapid response to a rapidly deteriorating situation. This project aims to explore the opportunity of identifying ransom notes in real time, which can enable automated real-time responses to ransomware execution. This methodology of Ransomware detection is worth exploring because the ransomnote is a common attribute of Ransomware attacks. The families of malware have diverse behaviors which makes behavioral detection a complex topic, however the ransom note has a consistent presence. Furthermore, some families of ransomware such as BlackMatter write the ransom note before starting the encryption process [4]. Situations like these are an opportunity for prevention. 1 https://id-ransomware.malwarehunterteam.com/ Page 8 of 42 Included here is the Cyber Kill Chain as envisioned by Lockheed Martin. In this scenario, prior alerting was ineffective or missed entirely. The attackers have successfully delivered and installed their Ransomware payload and are starting or about to start on phase 7 – Actions on Objectives. An early detection for 0-day ransomware may not be possible, because malware is not Ransomware until it strikes. Once an attack has been initiated, the campaign is already deep into the cyber kill chain and has full command over a section of the network. A rapid response to the early stages of an attack is the most effective solution by preventing the encryption of files and limiting the time available to move laterally across a network. The solution proposed in this paper is a detection method for reactive incident response at stages 5 through 7 where a ransomnote may begin to make an appearance across network connections and file shares. By moving the mean time to respond 2 away from human timescales and into automated timescales, an opportunity for failure recovery is gained. 2.2 Background of Toolkits and Technologies used This research was conducted primarily using Python and Scikit Learn. The Machine learning models used are Decision Trees and Support Vector Machines. Data was handled using Numpy arrays and Pandas data frames. 2 https://cyberhoot.com/cybrary/mean-time-to-respond-mttr/ Page 9 of 42 2.2.1 - Python “Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.” 3 In the context of this project, Python is a scripting language which is well suited for text handling while also having a diverse set of powerful libraries to add capabilities such as advanced data structuring and machine learning. 2.2.2 – NLTK “NLTK is a leading platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning, wrappers for industrial-strength NLP libraries...” 4 The Natural Language Toolkit is a python library with advanced text handling properties. It contains tools and common corpora used for manipulating documents containing written language. 2.2.2.1 - Tokens A feature of the NLTK library is Tokenization – which is the division of sentence “strings” into lists of substrings. Sentence: “ You cannot stop the signal ” Tokens: ['You', 'cannot', 'stop', 'the', 'signal'] For this project, a token is a word. A word is anything between two spaces. Under this model, a piece of punctuation can be a valid word if it is surrounded by whitespace. 2.2.3 - Bag of Words Vector Model This project closely follows the “Bag of Words” model, which is a process for converting a document into a machine-readable object called a “vector”. The focus is placed on the words a document contains, while discarding all contextual information such as the ordering of those words. The power of this model is the simplicity of implementation and the low cost of computing it. 2.2.4 - Corpora Corpus is a general term for a collection of writing or knowledge. This project uses several corpora to generate datasets which train machine learning models. The corpora are composed of two distinct 3 https://www.python.org/doc/essays/blurb/ 4 https://www.nltk.org/ Page 16 of 42 3.2.3.2 - Corpus2 Word Frequencies 3.2.3.3 - Corpus3 Word Frequencies 3.2.3.4 - Stopword Removal The process of stopword removal is important to explore because the future methods of feature selection involve choosing the most frequent words present in ransom note samples. If the Page 17 of 42 stopwords are not removed, then these frequent “joining words” will dominate the selected features and prevent more unique words from being selected. The list of stopwords is at the discretion of the researcher, however this project used a stopword dataset provided by the NLTK [8]. stopwords = nltk.corpus.stopwords.words('english') Here is a graphical representation of the word frequencies when stopwords are removed: 3.2.3.5 - Dictionary Building The next step after tokenizing is to build a dictionary. The dictionary is a document which represents every uniquely appearing word across the whole corpus of documents. With the dictionary, every document can be translated into a machine-readable data type called a vector. Vectorization is a process of converting a document into an integer expression equivalent to the original document. The dictionary is a key component needed for the upcoming vectorization step because the dictionary is the object which associates the integer indices to the words. 3.2.3.6 - Vectorization For every document in the corpus, words are translated into the indexes where the word can be found within the dictionary. This approach allows for representing words with integers. With a vocabulary of known words (Dictionary) and a measure of the presence of the known words, the bag of words model [9] can be assembled. 3.2.3.6.1 - Example Vector Here is an example dictionary: Dictionary = [‘you’, ‘cannot’, ‘stop’, ‘the’, ‘signal’] The zero vector which represents this dictionary is: < 0, 0, 0, 0, 0 > The first zero represents the word “you” The second zero represents the word “cannot” The third zero represents the word “stop” The fourth and fifth zeros are “the” and “signal” And here are two documents which have been converted into vectors using the above dictionary: Document_1 = “you cannot stop me now” Document_1_Vector = < 1, 1, 1, 0, 0 > Document_2 = “Urgent, I need you to send the signal” Document_2_Vector = < 1, 0, 0, 1, 1 > Page 18 of 42 Observe how every place in the vector represents a word, and the index of that word is aligned to the index of the vector. Using these pieces of information, it is possible to translate a document into a vector. 3.2.3.7 - Vector Length The length of the vector is a direct measure of how many features are in use because every word is a feature, and every feature is an index in the vector. The most frequently occurring words across the corpora are selected from the dictionary and will be represented by a vector. Every document will have a vector which represents it. Documents containing words available in the vector will have that index in the vector occupied. If a document does not have any words in common with the ones used to build the vector, the values of the vector will be all zeroes. The bag of words model for this project uses binary (1 or 0) values to represent the presence of a keyword in the vector. There are several reasons for this: • Using a has or has-not relationship instead of word counts helps to reduce the weighting of positivity when larger documents are analyzed. • Implicit feature reduction by cutting the amount of data to analyze (word counts) • Emphasizing the importance of the relationship between words usage and not the quantities of words. 3.2.4 - Step 4 Dataset Preparation 3.2.4.1 - Test / Train Split The test / train split is a process of dividing the data into a fraction for machine learning training and a fraction for testing predictions made by the trained machine learning model. Typically, the split is performed using a random seed, however for research purposes the random seed was statically set to the value of 42 9 . Unless otherwise stated, the testing fraction is 70% of the available data while the training fraction is 30% of the data. 3.2.4.2 - Correlation Analysis Correlation analysis is a technique used to reduce the dimensionality of a dataset. It can improve performance of a ML model by reducing the complexity of the data, therefore making it easier for an algorithm to spot trends which aid in classification. This is a tunable component by means of adjusting a threshold. 3.2.4.3 - Vector size The vector size is simply the number of features which represent every document. This project uses words as features, therefore increasing the vector size directly increases the number of words studied by an ML algorithm. A larger vector gives more information. Due to the correlation analysis, the final vector size used may be reduced as features are removed. The limit to how large a vector can be is the size of the shortest note. Any vector size longer than this constraint will have trailing zeros due to lack of information. 3.3 - Step 5 Machine Learning Training At this phase, three corpora have been translated into vector arrays and those arrays have been split into testing and training subsets. The training sets are now fitted to the machine learning model, and 9 https://simple.wikipedia.org/wiki/42_(answer) Page 19 of 42 then the corresponding test dataset is used to measure the accuracy of the predictions made by the newly trained AI. 3.3.1 - Confusion Matrix A confusion matrix is a useful tool for visualizing the quality of predictions made by a particular instance of a machine learning model. It visually represents where incorrect predictions were made by mapping the expected results against the predictions made. This is displayed in a two-by-two matrix containing the fractions of correct predictions and the fractions of incorrect predictions. 3.3.1.1 - Example confusion matrix The values on every row and column of a confusion matrix will sum to the value of 1. A high scoring model will have numbers close to one in the True Positive and True Negative boxes and numbers close to zero in the False Positive and False Negative boxes. The numbers in the boxes represent the percentage of values in each result class. Interpretation of a confusion matrix is valuable for understanding which predictions were incorrect and where those incorrect predictions were placed. The confusion matrix is used in this project for tuning a given model by a process of experimental changes and comparison of the results. Testing involves data not previously seen by the model during training and is therefore an acceptable simulation of how well the model will perform with new data. 3.3.2 - The Decision Trees There will be a decision tree model for each of the three prepared corpus. There are three corpus variants, therefore there will be three series of trained decision trees. There are three tunable attributes used by this ML model: 1. Decision tree depth 2. Correlation value for data pruning (1-100%) 3. Number of keywords selected (vector size) Page 20 of 42 3.3.2.1 - Decision tree depth It is important to note that re-execution of model training is always performed using the same test & train split. Results are achieved experimentally by increasing and decreasing the tree size and measuring overall Accuracy, Precision and Recall. The depth can be tuned immediately to expose the ideal corpus to use for further tuning. A series of fourteen decision tree depths is explored. The accuracy, precision and recall statistics are plotted for each corpus preparation strategy. The first corpus has the highest accuracy of the three possible opportunities. This is the corpus which has been manipulated the least. Corpus2 and Corpus3 remain consistent with each other and have worse accuracy than Corpus1. The precision of Corpus1 dominates the other strategies for nearly the whole graph. Corpus3 is competitive against Corpus 1 at a shallow depth and at depths beyond eleven. E E T EE E T orpus recision t orpus recision t orpus recision t Page 21 of 42 Corpus1 has the highest recall across the whole chart. Corpus2 and Corpus3 fluctuate between 85% and 90% recall. Overall, Corpus1 has the highest precision and accuracy which is favorable for the reduction of false positives. Additionally, Corpus1 also has the best recall. This indicates that feature reduction and data cleaning have impacted the results negatively. The decision tree performs best when it is trained using raw data. A depth of three has the highest accuracy and precision. 3.3.2.2 - Corpus 1 Here is a graphical representation of the decision tree trained using Corpus1 with a tree depth set to 3. Here is the confusion matrix for this decision tree. E E T EE E T orpus ecall t orpus ecall t orpus ecall t Page 22 of 42 The confusion matrix above shows the best performance we can expect to see from the decision trees. Observe the 6.4% false negative rate and a 2.6% false positive rate. Objectively these are not bad results, however for a file scanning application, these numbers need to be much closer to zero to be effective, especially the false positive rate. 3.3.2.3 - Corpus2 Here is a visual representation of a decision tree trained using Corpus2, which has stopwords removed and still contains punctuation. This tree has a much more complex appearance to it than the tree for Corpus1 due to the presence of more right leaves. This indicates that this model needs to divide the dataset into smaller groupings to achieve a sufficiently low entropy for confident classification. Here is the confusion matrix for this decision tree: Page 23 of 42 3.3.2.4 - Corpus3 Here is a visual representation of the decision tree trained with Corpus3. The tree for Corpus3 tree has the same shape as the tree for Corpus2. This indicates that it has the same characteristics (and problems) as the model trained by Corpus2. It is lacking in information which divides the data into large groups. Here is the confusion matrix for the model trained using Corpus3. Page 24 of 42 Comparing this matrix to the one for Corpus2 indicates that this model performs slightly better by reducing the number of false negatives from 15% to 9%. 3.3.2.5 - Conclusions about corpora performance Overall, all three of these trees are exhibiting favorable results with measured accuracies at or above 90%, however further analysis using the confusion matrices reveals that the high accuracy is indicative of a bias towards positive detection. These are issues which can be partially corrected with some model tuning. The best results were obtained with Corpus1 (stopwords and punctuation intact) at a tree depth of three, therefore all tuned models will be trained using this selection of feature reduction techniques. 3.3.2.6 - Decision Trees Correlation Tuning Correlation analysis is a feature reduction strategy. This process reduces the length of the vector and ensures the relationship between vector values does not exceed a specified correlation threshold. Values which are highly correlated contain the same information and can therefore be used interchangeably in the dataset, therefore only one of those values is worth keeping. The results obtained up to this point used a correlation value of 0.90 (90%). Values which had a correlation higher than 90% are considered as a duplicate and reduced to a single feature. This value can be adjusted experimentally to discover the optimal value. The following graphic depicts the results of adjusting the correlation threshold from 45% to 100% in 5% increments. Page 25 of 42 From the data in the graph, Corpus1 outperforms the others in all cases and performs the best at a Correlation Threshold of one. This means that this model performs best when the correlation threshold feature is turned off causing no features to be removed. Below are the precision and recall graphs. Observe how corpus1 overtakes the other two strategies upon reaching a threshold of 70%. 70% 75% 80% 85% 90% 95% 100% 45 50 55 60 65 70 75 80 85 90 95 100 ACCURACY CORRELATION THRESHOLD (%) ACCURACY BY CORPUS (TESTING) Corpus1-Accuracy Corpus2-Accuracy Corpus3-Accuracy 70% 75% 80% 85% 90% 95% 100% 45 50 55 60 65 70 75 80 85 90 95 100 PRECISION CORRELATION THRESHOLD (%) PRECISION BY CORPUS (TESTING) Corpus1 Precision-t Corpus2 Precision-t Corpus3 Precision-t Page 32 of 42 3.3.3.4.3 - Recall The highest recall score is held by Corpus1, and the best point on the graph is when the vector length is close to fifteen. Overall, Accuracy, Precision and Recall all have peaks at a vector length of fifteen. This would indicate that the optimum vector length is fifteen. To evaluate this, a model is retrained using Corpus1, with Correlation Threshold set at 1, with GridSearchCV enabled and a vector size of fifteen. Below is the resulting confusion matrix. While the Accuracy data during vector tuning may suggest that a vector size of fifteen is optimal, Experimental results indicate a loss of 3% accuracy for True Positive. The Vector size will remain at 20 for the testing and validation phase. 80% 85% 90% 95% 100% 510 15 20 25 30 35 40 45 50 RECALL VECTOR LENGTH (FEATURE COUNT) RECALL BY CORPUS SVM VECTOR LENGTH Corpus1 Recall-t Corpus2 Recall-t Corpus3 Recall-t Page 33 of 42 3.4 Step 6 - Testing and Validation The goal of this project is to train a machine learning algorithm on historical data to be able to make real-time detections on future data. Up until now, only data from the Lemmou dataset has been tested. This next phase involves performing predictions on ransomware notes which were published after the Lemmou dataset ceased adding note samples. The final commit on the Lemmou ransomnote repository is July 30th, 2019. Any ransomware note published after this date is considered a future note which is valid for making detections about ransomware notes published in the future. 3.4.1 - The validation data The table in Appendix B is a list of ten ransomware notes published after July 2019. The note data from this list is what will be used to validate the model. The collection of negative samples is taken from a different section of the 20_newsgroup dataset [6], titled “sci.med” – which is a different series of documents under the topic of medicine. Ten notes were selected from this set. In total, the validation step is made of twenty note samples. 3.4.2 - The Validation Parameters The Vector size will be set to 20 features. The threshold correlation is varied from 80% to 100% to discover the ideal setting. Decision Tree Depth is set to 3 for every model. SVM GridSearch will remain on for every model. 3.4.3 - Results 3.4.3.1 - Decision Trees 3.4.3.1.1 - Accuracy 40% 50% 60% 70% 80% 90% 100% 80 82 84 86 88 90 92 94 96 98 100 ACCURACY CORRELATION THRESHOLD (%) ACCURACY BY CORPUS DT CORRELATION TUNING Corpus1 Accuracy-t Corpus2 Accuracy-t Corpus3 Accuracy-t Page 34 of 42 3.4.3.1.2 - Precision 3.4.3.1.3 - Recall 3.4.3.1.4 - Conclusions about Decision Trees Validation Performance The graphed data above demonstrates that Corpus1 remains to be an ideal choice, however Corpus2 or Corpus3 could be used instead when the correlation threshold is set between 80% and 90%. 40% 50% 60% 70% 80% 90% 100% 80 82 84 86 88 90 92 94 96 98 100 PRECISION CORRELATION THRESHOLD (%) PRECISION BY CORPUS DT CORRELATION TUNING Corpus1 Precision-t Corpus2 Precision-t Corpus3 Precision-t 50% 60% 70% 80% 90% 100% 80 82 84 86 88 90 92 94 96 98 100 PRECISION CORRELATION THRESHOLD (%) RECALL BY CORPUS DT CORRELATION TUNING Corpus1 Recall-t Corpus2 Recall-t Corpus3 Recall-t Page 35 of 42 3.4.3.2 - Support Vector Machines 3.4.3.2.1 - Accuracy 3.4.3.2.2 - Precision 50% 60% 70% 80% 90% 100% 80 82 84 86 88 90 92 94 96 98 100 ACCURACY CORRELATION THRESHOLD (%) ACCURACY BY CORPUS SVM CORRELATION TUNING Corpus1 Accuracy-t Corpus2 Accuracy-t Corpus3 Accuracy-t 50% 60% 70% 80% 90% 100% 80 82 84 86 88 90 92 94 96 98 100 PRECISION CORRELATION THRESHOLD (%) PRECISION BY CORPUS SVM CORRELATION TUNING Corpus1 Precision-t Corpus2 Precision-t Corpus3 Precision-t Page 36 of 42 3.4.3.2.3 - Recall 3.4.3.2.4 - Conclusions about support vector machines validation performance Through validation, it can be observed that Corpus1 is the ideal data preparation method to train the most accurate model. It achieves the highest measured accuracy, precision and recall when the correlation threshold is disabled. 0% 20% 40% 60% 80% 100% 80 82 84 86 88 90 92 94 96 98 100 PRECISION CORRELATION THRESHOLD (%) RECALL BY CORPUS SVM CORRELATION TUNING Corpus1 Recall-t Corpus2 Recall-t Corpus3 Recall-t Page 37 of 42 4 - Conclusions While each note is unique to some degree, there exists strong parallels between different notes. By studying the language used to make up a ransom note, it is possible to train a machine learning algorithm to identify with a high degree of accuracy a note which it has never seen before. The preparation of the training dataset has a strong role in how successful the ML model will be in note detection. Through experimentation, it is discovered that stopwords and punctuation are useful features for machine learning models in situations where note samples are in short supply. Attempts to improve the models by removing punctuation and stopwords only served to make predictions worse in most situations. Through validation, it is demonstrated that ransomnotes used in old campaigns contain enough information to accurately detect future ransomnotes. The most frequently used words are a pattern which exists throughout a majority of ransomnotes and is therefore something a ML model is well suited to detect. Overall, the results of this project are favorable to the goal – it is demonstrated that a single ML model can recognize a ransom note by checking as few as twenty features. Shorter notes tend to have fewer features to check and therefore require an ML model biased towards false positives for reliable detection. To improve detections in real world implementations of a ransom note detector, I propose that it be implemented in an “ensemble” configuration [1] to create a system for indicating how confident a positive detection is. By leveraging multiple ML models, higher confidence of true positive is had by high precision models, while a large coverage of note variants is achieved through high recall models. 4.1 - Recommendations for future work 4.1.1 - Data cleaning Early in the design phases of this project, a special variable like the ##URL## and ##EMAIL## variables were conceived for crypto wallet addresses. This special variable was planned to be ##CRYPTO##. An issue with this variable is that the dataset used in this project often had redacted notes where the crypto wallet addresses were removed. Because of this detail, it was deemed not worth the time and effort to implement. 4.1.2 - Stemming and Lemmatization A feature of the NLTK library [8] which may be worth exploring is NLTK.STEM. This is another feature reduction method which attempts to find the root of words by shortening or swapping for a common root word. This would remove pluralization and other similar “morphing” so that only a root word remains. This feature was not implemented because most of the feature reduction strategies employed by this project did not yield better results than the raw data. If a larger dataset is available to be studied, this is a worthwhile feature to implement. 4.1.3 - Test file truncation The methods used in ML training made the vectors resistant to bias from word frequency, however it is not invulnerable to false positives from large documents. The ransomnotes used to train these models were no larger than 1429 words. A large document (such as a book) would fill the vector due to the presence of a larger set of words than the data studied. The following bash shell script is one example of how to truncate a file to be an appropriate length to better match the training data. #!/bin/bash Page 38 of 42 for f in ./*.txt; do truncate -s 13500 $f done This project had brief note samples in all cases, however future research may not. It is recommended that future versions of document handling should employ a truncator like the one posed here before submitting to an ML for prediction. 4.1.4 - Language Detection The model is trained using English. Results are likely to be sporadic or unpredictable when a language different from English is submitted for analysis. 4.1.5 - HTML and RTF ransomnote extraction This project is focused strictly on text processing. Higher level formats which need analysis must first be reduced to a text format. It was observed that the HTML ransomnotes often had multiple variations of the same ransomnote written in several languages. Future versions of this work should ensure that submitted samples are being handled in the same language as their feature reduction methodologies. For example: English stopwords should not be removed from Spanish text. Alternatively, a language agnostic approach could potentially be developed using minimal feature reduction and processing. Page 39 of 42 5 - Bibliography [1] F. Güneş, "Why do stacked ensemble models win data science competitions?," May . [Online]. Available: https://blogs.sas.com/content/subconsciousmusings/2017/05/18/stackedensemble-models-win-data-science-competitions/. [Accessed Sep 2022]. [2] Malwarebytes, "Threat spotlight: DarkSide, the ransomware used in the Colonial Pipeline attack," May 2021. [Online]. Available: https://www.malwarebytes.com/blog/news/2021/05/threat-spotlight-darkside-the- ransomware-used-in-the-colonial-pipeline-attack. [Accessed Aug 2022]. [3] L. Abrams, "Conti ransomware shows signs of being Ryuk's successor," Bleeping Computer, July 2020. [Online]. Available: https://www.bleepingcomputer.com/news/security/contiransomware-shows-signs-of-being-ryuks-successor/. [Accessed May 2022]. [4] "Dissecting BlackMatter Ransomware," cyble.com, August 2021. [Online]. Available: https://blog.cyble.com/2021/08/05/dissecting-blackmatter-ransomware/. [Accessed August 2022]. [5] Y. Lemmou, "lemmou/RansomNoteFiles [Dataset]," Jul 2019. [Online]. Available: https://github.com/lemmou/RansomNoteFiles. [Accessed Mar 2022]. [6] K. Lang, "CMU Text Learning Group Data Archives," Jan 2000. [Online]. Available: https://www.cs.cmu.edu/afs/cs.cmu.edu/project/theo-20/www/data/news20.html. [Accessed Jul 2022]. [7] K. K. Trujillo, "ai_ransomware_note_detection Public Code Repository," Aug 2022. [Online]. Available: https://gitlab.com/kipziptie/ai_ransomware_note_detection. [8] N. Project, "NLTK Documentation," Mar 2022. [Online]. Available: https://www.nltk.org/. [9] J. Brownlee, "A Gentle Introduction to the Bag-of-Words Model," Oct 2019. [Online]. Available: https://machinelearningmastery.com/gentle-introduction-bag-words-model/. [Accessed Mar 2022]. [10] C.-C. C. a. C.-J. L. Chih-Wei Hsu, "A Practical Guide to Support Vector Classification," May 2016. [Online]. Available: https://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf. [11] twitter:@ai_finesse, "SVM Kernels," 2021. [Online]. Available: https://www.aifinesse.com/svm/svm-kernels/. [Accessed August 2022]. [12] Scikit Learn, "SVM: Weighted samples," 2022. [Online]. Available: https://scikitlearn.org/stable/auto_examples/svm/plot_weighted_samples.html. [Accessed August 2022]. [13] Lockheed Martin, "the Cyber Kill Chain®," Jul 2022. [Online]. Available: https://www.lockheedmartin.com/en-us/capabilities/cyber/cyber-kill-chain.html. [14] Cyberhoot.com, "Cybrary Blog," Dec 2021. [Online]. Available: https://cyberhoot.com/cybrary/mean-time-to-respond-mttr/ . Page 40 of 42 [15] urlregex.com, "The Perfect URL Regular Expression," Apr 2022. [Online]. Available: https://urlregex.com/. [16] WHATWG, "URL Living Standard," Apr 2022. [Online]. Available: https://url.spec.whatwg.org/#concept-url. [17] emailregex.com, "Email Address Regular Expression That 99.99% Works. Disagree? Join discussion!," Aug 2022. [Online]. Available: https://emailregex.com/. [18] S. Ikeda, "Ransomware Gang Incorporates Website Defacement, Posts Ransom Notes to Public- Facing Websites," 10 Jun 2022. [Online]. Available: https://www.cpomagazine.com/cybersecurity/ransomware-gang-incorporates-website-defacement-posts-ransom-notes-to-public- facing-websites/. [19] S. T., "Entropy: How Decision Trees Make Decisions," Jan 2019. [Online]. Available: https://towardsdatascience.com/entropy-how-decision-trees-make-decisions-2946b9c18c8 . [20] scikit-learn developers , "API Reference," March 2022. [Online]. Available: https://scikitlearn.org/stable/modules/classes.html. [21] Wikipedia, "Precision and recall," Jun 2022. [Online]. Available: https://en.wikipedia.org/wiki/Precision_and_recall. [22] J.-L. L. a. E. M. S. Y. Lemmou, "In-Depth Analysis of Ransom Note Files," Computers, vol. 10, no 11, no. https://doi.org/10.3390/computers10110145, p. 145, 2021. Page 41 of 42 Appendix A – Tools and Libraries used • Decimal • Matplotlib • NLTK • Numpy • Pandas o dataframe • Python 3 o joblib o pickle o pprint o string o os o re o time • Scikit Learn o CountVectorizer o DecisionTreeClassifier o GaussianNB o GridSearchCV o metrics (accuracy_score, recall_score, precision_score) o SVC o train_test_split o tree • Seaborn o heatmap