<?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 Dhruva Bhattacharya on Medium]]></title>
        <description><![CDATA[Stories by Dhruva Bhattacharya on Medium]]></description>
        <link>https://medium.com/@dhruvab?source=rss-6f99de6c3e13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vF-K3tSDDrNLwUPN1gna8g.jpeg</url>
            <title>Stories by Dhruva Bhattacharya on Medium</title>
            <link>https://medium.com/@dhruvab?source=rss-6f99de6c3e13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:17:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhruvab/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[Decrypting all payloads of an “Agent Tesla” sample using DnSpy]]></title>
            <link>https://dhruvab.medium.com/decrypting-all-payloads-of-an-agent-tesla-sample-using-dnspy-0d26c8f12a31?source=rss-6f99de6c3e13------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d26c8f12a31</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[dnspy]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[agenttesla]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Dhruva Bhattacharya]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 08:37:19 GMT</pubDate>
            <atom:updated>2025-01-05T08:37:19.824Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Overview Of Agent Tesla</strong></h3><p>Agent Tesla is a Remote Access Trojan (RAT) and data-stealing malware, primarily written in .NET., that has been active since 2014. Cybercriminals often use it to gain access to victims’ systems through phishing emails, that trick users into downloading malicious attachments.</p><h3>Reverse Engineering an Agent Tesla Sample with DnSpy</h3><h4>Sample Details</h4><p>Sample SHA256: <strong>597a7ac2823f3ad1e10e287ed241cd662b7b8ce9694705b454b89c51e00c70ff</strong></p><p>Sample link : <a href="https://www.virustotal.com/gui/file/597a7ac2823f3ad1e10e287ed241cd662b7b8ce9694705b454b89c51e00c70ff/detection">https://www.virustotal.com/gui/file/597a7ac2823f3ad1e10e287ed241cd662b7b8ce9694705b454b89c51e00c70ff/detection</a></p><p>Download link : hxxps://virus.exchange/samples/21670996</p><h4>Payloads &amp; Work flow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*DSAfEjGKUMsJSOz99NDbbA.png" /><figcaption>Agent tesla sample Payloads</figcaption></figure><p>Agent Tesla utilizes a complex payload system, that consists of multiple encrypted components designed to enhance its stealth and effectiveness. The sample analyzed here has three payloads in total, each responsible for decrypting and executing the next one in sequence.</p><h4>Reversing</h4><p>After loading the sample on DnSpy, go to the entry point, right-click on sample name -&gt; Go to entry point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*qKyfgdeaOJWIZRGspK0L_g.png" /><figcaption>Entry poin (Main function)</figcaption></figure><p>The main() contains the “Activitor.CreateInstance()” function which is used to run the malware by creating an instance in the memory. It also makes use of reflective loading technique.</p><p>To analyze further, click on the argument being passed to the function (\u0655Z\…..61D).</p><p>You will now come across the load function, which is used by the malware to load a decrypted payload into memory. Click on the argument being passed into the function to get to the decryption loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*nFz_IoKWIEzZWoqqiek7Kw.png" /><figcaption>Load function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*W9mFXzpa_uHHu-f0VtEPqg.png" /><figcaption>Function argument passed in the load function</figcaption></figure><p>Step into the DecryptBytes function to reach the decryption loop. The image below shows the loop that decrypts the first DLL payload. Various arguments, passed into the function with the data type byte, contain the encrypted bytes of the PE file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*jiM-tR1ooPWcaK8BtRxwoA.png" /><figcaption>Decryption loop</figcaption></figure><p>To get the decrypted file, place a breakpoint on “return array” and start debugging. The entire decrypted file is saved in the “array” variable. In the image below, you can see the decrypted PE file. The first two bytes are 4D 5A, which are known as the magic bytes of PE files and can be used to identify them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*okFxL9l-B1bYcerUthtm5Q.png" /><figcaption>Decrypted file</figcaption></figure><p>For checking the file metadata and other details , you can also save this file by right clicking on “array” in Locals and then by clicking on save. The file is a win-32 dll.</p><p>Now let’s analyze the first payload by loading it in DnSpy.</p><p>In order to do that you’ll have to load the first dll in memory, which can be achieved by going to the CreateInstance function in Main(), and click on Step Into (The method varies from sample to sample). So, by performing a bit of Step-overs and Step-ins you’ll get to the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*NRm02GzNNKvc1j9jeSiABw.png" /><figcaption>Dll module loaded in memory</figcaption></figure><p>In this image you can see that the dll has been loaded and dnSpy also shows us the next method and function call, basically helping us trace the execution flow. Here you can see that “DarkUI.Control.UOBBssQL…..” is going to be called in the dll payload. Additionally, it also shows the name of the payload which is “Example”.</p><p>Now let’s analyze the first payload.</p><p><strong>Adding the payloads in DnSpy</strong></p><p>Add the dll payload as a module. As the dll has already been loaded in memory, you will be able see it in Modules. Go to Debug, then Windows and choose Modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dx7dKMv-dmdVCF1WhLNNJA.png" /><figcaption>Example.dll is the 1st payload</figcaption></figure><p>Here, we can see that “Example” has been loaded in Modules. Right click on it and click on “Go to module”, this will load the dll in DnSpy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*rWe38IABjCdlZ7L0_rfKNw.png" /><figcaption>Payload loaded in DnSpy</figcaption></figure><p>The dll has been loaded, and we can see all the modules of the dll. As we saw above that function “DarkUI.Control.UOBBssQL…..” is being called, directly navigate to the function.</p><p>Here you will come across the “Load” function which loads the 2nd payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6IFbHxs-UhpLCSq0BTZQ1w.png" /><figcaption>Loading the 2nd payload</figcaption></figure><p>Place a breakpoint here and start debugging. By stepping into the function you will get the decrypted 2nd payload. In the image below, you can see the decrypted PE file. (4D 5A)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDNogjfNh6uJjQxwPzEUSA.png" /><figcaption>2nd payload</figcaption></figure><p>You can also save the file and check the file meta data. The 2nd payload is also a 32 bit dll like the 1st one. Now lets load this in DnSpy, the way we loaded the first payload.</p><p>By performing some step-ins and step-overs we will finally get to the function that loads the dll into memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XXI-BEYS-RHH1hVP-RBuA.png" /><figcaption>2nd payload loaded in memory</figcaption></figure><p>The name of the payload is “AQipUvwTwkLZyiCs”, and you can also see the next function call here.</p><p>To load the second payload in dnSpy, follow the same steps you used to load the previous payload, then navigate to the function call within the loaded module.</p><p><em>While going through the 2nd payload I came across a very interesting function which decrypts various API calls. It’s in the same module that has the decryption loop, so I placed a breakpoint here and started debugging.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1xM4qQHPwwatS4p-Divf-A.png" /><figcaption>APIs being decrypted</figcaption></figure><p>In the above Image you can see that the “SetThreadContext” API has been decrypted, it further decrypts APIs like: WriteProcessMemory, VirtualAllocEx and Resume Thread</p><p>Malware authors often encrypt such API names to obfuscate the code, in order to evade AV detections. Malware uses these APIs in the following ways:</p><ul><li><strong>VirtualAllocEx</strong>: Allocates memory in the target process for the malicious code.</li><li><strong>WriteProcessMemory</strong>: Writes the malicious code into the allocated memory.</li><li><strong>SetThreadContext</strong>: Alters the thread’s context to execute the malicious code.</li><li><strong>ResumeThread</strong>: Resumes the thread to run the injected malicious code.</li></ul><p><strong>The Final Payload</strong></p><p>Well, we got a bit distracted there, now on to the final payload. By stepping over a few times from the previous function, we can get the final payload decrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*qWtRimRv2hAZxWsBCQWHKw.png" /><figcaption>Final payload</figcaption></figure><p>Now let’s save this file and check its properties in PEStudio. Here we can see that the file is a 32-bit .NET executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*TvL5FtP9uhGyTciisdfqew.png" /></figure><p>I executed this payload to see its behaviour using the SysInternals tool Process monitor. I found out that the exe is trying to steal sensitive information from the system.</p><p>In the image below we can see that the exe is querying the “\Microsoft\Credentials” directory, which means it is attempting to access, and exfiltrate stored credentials from applications that save username and passwords in the Windows Credential Manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*a0bB40xFCPWDPeM4_m4sig.png" /></figure><p>Additionally, it is also attempting to steal passwords saved by browsers, by querying the User Data folder, looking for files that contain sensitive data such as saved usernames, passwords and browsing history.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*RVSWrUjM4RU-Be0wgg_PhA.png" /></figure><p>This is a common behaviour of the Agent Tesla malware, as it is known for stealing sensitive information from the systems it has infected.</p><p>I hope this blog helped you understand how malware files like Agent Tesla use a payload-based approach and also how dnSpy can be used to debug .NET executables. Thank you for reading and happy debugging!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d26c8f12a31" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>