<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 7mo</title>
    <description>The latest articles on DEV Community by 7mo (@7mo_sec).</description>
    <link>https://dev.to/7mo_sec</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3715679%2Fca40422a-9a5f-48aa-aec6-56d7ae874c78.jpeg</url>
      <title>DEV Community: 7mo</title>
      <link>https://dev.to/7mo_sec</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/7mo_sec"/>
    <language>en</language>
    <item>
      <title>Secure Ransomware Development 101 ~ How Do malware researchers break your ransomware via faulted compiler optimization</title>
      <dc:creator>7mo</dc:creator>
      <pubDate>Thu, 19 Mar 2026 22:19:45 +0000</pubDate>
      <link>https://dev.to/7mo_sec/secure-ransomware-development-101-how-do-malware-researchers-break-your-ransomware-via-faulted-16a5</link>
      <guid>https://dev.to/7mo_sec/secure-ransomware-development-101-how-do-malware-researchers-break-your-ransomware-via-faulted-16a5</guid>
      <description>&lt;p&gt;so if you haven't seen part 1  you must go and check it out , so you can understand how does optimization influence code and what type of security issues does it bring to life  . &lt;/p&gt;




&lt;p&gt;lets dive strait into a simple example of a text encryption that is flawed not by the code , but the compiler optimization .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;_FALWEDcleanup&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;);}}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;_CRYPTR&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;inputLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;keyLen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;inputLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;keyLen&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;bufferSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bufferSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ourKEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;strcpy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ourKEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"i_love_you_000x"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"enter some text to encrypt :  "&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fgets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;bufferSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;strcspn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

        &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;_CRYPTR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ourKEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"results (hex so you can see it ): "&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%02X "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;_CRYPTR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ourKEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Decrypted: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// here is the error we are going to analyze&lt;/span&gt;
        &lt;span class="n"&gt;_FALWEDcleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ourKEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ourKEY&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you see this is a very simple exmaple&lt;br&gt;
we simply take in a user input XOR it with a key then print out the output , then xor it again that will reverse the operation and print out the decrypted text&lt;/p&gt;

&lt;p&gt;if you take a look at line 44 = we call a cleaner function which is doing :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;_FALWEDcleanup&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so in English this code is " writes zeros over our data to hide it and then tells the computer you're done using that memory. " &lt;/p&gt;

&lt;p&gt;so the developer is hoping that by setting it to zeros memory dumps wont show the key which is absolutely wrong if you optimize your code .&lt;/p&gt;

&lt;p&gt;lets first take a look at a disassembly of the non optimized code (without using the -O3)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqoy9lcj0rms9e00ghcsp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqoy9lcj0rms9e00ghcsp.png" alt=" " width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;as we see the cleanup function is there when we didn't optimize the code now lets check if its still there if we optimize the code with ' -O3 ' &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51dvchkw1buznl7bfc2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51dvchkw1buznl7bfc2z.png" alt=" " width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;as you see the cleanup function has been completely removed !!!&lt;/p&gt;

&lt;p&gt;so in theory this means the key will still reside in the memory ?&lt;/p&gt;

&lt;p&gt;(note : &lt;/p&gt;

&lt;p&gt;While a simple example might use a hardcoded key—which you could easily extract using tools like Microsoft Strings or flare FLOSS—real-world ransomware is much more sophisticated. In a live attack, the symmetric encryption key is typically generated at runtime, used to encrypt files, and then immediately wiped from memory or encrypted with an attacker’s public key to prevent recovery through memory forensics.&lt;/p&gt;

&lt;p&gt;and we are looking at the bugs that cause the key not to be fully wiped so we can fix them  ) &lt;/p&gt;




&lt;p&gt;~ BREAKING THE ENCRYPTION VIA MEMORY DUMPS ANALYSIS &lt;/p&gt;

&lt;p&gt;so before we start just edit the example code and append &lt;br&gt;
 "         getchar();      " &lt;br&gt;
at the end so we can capture the memory after everything has finished instead of the program just terminating &lt;/p&gt;

&lt;p&gt;to dump the memory of a process you can use the following command : &lt;/p&gt;

&lt;p&gt;sudo gcore -o (output_file) &lt;/p&gt;

&lt;p&gt;and to get the process id you can simply use pgrep  " pgrep   "&lt;/p&gt;

&lt;p&gt;so lets go ahead and compile &amp;amp; run the program with optimization : &lt;br&gt;
gcc -o code .c -O3&lt;/p&gt;

&lt;p&gt;then enter a string when it asks you and wait until it stops at the get char then we will use &lt;/p&gt;

&lt;p&gt;pgrep code&lt;/p&gt;

&lt;p&gt;then we will do &lt;/p&gt;

&lt;p&gt;sudo gcore DUMP.DUMP &lt;/p&gt;

&lt;p&gt;then you can run strings and grep for our key and you should 100/100 percent see it !!!&lt;/p&gt;

&lt;p&gt;and if you try without optimization you wont be able to see it since its zeroed out&lt;/p&gt;



&lt;p&gt;REEFER TO MY VIDEO WHERE I EXPLAIN THE CONCEPTS  : &lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/xR2eCh1AHug"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;note this is my first video and lowkey i cant speak, LOL. i have a mistake saying that the string is being copied to the pointer while it is actually being copied to the memory address that the pointer is looking at, but pointers are defined as  " a variable that stores the memory address of another variable, rather than a direct value " so in a way im correct but yk its better to say "memory address "  .......&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the video has a small delay (1.8 seconds) &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>computerscience</category>
      <category>asm</category>
      <category>codequality</category>
      <category>vulnerabilities</category>
    </item>
    <item>
      <title>Secure Ransomware Development 101 ~ understanding compiler optimizations</title>
      <dc:creator>7mo</dc:creator>
      <pubDate>Thu, 19 Mar 2026 08:39:29 +0000</pubDate>
      <link>https://dev.to/7mo_sec/secure-ransomware-development-101-understanding-compiler-optimizations-4jml</link>
      <guid>https://dev.to/7mo_sec/secure-ransomware-development-101-understanding-compiler-optimizations-4jml</guid>
      <description>&lt;h2&gt;
  
  
  PLEASE NOTE: Despite the provocative title, this article is strictly an educational deep-dive into ransomware internals and memory forensics. I’m showing you how the tech works under the hood—I am NOT telling you to develop ransomware or do anything illegal.
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;In this blog post, we’re going to explore Compiler Optimizations—what they are, how they work, and why sometimes they might not be as helpful as you think for your code.&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
So, let’s start with the basics: what exactly is compiler optimization, and how does it work?&lt;br&gt;
note : we use &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-O3 in this article &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  _
&lt;/h2&gt;
&lt;h1&gt;
  
  
  1 ~ what in the world is compiler optimization  ?
&lt;/h1&gt;

&lt;p&gt;in the design theory of it the fellow developers noted that the main goal of CO , is to make the code  " more efficient, without changing its original functionality " and of course the primary goals are typically to improve execution speed, reduce memory usage, minimize code size, or lower power consumption. &lt;/p&gt;

&lt;p&gt;now lets take a look at how do they work&lt;/p&gt;


&lt;h1&gt;
  
  
  2 ~ compilation pipeline
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F704i44e8f8jb8dnu9ctn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F704i44e8f8jb8dnu9ctn.png" alt=" " width="506" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OK cool now you understand how does the pipeline look like , but i focused at the ir (intermediate representation) optimization specifically (DEAD STORAGE ELIMINATION) since its the main topic of this blog . &lt;/p&gt;


&lt;h1&gt;
  
  
  3 ~ taking a look at how does the compiler work with the -O3 flag and what affects does it do on the code .
&lt;/h1&gt;

&lt;p&gt;ok , lets see this through a disassembler to understand whats really happening . &lt;/p&gt;

&lt;p&gt;take this example first  :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="c1"&gt;//printf("value was: %d, and now after memset: %d\n", val, data);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwuaxywvb8nt2j0g4z6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwuaxywvb8nt2j0g4z6z.png" alt=" " width="800" height="273"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nasm"&gt;&lt;code&gt;&lt;span class="nf"&gt;gef&lt;/span&gt;&lt;span class="err"&gt;➤&lt;/span&gt;  &lt;span class="nb"&gt;di&lt;/span&gt;&lt;span class="nv"&gt;sas&lt;/span&gt; &lt;span class="nv"&gt;main&lt;/span&gt;
&lt;span class="nf"&gt;Dump&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;assembler&lt;/span&gt; &lt;span class="nv"&gt;code&lt;/span&gt; &lt;span class="nv"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;function&lt;/span&gt; &lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001040&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;endbr64&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001044&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;xor&lt;/span&gt;    &lt;span class="nb"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;eax&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001046&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;ret&lt;/span&gt;
&lt;span class="nf"&gt;End&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;assembler&lt;/span&gt; &lt;span class="nv"&gt;dump.&lt;/span&gt;
&lt;span class="nf"&gt;gef&lt;/span&gt;&lt;span class="err"&gt;➤&lt;/span&gt;  

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you see nothing if this asm was code it will be just a return 0; as you see it xor eax to return zero and ret . &lt;/p&gt;

&lt;p&gt;because there is no output from this program &lt;/p&gt;

&lt;p&gt;first lets see the  Dead Store Elimination (DSE)&lt;/p&gt;

&lt;p&gt;This targets writes to memory.&lt;br&gt;
The "Store": memset(&amp;amp;data, 0, ...) is a command to write zeros to memory.&lt;br&gt;
Why it's "Dead": Because the variable data is never being used again after that line. The compiler sees you writing a value that will never be used by anyone.&lt;/p&gt;

&lt;p&gt;Result: The compiler deletes the memset call &lt;br&gt;
entirely.&lt;/p&gt;

&lt;p&gt;now lets take a look at Dead Code Elimination (DCE)&lt;br&gt;
This targets computations and logic that don't affect the program's output.&lt;/p&gt;

&lt;p&gt;The "Code": The variable val = secret(y) and the initialization int data = 42.&lt;/p&gt;

&lt;p&gt;Why it's "Dead": Once we commented out the printf, the variable val became useless. It doesn't influence the return value of main (which is hardcoded to 0), and it doesn't trigger any I/O.&lt;br&gt;
Result: The compiler deletes the secret function call and the int data variable itself.&lt;/p&gt;

&lt;p&gt;\ &lt;br&gt;
&lt;strong&gt;what happens if there was a printf ?&lt;/strong&gt; : &lt;/p&gt;

&lt;p&gt;something very interesting happens , fr your going to be surprised by how good are now day compilers in optimizing code &lt;/p&gt;

&lt;p&gt;\&lt;/p&gt;

&lt;p&gt;now lets check it with a printf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 


    &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 

    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"value was: %d, and now after memset: %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglqjcduym24nxy2rmvvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglqjcduym24nxy2rmvvd.png" alt=" " width="800" height="218"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nasm"&gt;&lt;code&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001060&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;endbr64&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001064&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;sub&lt;/span&gt;    &lt;span class="nb"&gt;rsp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mh"&gt;0x8&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001068&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;xor&lt;/span&gt;    &lt;span class="nb"&gt;ecx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;ecx&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x000000000000106a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;mov&lt;/span&gt;    &lt;span class="nb"&gt;edx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mh"&gt;0x2a&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x000000000000106f&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;mov&lt;/span&gt;    &lt;span class="nb"&gt;edi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mh"&gt;0x2&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001074&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;lea&lt;/span&gt;    &lt;span class="nb"&gt;rsi&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="nv"&gt;rip&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mh"&gt;0xf8d&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="mh"&gt;0x2008&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x000000000000107b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;xor&lt;/span&gt;    &lt;span class="nb"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;eax&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x000000000000107d&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;call&lt;/span&gt;   &lt;span class="mh"&gt;0x1050&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;__printf_chk@plt&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001082&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;xor&lt;/span&gt;    &lt;span class="nb"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;eax&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001084&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;add&lt;/span&gt;    &lt;span class="nb"&gt;rsp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mh"&gt;0x8&lt;/span&gt;
   &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="nf"&gt;x0000000000001088&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="nv"&gt;ret&lt;/span&gt;
&lt;span class="o"&gt;****&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the optimized assembly shows that the compiler removed all of that code. Instead of actually executing those functions at runtime, it realized that secret(y) always returns 42 and that data is only used in the subsequent printf. Since memset(&amp;amp;data, 0, sizeof(data)) simply sets data to zero and nothing else uses it, the compiler replaced the values directly in the printf call. In other words, the instructions for assigning 42, calling secret(), and zeroing data are gone — everything is hardcoded constants passed straight to printf .&lt;/p&gt;

&lt;p&gt;thats amazing tbh , cool asl . &lt;/p&gt;

&lt;p&gt;But how can some compiler optimization cause some security issues ? &lt;/p&gt;




&lt;h1&gt;
  
  
  4 ~ security issues !!
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;process_login&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;


    &lt;span class="n"&gt;strcpy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"_thx_for_reading"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 


    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"عيد مبارك &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


    &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;process_login&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the problem with this code if it has been compiled with optimizations the memset that zeros out the buffer in the memory will just be optimized under the rule that nothing after the memset touches the buffer again .&lt;/p&gt;

&lt;p&gt;whats the impact  ? : &lt;/p&gt;

&lt;p&gt;1 : If our program has a separate bug (like a buffer over-read), an attacker can trick the program into sending back more data than it should. Since the password was never wiped, it's just sitting in the "garbage" area of the RAM, ready to be leaked in a response. &lt;/p&gt;

&lt;p&gt;2 : core dumps and memory analysis&lt;/p&gt;

&lt;p&gt;3 : If another function runs right after process_login, it will re-use the same stack space.&lt;br&gt;
If that second function has a vulnerability (like a "format string" bug), an attacker can peek at the local variables of that function.&lt;br&gt;
Because the memory wasn't cleared, they aren't just seeing the new function's data—they are seeing the leftovers of our password.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;see you in part 2 ....  : )&lt;/code&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>performance</category>
      <category>testing</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Race to the Bottom: Weaponizing Concurrency , PART 1 . #THREADING</title>
      <dc:creator>7mo</dc:creator>
      <pubDate>Sat, 17 Jan 2026 02:34:25 +0000</pubDate>
      <link>https://dev.to/7mo_sec/race-to-the-bottom-weaponizing-concurrency-part-1-threading-2h7m</link>
      <guid>https://dev.to/7mo_sec/race-to-the-bottom-weaponizing-concurrency-part-1-threading-2h7m</guid>
      <description>&lt;h2&gt;
  
  
  btw im learning while creating this blog so if there is any mistake please tell me, and i will fix it and learn , THANKS !
&lt;/h2&gt;

&lt;p&gt;HI i like to dive into things immediately so take a look at this code sample here : &lt;/p&gt;

&lt;h2&gt;
  
  
  CHAPTER 1 : THREADS ?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;
#include &amp;lt;arpa/inet.h&amp;gt;

#define PORT 8080

void handle_request(int client_socket) {
    char response[2048];

    strcpy(response, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
    strcat(response, "&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;Hi&amp;lt;/h1&amp;gt;");
    write(client_socket, response, strlen(response));

    sleep(3);

    memset(response, 0, sizeof(response));  
    strcat(response, "&amp;lt;h1&amp;gt;Hi again!&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
    write(client_socket, response, strlen(response));

    close(client_socket);
}

/*-------------------------------------------------------------------------------------------*/

int main() {
    int server_socket, client_socket;
    struct sockaddr_in server_addr, client_addr;
    socklen_t client_len = sizeof(client_addr);

    server_socket = socket(AF_INET, SOCK_STREAM, 0);
    if (server_socket &amp;lt; 0) {
        perror("Error creating socket");
        exit(1);
    }

    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = INADDR_ANY;
    server_addr.sin_port = htons(PORT);  

    if (bind(server_socket, (struct sockaddr *)&amp;amp;server_addr, sizeof(server_addr)) &amp;lt; 0) {
        perror("Error binding");
        exit(1);
    }

    if (listen(server_socket, 5) &amp;lt; 0) {
        perror("Error listening");
        exit(1);
    }

    printf("Server listening on port %d...\n", PORT);

    while (1) {
        client_socket = accept(server_socket, (struct sockaddr *)&amp;amp;client_addr, &amp;amp;client_len);
        if (client_socket &amp;lt; 0) {
            perror("Error accepting connection");
            continue;
        }

        handle_request(client_socket);
    }

    close(server_socket);
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt; in the handle function , &lt;/li&gt;
&lt;li&gt;it has a response buffer that holds 2048 bytes , &lt;/li&gt;
&lt;li&gt;then it copies 200 ok and Content type into the response array after that it adds a message that says HI in the web page then writes it . &lt;/li&gt;
&lt;li&gt;sleep 3 means wait 3 seconds and then show me another message that simply says hi again after that it closes the connection . &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;--- # ---&lt;br&gt;
&lt;strong&gt;What could go wrong? The main issue with this code is that it is not threaded. This means the server processes each request sequentially — it handles one request at a time. The server blocks on each request, meaning it cannot process a new request until the current one is fully completed. As a result, the server essentially "locks itself up" while waiting for each request to finish. This approach becomes very inefficient, especially under heavy load, leading to poor performance when multiple clients try to connect at the same time. This is slow!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and also can be exploited to cause a DOS and brick the server  ? how lets get into it !&lt;/p&gt;
&lt;h2&gt;
  
  
  CHAPTER 2  :CAUSING THE DOS
&lt;/h2&gt;

&lt;p&gt;AFTER compiling the code as you can go to  : &lt;br&gt;
**&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;a href="http://127.0.0.1:8080" rel="noopener noreferrer"&gt;http://127.0.0.1:8080&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotvwqljrilme7o58o5lk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotvwqljrilme7o58o5lk.png" alt="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;yeah its working cool  ! &lt;br&gt;
but as you saw when you went it takes 3 seconds then prints hello again but the real question is how can we see the no thread thing ? &lt;br&gt;
open multiple tabs instances of the web app on the left and one on the right click them all and as you see the one on the right doesnt only take 3 seconds it takes much more time  ? &lt;br&gt;
why  ? ?? ?????&lt;br&gt;
welp simply because the server waits up until it process each one of them then goes to the last requested one &lt;/p&gt;

&lt;p&gt;if your too into it you can debug and see how does it like pause like wait until it process the first one &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkaobgkixoaztq44b4s34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkaobgkixoaztq44b4s34.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but no need running man accept tells you that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The  accept()  system  call is used with connection-based socket types (SOCK_STREAM, SOCK_SEQPACKET).  It extracts the&lt;br&gt;
       first connection request on the queue of pending connections for the listening socket&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;as you see it has a queue takes one process then close . yeah pretty slow ! &lt;/p&gt;
&lt;h2&gt;
  
  
  CHAPTER 3 : THREADING IT !
&lt;/h2&gt;

&lt;p&gt;first what is threading  ? &lt;/p&gt;
&lt;h2&gt;
  
  
  Threading in coding refers to the ability of a program to run multiple operations (or threads) concurrently. It allows a program to perform tasks in parallel, which can make it run more efficiently, especially when dealing with time-consuming operations like I/O (input/output) tasks, or heavy computations.
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread: A thread is the smallest unit of execution in a program. A thread is part of a process and can run concurrently with other threads, but each thread has its own instruction pointer, stack, and local variables.

Multithreading: This is the technique of running multiple threads at the same time within a single program. Threads share the same memory space, which allows them to communicate easily with each other but also means that you have to manage shared data carefully to avoid conflicts.

Why use threading?

Concurrency: While a single-threaded program can do only one thing at a time, a multithreaded program can perform several tasks in parallel, improving efficiency.

Responsiveness: For GUI applications, using threads can keep the user interface responsive, even while the program is working on background tasks.

Utilizing Multi-core Processors: Modern CPUs have multiple cores, and threading allows programs to use these cores for parallel processing.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;take a look here : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxia90tiygirxz3f3q8m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxia90tiygirxz3f3q8m.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this image is nice in visualizing the concept when multi threading the code all threads within the same process share the code, data, and files. This makes communication between threads very fast because they can all "see" the same global variables. and of course each one of them has its own stack and registers  &lt;/p&gt;

&lt;p&gt;before moving on to making our server multi threaded i recommend you to take a look at this blog : &lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://www.geeksforgeeks.org/c/multithreading-in-c/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.geeksforgeeks.org%2Fwp-content%2Fcdn-uploads%2Fgfg_200x200-min.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://www.geeksforgeeks.org/c/multithreading-in-c/" rel="noopener noreferrer" class="c-link"&gt;
            Multithreading in C - GeeksforGeeks
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.geeksforgeeks.org%2Fwp-content%2Fcdn-uploads%2Fgfg_favicon.png"&gt;
          geeksforgeeks.org
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
written by kartik   &lt;/p&gt;

&lt;p&gt;--------- # -------------&lt;br&gt;
so lets get into making our code multi threaded and explaining how does it work  : &lt;/p&gt;

&lt;p&gt;In C programming language, we use the POSIX Threads (pthreads) library to implement multithreading, which provides different components along with thread management functions that create the foundation of a multithreaded program in C.&lt;/p&gt;

&lt;p&gt;Creating a Thread&lt;br&gt;
The first step is to create a thread and give it a task. To create a new thread, we use the pthread_create() function provided by the thread library in C. It initializes and starts the thread to run the given function (which specifies its task).&lt;/p&gt;

&lt;p&gt;Syntax&lt;/p&gt;

&lt;p&gt;pthread_create(thread, attr, routine, arg);&lt;br&gt;
where,&lt;/p&gt;

&lt;p&gt;thread : Pointer to a pthread_t variable where the system stores the ID of the new thread.&lt;br&gt;
attr : Pointer to a thread attributes object that defines thread properties. Use NULL for default attributes.&lt;br&gt;
routine: Pointer to the function that the thread will execute. It must return void* and accept a void* argument.&lt;br&gt;
arg: A single argument passed to the thread function. Use NULL if no argument is needed. You can pass a struct or pointer to pass multiple values.&lt;/p&gt;



&lt;p&gt;&lt;code&gt;SEEMS EASY !&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we only need to simple changes  : &lt;/p&gt;

&lt;p&gt;1 --  &amp;gt; append the library header  : #include .&lt;br&gt;
2 -- &amp;gt; second we go back to filling the pthread_create() params&lt;/p&gt;

&lt;p&gt;------ filling the arguments ------&lt;br&gt;
looking at the man page of pthread_create the first argument is  : pthread_t *restrict thread which also explained in man is  :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---------------------------------------------------------------
Before  returning,  a  successful call to pthread_create() stores the ID of the new thread in the buffer pointed to by
       thread; this identifier is used to refer to the thread in subsequent calls to other pthreads functions.
-----------------------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  so we declare it by adding in the code :  pthread_t thread_id;
&lt;/h1&gt;

&lt;p&gt;second argument&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; The  attr  argument  points to a pthread_attr_t structure whose contents are used at thread creation time to determine
       attributes for the new thread; this structure is initialized using pthread_attr_init(3)  and  related  functions.   If
       attr is NULL, then the thread is created with default attributes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  so we leave our second argument as null
&lt;/h1&gt;

&lt;p&gt;third argument : in the function syntax it says  void &lt;em&gt;(*start_routine)&lt;br&gt;
so start routine most likely means the function and our function is simply the handler but looking at the blog written by kartik it says  : &lt;br&gt;
*&lt;/em&gt;&lt;em&gt;*&lt;em&gt;_routine: Pointer to the function that the thread will execute. It must return void&lt;/em&gt; and accept a void* argument.&lt;/em&gt;&lt;strong&gt;_&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;so first  we want to return a void pointer so in the function end it with &lt;/p&gt;

&lt;p&gt;&lt;code&gt;return NULL; &lt;br&gt;
&lt;/code&gt;&lt;br&gt;
2 -- &amp;gt; IT MUST ACCEPT A VOID ARGUMENT SO I SIMPLY DID  : &lt;br&gt;
void *client_socket_ptr&lt;/p&gt;

&lt;p&gt;so after fixing things casting and calling we are done and left with   :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;
#include &amp;lt;arpa/inet.h&amp;gt;
#include &amp;lt;pthread.h&amp;gt; 

#define PORT 8080

void *handle_request(void *client_socket_ptr) {
    int client_socket = *((int *)client_socket_ptr);  
    char response[2048];

    printf("Handling request...\n");

    strcpy(response, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
    strcat(response, "&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;Hi&amp;lt;/h1&amp;gt;");
    printf("Response sent: Hi\n");
    write(client_socket, response, strlen(response));

    sleep(3);  

    printf("Waiting for 3 seconds...\n");

    memset(response, 0, sizeof(response));  
    strcat(response, "&amp;lt;h1&amp;gt;Hi again!&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
    printf("Response sent: Hi again\n");
    write(client_socket, response, strlen(response));

    close(client_socket);
    printf("Client socket closed\n");

    return NULL;  
}

/*-------------------------------------------------------------------------------------------*/

int main() {
    int server_socket, client_socket;
    struct sockaddr_in server_addr, client_addr;
    socklen_t client_len = sizeof(client_addr);

    printf("Starting server...\n");

    server_socket = socket(AF_INET, SOCK_STREAM, 0);
    if (server_socket &amp;lt; 0) {
        perror("Error creating socket");
        exit(1);
    }
    printf("Server socket created\n");

    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = INADDR_ANY;
    server_addr.sin_port = htons(PORT);  

    if (bind(server_socket, (struct sockaddr *)&amp;amp;server_addr, sizeof(server_addr)) &amp;lt; 0) {
        perror("Error binding");
        exit(1);
    }
    printf("Socket bound to port %d\n", PORT);

    if (listen(server_socket, 5) &amp;lt; 0) {
        perror("Error listening");
        exit(1);
    }
    printf("Server listening on port %d...\n", PORT);

    while (1) {
        printf("Waiting for client connection...\n");

        client_socket = accept(server_socket, (struct sockaddr *)&amp;amp;client_addr, &amp;amp;client_len);
        if (client_socket &amp;lt; 0) {
            perror("Error accepting connection");
            continue;
        }

        printf("Client connected, handling request...\n");

        pthread_t thread_id;
        if (pthread_create(&amp;amp;thread_id, NULL, handle_request, (void *)&amp;amp;client_socket) != 0) {
            perror("Error creating thread");
        }

        pthread_detach(thread_id);
    }

    close(server_socket);
    printf("Server socket closed\n");

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you see super simple changes !&lt;br&gt;
recompile and run it &lt;br&gt;
access it from multiple browsers and tabs do whatever you see it always takes 3 seconds and your hi again is there !&lt;/p&gt;

&lt;h2&gt;
  
  
  BUT !!!!  (the way) this code has been developed has a security vulnerability in it , see you in part 2 ;) -- we will have a fun time debugging and understanding and finding such cool issues !
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frm2er0irseqsphfss4xw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frm2er0irseqsphfss4xw.jpg" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ctf</category>
      <category>hardwarehacking</category>
      <category>reversing</category>
    </item>
  </channel>
</rss>
