<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Crovax on Medium]]></title>
        <description><![CDATA[Stories by Crovax on Medium]]></description>
        <link>https://medium.com/@crovax?source=rss-bbc74ef8ef79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PZTWZlkG3FJWX_MxK5Hw4Q.jpeg</url>
            <title>Stories by Crovax on Medium</title>
            <link>https://medium.com/@crovax?source=rss-bbc74ef8ef79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:38:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@crovax/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Extracting Malware Genetic Traits]]></title>
            <link>https://medium.com/@crovax/extracting-malware-genetic-traits-cd340de3679f?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd340de3679f</guid>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Wed, 16 Apr 2025 06:04:21 GMT</pubDate>
            <atom:updated>2025-04-16T15:15:11.118Z</atom:updated>
            <content:encoded><![CDATA[<p>· <a href="#9940">Overview</a><br>· <a href="#4654">Identifying potential traits</a><br>· <a href="#ca0f">Generating our malware trait</a><br>· <a href="#0c0f">Function structure</a><br>· <a href="#8034">Identifying traits across multiple samples</a><br>· <a href="#314e">Conclusion</a><br>· <a href="#2a72">Sources</a></p><h3>Overview</h3><p>Malware genetic trait analysis draws inspiration from the principles of biological genetics and evolution, treating code fragments, behaviors and techniques as heritable “traits”. By extracting certain traits from malware, we can use these traits to:</p><ul><li>Attribute malware traits to known threats actors or malware families</li><li>Track the evolution of malware across different variants.</li><li>Identify functionality (C2 decryption routine, anti-analysis checks)</li></ul><p>In this write up, we will look at a beginner friendly approach on how we can extract genetic information and create malware traits from it. We’ll use this information to identify the command and control decryption routine of a known malware family IcedID.</p><h3>Identifying potential traits</h3><p>The idea is to find an area of interest for us, that we want to use as a unique malware trait. We want to use something that will be persistence across as many samples as possible, with minor variations in the future. One of the traits can be the command and control (C2) function of the malware family. These tend to stay the same until a newer, updated version comes out. Even then, the changes made to the C2 routine can be small.</p><p>Below is the c2 decryption routine of IcedID, and the function we will make our trait based on.</p><blockquote>Hash of the IcedID sample<br> sha256: 35d30d73e4ab515b7120e65fdda108c94ccd7de5f7e0ad35e1f1c41b3ec6f53c</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*4BntOP7u4Uq5cUD0dLzFig.png" /><figcaption>IcedID C2 decryption routine</figcaption></figure><h3>Generating our malware trait</h3><p>So how do we create a genetic trait? Although there are numerous methods to this, we’ll focus on a straightforward, beginner-friendly approach. By simplifying the process, we can better understand the foundational concepts.</p><p>We are going to extract the opcodes from this function (using a tool called <a href="https://angr.io/">Angr</a>) and then simply hash the those opcodes to get our unique trait.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*YZgpORjWGw53VBfaQ9neHg.png" /><figcaption>Disassembly view of the C2 routine</figcaption></figure><p>Setting up angr is straightforward, pass it a file and set the auto_lib to false and then generate the CFG analyses. Since we know the address of the C2 routine, were going to loop through all the function addresses until we locate the one were interested in. Later, we will modularize this approach as function addresses can change from binary to binary.</p><pre>from hashlib import sha1<br>import angr<br><br><br>file = &quot;enter file path here&quot;<br><br>proj = angr.Project(file, auto_load_libs=False )<br>cfg = proj.analyses.CFG(normalize=True)<br>for function_addr  in cfg.functions:<br>    hex_addr = hex(function_addr)<br>    <br>    if hex_addr == &quot;0x1400027c8&quot;:<br>        function = cfg.functions[function_addr]<br>        raw_bytes = proj.loader.memory.load(function.addr, function.size).hex()<br>        print(f&#39;Full bytes: {raw_bytes}&#39;)<br></pre><p>Once the function has been located, and we have successfully retrieved all the opcodes, the output should look like this.</p><blockquote>Full bytes: 4533c04c8d0d2e480000492bc94b8d140849ffc08a42403202884411404983f82072eac3</blockquote><p>Now that we have the opcodes, all we need to do is hash them and we’ve created our genetic trait for IcedID.</p><pre>print(f&quot;Creating malware trait for {function.name}: {sha1(raw_bytes.encode()).hexdigest()}&quot;)</pre><blockquote>Output:</blockquote><blockquote>Creating malware trait for sub_1400027c8: 61537f309a31bdcfad5c7ff887ad57b6365cef90</blockquote><p>And that is it! Pretty simple, huh? Although this might work for a hand full of samples, if one of the basic blocks changes, the genetic trait we just created wont be good. So we’re going to expand this concept and perform the same actions on each basic block as well. This will expand our ability to catch potential changes in the routine, while still being able to identify the function.</p><h3>Function structure</h3><p>Before we move on to the next part, lets take a look at the function structure of the c2 decryption routine. From the image below, we can see there are 3 basic blocks that make up the entirety of the function. The idea is to traverse the function ( hash it) and hash each basic block. This way, if one of the basic blocks change (decryption update) we will still be able to identify one or more of the basic blocks (genetic traits).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*NhBC8WQFtYS4xBrErshJNA.png" /><figcaption>IcedID c2 function structure</figcaption></figure><p>Expanding on the angr script, were going to get the basic blocks for this function, extract the opcodes from each block and then hash them to get our traits.</p><pre># snippet from the original code.<br>sorted_blocks = sorted(function.blocks, key=lambda x: x.addr)<br>        for block in sorted_blocks:<br>            block_bytes = block.bytes.hex()<br><br>            for insn in block.capstone.insns:<br>                print(f&quot;Address: {hex(insn.address):&lt;10} {insn.bytes.hex():&lt;15} {insn.mnemonic:&lt;15}  {insn.op_str:&lt;20}&quot;)</pre><p>Our output should look like this:</p><pre>Full bytes: 4533c04c8d0d2e480000492bc94b8d140849ffc08a42403202884411404983f82072eac3<br>Creating malware traits for sub_1400027c8: 61537f309a31bdcfad5c7ff887ad57b6365cef90<br><br>Function Trait hash: 61537f309a31bdcfad5c7ff887ad57b6365cef90<br><br>Address: 0x1400027c8 4533c0          xor              r8d, r8d            <br>Address: 0x1400027cb 4c8d0d2e480000  lea              r9, [rip + 0x482e]  <br>Address: 0x1400027d2 492bc9          sub              rcx, r9             <br>Block hash trait: 59f1da60bdf6ef88dd4a3bb1dd7fefc887d226f1<br><br>Address: 0x1400027d5 4b8d1408        lea              rdx, [r8 + r9]      <br>Address: 0x1400027d9 49ffc0          inc              r8                  <br>Address: 0x1400027dc 8a4240          mov              al, byte ptr [rdx + 0x40]<br>Address: 0x1400027df 3202            xor              al, byte ptr [rdx]  <br>Address: 0x1400027e1 88441140        mov              byte ptr [rcx + rdx + 0x40], al<br>Address: 0x1400027e5 4983f820        cmp              r8, 0x20            <br>Address: 0x1400027e9 72ea            jb               0x1400027d5         <br>Block hash trait: 510f5893a5af1775d6f37a50d2cea84c0a638eca<br><br>Address: 0x1400027eb c3              ret                                  <br>Block hash trait: a625406f6977d45c1391b078f4d3656e0b75bfcb</pre><p>As you can see, we have now created a genetic trait from the function, and also from each basic block of the function. We can now refine our program and to look for these traits and return their location.</p><h3>Identifying traits across multiple samples</h3><p>Before we wrap this up, lets test this concept out on a number of other IcedID samples and see if our approach works.</p><blockquote>Hashes of the files Ill be testing</blockquote><blockquote>9602494ea416005d1e728b66c9c20ce273f2810c4d92b75c09b52cb5b39c0244 <br>e12a44bafadd5cca534500decca51609848ca49708f8c0c142149a8939323963<br>eb48c54eb5cfbd00fb55e13de35c147f407d3f962a09961534e12eda1391bae2 <br>c139cc51b09e6a0c0415b665c3cec704299cca185f5f7c9e239bdf82e3911245<br>9602494ea416005d1e728b66c9c20ce273f2810c4d92b75c09b52cb5b39c0244</blockquote><p>We will create a function to handle both the functions, basic blocks and perform some basic metrics.</p><pre>def analyze_function(proj, target_function):<br>    results = {<br>        &quot;function_match&quot;: False,<br>        &quot;block_matches&quot;: [],<br>        &quot;match_percentage&quot;: 0.0<br>    }<br>    raw_bytes = proj.loader.memory.load(target_function.addr, target_function.size).hex()<br>    function_trait = sha1(raw_bytes.encode()).hexdigest()<br><br>    if function_trait == malware_traits[&#39;function_trait_hash&#39;]:<br>        results[&#39;function_match&#39;] = True<br><br>    matched_blocks = []<br>    sorted_blocks = sorted(target_function.blocks, key=lambda x: x.addr)<br>    for block in sorted_blocks:<br>        block_bytes = block.bytes.hex()<br>        block_trait = sha1(block_bytes.encode()).hexdigest()<br><br>        if block_trait in malware_traits[&#39;block_hashes&#39;]:<br>            matched_blocks.append({<br>                &quot;block_addr&quot;: hex(block.addr),<br>                &quot;block_trait&quot;: block_trait,<br>            })<br><br>    total_blocks = len(sorted_blocks)<br>    if total_blocks &gt; 0:<br>        results[&#39;match_percentage&#39;] = len(matched_blocks) / total_blocks * 100<br>    results[&#39;block_matches&#39;] = matched_blocks<br>    return results</pre><p>Now, as we traverse each sample set, we can pass the functions to our analyze_function and have it perform the extraction and trait analysis for us.</p><p>When we have analyzed all of the files, our output should look like this:</p><pre>Function sub_1400027c8 matched with:<br>Function match: True<br>Match percentage: 100.00%<br>Matched blocks:<br>  Block address: 0x1400027c8<br>  Block trait: 59f1da60bdf6ef88dd4a3bb1dd7fefc887d226f1<br>  Block address: 0x1400027d5<br>  Block trait: 510f5893a5af1775d6f37a50d2cea84c0a638eca<br>  Block address: 0x1400027eb<br>  Block trait: a625406f6977d45c1391b078f4d3656e0b75bfcb<br>------------------------------------------------------------------------------------------------------------------------<br>Function sub_180001c90 matched with:<br>Function match: False<br>Match percentage: 66.67%<br>Matched blocks:<br>  Block address: 0x180001c9d<br>  Block trait: 510f5893a5af1775d6f37a50d2cea84c0a638eca<br>  Block address: 0x180001cb3<br>  Block trait: a625406f6977d45c1391b078f4d3656e0b75bfcb<br>------------------------------------------------------------------------------------------------------------------------</pre><p>We can see from the output, the first file was a 100% match but the second file did not match on the function. It instead was able to match on two of the basic blocks. This would suggest that the function is still responsible for decrypting the c2 , just one of the basic blocks have changed.</p><h3>Conclusion</h3><p>By using identifying and extracting “genetic traits” from malicious binaries, you can gain insight into behavior patterns and other functionality of the malware. Although, this was a simplistic approach to perform genetic trait analysis, we were able to identify changes in the c2 decryption routine of one of the samples and determine the other samples in our set were unchanged.</p><p>The full code can be found on my <a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/blob/main/Malware_Analysis/Genetic_trait_analysis/malware_trait_analysis.ipynb">github</a> in case you want to play around with the concepts.</p><h3>Sources</h3><p><a href="https://intezer.com/blog/defining-genetic-malware-analysis-2/">https://intezer.com/blog/defining-genetic-malware-analysis-2/</a></p><p><a href="https://www.researchgate.net/publication/255315851_Evaluation_of_Malware_Phylogeny_Modelling_Systems_Using_Automated_Variant_Generation">https://www.researchgate.net/publication/255315851_Evaluation_of_Malware_Phylogeny_Modelling_Systems_Using_Automated_Variant_Generation</a></p><p><a href="https://github.com/bediger4000/malware-phylogeny">GitHub - bediger4000/malware-phylogeny: malware phylogeny for WSO web shell, Shellbot IRC bot and algorithm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd340de3679f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t LLM My ML Models: Using Mnemonic Frequency Distribution for Malware Classification]]></title>
            <link>https://medium.com/@crovax/dont-llm-my-ml-models-using-mnemonic-frequency-distribution-for-malware-detection-a5ae134f9abd?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5ae134f9abd</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 20:09:17 GMT</pubDate>
            <atom:updated>2024-08-10T02:34:06.450Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>Everywhere you look, there is Large Language Model (LLM) being using for text summarization, report generation, research etc. Although, LLMs are powerful, they can also be costly and time consuming when fine-tuning. Also, unless trained specifically, they might not have domain specific knowledge but general information. Lastly, they require a massive amount of data for training and fine-tuning.</p><p>Using “traditional” models, we can train it for a specific use case (classification) that would be better suited for these types of models. Below we will go over the first few steps of the ML life-cycle, to build and evaluate two different popular models (Support Vector Machines and Random Forest) to solve a classification problem.</p><h3>The Dataset</h3><p>The total dataset contains 497 PE binaries ( yes, very small dataset) which consist of 407 exe’s and 90 dll’s. The files consist of a mixture of malicious (1) and benign (0) samples.</p><pre>File_Type<br>EXE    407<br>DLL     90<br>Name: count, dtype: int64</pre><pre><br>File_Type Label Count<br>0 DLL      0     56<br>1 DLL      1     34<br>2 EXE      0     188<br>3 EXE      1     219</pre><p>Below is a list of the columns and their description in the dataset. But for this demo we’ll only be using the mnemonics column to train our model.</p><pre><br>Exports : This column contains information about the functions or symbols that are exported by the binary file.<br><br>File_Type: This column indicates the type of the file, such as executable or dynamic link library (DLL).<br><br>Imports: This column contains information about the functions imported by the binary file. <br><br>Mnemonics: This column contains the mnemonics used in the binary file. <br><br>Library: This column contains the libraries that are used or referenced by the binary file.<br><br>sha256_hash: This column contains the SHA-256 hash of each binary file.<br><br>Label: This column contains the label or classification of the binary file, such as &#39;malware&#39; or &#39;benign&#39;. <br>This is the target variable for the binary classification problem.</pre><p>We can view this information within Pandas by using the following command&#39;s:</p><pre># load the dataset<br>df = pd.read_csv(&#39;malware_dataset.csv&#39;)</pre><pre># display the columns in the dataset<br>df.columns<br><br><br># output<br>Index([&#39;Exports&#39;, &#39;File_Type&#39;, &#39;Imports&#39;, &#39;Mnemonics&#39;, &#39;Library&#39;,<br>       &#39;sha256_hash&#39;, &#39;Label&#39;],<br>      dtype=&#39;object&#39;)</pre><pre># Get the count of each file type<br>df.File_Type.value_counts()<br><br><br># output<br>File_Type<br>EXE    407<br>DLL     90<br>Name: count, dtype: int64</pre><p>Something else we might want to look at, is the distribution of malicious vs benign files based on their file types. We can use <strong>method chaining</strong> to string together a number of commands to get this information.</p><pre># The code snippet groups the DataFrame [`df`](command:_github.copilot.openSymbolFromReferences?%5B%22df%22%2C%5B%7B%22uri%22%3A%7B%22%24mid%22%3A1%2C%22fsPath%22%3A%22%2Fhome%2Fcrovax%2FProjects%2FMaldex%2Fml_blog_test.ipynb%22%2C%22external%22%3A%22vscode-notebook-cell%3A%2Fhome%2Fcrovax%2FProjects%2FMaldex%2Fml_blog_test.ipynb%23W5sZmlsZQ%253D%253D%22%2C%22path%22%3A%22%2Fhome%2Fcrovax%2FProjects%2FMaldex%2Fml_blog_test.ipynb%22%2C%22scheme%22%3A%22vscode-notebook-cell%22%2C%22fragment%22%3A%22W5sZmlsZQ%3D%3D%22%7D%2C%22pos%22%3A%7B%22line%22%3A0%2C%22character%22%3A1%7D%7D%5D%5D &quot;Go to definition&quot;) by &#39;File_Type&#39; and &#39;Label&#39;, counts the occurrences in each group, and resets the index to include these counts in a new column named &#39;Count&#39;.<br><br>(df.groupby([&#39;File_Type&#39;, &#39;Label&#39;])<br> .size()<br> .reset_index(name=&#39;Count&#39;)<br>)<br><br><br># output<br>File_Type Label Count<br>0 DLL       0     56<br>1 DLL       1     34<br>2 EXE       0     188<br>3 EXE       1     219<br></pre><p>Now we have an idea of our file distribution based on file type and label (1: malicious and 0: benign) we can prepare our dataset for our models.</p><pre># convert the list of strings to objects<br>df[&#39;Mnemonics&#39;] = df[&#39;Mnemonics&#39;].apply(eval)<br><br># flatten the list of mnemonics and reset the index based on freequency. <br>mnemonic_freq =(<br>    df.explode(&#39;Mnemonics&#39;)<br>    .groupby([&#39;Label&#39;, &#39;Mnemonics&#39;])<br>    .size()<br>    .reset_index(name=&#39;Frequency&#39;)<br>    .sort_values(&#39;Frequency&#39;, ascending=False)<br>)<br><br><br><br># output<br>     Label      Mnemonics  Frequency<br>172      0            mov    3823475<br>664      1            mov    2409307<br>776      1           push    1056148<br>25       0           call     859774<br>140      0            lea     830827<br>..     ...            ...        ...<br>82       0          faddp          1<br>72       0      cvttps2dq          1<br>86       0         fidivr          1<br>937      1        vpsrldq          1<br>967      1  xrelease xchg          1<br><br>[968 rows x 3 columns]</pre><p>There are multi ways to tackle this next part but I wanted to view the distribution based on some common mnemonics and their frequency based on the associated labels (malicious vs benign) .Once again, this is just one of many approaches you can take.</p><pre># filter based on Opcodes in list<br><br>opcodes = [&#39;mov&#39;, &#39;push&#39;, &#39;pop&#39;, &#39;call&#39;, &#39;lea&#39;, &#39;cmp&#39;]<br>filtered_df = mnemonic_freq[mnemonic_freq[&#39;Mnemonics&#39;].isin(opcodes)]<br><br>filtered_df.sort_values(&#39;Mnemonics&#39;, ascending=False)<br><br><br># output<br>     Label Mnemonics  Frequency<br>776      1      push    1056148<br>251      0      push     243887<br>739      1       pop     399788<br>228      0       pop     244597<br>172      0       mov    3823475<br>664      1       mov    2409307<br>140      0       lea     830827<br>633      1       lea     329855<br>48       0       cmp     425793<br>466      1       cmp     415572<br>25       0      call     859774<br>442      1      call     663762</pre><p>We can create a bar graph to better visualize the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pXQLVHSlyFFWw6x7v8kGQ.png" /><figcaption>Bar graph showing the mnemonic distribution across dataset.</figcaption></figure><h3>Building the model’s</h3><p>We will need to separate the dataset by the features and our target label and then create the testing and training set.</p><pre># convert the list of mnemonics into a string<br># separate features and target values<br>X = df[&#39;Mnemonics&#39;].apply(lambda x: &#39; &#39;.join(x))<br>y = df[&#39;Label&#39;]<br><br><br># split data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)</pre><p>Now we have our training and test set, we’ll need to convert mnemonics to numerical features using CountVectorizer class within sklearn.</p><pre># Convert opcodes to numerical features using CountVectorizer<br>vectorizer = CountVectorizer()<br><br>X_train_vectorized = vectorizer.fit_transform(X_train)<br><br>X_test_vectorized = vectorizer.transform(X_test)</pre><h4><strong>Support Vector Machine (SVM) Model</strong></h4><blockquote><strong>Support vector machines (SVMs)</strong> are a set of supervised learning methods used for <a href="https://scikit-learn.org/stable/modules/svm.html#svm-classification">classification</a>, <a href="https://scikit-learn.org/stable/modules/svm.html#svm-regression">regression</a> and <a href="https://scikit-learn.org/stable/modules/svm.html#svm-outlier-detection">outliers detection</a>.</blockquote><p>For the SVM model I am going to use the rbf kernel for this demonstration but to note, there a number of other kernels you can use for optimization [<a href="https://scikit-learn.org/stable/modules/svm.html#kernel-functions">link here</a>].</p><pre><br># Train SVM model<br>svm_model = SVC(kernel=&#39;rbf&#39;, random_state=42)<br>svm_model.fit(X_train_vectorized, y_train)<br><br># make a prediction<br>svm_predictions = svm_model.predict(X_test_vectorized)</pre><p>Now the SVM model has been trained and passed the vectorized test set for predictions, we can view the models accuracy metrics to see how well it did.</p><pre>SVM Model Evaluation<br>accuracy: 0.84<br><br>Classification Report:<br>              precision    recall  f1-score   support<br><br>           0       0.75      1.00      0.86        48<br>           1       1.00      0.69      0.82        52<br><br>    accuracy                           0.84       100<br>   macro avg       0.88      0.85      0.84       100<br>weighted avg       0.88      0.84      0.84       100<br><br><br>Confusion Matrix:<br>[[48  0]<br> [16 36]]</pre><p>Here is a breakdown of the confusion matrix and classification report:</p><pre>Let&#39;s break down the elements of this confusion matrix:<br><br>- True Positives (TP): 36<br>- True Negatives (TN): 48<br>- False Positives (FP): 0<br>- False Negatives (FN): 16<br><br><br>True Negatives (TN) = 48:<br>   - The model correctly predicted 48samples as non-malware (true negatives).<br><br>2. False Positives (FP) = 0:<br>   - The model incorrectly predicted 0 samples as malware when they were actually non-malware (false positives). <br><br>3. False Negatives (FN) = 16:<br>   - The model incorrectly predicted 16 samples as non-malware when they were actually malware (false negatives). <br><br>4. True Positives (TP) = 36:<br>   - The model correctly predicted 36 samples as malware (true positives).<br><br>. Accuracy:<br>   - Accuracy is the proportion of correctly classified samples (both true positives and true negatives) out of the total number of samples.<br> <br>Precision:<br>   - Precision is the proportion of true positive predictions out of all positive predictions (true positives and false positives).<br><br>Recall (Sensitivity):<br>   - Recall is the proportion of true positive predictions out of all actual positive samples (true positives and false negatives).<br>F1 Score:<br>   - The F1 score is the harmonic mean of precision and recall, providing a balance between the two.</pre><p>Here is a heatmap of the confusion matrix to convey the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uiEdJhCPY610rpvoZOHwg.png" /></figure><h4><strong>Random Forest Model</strong></h4><p>Now lets see if we can get better results using a Random Forest classifier model.</p><pre># Create the random forest classifier mdoel <br>from sklearn.ensemble import RandomForestClassifier<br><br>rf_model = RandomForestClassifier(n_estimators=100, random_state=42)<br>rf_model.fit(X_train_vectorized, y_train)<br><br><br># make the predictions <br>rf_preds = rf_model.predict(X_test_vectorized)<br><br><br># Evaluate the model<br># Evaluate the model<br>print(&quot;Random Forest Model Evaluation:&quot;)<br>print(&quot;Accuracy:&quot;, accuracy_score(y_test, rf_preds))<br>print(&quot;\nClassification Report:&quot;)<br>print(classification_report(y_test, rf_preds))<br><br>print(&quot;\nConfusion Matrix:&quot;)<br>cm = confusion_matrix(y_test, rf_preds)<br>print(cm)</pre><p>The results</p><pre>Random Forest Model Evaluation:<br>Accuracy: 0.98<br><br>Classification Report:<br>              precision    recall  f1-score   support<br><br>           0       0.98      0.98      0.98        48<br>           1       0.98      0.98      0.98        52<br><br>    accuracy                           0.98       100<br>   macro avg       0.98      0.98      0.98       100<br>weighted avg       0.98      0.98      0.98       100<br><br><br>Confusion Matrix:<br>[[47  1]<br> [ 1 51]]</pre><p>Random Forest confusion matrix heatmap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yt7uB6fsR9LaFY72GQZH0g.png" /></figure><p>Compare the results from both models</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOqKxOTFRZmR1eTuisyk3A.png" /><figcaption>svm vs random forest accuracy.</figcaption></figure><h3>Summary</h3><p>By using the mnemonics from known malicious and benign files, we were able to build two different classifiers with relatively high accuracy. Something to keep in mind, the dataset is relatively small, we only used one feature vector for our classifier and we did not perform hyper-parameter tuning to final optimal parameters, for the best outcomes.</p><p>The goal was to demonstrate how to use traditional models, with a real world scenario and dataset, to build a malware classifer. In future post, I will expand on these other topics and use a more feature rich dataset.</p><p>You can find the notebook on my github with the dataset and full source code[<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/ML_Model_Writeups/SVM_Randomforest">here</a>].</p><h3>References</h3><ol><li><a href="https://hackernoon.com/the-challenges-costs-and-considerations-of-building-or-fine-tuning-an-llm">https://hackernoon.com/the-challenges-costs-and-considerations-of-building-or-fine-tuning-an-llm</a></li><li><a href="https://www.datacamp.com/blog/machine-learning-lifecycle-explained">https://www.datacamp.com/blog/machine-learning-lifecycle-explained</a></li><li><a href="https://scikit-learn.org/stable/api/sklearn.svm.html">https://scikit-learn.org/stable/api/sklearn.svm.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5ae134f9abd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ducktail: Multi stage analysis]]></title>
            <link>https://medium.com/@crovax/ducktail-multi-stage-analysis-39c2a7d9675d?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/39c2a7d9675d</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Sun, 10 Sep 2023 01:30:35 GMT</pubDate>
            <atom:updated>2023-09-10T07:24:30.803Z</atom:updated>
            <content:encoded><![CDATA[<p>sample hash: dce2488ddc3ab45fe8df1c2bb3e21cd11d4e697e94e0e2a88b4bfd35c6516055<br><a href="https://www.virustotal.com/gui/file/dce2488ddc3ab45fe8df1c2bb3e21cd11d4e697e94e0e2a88b4bfd35c6516055?nocache=1">Virustotal link</a></p><h3>Introduction</h3><p>Ducktail malware is a .net infostealer, which utilizes single-file deployment(<a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli">link here</a>). It allows numerous dependency files to be bundled up into one binary for execution on a host (see screenshot below).</p><p>It attempts to hijack social media business accounts to later use to run ads for monetary gain. Ducktail uses both aes encryption and base64 encoding to hide key functionality.<br>Given this is a .net binary, I figured this would be a good opportunity to use PAN-Unit42’s dotnetfile (<a href="https://github.com/pan-unit42/dotnetfile">link</a>)to perform our analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wj3p0OAeBqmXfNpgmlMBOw.png" /><figcaption>Bundled dependency files</figcaption></figure><h3>Initial triage</h3><p>Within the initial executable, are a couple areas of interest. In the resource section, contains a resource called <br>“MINIDUMP_EMBEDDED_AUXILIARY_PROVIDED” which is a PE file. Once hashed, virustotal reveals the file to be “mscordaccore.dll” which is a Microsoft signed .net core dll (<a href="https://www.virustotal.com/gui/file/879c3afb740ced8a66537801dcc0184c219955993ce6fe51762845102d1a3187/details">link here</a>).</p><p>The second area of interest is the overlay section appended at the of the binary. Ducktail typically ranges from 50 to 90 MB&#39;s in size. The majority of that is due to the size of the overlay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGpgVpj5TGkX56LjZnwLUA.png" /><figcaption>Ducktail file size vs overlay size</figcaption></figure><p>You can use lief, Pefile or a hex editor to extract the overlay and dump it to a file for further inspection.</p><blockquote>N<strong>ote</strong>: The first few hundred bytes may be null padding so you’ll need to remove those.</blockquote><p>Im using MalCat to perform the static analysis(<a href="https://malcat.fr/">link here</a> ) but you can use PEStudio or any similar tool to get the results. As you can see, the overlay contains a giant .net PE file. We can load the dumped file in dnspy for further inspection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCU044B5SHoxfbKCF0noEA.png" /><figcaption>extracted dotnet file</figcaption></figure><p>Once loaded in dnSpy, we’ll follow the programs main method. This will redirect us to the <strong>Start()</strong> method which will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*zmRnD1rRE1xtM6VGA-nXOQ.png" /></figure><p>Drilling down into the function, we immediately see a number of interesting methods (Open and Execute).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*TLTc-i4xUeYeFCJ2R_84Lg.png" /></figure><p>The <strong>Open </strong>method is responsible for retrieving data from a resource entry named <strong>c03p1_2 </strong>via the GetResource<strong> </strong>method. The data is aes encrypted, base64 encoded and the data blob is reversed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*1miaS_YKvcN_BmYXuYGWrg.png" /><figcaption>retrieve of the string resource</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*LqyANeEbCGg8S3Yxq9oi2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*SivcM_JsedfpoLEMQsZOUg.png" /></figure><p>The Execute method attempts to create a mutex called “HJASDHJASJHD” then retrieves a giant data blob string called “BUNDLE”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRJ_LNv4ytFdW_pXniJVCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXtuOQNtYuXMrVWxNyjRqw.png" /></figure><p>The string goes through the sample decryption routine as the resource entry previously discovered. There are two other strings that have the same operation performed on them as well, those will need to get decrypted too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRJ_LNv4ytFdW_pXniJVCA.png" /></figure><p>The last item we need is the key. This can be located by clicking on the <strong>read</strong> method and then GetParam method. Now that we have the located the key (“==AUyLZ7aRzyWlgazfkD/hZf”) we can start extracting and decrypting these strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*XaAw8d6EDGdPrzaDbaOeYg.png" /><figcaption>Read method</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*sL4tjEIoWoOC0rt6QxqACw.png" /><figcaption>GetKey and GetParam methods</figcaption></figure><h3>Analyzing Stage 1</h3><p>The goal of these different stages is to use dotnetfile to extract and decrypt each layer to see what functionality we can uncover.</p><p>We’ll first look at the resource entry called “c03p1_2” to determine its purpose. We can use dotnetfile to parse the resource entries and retrieve their contents.</p><pre>res_data = dFile.get_resources()<br>print(res_data)</pre><p>Looking at the output we can quickly see some items of interest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FXRVgqcNPON-aahFfpGM-Q.png" /></figure><p>Looking back at the open function, the c03p1_2 data will be split and the file extension used or “text” variable string will be the 2nd index (string reversed) after the data has been split. Once the data has been properly parsed , it will look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndWhm_RdK_6ix38TuFMpwQ.png" /><figcaption>Parsed pdf content</figcaption></figure><blockquote><strong>Note</strong>: The data needs to have the following operations performed to get the pdf contents.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*2vqpRbvW5rvJlIYmtd-9wA.png" /><figcaption>decryption routine</figcaption></figure><p>We can output the contents to a PDF file and see what it contains.<br>hash: 99a23191275fc941662faa780118866082f55b70948e97a540e47b7109c8a5c1</p><p>Once opened, the PDF is a job description for Nike. This a common tactic of ducktail, to create decoy documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*kOidDBb7OJP3tg3zqPCVuA.png" /><figcaption>decoy job description</figcaption></figure><p>The key, mutex, bundled data blob and the other encrypted strings we saw above are located in the user strings metadata section. Using the code below will display all this information. The data blob would’t fit, so I excluded it from the screenshot below.</p><pre>from dotnetfile import DotNetPE<br><br>dFile = DotNetPE(&quot;ducktail_extraction.bin&quot;)<br>us_strings = []<br>for stream in dFile.get_user_stream_strings():<br>    us_strings.append(stream)<br>for item1, item2 in zip(us_strings[:4], us_strings[-5:]):<br>    print(f&#39;{item1}\n{item2}&#39;)<br></pre><p>The output should look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*k828XGBdegSyc-Npbb-YVA.png" /></figure><p>Once the two encrypted strings have been decrypted, it reveals the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*3TpxFU5ZCu8T3xL6MWO4Gg.png" /></figure><p>The command is going to execute the data blob discovered previously. In order to see what data is going executed, we’ll use the same algorithm as before to decrypt the data.</p><blockquote><strong>Note: </strong>Some of the decrypted strings need to be base64 decoded a 2nd time to completely recover the decrypted version. Below is a graph outlining the typical order of operation.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AMXRUvRvfKJ457MStKQnTg.png" /><figcaption>Typical decryption routine</figcaption></figure><pre>data_blob = b64decode(us_strings[4][::-1]) # giant data blob<br>decrypted = aes_decrypt(key, data_blob)<br>complete_decrypt = b64decode(decrypted) # 2nd round of b64<br>print(complete_decrypt[:20])            # print first 20 bytes</pre><p>After decrypting the data blob and printing out 20 bytes, we see another PE (‘MZ’ header) file. Just like last time, well dump it , perform a quick assessment before determining the next steps.</p><pre>b&#39;MZ\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00&#39;</pre><p>Taking a look at the file, it appears to be another .net PE file but this time it is obfuscated with ‘smart assembly’.</p><blockquote><strong>Note: </strong>For the most part, de4dot can handle the obfuscation but some sample’s will need to be manually deobfuscated if you want to extract the encrypted strings.<br>sha256:f31c9e1565a73dccab8c9cafb21059275f7e8b5b3911f4bab66d36aa929d51ba</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4cgcZWdpJ14PaoRU0-F5PA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8P9pM8rl6SenomNarp4fJg.png" /><figcaption>Some interesting strings discovered</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*BlM13cGV2uajOp041_rIIQ.png" /><figcaption>Detect it easy</figcaption></figure><h3>Analyzing Stage 2</h3><p>Just like before, we’ll load the file into dnSpy and see if we can locate any encryption algorithms and other schema’s we can use to gain insight into this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*zn9ZVjt62VyZ2QzF0pGfOw.png" /><figcaption>Main function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*weUrVWUTRSbptXY4MY_dWA.png" /><figcaption>default method name from deobfuscator</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*5baEkMvHB8CT6FtwDXWR8A.png" /><figcaption>drilling down into potential areas of interest</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11sRXYJp4_jl1mvAEDf--w.png" /><figcaption>another method for file creation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mo4NANzWUL24bDFTCthNXA.png" /><figcaption>decryption algo and key location</figcaption></figure><p>After drilling down into a number of methods, we found a similar aes decryption routine just like before. The <strong>string_1 method holds the new encryption key we need.</strong></p><pre>string_1 = &quot;==QW9taEzwM1g7tdWHoDeqm6&quot;; # new encryption key</pre><p>Now we have the key lets parse the user strings again and decrypt any strings we find.</p><pre>dot = DotNetPE(&quot;dumped_file&quot;)<br>for i in dot.get_user_stream_strings():<br>    print(i)</pre><p>Simply looping through the strings we automatically find all kinds of interesting artifacts. Below is a small snippet but if you want the full list I’ve uploaded a file to my <a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/ducktail">GitHub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJhAdn_YeBEA2WUnRWP-pQ.png" /><figcaption>snippet from the parsed user strings</figcaption></figure><p>We’ll just focus on the on base64 strings below and see what we uncover. To make things easier, I’m just going to return any string that ends with a ‘=’ sign and perform the error checking.</p><blockquote><strong>Note: </strong>The last stage binary contains a lot of different obfuscated strings and other encryption routines (RSA etc.) but I wont cover those here.</blockquote><p>Before we try and blindly decrypt a bunch of unknown strings and have to deal with some error messages, Im going to a take a few of them and test a small decryption function I created first.</p><pre>new_key = b64decode(&quot;==QW9taEzwM1g7tdWHoDeqm6&quot;[::-1])<br>def decrypt(string):<br>    print(aes_decrypt(new_key, b64decode(string)))<br>string = &quot;rhzzIvWWVoeQEVVWeh+mrSsOuhxjynmXhKU3W8nWit/aGJv6QI5u8caZUdy5Ru4g&quot;<br>string2 = &quot;eTawRuHZ6QqkRHhdNqIuHpLoXCsIgHbW+tA+5KK4iI1XHEaxH/m6V6uid7Kc8Eb5cWC224vV+cOTEhHjy4xJ6OFzRFDv1DnEydQRR8/QkULmpA6IJ73QMgBXYFg6gRyWvSJNIDfm+GUmYiEBgaHCMg==&quot;<br>string3 = &quot;2KTckDd19KRIG4z42mLQv822PDAFkVZDrwGB/kljI1ESROJIcQHtVBhRVGX68f9HyYT0d7wFcHcoRcBOb4wE//Q5F0unyXVOI7k15LY/H4Oh1uuRgtsyAVGwETmIcyI/nihRCNjCJxFFEakAUMwbUA==&quot;<br>for i in [string, string2, string3]:<br>    decrypt(i)</pre><p>running the code above reveals the following facebook urls.</p><pre>b&#39;origin: https://m.facebook.com&#39;<br>b&#39;https://graph.facebook.com/{0}/me/adaccounts?fields={1}&amp;limit=50&amp;access_token={2}&#39;<br>b&#39;https://graph.facebook.com/{0}/me/businesses?fields={1}&amp;limit=50&amp;access_token={2}&#39;</pre><p>Our decryption function and key work! Now, we loop through each string and see which ones we can decrypt.</p><pre>for i in dot.get_user_stream_strings():<br>    if i.endswith(&quot;=&quot;):<br>        try:<br>            decrypt_str = aes_decrypt(new_key, b64decode(i))<br>            if decrypt_str.isascii():<br>                print(decrypt_str)<br>        except:<br>            pass</pre><p>Below is a small snippet of the decrypted strings but the full list has been uploaded to my <a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/ducktail">Github</a>.</p><pre>https://graph.facebook.com/{0}/me/adaccounts?fields={1}&amp;limit=50&amp;access_token={2}<br>business{id},id,name,balance,currency,amount_spent,adtrust_dsl,funding_source_details{type,display_string},adspaymentcycle{threshold_amount},account_status<br>https://graph.facebook.com/{0}/me/businesses?fields={1}&amp;limit=50&amp;access_token={2}<br>sdc<br>BraveSoftware\Brave-Browser\User Data<br>https://business.facebook.com/settings/ad-accounts?business_id=<br>_base_session<br>dbln=<br>_fbp=<br>c_user=<br>https://www.facebook.com/settings?tab=mobile<br>\[&quot;DTSGInitialData&quot;,\[\],{&quot;token&quot;:&quot;(.*?)&quot;<br>https://graph.facebook.com/v14.0/me?access_token=<br>https://business.facebook.com/settings/ad-accounts?business_id=<br>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/<br> Safari /537.36<br>Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0<br>Google<br>Edge<br>Firefox<br>Brave<br>SOFTWARE\WOW6432Node\Clients\StartMenuInternet<br>SOFTWARE\Clients\StartMenuInternet<br>Local State<br>Google<br>History<br>Login Data<br>Cookies<br>Network<br>cookies.sqlite<br>Google<br>https://graph.facebook.com/v14.0/<br>https://business.facebook.com/security/twofactor/reauth<br>https://business.facebook.com/security/twofactor/reauth/enter<br>approvals_code={0}&amp;save_device=false&amp;__user={1}&amp;__a=1&amp;__comet_req=0&amp;fb_dtsg={2}&amp;__jssesw=1<br>https://mbasic.facebook.com/me/about<br>https://www.facebook.com/ads/manager/billing_history/summary<br>https://business.facebook.com/settings/people<br>https://business.facebook.com/settings/people?business_id=<br>https://www.facebook.com/adsmanager/manage/campaigns<br>https://www.facebook.com/adsmanager/manage/campaigns?act=<br>https://www.facebook.com/ajax/bootloader-endpoint/?modules=AdsLWIDescribeCustomersContainer.react<br>StartReceiving<br>StopReceiving<br>Telegram.Bot.Types.InputFiles.InputOnlineFile<br>Telegram.Bot.Args.UpdateEventArgs<br>Telegram.Bot.Types.Enums.UpdateType</pre><h3>But wait there’s more!</h3><p>Normally I would wrap up by now buuut, while sifting through all the decrypted strings I noticed another giant data blob that is most likely another file :)</p><p>So lets decode this and see what we get (then wrap up).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vhsX3WhABs5aoUYVKk_LQ.png" /></figure><p>We can create a small python script to locate the index number of the data blob and assign it to a variable.</p><pre>for idx, i in enumerate(dec_strings):<br>    if len(i) &gt; 1000:<br>        print(f&#39;Large blob found at index:{idx}: {i}&#39;)</pre><pre>Large blob found at index:101: <br>b&#39;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtA</pre><pre>new_file = b64decode(dec_strings[101])<br>new_file[:20]</pre><pre>b&#39;MZ\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00&#39;</pre><p>Another PE file! Lets dump this file and see what it is.</p><p>It would appear this is a telegram bot for api communication. That would makes sense given we decrypted a couple of strings that look like telegram api commands.</p><blockquote>sha256: 470b943b90eb1c7618fcee39ddccc1afdc5b84c8014d8a5db9c2002edf8ca7de</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GxC8q2xQi-pOP9H3UzIwyg.png" /></figure><h3>Wrap up</h3><p>Trying to perform static analysis on .net files have always been a pain given a majority of the parser’s require additional packages(.net) or a bunch of configuration. Dotnetfile is pure python, so all you need to do is install it and you&#39;re ready to … get your parse on… get your parse on.</p><p>Ok, Im done!</p><blockquote>All files have been uploaded to virustotal and tria.ge in case you want to try this out.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39c2a7d9675d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[There and Back Again… a Qbot tale.]]></title>
            <link>https://medium.com/@crovax/there-and-back-again-a-qbot-tale-b028e3f23cce?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/b028e3f23cce</guid>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Mon, 01 May 2023 19:28:57 GMT</pubDate>
            <atom:updated>2023-05-01T19:39:36.330Z</atom:updated>
            <content:encoded><![CDATA[<h4>from BB campaigns and beyond</h4><h3>Overview</h3><p>Qbot has gone through a few iteration changes with its configuration decryption routine over the years. Some of these changes have been to c2 (command and control) structure, decryption structure and decryption keys (no surprise).</p><p>The purpose of this article is to look at some of these changes, how to tackle them and then build a robust(-ish) configuration extractor, that can work across old, new and future samples. The full code can be found on my github (<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/binja_script">here</a>).</p><p><strong><em>disclaimer</em></strong>: I will be using Binary Ninja (team binja) for the analysis and configuration extractor but the logic is the same regardless of the RE framework used. Ill provide some code suggestion that can used to create a standalone version.</p><h3>String decryption</h3><p>Qbot historically has stored its encrypted strings in the .data section of the binary, along with the decryption key. With older versions of Qbot, the decryption key length was 0x5a bytes and the newer versions were upgraded to 0x80 bytes. Regardless of the key size, the decryption routine has not changed. Qbot uses a xor method to both encrypt and decrypt the strings within the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCEUq6s8uU6dUYMdC9-Vnw.png" /><figcaption>older version of Qbot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6QSTTKKXu12uWHDpCkoIA.png" /><figcaption>newer version of Qbot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCnS0LFvNl8BzOrt1yD9KA.png" /><figcaption>string decryption structure</figcaption></figure><p>There are two ways we can approach the string decryption method:</p><ol><li>Take the key bytes and use binary ninjas transformers to auto decrypt the string for us. This will decrypt all strings in each data blob but you will have to determine the index position yourself.</li><li>leverage the binary ninja API to perform the decryption and mark the address with decrypted string. This method will help us later down the road when we want to reverse engineer and uncover functionality.</li></ol><h4>Method 1 ( using built-in xor transformer)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5m_QyjE_JJisiwRLQzIww.png" /><figcaption>xor transform accepts encryption key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*ikR7c9K4Gxb5vrEvG0dBQQ.png" /><figcaption>after decryption</figcaption></figure><h4>Method 2 ( leveraging binary ninjas API)</h4><p>Here are the steps we’re going to take in order to get the string index position and the necessary argument values to decrypt each string.</p><ol><li>Get all cross references to the function calling the string decryption routine.</li><li>walk each cross reference code instruction until a call function is found. Then check if the address matches our original function call to the string decryption routine.</li><li>Once we found the call function, we can get the argument value being passed to it (string index value) by using “<em>instruct.params[0].value.value”.</em></li><li>Next, we can walk the instructions to the original call function and perform the same steps we took to find the string index. Walk down each instruction until a call function is found (there is only one) and then parse the arguments for the key address, encrypted data address and the data length.</li></ol><p>Below is a code snippet of the function to decrypt each string based on its string index position.</p><pre>def perform_decryption(address):<br> decrypted_string = list()<br> encrypted_data, encrypt_key = get_decryption_args(address)<br> for addr in set(address.callers):<br>  for instruct in addr.medium_level_il.instructions:<br>   if (instruct.operation == MediumLevelILOperation.MLIL_CALL and str(instruct.dest) == hex(address.start)):<br>    string_index = instruct.params[0].value.value<br><br>    print(f&#39;Address:{hex(instruct.address)}:--&gt;{hex(string_index)}&#39;)<br>    comment_addr = instruct.address<br>    decrypt_string = decrypt(encrypt_key, encrypted_data, string_index)<br>    decrypted_string.append(decrypt_string)<br>    mark_db(comment_addr, decrypt_string)<br><br> return decrypted_string</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1elmGQb7o5OAWLKUbBNwQ.png" /><figcaption>result of the string decryption function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*vKF_Mhwla1UAjuz5-3vlBA.png" /><figcaption>the decrypted string are marked as a comment</figcaption></figure><h3>Resolve Command and Control IPs</h3><p>Qbot has been using one of the decrypted strings as the ‘key’ to decrypt it’s c2 configuration, which is embed in the .rsrc section of the binary.</p><p>The older versions used the full path to powershell or a variation of (powershell.exe or powershel1.exe) as the key. In the newer versions, it been using a custom string with upper, lower and special characters as the key ( see above screenshot). In order to make the configuration extractor more robust, were going use every decrypted string as the key and check if the output is valid. If so, we know we found a match and we can stop processing the other strings. This approach will allow us to extract future iterations of Qbot’s config, even if the key value changes.</p><p>Below is a rough outline of the c2 decryption method:</p><ol><li>loop through each child node in the resource section until we return the node with data it in.</li><li>loop through each decrypted string and pass it as a key to our decrypt_rsrc function along with the bot id and c2 data we parsed from the resource section</li><li>Get sha1 hash of the key, then perform rc4 on the data, using the new sha1 hash. Finally take the result and use the bytes[20:40] for the new key and all the data after the 40th byte, and use rc4 one more time to get the final decrypted data.</li><li>if a valid ASCII string is returned we know we found the right key combination and we can break out of the loop and return the decrypted data.</li></ol><pre># config decryption logic<br>def decrypt_rsrc(rsrc_data, key):<br>    sha = Transform[&#39;SHA1&#39;]<br>    sha_key = sha.encode(key)<br>    rc4 = Transform[&#39;RC4&#39;]<br>    decrypt_data = rc4.encode(rsrc_data, {&#39;key&#39;:sha_key})<br><br>    decrypted_rsrc = rc4.encode(decrypt_data[40:], {&#39;key&#39;:decrypt_data[20:40]})<br>    return decrypted_rsrc</pre><p>You can see the configuration successfully extracted below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4-mEdBz83lX_7o7fJWvSQ.png" /><figcaption>Qbot config extracted</figcaption></figure><h3>Code suggestions</h3><p>If you want to create a stand-alone version here are a few suggestions:</p><ol><li>Instead of using binja transformer API for the resource decryption, you can use the Cryptodome library to create the SHA1 hash and perform RC4 decryption.</li></ol><pre># import the following libraries<br>from Crypto.Cipher import ARC4<br>from Crypto.Hash import SHA1<br>sha1_key = SHA1.new()<br>sha1_key.update(key) # key is being passed to this function<br>new_sha1 = binascii.unhexlify(sha1_key.hexdigest())<br><br>decrypt_block = ARC4.new(new_sha1)<br>decrypt_config = decrypt_block.decrypt(rsrc_data) # rsrc_data is being passed to this function<br>final_key = ARC4.new(decrypt_config[20:40])<br>return final_key.decrypt(decrypt_config[40:])</pre><p>2. use lief or pefile to parse the data section and retrieve the key and encrypted data.</p><p>3. Once you get the key and encrypted data you can pass them to the already decrypt function (just remove the index arg unless you want it.)</p><pre># string decryption function<br>def decrypt(key, data, index):<br> dec_str = [data[i] ^  key[i % len(key)] for i in range(len(data))]<br> return bytes(dec_str[index:]).decode().split(&#39;\x00&#39;)[0]</pre><p>4. The majority of the other functions can all be imported into a standard python file and used to create a standalone version.</p><h3>Conclusion</h3><p>Hopefully this was helpful in building a useful config extractor that will require little alterations, if/when there are changes to Qbot in the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b028e3f23cce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Similarity Analysis using Machine Learning Part 2.]]></title>
            <link>https://medium.com/@crovax/code-similarity-analysis-using-machine-learning-part-2-c6b1551fb995?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6b1551fb995</guid>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Sun, 10 Jul 2022 17:26:09 GMT</pubDate>
            <atom:updated>2022-07-10T17:26:09.044Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Table on Contents</strong></h3><blockquote><a href="#e3c3"><strong>Overview</strong></a><strong><br> </strong><a href="#7eb9"><strong>Jaccard Similarity</strong></a><strong><br></strong><a href="#f166"><strong><em>Building our similarity model</em></strong></a><strong><em> <br></em></strong><a href="#2247"><strong><em>Conclusion</em></strong></a></blockquote><h3>Overview</h3><p>Picking up where we left off from part 1 (<a href="https://medium.com/@crovax/using-machine-learning-for-malicious-code-detection-a336393c8379">link</a>) were going to dive straight into building our model. The sample binary set can be downloaded from my GitHub(<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/blob/main/Malware_Analysis/Malware_projects/hancitor/Hancitor.zip">link</a>). There should be 10 binaries zipped up, and named Hancitor1 through 10.</p><p>In this section, we’re going to use Jaccard Similarity to analyze a portion of Hancitor’s decryption routine to see if there have been changes from sample to sample. The idea is to detect if there has been any significant changes within the binary that may warrant our attention, and need to reverse engineer or update our config extractor.</p><blockquote>Warning: Even though the binaries extensions have been changed to .bin extension, always be cautious as were analyzing real malware.</blockquote><h3>Jaccard Similarity</h3><blockquote>“The Jaccard similarity index (sometimes called the Jaccard similarity <em>coefficient</em>) compares members for two sets to see which members are shared and which are distinct. It’s a measure of similarity for the two sets of data, with a range from 0% to 100%. The higher the percentage, the more similar the two populations.”<br><a href="https://www.statisticshowto.com/jaccard-index/">source</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*rZoETugBJY8LPQLViuPbag.png" /><figcaption><a href="https://en.wikipedia.org/wiki/Jaccard_index">source</a></figcaption></figure><p>By using Jaccard similarity, we’ll be able to compare each samples opcodes from a portion of the decryption routine, and determine (within a percentage range) if any of the binaries are different.</p><h3>Building our similarity model</h3><p>The first thing we need to do is import a few libraries that will allow us to interact with the sample set.</p><ul><li>Lief: allows us to parse the binaries structure for information ( imports, exports etc)</li><li>OS : allows us to handle the file and file path</li><li>Capstone: is our disassembly engine</li><li>re: for use of regex</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*MKuOMkK7sIF7uNpTZ-S3KQ.png" /></figure><p>Here is an example of lief loading each binary in our directory(Hancitor) and retrieving the .text section .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*Cuq89Leqe3yp3hfNSG2DXA.png" /></figure><p>Once we’ve loaded the our libraries, we’ll need to define a few functions that will help us parse each binary and find retrieve our opcode byte pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*FlCccGgxTF1mblCBawMXeQ.png" /><figcaption>Function to disassembly our pattern opcodes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*ydMen28VnHgZyDbzhD7K4w.png" /><figcaption>Function to parse the .text section of a binary</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*YcDz9YNzqcedL8RWCE1yrA.png" /><figcaption>Function to find retrieve the opcode instructions</figcaption></figure><p>The last function “get_instructions” is the first major piece of our code. A file is being passed to it (Hancitor) the .text section is then being parsed and passed to the regex search function, along with one of our patterns. If our pattern finds a match then its returns all of those bytes, else it returns 3 NOPs ( I’m using those as a place holder identifier).</p><blockquote>The pattern variables come from a series of opcodes associated to two different Hancitor samples. The dot(.) is wild card notion in regex. We use them in case we have a sample that changes its code structure, we’re still able to locate different variations. The idea is to catch as many instructions around with the algorithm id that gets passed to the CryptDeriveKey function. If the algorithm id changes our pattern match will pick up (which is what we want).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*rcJ7ebtlkJkubDiwkiOi6g.png" /><figcaption>Jaccard Similarity function</figcaption></figure><p>Now that we have our functions set up, we can start looping through each file in our directory and pass the file to our functions to receive a score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*52hE5BZzkgwvXXhhndUceA.png" /></figure><ol><li>Assigns our similarity score and some additional variables we’ll use to store some output.</li><li>Create a list of every binary in our directory. Passes each file to our ‘get_instruction’ function then stores the file name(key)and result(value) in a dictionary.</li><li>Pass each binaries assembly instruction to our Jaccard_Similarity function to determine its score. If the value is less than .6 it stores it in our similarities list.</li></ol><p>Once executed you should see something like this:</p><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor3.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x584018]’]</blockquote><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor2.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x5c4018]’]</blockquote><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor8.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x5c4018]’]</blockquote><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor9.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x3004018]’]</blockquote><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor4.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x2b44018]’]</blockquote><blockquote>pattern 2 found</blockquote><blockquote>./Hancitor/Hancitor1.bin — -&gt; [‘lea eax, [ebp — 8]’, ‘push eax’, ‘push 0x280011’, ‘push dword ptr [ebp — 4]’, ‘push 0x6801’, ‘push dword ptr [ebp — 0xc]’, ‘call dword ptr [0x10003018]’]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*2NYQxj4m-kh3MSi-I3eDgQ.png" /><figcaption>Results were truncated</figcaption></figure><p>So what does the above output tell us so far? The output displays which of our patterns (1 or 2) were matched and retrieved, the file (full path) and the retrieved assembly instructions. Now, don’t worry if your knowledge of assembly is a little fuzzy, I’ve provided a link to the intel architecture developers manual <a href="https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html">here</a> (joking, you don’t need to read it).</p><p>In all seriousness, the output helps us determine which binary instructions are different, and more importantly if Hancitor’s decryption algorithm ID has changed. The instruction ‘<strong>push 0x6801’ </strong>tells us which algorithm it will use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*8dpPfHoK78NZ4Rq2eMyFcg.png" /><figcaption><a href="https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id">source</a></figcaption></figure><p>This is why I chose to wild card (.) the algorithm id portion of the regex because I wanted to capture any value that might populate. By looking back at our output we can see that everyone of our samples contain the ‘<strong>push 0x6801</strong>’ instruction (boooooo, I know) but it also shows which binaries have a different code structure.</p><p>If we add the following code we can get a better idea of which binaries are in fact different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*eg_CLUfeWdf4LHrnYd6j6w.png" /><figcaption>Print each binary and its similarity score</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*gROB74T84zJpz0jO7tr3oA.png" /><figcaption>output</figcaption></figure><p>We can better see from the output Hancitor1.bin and Hancitor10.bin when compared to the other binaries, have a very low similarity score. Which can be validated by looking back at the instructions ( see below)</p><blockquote>pattern 2 found</blockquote><blockquote>./Hancitor/Hancitor10.bin — -&gt; [‘lea eax, [ebp — 8]’, ‘push eax’, ‘push 0x280011’, ‘push dword ptr [ebp — 4]’, ‘push 0x6801’, ‘push dword ptr [ebp — 0xc]’, ‘call dword ptr [0x10003018]’]</blockquote><blockquote>pattern 2 found</blockquote><blockquote>./Hancitor/Hancitor1.bin — -&gt; [‘lea eax, [ebp — 8]’, ‘push eax’, ‘push 0x280011’, ‘push dword ptr [ebp — 4]’, ‘push 0x6801’, ‘push dword ptr [ebp — 0xc]’, ‘call dword ptr [0x10003018]’]</blockquote><blockquote>pattern 1 found</blockquote><blockquote>./Hancitor/Hancitor7.bin — -&gt; [‘lea eax, [ebp — 0xc]’, ‘push eax’, ‘mov ecx, dword ptr [ebp — 0x14]’, ‘push ecx’, ‘mov edx, dword ptr [ebp — 4]’, ‘push edx’, ‘push 0x6801’, ‘mov eax, dword ptr [ebp — 8]’, ‘push eax’, ‘call dword ptr [0x564018]’]</blockquote><blockquote>My Jupyter notebook with all the code can be downloaded on my GitHub page (l<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/blob/main/Malware_Analysis/Malware_projects/hancitor/myproject2.ipynb">ink</a>)</blockquote><h3>Conclusion</h3><p>By using Jaccard Similarity we were able to locate the differences in the code structure of each binary. It allowed us to see which binaries had changed their code structure and quickly determine if the algorithm id changed as well.</p><p>Even though all of the samples use the same RC4 algorithm, and our original configuration extractor should work on all of them( want to verify?) using this model can help quickly identify any changes in future samples that you may come across.</p><p>In the next part of this series, we will focus on feature extraction and selection to see if we can build a model that can help us classify Hancitor. Well then test our model against benign samples to test it’s accuracy.</p><p>As always, don’t expect much, as I have no clue what I’m doing. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6b1551fb995" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Similarity Analysis using Machine Learning part 1.]]></title>
            <link>https://medium.com/@crovax/using-machine-learning-for-malicious-code-detection-a336393c8379?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/a336393c8379</guid>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Sat, 14 May 2022 01:48:03 GMT</pubDate>
            <atom:updated>2022-07-10T00:08:15.528Z</atom:updated>
            <content:encoded><![CDATA[<h3>Table of contents</h3><blockquote><a href="#b15f">Overview</a><br><a href="#2a94">Installing tools</a><br><a href="#a6b7">Quick demo</a><br><a href="#e96a">Conclusion</a></blockquote><h3>Overview</h3><p>In this series we’ll continue analyzing hancitor (poor hancitor) but our analysis will be from a different angle. We’ll be concentrating our analysis around the decryption algorithm hancitor utilizes. We don’t want to reanalyze a sample if we don’t have to ( we can use our config extractor) but we are interested in new variants , that have been updated, which might thwart our config extractor(<a href="https://medium.com/@crovax/extracting-hancitors-configuration-with-ghidra-7963900494b5">link to building the config extractor)</a>.</p><p>We could use Ghidra program diff feature or other 3rd party tools for comparative analysis but what if we have 5 samples, or 8. We don’t want to manually load a bunch of sample into a program like Ghidra (yes, you can use headless mode for mass analysis) when we can build automation, based around code similarity, using machine learning(also, ML is pretty cool).</p><p>This is going to be the main focus of this series, can we built effective automation around detecting new encryption algorithms employed by hancitor. This will enable us to focus on reverse engineering around new variants, while letting our config extractor take care of the rest. This first part is going to cover installing the necessary tools, the thought process and then demonstrate a few use cases to get familiar with the tools.</p><h3>Installing tools</h3><p>The main environment we’ll be programming in, will be Jupyter notebooks. It makes code execution and troubleshooting much easier than your typical python IDE. Also, its one of the most used among the ML community, due to its ease of displaying charts, graphs and other types of output. You can download the standalone application (<a href="https://jupyter.org/">here</a>) or you can install vscode (<a href="https://code.visualstudio.com/">here</a>) and add the extension(I’ve chosen the latter).</p><p>Once you have vscode installed, we’ll need to install some extensions and packages, to get our environment ready. One the left hand side in vscode you should see an icon with four blocks, click on it. On the top, you can search for the extensions to install. Below are the are 5 extensions you want to have installed:</p><blockquote>Jupyter<br>Jupyter Keymap<br>Jupyter Notebook Renderers<br>Python<br>Pylance</blockquote><p>Once everything is installed, your extension list should look something this(see below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJ36ClbdLoMVHg-JioKqnA.png" /><figcaption>List of extensions</figcaption></figure><p>Next, we need to create a directory to work out of. By clicking on the file icon on left hand side, it will give you the option to open a directory (if you havent already created one) or from the File option drop down, you can create one.</p><p>Once you’ve created your working directory, we’ll need to install a couple of packages via pip (comes preinstalled with python). Open a command shell and type the following to get the packages installed:</p><pre># Get updated version of setuptools<br>pip install setuptools --upgrade</pre><pre># Install Lief<br>pip install lief</pre><pre># Install capstone<br>pip install capstone</pre><pre># Install numpy<br>pip install numpy</pre><pre># Install pandas<br>pip install pandas</pre><pre># Install matplotlib<br>pip install matplotlib</pre><pre># install scikit-learn<br>pip install scikit-learn</pre><p>Don’t worry if you haven&#39;t heard of these tools before, below is a small description of each. I have also provided links to their documentation as well. All these tools together, will allow us to parse, extract features and provide visualizations, to help us accomplish our objective.</p><blockquote>Lief is a cross platform library which can parse, modify and abstract ELF, PE, MachO and Android formats (L<a href="https://lief-project.github.io/doc/latest/intro.html">ink</a>)</blockquote><blockquote>Capstone a lightweight multi-platform, multi-architecture disassembly framework. (L<a href="https://www.capstone-engine.org/">ink</a>)</blockquote><blockquote>Numpy is the fundamental package for scientific computing in Python. (<a href="https://numpy.org/doc/stable/">Link</a>)</blockquote><blockquote>Pandas aims to be the fundamental high-level building block for doing practical, real world data analysis in Python. (<a href="https://pandas.pydata.org/pandas-docs/stable/">Link</a>)</blockquote><blockquote>Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. (<a href="https://matplotlib.org/">Link</a>)</blockquote><blockquote>Scikit-Learn allows for various classification, regression and clustering algorithms to be used. (<a href="https://scikit-learn.org/stable/index.html">Link</a>)</blockquote><h3>Quick demo</h3><p>Now that we have our environment setup, we can get familiar with some of the basic commands and features, we’ll be using through this series.</p><p>Going back to vscode ( after creating a new directory) we’ll want to create a Jupyter notebook file (file with .ipynb extension). Clicking on the down arrow in our directory, a few icons will appear. Clicking on the first will allow us to create a file of our choosing. Create a file and give it a .ipynb extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*qziyAvwB-GTxBdZ43GiFOg.png" /><figcaption>Create a new file</figcaption></figure><p>Once you have created the new file, you should be presented with a blank notebook with an open cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3XLVGQEa84iZ71Gmfl5m2w.png" /><figcaption>Newly created Jupyter notebook</figcaption></figure><p>For this demo were going to use lief to parse a file and display its imports and give us the total length (we’ll leave the fancy stuff for part 2).</p><p>First we’ll want to import the necessary library (lief) into our notebook and execute the cell to make sure everything worked OK.</p><blockquote><strong>note</strong>: while in a cell if you hold shift then press enter, Jupyter notebooks will auto execute the current cell and create a new one below it.<br>Also, if its your first time executing the first cell, jupyter notebooks might need to start the local server. Before doing so, vscode might ask which python version (if you have multiple) you want to use. Just select the newest version or the suggested one, and you should be good to go.</blockquote><p>To start enter the code below into the first cell of your notebook. The first line is just a commented line to provide a description of what the code is doing. The second line is where we’re importing lief package.</p><p>code snippet:</p><pre>#import library<br>import lief</pre><p>Once executed, and if everything worked ok, the first cell should execute and created another below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scnnW84YzlNyRKLAyktf4Q.png" /></figure><p>Well now need to provide lief with the path to a binary to parse. You can use your own, or you can download the hancitor sample set were going to use in part 2 and use one of those (<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/samples">link</a>). Regardless on your choice, make sure to provide the full path.</p><blockquote>note: All the samples extensions have been changed to .bin to prevent accidental execution but as always proceed with caution.</blockquote><p>Code snippet:</p><ul><li>First line is assigning the full path of our binary to a variable call “path”</li><li>Second line is passing the path variable to liefs parse function and assigning the output to another variable called “binary”</li></ul><pre><br>path = &quot;/home/crovax/Malware_Research/Malware_projects/Hancitor1.bin&quot;</pre><pre>binary = lief.parse(path)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*vZ5k0yWblYgZqwNNutVcrg.png" /><figcaption>Current code layout</figcaption></figure><p>Now that we have access to out binary data, we can leverage some of the other functions in lief to extract all kinds of information (sections, imports, exports etc.). What we want to do is list all the libraries and their imports within the binary. To do this, we’ll use lief’s libraries method to retrieve an object that is iterable. We’ll through the object and append each result to a list called “my_library” then print the results.</p><p>code snippet:</p><ul><li>Lines 1 and 2 are just commented lines for code description</li><li>Line 3 is creating a list to store our results in</li><li>The rest of the code is looping through the binary.libraries object and assign each entry in library then appending the result to our list. Once completed, we print our list to the screen.</li></ul><pre><br># create a list to store each library retrieved from the binary <br># then print the list</pre><pre>my_library = []</pre><pre>for library in binary.libraries:</pre><pre>    my_library.append(library)</pre><pre>print(my_library)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzNmgeuZQrtG96BwFd1QFQ.png" /></figure><blockquote>Note: if you want a copy of the notebook created I have uploaded it to my GitHub(<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/blob/main/Malware_Analysis/Malware_projects/hancitor/myproject.ipynb">link</a>).</blockquote><h3>Conclusion</h3><p>To wrap this part off, we have covered how to install the necessary tools and packages to get us started with code similarity analysis and feature extraction. In the next part of this series, we’ll use lief to parse the .text section of hancitor, then use capstone to disassembly the bytes for us to perform our code analysis.</p><p>As always, don’t expect much, as I have no clue what I’m doing. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a336393c8379" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extracting Hancitor’s Configuration with Ghidra part 2]]></title>
            <link>https://medium.com/@crovax/extracting-hancitors-configuration-with-ghidra-part-2-5dc57941b0b8?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dc57941b0b8</guid>
            <category><![CDATA[yara]]></category>
            <category><![CDATA[hancitor]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Sun, 03 Apr 2022 19:53:13 GMT</pubDate>
            <atom:updated>2022-04-03T19:53:13.689Z</atom:updated>
            <content:encoded><![CDATA[<h3>Topics covered</h3><ul><li>Identify valid use cases for rule generation</li><li>Create test yara file</li><li>refine yara rule</li><li>repeat steps 1–3 until satisfied</li></ul><h3>Overview</h3><p>Continuing from part 1 of this series(<a href="https://medium.com/@crovax/extracting-hancitors-configuration-with-ghidra-7963900494b5">here</a>) were going to identify some key pieces of data that can help assist us in creating a yara detection rule. The idea is to find enough similarities within each sample to create a detection rule. Although, each sample varies, there will key bits of data we can use to create this yara rule( file format, file size etc)</p><blockquote><strong>SHA256 Hash of samples</strong></blockquote><blockquote>16DD71F91B8F9DA346A6A71438C0DEB707B01DFBD4846CE1E6E8DB639EA342E6<br>62E76FA1680CE02D7AED775BB83ADCD3F7DD5C9857AA074B8B3DB10ED68DA634<br>B8249F3843C307D11DD4D73A239C3B52DD14FFD3FAAAD67C920D083C21189D57<br>EC2C2CA3355CE23BE6CF74726E2E7745587674EEF4384C5EDF3BADA3D44F97E5</blockquote><h3><strong>Starting template</strong></h3><p>Below will be our starting template to use for our samples.</p><pre>import &quot;pe&quot;</pre><pre>rule hancitor_detection<br>{<br> meta:<br>  description = &quot;&quot;<br>  author = &quot;&quot;<br> <br> <br> <br> condition:<br>  <br>}</pre><p>Now we need to start adding some information we know will be present in any of our samples (some information will be broad). There are two data points that we can use that will initially catch all these samples; matching the magic number to that of ‘MZ’ and finding a file size range. We will need to add more context(we will later) to make this more granular and hancitor specific.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*bpF0j23K5Qmuit_rr7HWxg.png" /></figure><p>Getting an idea of the file size ranges, we can use this as one of our condition statements for building our rule. Since 40kb seems to be the highest among our samples, we could use that as our “max limit” and anything less than that will meet our condition. The issue with that is we dont know if that is the max size for every hancitor sample, so we’ll need to add a little “padding” just to be safe. I think adding 50% to the max file size (40kb) would be a safe bet for an unpacked sample.</p><p>Our yara rule at this point should look something like this:</p><pre>import &quot;pe&quot;</pre><pre>rule hancitor_detection<br>{<br> meta:<br>  description = &quot;Yara rule for detecting hancitor malware.&quot;<br>  author = &quot;&lt;enter your name here&gt;&quot;<br> <br> condition:<br>  (uint16(0) == 0x5A4D <br>  and filesize &lt; 60KB) <br>  <br>}</pre><p>After running our newly created yara rule against our samples, we have successfully detected all 4 of the samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSFfCPMxSW-ROSq1wy6EVg.png" /></figure><p>At first, you might think were done but were far from it (kind of). Although this worked, the issue is our rule is still broad. Any PE file less than 60kb would match this rule, which would cause a bunch of false positives. We can use the information we gathered from part 1 of this series (<a href="https://medium.com/@crovax/extracting-hancitors-configuration-with-ghidra-7963900494b5">Link</a>) on how the configuration data is being operated on. Some of the instructions used are most likely going to be the same across variants of hancitor. So we can use the opcodes from both the instructions used (PUSH etc) and the operands to add to our rule.</p><p>Before adding the opcodes, there is one more condition we can add to finalize our rule. That is the imphash from one of our samples. Mandiant pushed out a good article on this topic (<a href="https://www.mandiant.com/resources/tracking-malware-import-hashing">here</a>) although a bit old, the principals still apply. One method of obtaining the imphash, is take on of the hancitor samples and have Virustotal calculate it for you (see below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmbivfWMsuwpFLS_iQEF9w.png" /></figure><p>Now that we have the imphash and our opcodes, we can add both to our yara rule and test it out. The new yara rule should look something like this, if you&#39;ve been following along.</p><pre>import &quot;pe&quot;</pre><pre>rule hancitor_detection<br>{<br> meta:<br>  description = &quot;Yara rule for detecting Hancitor malware.&quot;<br>  author = &quot;Crovax&quot;</pre><pre>strings:<br>        $opcodes = {6a [1] 68 [4] 68 00 20 00 00}</pre><pre>condition:<br>  uint16(0) == 0x5A4D<br>  and filesize &lt; 60KB<br>  and ($opcodes or pe.imphash() ==<br>&quot;57265d838ef6737ecad7f941f2f02016&quot;)<br>  <br>}</pre><p>Once we run the new rule against the directory that contains our hancitor samples, we see all of the samples have been successfully matched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrabeRzJXC-njFJqiCzA-g.png" /></figure><h3>Conclusion</h3><p>By gathering some basic meta data from the our samples ( and from the previous analysis) we were able to create a yara rule to detect 4 different hancitor samples. The rule can be expanded upon to make it more robust but this is a good starting point. Here is a link to my github (<a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/samples">here</a>) where you can download a zipped folder with a number of hancitor samples (unpacked) to test on.</p><p>Also, Ill be using the same sample set for the upcoming machine learning project series(whaaaa !!). As always, don’t expect much, as I, have no clue what I’m doing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dc57941b0b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extracting Hancitor’s Configuration with Ghidra part 1]]></title>
            <link>https://medium.com/@crovax/extracting-hancitors-configuration-with-ghidra-7963900494b5?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/7963900494b5</guid>
            <category><![CDATA[ghidra]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 23:54:33 GMT</pubDate>
            <atom:updated>2022-01-21T15:06:07.174Z</atom:updated>
            <content:encoded><![CDATA[<h3>Topics covered</h3><ul><li>Locate the decryption function</li><li>Determine the decryption algorithm</li><li>Build Ghidra script to decrypt the configuration file</li><li>Build yara detection rule (In part 2)</li></ul><h3>Hancitor Overview</h3><p>Hancitor is an older malware loader that is known to drop additional malware on to the system once infected (cobalt strike and some ransomware variants). The entry point is from your typical malspam campaign, that contains a link to an office doc or already has one embedded in the email.</p><p>The original dll is usually packed, and once unpacked, will execute the hancitor payload and reach out to one of its hard coded c2&#39;s.</p><blockquote><strong>Original packed samples:</strong></blockquote><p><a href="https://www.malware-traffic-analysis.net/2021/06/17/index.html">https://www.malware-traffic-analysis.net/2021/06/17/index.html</a></p><blockquote><strong>Unpacked Sample</strong>:</blockquote><blockquote>SHA-256</blockquote><blockquote>882b30e147fe5fa6c79b7c7411ce9d8035086ad2f58650f5d79aadfb2ffd34f4</blockquote><h3>Locating the decryption function</h3><p>Hancitor leverages the Windows native Cryptographic Service provider (CSP) context to perform its decryption routine. Knowing that, locating the decryption function will be relatively easy.</p><p>One way, is to load the binary into Ghidra and look at import table list for one of the cryptographic functions (CryptDecrypt, CryptAcquireContextA etc) then follow the referenced function from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cnej7WsFM_HKJ8SWuBG2gw.png" /></figure><p>Now that we have located the function leveraging the CryptDecrypt routine, we can get a better picture of how the decryption process works. Below is the decompiled view of the function performing the decryption routine. We’ll step through each function to determine how the decryption logic works then start programming it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1PF2eyPUWAy--lWLMaGSQ.png" /></figure><h3>CryptAcquireContextA</h3><p>The CryptAcquireContextA function initiates the call to the Cryptographic Service Provider (CSP) to determine what kind of CSP to use for the CryptoAPI functions. This function is straightforward as its role is just to initiate the CSP context for use. We can determine which CSP is going to be used by the first ‘PUSH 0x0&quot; instruction. Since its a null value being used, the default selection is made (native windows cryptographic service provider).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wO8LGNfzZbiq35vTfi-g7w.png" /></figure><h3>CryptCreateHash</h3><p>When the CryptCreateHash function is called, it creates the hashing object to be used in the cryptographic routine, and determines the type of hashing algorithm to be used. Once successful, it returns a handle to the object, for subsequent calls to the other cryptographic functions.</p><p>To determine what hashing algorithm is being used, we can look at the ‘Algid’ value that will be pushed on to the stack. In this case, we see the ‘PUSH CALG_SHA1’ instruction is being used. So, we know that the hashing algorithm is SHA1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_AuoTBQjMaN3fsfvFNAfw.png" /></figure><h3>CryptHashData</h3><p>This function is going to hash the data passed to it, using the previously specified algorithm(SHA1). But what is being hashed and how do we figure it out?</p><p>First we need to look back at the arguments being passed into the function (I have labeled it “Decryption’) to see what data is being passed and where its located.</p><p>by looking at the arguments and their position in which they&#39;re being passed in, we need to find out what the data is expecting and where is it located. In order to find this information we can follow the data that is being passed into the function.</p><p>Hint: I have already labeled it 😃</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMkeojEP9Sl_U5b7hmoxew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2463yELD5d5QoHhxZ_HYcA.png" /></figure><p>As you can see, the third argument being passed is a pointer to the ‘key’ thats going to be hashed, and the argument being passed to the right of it (8) is the key length.</p><p>so we know the following:</p><p><strong>Key</strong> = b’\xb3\x03\x18\xaa\x0a\xd2\x77\xde’</p><p><strong>Key length</strong> = 8 bytes</p><h3>CryptDeriveKey</h3><p>This next part is going to be a bit tricky. The CryptDeriveKey is going to accept a few parameters:</p><p><strong>hProv </strong>= handle to the cryptographic service provided being used.</p><p><strong>Algid</strong> = algorithm for which the key is to be generated. In this case, its going to be RC4.</p><p><strong>hHash or hBaseData =</strong> handle to the hash object that points to the data.</p><p><strong>dwFlags </strong>= this is going to be key length that is going to be used. Which is the lower 16 bits of the value being passed. In our case that value is 0x00280011, so we only want the lower values or 0x0028 (we can truncate the leading zeros). So by dividing 0x28 / key length(8) that was being passed to the CryptHashData function, we know how many bytes of the RC4 key is going to be used to decrypt the configuration data.</p><p><strong>RC4 key</strong>: 0x28 / 8 = (5 bytes)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3R-8QV9CBii2KS_TXnqkmA.png" /></figure><h3>CryptDecrypt</h3><p>This function is straightforward, it accepts the data to be decrypted, the key used, and the length of the data as parameters. To verify, we can once again look at the arguments that are being passed to the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8Yo-6FGQbFiaTAYW8CrWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wMFx0VsGW1MmrZJxBul4A.png" /></figure><p>based on the value being passed in, we can see the encrypted data length is equal to 0x2000 bytes.</p><p>Below is a graphical representation of the actions performed thus far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sa3RvlyN0JNbKP1ScwzaUQ.png" /></figure><h3>Creating the Ghidra script</h3><p>We now understand how the decryption process works. The next step is to create a script in Ghidra to automate this whole process, so we can extract the build/campaign id and the c2 domains from this sample.</p><p><strong>Note</strong>: the python script can be downloaded from my github (link <a href="https://github.com/CrovaxTheCursed/CrovaxTheCursed/tree/main/Malware_Analysis/Hancitor_Ghidra_Script">here</a>). Your cursor needs to be pointing to the first address of the encrypted data before running the script. This is due to the ‘currentAddress’ method.</p><p>We know we need to create a sha1 hash of the 8 byte key that’s being passed into the Decryption function. So we can copy those bytes out of Ghidra and store them into a variable. The next step is to get a hash (sha1) of the key and extract the first 5 bytes (Key Hash: a956a1e6ff).</p><pre><em>import hashlib <br>import binascii</em></pre><pre><em>key_bytes = ‘\xb3\x03\x18\xaa\x0a\xd2\x77\xde’<br>print ‘key length’, len(key_bytes)<br>get_hash = hashlib.sha1()<br>get_hash.update(key_bytes)<br>key_hash = get_hash.digest()[:5]</em></pre><p>Next we need to get the encrypted data using ghidra’s getBytes function, and then perform any necessary conversions on the hex values</p><pre>def get_encrypted_bytes():   <br>    get_addr = currentAddress<br>    get_bytes = list(getBytes(get_addr, 2000))<br>    converted_bytes = &#39;&#39;<br>    cByte = &#39;&#39;<br>    for byte in get_bytes:<br>        if byte &lt; 0:<br>            cByte = (0xff - abs(byte) + 1)<br>        else:<br>            cByte = byte<br>        converted_bytes += chr(cByte)<br>        <br>    return converted_bytes</pre><p>We now have our key and the encrypted data we need to decrypt. The last step is to pass these parameters to a our rc4 decryption function to perform the remaining steps.</p><pre>def rc4_decrypt(key, data):<br>    x = 0<br>    box = range(256)<br>    for i in range(256):<br>        x = (x + box[i] + ord(key[i % len(key)])) % 256<br>        box[i], box[x] = box[x], box[i]<br>    x = 0<br>    y = 0<br>    out = []<br>    for char in data:<br>        x = (x + 1) % 256<br>        y = (y + box[x]) % 256<br>        box[x], box[y] = box[y], box[x]<br>        out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))<br>    return &#39;&#39;.join(out)</pre><p>Now that we have our decrypted data, we just need to format the data we want and discard any null bytes.</p><pre>print &#39;Current Address:&#39;, currentAddress <br>print &#39;Key Hash:&#39;,binascii.hexlify(key_hash)</pre><pre>get_data = get_encrypted_bytes()</pre><pre>config =  rc4_decrypt(key_hash, get_data)<br>build_id = config.split(&#39;\x00&#39;)[0]<br>print  &#39;Build_id:&#39;, build_id</pre><pre>for string in config.split(&#39;\x00&#39;)[1:]:<br>    if string != &#39;&#39;:<br>        c2 = string<br>        break<br>c2_List = c2.split(&#39;|&#39;)</pre><pre>for c2 in c2_List:<br>    if c2 != &#39;&#39;:<br>        print &#39;c2:&#39;, c2</pre><p>The output should look something like this 😃</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*VF48UKBfq-QQi-JJHV7hBQ.png" /></figure><p><em>Decode_Config.py&gt; Running…<br>key length 8<br>Current Address: 005c5018<br>Key Hash: a956a1e6ff<br>Build_id: 1706_apkreb6<br>c2: http://thestaccultur.com/8/forum[.]php<br>c2: http://arguendinfuld.ru/8/forum[.]php<br>c2: http://waxotheousch.ru/8/forum[.]php</em></p><h3>Conclusion</h3><p>By breaking down the individual functions of the decryption routine we were able to determine how hancitor was decrypting its c2 domain configuration. We then applied the same process in creating a Ghidra script to automatically perform the same steps statically, to reveal the encrypted data.</p><p>In part 2, we well take a similar approach and build a yara rule to test our theory and see if we can detect multiple hancitor variants.</p><p>As always, Don’t expect much, as I have no clue what I’m doing. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7963900494b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Panda Banker Analysis Part 1]]></title>
            <link>https://medium.com/@crovax/panda-banker-analysis-part-1-d08b3a855847?source=rss-bbc74ef8ef79------2</link>
            <guid isPermaLink="false">https://medium.com/p/d08b3a855847</guid>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[memory-forensics]]></category>
            <dc:creator><![CDATA[Crovax]]></dc:creator>
            <pubDate>Sat, 21 Aug 2021 00:10:57 GMT</pubDate>
            <atom:updated>2021-08-26T00:18:33.989Z</atom:updated>
            <content:encoded><![CDATA[<h4>From a memory analysis perspective</h4><p>Panda banker is a banking trojan which shares some of its code base with an older malware variant called ‘Zeus.’ It’s known to inject code into the users web browser and attempt to steal banking/credit card credentials.</p><p>Panda banker has a series of different anti-analysis and code obfuscation techniques to thwart any attempt in analyzing it. Some of these techniques consist of checking for process monitoring tools and packet analysis tool. The executable, once it has detected one of these tools, it will delete itself from the host system.</p><p>After execution Panda banker would spawn another binary in the AppData directory then execute it. Once running, the original process would then terminate and delete itself. After a while of running, it would spawn two additional processes (svchost.exe) then terminate itself as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*NElQBGTQ85n99geuDSkNXQ.png" /></figure><p>Based off the initial analysis I conducted ,you can see an unknown process (pid 1960) spawning another process named ‘data_1.exe’ (pid 3816) then terminating itself. We can see this during the process tree listing in volatility because we don&#39;t have the matching parent process in the pslist output. I attached the graph output of the analysis I did (see below) to get a better visual representation of this activity. The rest of the memory analysis was focused on the data_1.exe activity captured during the time of execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*rbdrqrIPJ29FOILg1Edy6Q.png" /></figure><p>To note: During part 2 of this analysis, I’ll cover the behavioral and reverse engineering sections of Panda banker. This is where we’ll discover additional functionalities not covered in this write up. :)</p><p>Link to memory analysis:</p><p><a href="https://crovaxthecursed.github.io/malware%20analysis/Panda_Banker/">https://crovaxthecursed.github.io/malware%20analysis/Panda_Banker/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d08b3a855847" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>