<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by jamdagnya on Medium]]></title>
        <description><![CDATA[Stories by jamdagnya on Medium]]></description>
        <link>https://medium.com/@_jamdagnya_?source=rss-4490160580c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BarNmDViWuOczTc_S0BGjw.jpeg</url>
            <title>Stories by jamdagnya on Medium</title>
            <link>https://medium.com/@_jamdagnya_?source=rss-4490160580c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 04:12:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_jamdagnya_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Windows Internals Room TryHackMe Solutions]]></title>
            <link>https://medium.com/@_jamdagnya_/windows-internals-room-tryhackme-solutions-8cb25f5920f8?source=rss-4490160580c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cb25f5920f8</guid>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <dc:creator><![CDATA[jamdagnya]]></dc:creator>
            <pubDate>Sat, 10 Sep 2022 06:38:52 GMT</pubDate>
            <atom:updated>2022-09-10T06:38:52.975Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://tryhackme.com/room/windowsinternals">TryHackMe | Cyber Security Training</a></p><p>This only contains the solutions for the room, and is not a walkthrough for questions step by step.</p><h3>Task 1 Introduction</h3><p>Operating systems have a lot more technology and architecture behind them than we may see at first. In this room, we will be observing the Windows operating systems and common internal components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*Llu9N4EX6np-NURj.png" /></figure><h3>Learning Objectives</h3><ul><li>Understand and interact with Windows processes and their underlying technologies.</li><li>Learn about core file formats and how they are used.</li><li>Interact with Windows internals and understand how the Windows kernel operates.</li></ul><p>With Windows machines making up a majority of corporate infrastructure, red teams need to understand Windows internals and how they can be (ab)used. The red team can (ab)use Windows to aid in evasion and exploitation when crafting offensive tools or exploits.</p><p>Before beginning this room, familiarize yourself with basic Windows usage and functionality. Basic programming knowledge in C++ and PowerShell is also recommended but not required.</p><p>We have provided a base Windows machine with the files needed to complete this room. You can access the machine in-browser or through RDP using the credentials below.</p><p>Machine IP: MACHINE_IP Username: THM-Attacker Password: Tryhackme!</p><p>This is going to be a lot of information. Please buckle your seatbelts and locate your nearest fire extinguisher.</p><p>Answer the questions below</p><p>Start the provided machine and move on to the next tasks.</p><p>Question Done</p><h3>Task 2 Processes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*RqYZ1OV-7buzAiS-.png" /></figure><p>A process maintains and represents the execution of a program; an application can contain one or more processes. A process has many components that it gets broken down into to be stored and interacted with. The <a href="https://docs.microsoft.com/en-us/windows/win32/procthread/about-processes-and-threads">Microsoft docs</a> break down these other components, “Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution.” This information may seem intimidating, but this room aims to make this concept a little less complex.</p><p>As previously mentioned, processes are created from the execution of an application. Processes are core to how Windows functions, most functionality of Windows can be encompassed as an application and has a corresponding process. Below are a few examples of default applications that start processes.</p><ul><li>MsMpEng (Microsoft Defender)</li><li>wininit (keyboard and mouse)</li><li>lsass (credential storage)</li></ul><p>Attackers can target processes to evade detections and hide malware as legitimate processes. Below is a small list of potential attack vectors attackers could employ against processes,</p><ul><li>Process Injection (<a href="https://attack.mitre.org/techniques/T1055/">TI055</a>)</li><li>Process Hollowing (<a href="https://attack.mitre.org/techniques/T1055/012/">TI055.012</a>)</li><li>Process Masquerading (<a href="https://attack.mitre.org/techniques/T1055/013/">TI055.013</a>)</li></ul><p>Processes have many components; they can be split into key characteristics that we can use to describe processes at a high level. The table below describes each critical component of processes and their purpose.</p><p><strong>Process Component<br>Purpose</strong><br>Private Virtual Address Space<br>Virtual memory addresses that the process is allocated.<br>Executable Program<br>Defines code and data stored in the virtual address space.<br>Open Handles<br>Defines handles to system resources accessible to the process.<br>Security Context<br>The access token defines the user, security groups, privileges, and other security information.<br>Process ID <br>Unique numerical identifier of the process.<br>Threads<br>Section of a process scheduled for execution.</p><p>We can also explain a process at a lower level as it resides in the virtual address space. The table and diagram below depict what a process looks like in memory.</p><p><strong>Component<br>Purpose</strong><br>Code<br>Code to be executed by the process.<br>Global Variables<br>Stored variables.<br>Process Heap<br>Defines the heap where data is stored.<br>Process Resources<br>Defines further resources of the process.<br>Environment Block<br>Data structure to define process information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*umYWt_zWA8h4ryaD.png" /></figure><p>This information is excellent to have when we get deeper into exploiting and abusing the underlying technologies, but they are still very abstract. We can make the process tangible by observing them in the <em>Windows Task Manager</em>. The task manager can report on many components and information about a process. Below is a table with a brief list of essential process details.</p><p><strong>Value/Component<br>Purpose<br>Example</strong><br>Name<br>Define the name of the process, typically inherited from the application<br>conhost.exe<br>PID<br>Unique numerical value to identify the process<br>7408<br>Status<br>Determines how the process is running (running, suspended, etc.)<br>Running<br>User name<br>User that initiated the process. Can denote privilege of the process<br>SYSTEM</p><p>These are what you would interact with the most as an end-user or manipulate as an attacker.</p><p>There are multiple utilities available that make observing processes easier; including <a href="https://github.com/processhacker/processhacker">Process Hacker 2</a>, <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer">Process Explorer</a>, and <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/procmon">Procmon</a>.</p><p>Processes are at the core of most internal Windows components. The following tasks will extend the information about processes and how they’re used in Windows.</p><p>Answer the questions below</p><p>Open the provided file: “Logfile.PML” in Procmon and answer the questions below.</p><p>Question Done</p><p>What is the process ID of “notepad.exe”?</p><p>Correct Answer</p><p><strong>5984</strong></p><p>What is the parent process ID of the previous process?</p><p>Correct Answer</p><p><strong>3412</strong></p><p>What is the integrity level of the process?</p><p>Correct Answer</p><p><strong>High</strong></p><h3>Task 3 Threads</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*qEcvCAEkpiWcYS8S.png" /></figure><p>A thread is an executable unit employed by a process and scheduled based on device factors.</p><p>Device factors can vary based on CPU and memory specifications, priority and logical factors, and others.</p><p>We can simplify the definition of a thread: “controlling the execution of a process.”</p><p>Since threads control execution, this is a commonly targeted component. Thread abuse can be used on its own to aid in code execution, or it is more widely used to chain with other API calls as part of other techniques.</p><p>Threads share the same details and resources as their parent process, such as code, global variables, etc. Threads also have their unique values and data, outlined in the table below.</p><p><strong>ComponentPurpose</strong></p><p>Stack <br>All data relevant and specific to the thread (exceptions, procedure calls, etc.)<br>Thread Local Storage<br>Pointers for allocating storage to a unique data environment<br>Stack Argument<br>Unique value assigned to each thread<br>Context Structure<br>Holds machine register values maintained by the kernel</p><p>Threads may seem like bare-bones and simple components, but their function is critical to processes.</p><p>Answer the questions below</p><p>Open the provided file: “Logfile.PML” in Procmon and answer the questions below.</p><p>Question Done</p><p>What is the thread ID of the first thread created by notepad.exe?</p><p>Correct Answer</p><p><strong>5908</strong></p><p>What is the stack argument of the previous thread?</p><p>Correct Answer</p><p><strong>6584</strong></p><h3>Task 4 Virtual Memory</h3><p>Virtual memory is a critical component of how Windows internals work and interact with each other. Virtual memory allows other internal components to interact with memory as if it was physical memory without the risk of collisions between applications. The concept of modes and collisions is explained further in task 8.</p><p>Virtual memory provides each process with a <a href="https://docs.microsoft.com/en-us/windows/win32/memory/virtual-address-space">private virtual address space</a>. A memory manager is used to translate virtual addresses to physical addresses. By having a private virtual address space and not directly writing to physical memory, processes have less risk of causing damage.</p><p>The memory manager will also use <em>pages</em> or <em>transfers</em> to handle memory. Applications may use more virtual memory than physical memory allocated; the memory manager will transfer or page virtual memory to the disk to solve this problem. You can visualize this concept in the diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*1UY1cs-fAauuYQmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*k70SlhWOU2f_6Lnx.png" /></figure><p>The theoretical maximum virtual address space is 4 GB on a 32-bit x86 system.</p><p>This address space is split in half, the lower half (<em>0x00000000–0x7FFFFFFF</em>) is allocated to processes as mentioned above. The upper half (<em>0x80000000–0xFFFFFFFF</em>) is allocated to OS memory utilization. Administrators can alter this allocation layout for applications that require a larger address space through settings (<em>increaseUserVA</em>) or the <a href="https://docs.microsoft.com/en-us/windows/win32/memory/address-windowing-extensions">AWE (<strong>A</strong>ddress <strong>W</strong>indowing <strong>E</strong>xtensions)</a>.</p><p>The theoretical maximum virtual address space is 256 TB on a 64-bit modern system.</p><p>The exact address layout ratio from the 32-bit system is allocated to the 64-bit system.</p><p>Most issues that require settings or AWE are resolved with the increased theoretical maximum.</p><p>You can visualize both of the address space allocation layouts to the right.</p><p>Although this concept does not directly translate to Windows internals or concepts, it is crucial to understand. If understood correctly, it can be leveraged to aid in abusing Windows internals.</p><p>Answer the questions below</p><p>Read the above and answer the questions below.</p><p>Question Done</p><p>What is the total theoretical maximum virtual address space of a 32-bit x86 system?</p><p>Correct Answer</p><p><strong>4 GB</strong></p><p>What default setting flag can be used to reallocate user process address space?</p><p>Correct Answer</p><p><strong><em>increaseUserVA</em></strong></p><p>Open the provided file: “Logfile.PML” in Procmon and answer the questions below.</p><p>Question Done</p><p>What is the base address of “notepad.exe”?</p><p>Correct Answer</p><p><strong>0x7ff652ec0000</strong></p><h3>Task 5 Dynamic Link Libraries</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*lnXANjr2c5auhLjF.png" /></figure><p>The <a href="https://docs.microsoft.com/en-us/troubleshoot/windows-client/deployment/dynamic-link-library#:~:text=A%20DLL%20is%20a%20library,common%20dialog%20box%20related%20functions.">Microsoft docs</a> describe a DLL as “a library that contains code and data that can be used by more than one program at the same time.”</p><p>DLLs are used as one of the core functionalities behind application execution in Windows. From the <a href="https://docs.microsoft.com/en-us/troubleshoot/windows-client/deployment/dynamic-link-library#:~:text=A%20DLL%20is%20a%20library,common%20dialog%20box%20related%20functions.">Windows documentation</a>, “The use of DLLs helps promote modularization of code, code reuse, efficient memory usage, and reduced disk space. So, the operating system and the programs load faster, run faster, and take less disk space on the computer.”</p><p>When a DLL is loaded as a function in a program, the DLL is assigned as a dependency. Since a program is dependent on a DLL, attackers can target the DLLs rather than the applications to control some aspect of execution or functionality.</p><ul><li>DLL Hijacking (<a href="https://attack.mitre.org/techniques/T1574/001/">T1574.001</a>)</li><li>DLL Side-Loading (<a href="https://attack.mitre.org/techniques/T1574/002/">T1574.002</a>)</li><li>DLL Injection (<a href="https://attack.mitre.org/techniques/T1055/001/">T1055.001</a>)</li></ul><p>DLLs are created no different than any other project/application; they only require slight syntax modification to work. Below is an example of a DLL from the <em>Visual C++ Win32 Dynamic-Link Library project</em>.</p><pre>#include &quot;stdafx.h&quot;<br>#define EXPORTING_DLL<br>#include &quot;sampleDLL.h&quot;<br>BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved<br>)<br>{<br>    return TRUE;<br>}</pre><pre>void HelloWorld()<br>{<br>    MessageBox( NULL, TEXT(&quot;Hello World&quot;), TEXT(&quot;In a DLL&quot;), MB_OK);<br>}</pre><p>Below is the header file for the DLL; it will define what functions are imported and exported. We will discuss the header file’s importance (or lack of) in the next section of this task.</p><pre>#ifndef INDLL_H<br>    #define INDLL_H<br>    #ifdef EXPORTING_DLL<br>        extern __declspec(dllexport) void HelloWorld();<br>    #else<br>        extern __declspec(dllimport) void HelloWorld();<br>    #endif</pre><pre>#endif</pre><p>The DLL has been created, but that still leaves the question of how are they used in an application?</p><p>DLLs can be loaded in a program using <em>load-time dynamic linking</em> or <em>run-time dynamic linking</em>.</p><p>When loaded using <em>load-time dynamic linking</em>, explicit calls to the DLL functions are made from the application. You can only achieve this type of linking by providing a header (<em>.h</em>) and import library (<em>.lib</em>) file. Below is an example of calling an exported DLL function from an application.</p><pre>#include &quot;stdafx.h&quot;<br>#include &quot;sampleDLL.h&quot;<br>int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br>{<br>    HelloWorld();<br>    return 0;<br>}</pre><p>When loaded using <em>run-time dynamic linking</em>, a separate function (LoadLibrary or LoadLibraryEx) is used to load the DLL at run time. Once loaded, you need to use GetProcAddress to identify the exported DLL function to call. Below is an example of loading and importing a DLL function in an application.</p><pre>...<br>typedef VOID (*DLLPROC) (LPTSTR);<br>...<br>HINSTANCE hinstDLL;<br>DLLPROC HelloWorld;<br>BOOL fFreeDLL;</pre><pre>hinstDLL = LoadLibrary(&quot;sampleDLL.dll&quot;);<br>if (hinstDLL != NULL)<br>{<br>    HelloWorld = (DLLPROC) GetProcAddress(hinstDLL, &quot;HelloWorld&quot;);<br>    if (HelloWorld != NULL)<br>        (HelloWorld);<br>    fFreeDLL = FreeLibrary(hinstDLL);<br>}<br>...</pre><p>In malicious code, threat actors will often use run-time dynamic linking more than load-time dynamic linking. This is because a malicious program may need to transfer files between memory regions, and transferring a single DLL is more manageable than importing using other file requirements.</p><p>Answer the questions below</p><p>Open the provided file: “Logfile.PML” in Procmon and answer the questions below.</p><p>Question Done</p><p>What is the base address of “ntdll.dll” loaded from “notepad.exe”?</p><p>Correct Answer</p><p><strong>0x7ffd0be20000</strong></p><p>What is the size of “ntdll.dll” loaded from “notepad.exe”?</p><p>Correct Answer</p><p><strong>0x1ec000</strong></p><p>How many DLLs were loaded by “notepad.exe”?</p><p>Correct Answer</p><p><strong>51</strong></p><h3>Task 6 Portable Executable Format</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/0*7wSFATAlyCpcGNCX.png" /></figure><p>Executables and applications are a large portion of how Windows internals operate at a higher level. the PE (<strong>P</strong>ortable <strong>E</strong>xecutable) format defines the information about the executable and stored data. The PE format also defines the structure of how data components are stored.</p><p>The PE (<strong>P</strong>ortable <strong>E</strong>xecutable) format is an overarching structure for executable and object files. The PE (<strong>P</strong>ortable <strong>E</strong>xecutable) and COFF (<strong>C</strong>ommon <strong>O</strong>bject <strong>F</strong>ile <strong>F</strong>ormat) files make up the PE format.</p><p>PE data is most commonly seen in the hex dump of an executable file. Below we will break down a hex dump of calc.exe into the sections of PE data.</p><p>The structure of PE data is broken up into seven components,</p><p>The <strong>DOS Header</strong> defines the type of file</p><p>The MZ DOS header defines the file format as .exe. The DOS header can be seen in the hex dump section below.</p><pre>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br>00000000  4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00  MZ..........ÿÿ..<br>00000010  B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  ¸.......@.......<br>00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................<br>00000030  00 00 00 00 00 00 00 00 00 00 00 00 E8 00 00 00  ............è...<br>00000040  0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C CD 21 54 68  ..º..´.Í!¸.LÍ!Th</pre><p>The <strong>DOS Stub</strong> is a program run by default at the beginning of a file that prints a compatibility message. This does not affect any functionality of the file for most users.</p><p>The DOS stub prints the message This program cannot be run in DOS mode. The DOS stub can be seen in the hex dump section below.</p><pre>00000040  0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C CD 21 54 68  ..º..´.Í!¸.LÍ!Th<br>00000050  69 73 20 70 72 6F 67 72 61 6D 20 63 61 6E 6E 6F  is program canno<br>00000060  74 20 62 65 20 72 75 6E 20 69 6E 20 44 4F 53 20  t be run in DOS <br>00000070  6D 6F 64 65 2E 0D 0D 0A 24 00 00 00 00 00 00 00  mode....$.......</pre><p>The <strong>PE File Header</strong> provides PE header information of the binary. Defines the format of the file, contains the signature and image file header, and other information headers.</p><p>The PE file header is the section with the least human-readable output. You can identify the start of the PE file header from the PE stub in the hex dump section below.</p><pre>000000E0  00 00 00 00 00 00 00 00 50 45 00 00 64 86 06 00  ........PE..d†..<br>000000F0  10 C4 40 03 00 00 00 00 00 00 00 00 F0 00 22 00  .Ä@.........ð.&quot;.<br>00000100  0B 02 0E 14 00 0C 00 00 00 62 00 00 00 00 00 00  .........b......<br>00000110  70 18 00 00 00 10 00 00 00 00 00 40 01 00 00 00  p..........@....<br>00000120  00 10 00 00 00 02 00 00 0A 00 00 00 0A 00 00 00  ................<br>00000130  0A 00 00 00 00 00 00 00 00 B0 00 00 00 04 00 00  .........°......<br>00000140  63 41 01 00 02 00 60 C1 00 00 08 00 00 00 00 00  cA....`Á........<br>00000150  00 20 00 00 00 00 00 00 00 00 10 00 00 00 00 00  . ..............<br>00000160  00 10 00 00 00 00 00 00 00 00 00 00 10 00 00 00  ................<br>00000170  00 00 00 00 00 00 00 00 94 27 00 00 A0 00 00 00  ........”&#39;.. ...<br>00000180  00 50 00 00 10 47 00 00 00 40 00 00 F0 00 00 00  .P...G...@..ð...<br>00000190  00 00 00 00 00 00 00 00 00 A0 00 00 2C 00 00 00  ......... ..,...<br>000001A0  20 23 00 00 54 00 00 00 00 00 00 00 00 00 00 00   #..T...........<br>000001B0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................<br>000001C0  10 20 00 00 18 01 00 00 00 00 00 00 00 00 00 00  . ..............<br>000001D0  28 21 00 00 40 01 00 00 00 00 00 00 00 00 00 00  (!..@...........<br>000001E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................</pre><p>The <strong>Image Optional Header</strong> has a deceiving name and is an important part of the <strong>PE File Header</strong></p><p>The <strong>Data Dictionaries</strong> are part of the image optional header. They point to the image data directory structure.</p><p>The <strong>Section Table</strong> will define the available sections and information in the image. As previously discussed, sections store the contents of the file, such as code, imports, and data. You can identify each section definition from the table in the hex dump section below.</p><pre>000001F0  2E 74 65 78 74 00 00 00 D0 0B 00 00 00 10 00 00  .text...Ð.......<br>00000200  00 0C 00 00 00 04 00 00 00 00 00 00 00 00 00 00  ................<br>00000210  00 00 00 00 20 00 00 60 2E 72 64 61 74 61 00 00  .... ..`.rdata..<br>00000220  76 0C 00 00 00 20 00 00 00 0E 00 00 00 10 00 00  v.... ..........<br>00000230  00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 40  ............@..@<br>00000240  2E 64 61 74 61 00 00 00 B8 06 00 00 00 30 00 00  .data...¸....0..<br>00000250  00 02 00 00 00 1E 00 00 00 00 00 00 00 00 00 00  ................<br>00000260  00 00 00 00 40 00 00 C0 2E 70 64 61 74 61 00 00  ....@..À.pdata..<br>00000270  F0 00 00 00 00 40 00 00 00 02 00 00 00 20 00 00  ð....@....... ..<br>00000280  00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 40  ............@..@<br>00000290  2E 72 73 72 63 00 00 00 10 47 00 00 00 50 00 00  .rsrc....G...P..<br>000002A0  00 48 00 00 00 22 00 00 00 00 00 00 00 00 00 00  .H...&quot;..........<br>000002B0  00 00 00 00 40 00 00 40 2E 72 65 6C 6F 63 00 00  ....@..@.reloc..<br>000002C0  2C 00 00 00 00 A0 00 00 00 02 00 00 00 6A 00 00  ,.... .......j..<br>000002D0  00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 42  ............@..B</pre><p>Now that the headers have defined the format and function of the file, the sections can define the contents and data of the file.</p><p><strong>Section<br>Purpose</strong><br>.text<br>Contains executable code and entry point<br>.data <br>Contains initialized data (strings, variables, etc.)<br>.rdata or .idata<br>Contains imports (Windows API) and DLLs.<br>.reloc<br>Contains relocation information<br>.rsrc<br>Contains application resources (images, etc.)<br>.debug<br>Contains debug information</p><p>Answer the questions below</p><p>Read the above and answer the questions below.</p><p>Question Done</p><p>What PE component prints the message “This program cannot be run in DOS mode”?</p><p><strong>DOS Stub</strong></p><p>Open “notepad.exe” in Detect It Easy and answer the questions below.</p><p>Question Done</p><p>What is the entry point reported by DiE?</p><p><strong>000000014001acd0</strong></p><p>What is the value of “<em>NumberOfSections</em>”?</p><p><strong>0006</strong></p><p>What is the virtual address of “<em>.data</em>”?</p><p>Correct Answer</p><p><strong>00024000</strong></p><p>What string is located at the offset “0001f99c”?</p><p>Correct Answer</p><p><strong>Microsoft.Notepad</strong></p><h3>Task 7 Interacting with Windows Internals</h3><p>Interacting with Windows internals may seem daunting, but it has been dramatically simplified. The most accessible and researched option to interact with Windows Internals is to interface through Windows API calls. The Windows API provides native functionality to interact with the Windows operating system. The API contains the Win32 API and, less commonly, the Win64 API.</p><p>We will only provide a brief overview of using a few specific API calls relevant to Windows internals in this room. Check out the <a href="https://tryhackme.com/room/windowsapi">Windows API room</a> for more information about the Windows API.</p><p>Most Windows internals components require interacting with physical hardware and memory.</p><p>The Windows kernel will control all programs and processes and bridge all software and hardware interactions. This is especially important since many Windows internals require interaction with memory in some form.</p><p>An application by default normally cannot interact with the kernel or modify physical hardware and requires an interface. This problem is solved through the use of processor modes and access levels.</p><p>A Windows processor has a <em>user</em> and <em>kernel</em> mode. The processor will switch between these modes depending on access and requested mode.</p><p>The switch between user mode and kernel mode is often facilitated by system and API calls. In documentation, this point is sometimes referred to as the “<em>Switching Point</em>.”</p><p><strong>User modeKernel Mode</strong>No direct hardware access<br>Direct hardware access<br>Creates a process in a private virtual address space<br>Ran in a single shared virtual address space<br>Access to “owned memory locations”<br>Access to entire physical memory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/0*TurMpvA-5NIcIg57.png" /></figure><p>Applications started in user mode or “<em>userland” </em>will stay in that mode until a system call is made or interfaced through an API. When a system call is made, the application will switch modes. Pictured right is a flow chart describing this process.</p><p>When looking at how languages interact with the Win32 API, this process can become further warped; the application will go through the language runtime before going through the API. The most common example is C# executing through the CLR before interacting with the Win32 API and making system calls.</p><p>We will inject a message box into our local process to demonstrate a proof-of-concept to interact with memory.</p><p>The steps to write a message box to memory are outlined below,</p><ol><li>Allocate local process memory for the message box.</li><li>Write/copy the message box to allocated memory.</li><li>Execute the message box from local process memory.</li></ol><p>At step one, we can use OpenProcess to obtain the handle of the specified process.</p><pre>HANDLE hProcess = OpenProcess(<br>	PROCESS_ALL_ACCESS, // Defines access rights<br>	FALSE, // Target handle will not be inhereted<br>	DWORD(atoi(argv[1])) // Local process supplied by command-line arguments <br>);</pre><p>At step two, we can use VirtualAllocEx to allocate a region of memory with the payload buffer.</p><pre>remoteBuffer = VirtualAllocEx(<br>	hProcess, // Opened target process<br>	NULL, <br>	sizeof payload, // Region size of memory allocation<br>	(MEM_RESERVE | MEM_COMMIT), // Reserves and commits pages<br>	PAGE_EXECUTE_READWRITE // Enables execution and read/write access to the commited pages<br>);</pre><p>At step three, we can use WriteProcessMemory to write the payload to the allocated region of memory.</p><pre>WriteProcessMemory(<br>	hProcess, // Opened target process<br>	remoteBuffer, // Allocated memory region<br>	payload, // Data to write<br>	sizeof payload, // byte size of data<br>	NULL<br>);</pre><p>At step four, we can use CreateRemoteThread to execute our payload from memory.</p><pre>remoteThread = CreateRemoteThread(<br>	hProcess, // Opened target process<br>	NULL, <br>	0, // Default size of the stack<br>	(LPTHREAD_START_ROUTINE)remoteBuffer, // Pointer to the starting address of the thread<br>	NULL, <br>	0, // Ran immediately after creation<br>	NULL<br>);</pre><p>Answer the questions below</p><p>Open a command prompt and execute the provided file: “inject-poc.exe” and answer the questions below.</p><p>Question Done</p><p>Enter the flag obtained from the executable below.</p><p><strong>THM{1Nj3c7_4lL_7H3_7h1NG2}</strong></p><h3>Task 8 Conclusion</h3><p>Windows internals are core to how the Windows operating system works. These internals cannot change without compromising how the operating system operates at a bare-bones level. Because of this, the Windows internals are a rewarding target for attackers.</p><p>As mentioned throughout the room, attackers can easily abuse the functionality of Windows internals components for nefarious reasons. For more information about this, check out the Abusing Windows Internals room.</p><p>Many of the concepts covered in this room can even translate to Unix counter-parts. While specifics of the attacks and how they are executed may change, many of the core concepts stay the same.</p><p>Overall, Windows internals are here to stay; both the red and blue teams need to be aware of their capabilities, including how and why they are used.</p><p>Answer the questions below</p><p>Read the above and continue learning!</p><p>Question Done</p><p>Thanks for reading. Have a great day ahead!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cb25f5920f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>