<?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 Nick Powers on Medium]]></title>
        <description><![CDATA[Stories by Nick Powers on Medium]]></description>
        <link>https://medium.com/@zyn3rgy?source=rss-e8d131c41615------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4iCSUS4ok3rEC6CJGYKywA.png</url>
            <title>Stories by Nick Powers on Medium</title>
            <link>https://medium.com/@zyn3rgy?source=rss-e8d131c41615------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:26:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zyn3rgy/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[Relay Your Heart Away: An OPSEC-Conscious Approach to 445 Takeover]]></title>
            <link>https://medium.com/specter-ops-posts/relay-your-heart-away-an-opsec-conscious-approach-to-445-takeover-1c9b4666c8ac?source=rss-e8d131c41615------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9b4666c8ac</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[command-and-control]]></category>
            <category><![CDATA[ntlm-relay]]></category>
            <category><![CDATA[offensive-security]]></category>
            <dc:creator><![CDATA[Nick Powers]]></dc:creator>
            <pubDate>Thu, 01 Aug 2024 16:12:53 GMT</pubDate>
            <atom:updated>2024-08-01T16:12:53.605Z</atom:updated>
            <content:encoded><![CDATA[<p>Even within organizations that have achieved a mature security posture, targeted NTLM relay attacks are still incredibly effective after all these years of abuse. Leveraging several of these NTLM relay primitives, specifically ones that require coercing SMB-based authentication, come with additional challenges to overcome while operating over command and control (C2). This technique will the ease abuse of several popular NTLM relay primitives by allowing attackers to control inbound 445/tcp traffic without loading a driver, loading a module into LSASS, or requiring a reboot of the target Windows machine.</p><h3>Introduction</h3><p>When conducting a penetration test or red team from a device that can directly route into a target network, there is often a straightforward path to control inbound SMB-based traffic on port 445/tcp. Common scenarios include a Windows laptop plugged directly into ethernet, a deployed Linux virtual machine, VPN accessibility, etc.</p><p>In the case of Windows, the `LanmanServer` service can be disabled, followed by a reboot, and the Windows kernel is no longer bound to the target port. In the case of a Linux machine, having escalated privileges on your testing device will allow for binding to the target port.</p><p>However, conducting your offensive assessment through a C2 agent includes a few additional hurdles to overcome. A commonly problematic step is gaining is gaining control of inbound SMB-based authentication attempts on port 445/tcp from a compromised Windows host.</p><p>If you’re interested in skipping the technical analysis and getting straight to the solution, see the <strong>Implementation Summary </strong>section.</p><h3>Existing Solutions</h3><h4>WinDivert driver</h4><p>The <a href="https://github.com/basil00/Divert">WinDivert </a>driver is described as a “a user-mode packet interception library that enables user-mode capturing/modifying/dropping of network packets sent to/from the Windows network stack”. Many popular open-source projects have been created to leverage this driver to redirect inbound SMB-based authentication, such as <a href="https://github.com/praetorian-inc/PortBender">PortBender</a>, <a href="https://github.com/pkb1s/SharpRelay">SharpRelay</a>, <a href="https://github.com/jellever/StreamDivert">StreamDivert</a>, <a href="https://github.com/Arno0x/DivertTCPconn">DivertTCPconn</a>, <a href="https://github.com/MRGEffitas/hwfwbypass">hwfwbypass</a>, and more.</p><h4>Lsarelayx</h4><p>The <a href="https://github.com/CCob/lsarelayx">lsarelayx</a> by <a href="https://x.com/_EthicalChaos_">@_EthicalChaos_</a> is a “system wide NTLM relay tool designed to relay incoming NTLM based authentication to the host it is running on” by leveraging “a fake LSA authentication provider to hook the NTLM and Negotiate packages and facilitate redirecting authentication requests”.</p><h4>Disabling LanmanServer w/ Reboot</h4><p>The LanmanServer service can simply be set to a ‘disabled’ start type. When the Windows machine is rebooted, 445/tcp will no longer be bound by the kernel.</p><h3>OPSEC Considerations</h3><p>Leveraging a driver for post-exploitation involves several considerations, such as potential for BSOD. This is a risk we cannot afford to take in certain situations. Especially when conducting activities on high-uptime, critical infrastructure. Loading a driver, especially one publicly associated with popular abuse primitives, can also be a single point of failure regarding detection and prevention.</p><p>Loading a customer LSA authentication provider can come with similar risks, as it can affect the stability of the LSASS process. You could be one incorrectly handled error away from a forced reboot depending on your code. As a Microsoft-specific limitation of how LSA plugins work, the provider also cannot be unloaded until a reboot occurs (<a href="https://github.com/CCob/lsarelayx?tab=readme-ov-file#caveats">without getting creative</a>).</p><p>Disabling the LanmanServer service also requires either forcing, or waiting for, a reboot of the target machine. This often isn’t an option due to time constraints or high-uptime needs of a production environment.</p><p>Ideally, we would be able to control traffic inbound on the target port without loading a driver, loading a module into LSASS, or rebooting the target machine.</p><h3>Technical Analysis</h3><h4>Prerequisite Notes</h4><p>As previously mentioned, configuring the `<em>LanmanServer</em>` service to a start type of `<em>disabled</em>` and rebooting Windows will result in the machine no longer being bound to 445/tcp by default. Another important note — when reconfiguring the `LanmanServer` service back to the default start type of `auto start` and manually starting the service, the Windows machine will again bind to 445/tcp and reloading all the necessary resources to resume normal SMB-based functionality. Remember, the goal here is to do <em>something</em> to <em>release </em>this port without requiring a reboot, loading a driver, or loading a module into LSASS. Being able to repeat and debug the same thing in reverse (i.e., binding to the port) will be helpful for understanding the potential associated code path(s) for our desired result.</p><h4>Initial Items of Interest</h4><p>To start, let’s verify <em>what</em> is binding to the port we are interested in. Here’s one way to do this quickly, using PowerShell:</p><pre>PS C:\&gt; Get-NetTCPConnection -LocalPort 445 | ForEach-Object { Get-Process -Id $_.OwningProcess }<br>Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName<br> - - - - - - - - - - - - - - - - - - - - - - - -<br> 6600 0 224 7424 9,175.72 4 0 System</pre><p>So we know the process with a handle to the socket bound on 445/tcp is `<em>System</em>`, and we can begin looking at loaded modules/drivers associated with opening and closing sockets. Using <a href="https://github.com/winsiderss/systeminformer">System Informer</a> to obtain a list of loaded modules is a good starting point for this enumeration. After reading through driver names, descriptions, and <em>definitely not using ChatGPT</em>, the initial list for inspection was narrowed down to:</p><ul><li>afd.sys — Ancillary Function Driver for WinSock</li><li>tcpip.sys — TCP/IP Driver</li><li>netbt.sys — MBT Transport driver</li></ul><h4>Understanding the Binding Process</h4><p><strong>NOTE</strong>: <a href="https://winbindex.m417z.com/">Winbindex</a> was used to ensure the same binaries were being analyzed on the remote machine during dynamic analysis and locally during static analysis.</p><p>The next objective was to identify function(s) within these drivers used to bind to the SMB-related port. <a href="https://hex-rays.com/ida-free/">IDA Free</a> was used to conduct initial inspection for potentially related functions, and thanks to <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/microsoft-public-symbols">Microsoft symbols</a>, several were found. Searching function names for related keywords such as “port”, “socket”, and “bind”, some of the functions initially identified included:</p><ul><li>afd!WskProAPIBind</li><li>afd!Bind</li><li>afd!WskProAPISocket</li><li>tcpip!InspectBindEndpoint</li><li>tcpip!InetAcquirePort</li><li>(many… many more)</li></ul><p>The target Windows VM was configured to <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection-automatically">enable kernel debugging</a>. To make the action of binding to 445/tcp a repeatable behavior, the VM was also configured with the `<em>LanmanServer</em>` service to a start type of `<em>disabled</em>` and rebooted (mentioned in <strong>Prerequisite Notes</strong>). Once the machine was no longer listening on the port in question, the VM was snapshotted for easily repeatable behavior. This was coupled with a simple PowerShell one-liner (below) to quickly iterate over the action of rebinding to 445/tcp while using WinDbg.</p><pre>Set-Service -Name &quot;lanmanserver&quot; -StartupType Automatic; Start-Service -Name &quot;lanmanserver&quot;</pre><p>Breakpoints were set on many of these interesting functions, which eventually led to the <a href="https://pastebin.com/raw/s7i1KD57">inspection of `tcpip!InetAcquirePort`</a>. A breakpoint set for this function was reliably hit when `LanmanServer` was restarted (i.e., when the port was being bound). To ensure this activity was associated with the binding of port 445, I wanted to see the port number passed in function call parameters. Early in the logic of the `tcpip!InetAcquirePort` function, there was a call to another function, `tcpip!IsPortInExclusion`.</p><pre>ExAcquireResourceExclusiveLite(a1, v16);<br>v68 = (unsigned __int16)__ROR2__(*a6, 8);<br>v69 = IsPortInExclusion(*(_QWORD *)(a1 + 136), v68);<br>if ( v69 &amp;&amp; (*(_BYTE *)(v69 + 16) &amp; 0x12) == 2 )</pre><p>As seen above, the ‘tcpip!IsPortInExclusion’ function took two parameters. The second parameter was an `unsigned __int16`, which could likely represent a port number between 0–65535. Using the standard fastcall calling convention, this parameter should appear in the RDX register. Stepping through execution of `tcpip!InetAcquirePort` until `tcpip!IsPortInExclusion` was called and obtaining the RDX register value looked like this:</p><pre>1: kd&gt; p<br>tcpip!InetAcquirePort+0xbae:<br>fffff806`3e93c646 e8f9bd0100 call tcpip!IsPortInExclusion (fffff806`3e958444)<br><br>1: kd&gt; ? rdx<br>Evaluate expression: 445 = 00000000`000001bd</pre><p>So we know this function call is associated with the binding of port 445 when starting the `LanmanServer` service. What information can we gather from the call stack (below) and how we got to this function call? Where can we start in terms of attempting to unbind this port while considering our given prerequisites?</p><pre>[0x0] tcpip!InetAcquirePort+0xbae<br>[0x1] tcpip!TcpBindEndpointRequestInspectComplete+0x2cc<br>[0x2] tcpip!TcpIoControlEndpoint+0x2e9<br>[0x3] tcpip!TcpTlEndpointIoControlEndpointCalloutRoutine+0x74<br>[0x4] nt!KeExpandKernelStackAndCalloutInternal+0x78<br>[0x5] nt!KeExpandKernelStackAndCalloutEx+0x1d<br>[0x6] tcpip!TcpTlEndpointIoControlEndpoint+0x6e<br>[0x7] afd!WskProIRPBind+0x11e<br>[0x8] afd!AfdWskDispatchInternalDeviceControl+0x3c<br>[0x9] nt!IofCallDriver+0x55<br>[0xa] afd!WskProAPIBind+0x47<br>[0xb] srvnet!SrvNetWskOpenListenSocket+0x3ef<br>[0xc] srvnet!SrvNetAllocateEndpointCommon+0x34a<br>[0xd] srvnet!SrvNetAllocateEndpoint+0x3e02<br>[0xe] srvnet!SrvNetAddServedName+0x564<br>[0xf] srvnet!SvcXportAdd+0x14e<br>[0x10] srvnet!SrvAdminProcessFsctlFsp+0xbe<br>[0x11] nt!IopProcessWorkItem+0x93<br>[0x12] nt!ExpWorkerThread+0x105<br>[0x13] nt!PspSystemThreadStartup+0x55<br>[0x14] nt!KiStartSystemThread+0x28</pre><h4>So What About Unbinding?</h4><p>We have several places we can continue on from this point. My first thought was to identify functionality exposed by these drivers, through device I/O control codes (IOCTLs) for example. Something more straightforward was identified first, though.</p><p>Starting with the `srvnet.sys` driver, I attempted to identify similar functions to what was previously identified when debugging 445/tcp being bound. Referencing our call stack from before, we see the `srvnet!SrvNetWskOpenListenSocket` function. Stepping back through the cross-references, we see another function call that is comparable to the functions used to bind to the target port. In this case we see `srvnet!SrvNetCloseEndpoint` calling `srvnet!SrvNetWskCloseListenSocket`, similarly to `srvnet!SrvNetAllocateEndpoint` calling `srvnet!SrvNetWskOpenListenSocket` previously observed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*LKHmiQJYDcjn_Twa" /></figure><p>Checking the cross-references for `srvnet!SrvNetAllocateEndpoint` yields several more results. After manual triage, it was identified that one of those several cross-references (`srvnet!SrvNetCleanupDeviceExtensionPreScavengerTermination`) was called by `srvnet!DriverUnload`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/0*u3UUXbbyKZ6iTZVt" /></figure><p>This is the part where I thought to myself… “no way it’ll be this easy”. If we can use the Service Control Manager (SCM) to stop the service associated with the srvnet.sys driver, would the target code path leading to the release of port 445 be reached?</p><h4>Service Dependents and Configuration</h4><p>The `LanmanServer` service is configured with a start type of `auto start` by default. We will first configure this to `disabled` to prevent it from restarting, for testing purposes.</p><p>Stopping the `srvnet` service, responsible for loading the `srvnet.sys` driver should make use of the Service Control Manager (SCM) to ultimately call `srvnet!DriverUnload`. However, using System Informer we can quickly determine that `srvnet` has two dependent services:</p><ul><li>srv2</li><li>LanmanServer</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*8AYd8CVzFjC5RlAY" /></figure><p>So both of these services must first be stopped before attempting to stop the target service. The `srv2` service also has a dependency of `LanmanServer`. Stopping these services in the following order (based on the previously mentioned dependencies) should allow for all three of the services in question to be stopped:</p><ol><li>LanmanServer</li><li>srv2</li><li>srvnet</li></ol><p>We now see the first major indicator that our assumption might be correct. The port 445/tcp is no longer locally bound.</p><pre>PS C:\Windows\system32&gt; Get-NetTCPConnection -LocalPort 445<br>Get-NetTCPConnection : No MSFT_NetTCPConnection objects found with property &#39;LocalPort&#39; equal to &#39;445&#39;. Verify the<br>value of the property and retry.<br>At line:1 char:1<br>+ Get-NetTCPConnection -LocalPort 445<br>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> + CategoryInfo : ObjectNotFound: (445:UInt16) [Get-NetTCPConnection], CimJobException<br> + FullyQualifiedErrorId : CmdletizationQuery_NotFound_LocalPort,Get-NetTCPConnection</pre><p>To further validate our assumptions, we can return to the kernel debugger. When we were previously getting a better understanding of the binding process, we set a breakpoint on `tcpip!InetAcquirePort`. Similarly, there is a function in the same driver that will likely reveal what we are looking for when unbinding, `tcpip!InetReleasePort`. We can reconfigure the services to their original state (or just revert the VM) and set the appropriate breakpoint using WinDbg.</p><p>Upon repeating reconfiguring and disabling of target services, the breakpoint is hit:</p><pre>0: kd&gt; g<br>Breakpoint 2 hit<br>tcpip!InetReleasePort:<br>fffff807`7d92a3fc 4c8bdc mov r11,rsp<br>1: kd&gt; r<br>rax=ffffcf8d773ed190 rbx=ffffcf8d7a1eacb0 rcx=ffffcf8d77475000<br>rdx=000000000000bd01 rsi=ffffcf8d7a782770 rdi=0000000000000000<br>rip=fffff8077d92a3fc rsp=fffffe8bfb1ea0b8 rbp=fffffe8bfb1ea3a0<br> r8=ffffcf8d7a1ead28 r9=0000000000000000 r10=fffff80779cd2250<br>r11=fffffe8bfb1ea178 r12=0000000000000001 r13=0000000000000000<br>r14=ffffcf8d7a80ad98 r15=fffff807901ee040</pre><p>We don’t immediately see “445” as an argument passed to the function, so to make sure this is our activity that cause the breakpoint let’s take a quick look at the function’s pseudocode in IDA free.</p><pre>__int64 __fastcall InetReleasePort(__int64 a1, __int64 a2, __int64 a3, __int64 a4)<br>{<br> unsigned __int16 v4; // r14<br>…<br> __int128 v21; // [rsp+20h] [rbp-48h] BYREF<br> __int64 v22; // [rsp+30h] [rbp-38h]<br> v4 = __ROR2__(a2, 8);<br> v21 = 0i64;<br>…<br>v13 = IsPortInExclusion(*(__int64 **)(a1 + 136), v4);<br>if ( (unsigned __int8)IsEmptyAssignment(v12, v13) )<br>…</pre><p>The variable of `v4` is declared as an `__int16`, which helped us previously identify the port being used in the `tcpip!InetAcquirePort` call during the binding process. This variable is used shortly thereafter when calling the `tcpip!IsPortInExclusion` function, where it should appear in the `rdx` register (as the second parameter for that function). We set another breakpoint for `tcpip!IsPortInExclusion`, hit the additional breakpoint, and see that port 445 is the target of this activity.</p><pre>0: kd&gt; g<br>Breakpoint 1 hit<br>tcpip!IsPortInExclusion:<br>fffff807`7d918444 6690 nop<br>0: kd&gt; ? rdx<br>Evaluate expression: 445 = 00000000`000001bd</pre><p>Now we have our validation that the following behavior, from simply interacting with the Service Control Manager (SCM), is achieved:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/0*bHrbaJcROsV-RMAL" /></figure><h3>Implementation Summary</h3><p>I’ve published two tools (Python and BOF format) to automate abuse of this technique, and the <a href="https://github.com/zyn3rgy/smbtakeover">code can be found on Github</a>. They both include simple commands of “check”, “stop”, and “start” to automate the Service Control Manager interactions discussed in the previous section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o7KEIJ_07UjClmXh" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ojwh8TZL_XZ9DiMI" /></figure><h3>Operational Usage Notes</h3><p>You don’t need to use my PoCs, as you can just use your favorite tool to manage services remotely or locally. Below I’ve included some example commands of using ‘sc.exe’ <a href="https://posts.specterops.io/proxy-windows-tooling-via-socks-c1af66daeef3">proxied into a network from remote Windows machine</a>, as well as ‘<a href="https://github.com/XiaoliChan/wmiexec-Pro">wmiexec-Pro</a>’:</p><p><strong>sc.exe</strong></p><ul><li>sc config LanmanServer start= disabled</li><li>sc stop LanmanServer</li><li>sc stop srv2</li><li>sc stop srvnet</li></ul><p><strong>wmiexec-Pro</strong></p><ul><li>wmiexec-pro.py lab.local/admin@target.lab.local service -action disable -service-name “LanmanServer”</li><li>wmiexec-pro.py lab.local/admin@target.lab.local service -action stop -service-name “LanmanServer”</li><li>wmiexec-pro.py lab.local/admin@target.lab.local service -action stop -service-name “srv2”</li><li>wmiexec-pro.py lab.local/admin@target.lab.local service -action disable -service-name “srvnet”</li></ul><blockquote><strong>NOTE:</strong> Disabling these services effectively hinders the target machine’s ability to facilitate named pipe / SMB communication. This is important to know for two reasons:</blockquote><blockquote>1. If the target machine is a server that is, let’s say, a large file share server, it will no longer be able to serve its function.</blockquote><blockquote>2. If you disable these services on a remote machine, and the tools you’re using rely on RPC over named pipes (ncacn_np) for Service Control Manager interactions, you will not be able to re-enable them remotely. The examples I’ve given above, as well as my PoCs, make use of RPC over TCP (ncacn_ip_tcp), which should not be affected.</blockquote><p>A big perk of this technique is that re-enabling SMB functionality to its default state is a straightforward task and takes effect immediately. You can just set the LanmanServer service to a start-type of “auto-start” again, and a service trigger will soon reenable the service itself which will reload all the necessary drivers and resources to resume normal functionality. If you don’t want to wait, you can just manually start the LanmanServer service again.</p><h3>Demo</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbCc622mtQKM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbCc622mtQKM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbCc622mtQKM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bf3f58ae1a7ba15ba1b1d38d95b6d4e/href">https://medium.com/media/3bf3f58ae1a7ba15ba1b1d38d95b6d4e/href</a></iframe><h3>Conclusion</h3><p>My hope is that this technique provides a “lower-touch” alternative to existing solutions for taking control of port 445/tcp on compromised Windows hosts while operating over C2. My code to automate this can be <a href="https://github.com/zyn3rgy/smbtakeover">found on GitHub</a> and if you’re using other tools, be sure to determine if they use ‘ncacn_np’ vs ‘ncacn_ip_tcp’ to avoid issues with re-enabling remotely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c9b4666c8ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/specter-ops-posts/relay-your-heart-away-an-opsec-conscious-approach-to-445-takeover-1c9b4666c8ac">Relay Your Heart Away: An OPSEC-Conscious Approach to 445 Takeover</a> was originally published in <a href="https://medium.com/specter-ops-posts">Posts By SpecterOps Team Members</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Less SmartScreen More Caffeine: (Ab)Using ClickOnce for Trusted Code Execution]]></title>
            <link>https://medium.com/specter-ops-posts/less-smartscreen-more-caffeine-ab-using-clickonce-for-trusted-code-execution-1446ea8051c5?source=rss-e8d131c41615------2</link>
            <guid isPermaLink="false">https://medium.com/p/1446ea8051c5</guid>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[dot-net-framework]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[clickonce]]></category>
            <dc:creator><![CDATA[Nick Powers]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 17:42:49 GMT</pubDate>
            <atom:updated>2023-06-07T20:29:37.562Z</atom:updated>
            <content:encoded><![CDATA[<p>The contents of this blogpost was written by Nick Powers (<a href="https://twitter.com/zyn3rgy">@zyn3rgy</a>) and Steven Flores (<a href="https://twitter.com/0xthirteen">@0xthirteen</a>), and is a written version of the content <a href="https://www.youtube.com/watch?v=cyHxoKvD8Ck">presented at Defcon30</a>.</p><p>With the barrier to entry for initial access ever increasing, we spent some time digging into potentially lesser-known weaponization options for ClickOnce deployments. A few of the hurdles we’d like to overcome by implementing these weaponization options include:</p><ul><li>Install / execute application without administrative privileges</li><li>Reputable, known-good file(s) used during execution</li><li>Streamlined, minimal user interaction required</li><li>Ease of rerolling execution implementations</li></ul><p>Ultimately, we want to take a relatively common initial access technique known as ClickOnce and extend its value for the offensive use case by abusing the trust of third-party applications.</p><h3><strong>ClickOnce Overview and Current Weaponizations</strong></h3><blockquote>“ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction” -<a href="https://learn.microsoft.com/en-us/visualstudio/deployment/clickonce-security-and-deployment?view=vs-2022">MSDN</a></blockquote><p>ClickOnce is a vehicle for installing and updating .NET applications. Deployments can be published through a variety of options (e.g. network file shares, legacy media [CD-ROM], and web pages). We will be focusing on the web page method of publishing deployments. Legitimate applications exist and make use of ClickOnce deployments for installation or updating software such as Chrome (previously), Fidelity, and others.</p><p>ClickOnce deployments rely on manifests which are formatted in a very specific way. Just like .NET applications, there will be different types of manifests that need to be accounted for. There are three types of manifest to become familiar with when discussing ClickOnce deployments:</p><p>&gt; ClickOnce deployment manifests</p><ul><li>*.application is the file extension for these</li><li>References the ClickOnce application manifest to deploy</li><li>APPREF-MS file will point to this (if used)</li></ul><p>&gt; ClickOnce application manifests</p><ul><li>*.exe.manifest is the file extension for these</li><li>Specifies dependencies for the deployment (states version of .NET that will be utilized)</li><li>Conducts integrity check of deployment manifest</li><li>References to dependencies and other files for delivery</li></ul><p>&gt; Embedded application and assembly manifests</p><ul><li>Application manifest can also be called unmanaged or fusion manifest</li><li>Assembly manifest can also be called managed manifest</li><li>At runtime, ClickOnce makes comparisons against these</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*lm1YgIibJbPnLTiVV8_t9w.png" /><figcaption>Embedded Assembly Manifest</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1E1Ch3nS_lrpQ_VtrpMnw.png" /><figcaption>Embedded Application Manifest</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUHv7A76XqKkr6iwCGRdPg.png" /><figcaption>ClickOnce Deployment Manifest, Executable, and Application Manifest</figcaption></figure><p>ClickOnce applications can be deployed to a client by visiting the <em>*.application</em> deployment manifest using a browser. The download and execution process of a standard ClickOnce deployment requires the end user to be using a Microsoft Edge or Internet Explorer browser. An alternative to requiring the target user to access your deployment manifest from either Edge or Internet Explorer would be to <a href="https://i.blackhat.com/USA-19/Wednesday/us-19-Burke-ClickOnce-And-Youre-In-When-Appref-Ms-Abuse-Is-Operating-As-Intended.pdf">leverage APPREF-MS</a>. When creating an <em>*.appref-ms</em> file, UTF-16 LE encoding is required. An <em>appref-ms</em> file would be used if the end user is using something like Chrome or Firefox to access the application.</p><blockquote><strong>NOTE:</strong> A simple user-agent check can be done prior to reaching the landing page to determine whether the incoming request should be pointed towards the standard deployment manifest or an appref-ms file.</blockquote><p>The host assembly, specified in the manifest, will spawn as a child process of ‘<em>dfsvc.exe</em>’, which handles the ClickOnce deployment functionality that is imported from ‘<em>System.Deployment.dll</em>’. The contents of the ClickOnce application manifest will specify what dependencies and other resources will be delivered during the deployment process. The contents of the deployment will ultimately be saved to:</p><p><em>C:\Users\%USERNAME%\AppData\Local\Apps\2.0\&lt;randomstring&gt;</em></p><p>Once a user has accepted to run the application, the deployment manifest will look to the ClickOnce application manifest for all the files that need to be downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nwk_ecNbRPDZ7ydd_1Bkuw.png" /><figcaption>ClickOnce Deployment Manifest Example</figcaption></figure><p>There will be different pieces of information located throughout the manifest that look very similar to .NET application manifests. This will contain all of the files and dependencies the deployment will need to execute properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*vXum75dbNZoNDrt5pU_s7w.png" /><figcaption>ClickOnce Application Manifest Example</figcaption></figure><p>The <em>dfsvc </em>process will make a series of HTTP requests for the downloads and save in the <em>%LocalAppData%</em> location mentioned above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*pfN16WppCXbZzGgd9IKTUQ.png" /><figcaption>HTTP Requests While Downloading a ClickOnce Application</figcaption></figure><p>In some scenarios users may want to interact with ClickOnce applications but are not using Microsoft Edge or Internet Explorer. An appref-ms file can be created that will act similar to an LNK or shortcut file that will contain the URL of the deployment manifest and some other pieces of information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*eFF9v_vDY8txYOMMteqkrA.png" /><figcaption>APPREF-MS Example</figcaption></figure><p>During the process before all the downloading happens, the System.Deployment DLL will be utilized to run through various checks and ensure the ClickOnce application can properly execute. One important check to note is the .NET application and ClickOnce deployment identities that are configured in the assembly and the deployment manifests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g600iwZzDS8kN0eqgKySqQ.png" /><figcaption>System.Deployment.dll Logic to Parse Manifests</figcaption></figure><p>Commonly, when crafting an initial access payload and using ClickOnce, you’d go through the process of writing it up in an IDE like Visual Studio and building the ClickOnce application. So what does standard ClickOnce deployment execution look like, using a newly created .NET application?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLU0Ec8Z9JpU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLU0Ec8Z9JpU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLU0Ec8Z9JpU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/89e79bb1f51bfbfbf9b2401ae678f980/href">https://medium.com/media/89e79bb1f51bfbfbf9b2401ae678f980/href</a></iframe><h3><strong>Current ClickOnce Weaponization Pressure Points</strong></h3><p>As seen in the first demo, we experience a few issues. For instance, Microsoft SmartScreen was triggered. This is because the assembly that ultimately executed with our arbitrary code was compiled recently and had never been seen by SmartScreen before. The reputation for Microsoft SmartScreen can be based on a number of factors such as the hash of the host assembly or the certificate used to sign the assembly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*4X8ZbLQf-Yf59nlU6La9CQ.jpeg" /><figcaption>BloodHound Slack Discussion on ClickOnce</figcaption></figure><p>Achieving arbitrary code execution within the context of an application seen and otherwise trusted by Microsoft SmartScreen or EDR products can decrease likelihood of prevention. Solutions such as application control or whitelisting prevention can be noteworthy when considering how we want to conduct our code execution, especially during initial access attempts. An Extended Validation (EV) code signing certificate can be used to obtain immediate SmartScreen reputation, but the vetting process and price point increase the barrier to entry. When code-signing certificates are used, there are also additional attribution concerns.</p><p>Generally, a ClickOnce deployment can be tedious to make sure “all the stars align” for a successful deployment. Oftentimes people view ClickOnce as tedious to deploy successfully and having many configuration requirements. We hope the next couple sections outline the important fields within ClickOnce manifests to focus on, to assist in reproducing these techniques.</p><h3><strong>Alleviation of ClickOnce Weaponization Pressure Points</strong></h3><p>If legitimate .NET applications make use of ClickOnce, and we can reliably sideload or hijack those .NET applications, why not just backdoor an existing deployment? An existing deployment that already has, lets say, a valid EV code signature and SmartScreen reputation?</p><blockquote><strong>NOTE: </strong>We will backdoor a dependency of a ClickOnce deployment, not the host assembly itself. We <em>maintain the valid signature</em> associated with that host assembly.</blockquote><p>Identifying existing ClickOnce deployments can be as easy as leveraging a couple search engine dorking techniques (or using the ClickonceHunter tool which will be covered later). Several tools can be used throughout this process (e.g. dnSpy, reshacker, mage, sigcheck, etc).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YsMHwBwOEgyRg4QPHsoTww.png" /><figcaption>Download of ClickOnce Application Discovered from Google</figcaption></figure><p>We will want to identify sideloading opportunities for dependencies of the target .NET assembly that the ClickOnce deployment will execute. Any way for us to hijack the flow of execution shortly after the application entry point is what we are looking for. Oftentimes this process consists of using dnSpy to decompile the target .NET assembly to understand the execution flow enough to identify a sideload opportunity.</p><p>Once an ideal DLL to backdoor has been identified, use dnSpy to add your code to the target DLL. At this point, the ClickOnce manifests of the deployment you’ve chosen will need to be tweaked to pass their integrity checks. If you cannot identify an ideal sideload opportunity in the existing codepath(s), techniques such as AppDomainManager injection or .NET deserialization abuse can be helpful here.</p><p>The image below is a quick example of what sideloading an existing, signed ClickOnce deployment would look like. First, we find a ClickOnce deployment published online, download it, and verify the assembly that the deployment executes meets our needs (valid code signature, SmartScreen reputation, etc):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*gh6RhbJlbcJhnBSF47P3CA.png" /><figcaption>Example of Signed ClickOnce Application</figcaption></figure><p>Next we take a look at the references within the signed .NET assembly we want to sideload. A few of the DLLs the assembly uses are not strongly named, which can be helpful in certain situations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLfd__iJPtUlIx_rEm1ZSg.png" /><figcaption>Dependencies of Target Assembly</figcaption></figure><p>Using DnSpy to begin at the target .NET assembly’s entry point, we follow the code to the first method call of “SetDpiAwareness()”. This function exists within on the the Dlls previously identified:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIUlVr_fMHzOxYKPeJDezQ.png" /><figcaption>Following the Code Path</figcaption></figure><p>We observe the code within this method and verify it exists within a DLL dependency (not the host .NET assembly):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AtLh0G3cBjLjZz2nKBO7Nw.png" /><figcaption>Identified Location to Place Additional Code</figcaption></figure><p>The additional code we’d like to sideload the ClickOnce deployment with can be added here. For proof-of-concept sake, we will just spawn notepad and prompt with a MessageBox:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKmTqsGW7IAl-JknhKqZ_A.png" /><figcaption>Adding Code to Target Dependency</figcaption></figure><p>At this point, dnSpy can add your changes to intermediary language (IL) and you will have your backdoored dependency of the target ClickOnce application. Now is a good time to test and make sure the additional code you’ve added properly executes when running the host .NET assembly.</p><blockquote><strong>NOTE:</strong> We previously thought a prerequisite was targeting only non-strongly named DLLs. We discovered this is not a requirement because modifying a DLL does not modify the PublickeyToken value of the DLL. The PublickeyToken value is in reference to the hash of the assembly’s embedded manifest rather than the code itself. If the manifest is not modified, the PublickeyToken value remains the same and will still be loaded successfully.</blockquote><p>Now that we have our sideload of a signed .NET application that is part of an existing ClickOnce deployment, our last step to have a functioning deployment is to tweak the two ClickOnce manifests such that the integrity checks that occur during deployment do not fail. Here’s a few tips that will hopefully speed the process up:</p><ul><li><strong>publicKeyToken</strong> — this value is required, but can be nulled out by replacing the value with 16 zeros</li><li><strong>&lt;hash&gt; — </strong>this block is optional and can be removed or recalculated (EX: <em>openssl -dgst -binary -sha1 Program.exe.manifest |openssl enc -base64)</em></li><li><strong>&lt;publisherIdentity&gt; — </strong>included if the manifests have been signed, but is optional and can be removed</li></ul><p>A noteworthy mention regarding modification of an existing ClickOnce manifest is that if the manifest was signed with a valid certificate, then making these modifications will break that integrity. The difference to the end user is minimal and many legitimate ClickOnce deployments do not sign their manifests at all. We still have control of the prompt observed by the target user, such as “Name” and “From”. A signed vs unsigned look similar to the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FKW3YLIWRUB3veYKZuRQ8g.png" /><figcaption>Difference Between Signed and Unsigned Deployment Manifest</figcaption></figure><p>So the question posed is this: <em>Do we really need a code signing certificate to effectively weaponize ClickOnce deployments?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*ZWnH2gC3f7R201RGe-wpWg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FP_xUIOg32BY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DP_xUIOg32BY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FP_xUIOg32BY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e9d9500edcdde52bfda392ef95832a/href">https://medium.com/media/26e9d9500edcdde52bfda392ef95832a/href</a></iframe><h3><strong>Extending Past Existing ClickOnce Deployments</strong></h3><p>The number of published ClickOnce deployments easily identifiable through dorking is finite. It’s not a new technology, nor is it the most popular to deploy and update .NET applications. We foresaw this as a potential issue and sought to find a way to take <em>any</em> ideal .NET assembly, identify a sideload opportunity, and wrap it up as a new ClickOnce deployment. As it turns out, this was possible, with a few prerequisites.</p><ol><li>The &lt;assemblyIdentity&gt; field within the embedded application manifest must <em>not </em>exist, or the entire embedded application manifest must not exist (more on this in a bit)</li><li>The UAC settings cannot be set to ‘requireAdministrator’ or ‘highestAvailable’</li></ol><p>.NET assemblies that meet these prerequisites can be weaponized as backdoored ClickOnce deployments relatively easily. The <em>System.Deployment</em> DLL has code that checks the assembly identity which is found in the embedded application manifest. This check cross-references the application manifest’s identity to ensure the identity values are the same. The image below shows what the embedded assembly manifest default identity will be if it is present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*o_TQIKH4WCSQxOZhGNaJxQ.png" /><figcaption>Example of Default “assemblyIdentity” Field</figcaption></figure><p>As you can see the identity contains two pieces of information, the version and the name. The figure below shows what is in the deployment manifest for the identity value. If you look at the difference there is a value of processorArchitecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wogHpFRRRdTgVUYVik-MHw.png" /><figcaption>ClickOnce Deployment “assemblyIdentity”</figcaption></figure><p>The ‘<em>processorArchitecture’ </em>value is a required value to be present for the assembly identity in the deployment manifest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*J8sJrXGwzPG7Xlf7yP6-fw.png" /><figcaption>MSDN Documentation Showing Required Values</figcaption></figure><p>These two values are checked against each other to validate assembly identities are the same. If the default identity value is present in the assembly’s embedded manifest it will fail because there is no ‘<em>processorArchitecture’</em> value present. Therefore, this type of assembly is not possible to use as a ClickOnce application for our purposes. Modifying this value would require modifying the host assembly of our code execution, losing any benefit of a valid code-signature or reputations with Microsoft SmartScreen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2DVMN62FzGZ41tCPYF-9Ew.png" /><figcaption>System.Deployment dll Checking Identities</figcaption></figure><p>Fortunately there are a lot of assemblies that exist which do not have an identity in the application’s manifest. In the next section we will show how to identify these assemblies, but in the meantime, the figure below shows what an embedded manifest looks like when the default identity is not set, and a non-default manifest was used during the build process instead.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;asmv1:assembly manifestVersion=&quot;1.0&quot; xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot; xmlns:asmv1=&quot;urn:schemas-microsoft-com:asm.v1&quot; xmlns:asmv2=&quot;urn:schemas-microsoft-com:asm.v2&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;<br>  &lt;trustInfo xmlns=&quot;urn:schemas-microsoft-com:asm.v2&quot;&gt;<br>    &lt;security&gt;<br>      &lt;requestedPrivileges xmlns=&quot;urn:schemas-microsoft-com:asm.v3&quot;&gt;<br>        &lt;!-- UAC Manifest Options<br>            If you want to change the Windows User Account Control level replace the <br>            requestedExecutionLevel node with one of the following.<br><br>            &lt;requestedExecutionLevel  level=&quot;asInvoker&quot; uiAccess=&quot;false&quot; /&gt;<br>            &lt;requestedExecutionLevel  level=&quot;requireAdministrator&quot; uiAccess=&quot;false&quot; /&gt;<br>            &lt;requestedExecutionLevel  level=&quot;highestAvailable&quot; uiAccess=&quot;false&quot; /&gt;<br><br>            Specifying requestedExecutionLevel node will disable file and registry virtualization.<br>            If you want to utilize File and Registry Virtualization for backward <br>            compatibility then delete the requestedExecutionLevel node.<br>        --&gt;<br>        &lt;requestedExecutionLevel level=&quot;asInvoker&quot; uiAccess=&quot;false&quot; /&gt;<br>      &lt;/requestedPrivileges&gt;<br>    &lt;/security&gt;<br>  &lt;/trustInfo&gt;<br><br>  &lt;compatibility xmlns=&quot;urn:schemas-microsoft-com:compatibility.v1&quot;&gt;<br>    &lt;application&gt;<br>      &lt;!-- A list of all Windows versions that this application is designed to work with. <br>      Windows will automatically select the most compatible environment.--&gt;<br><br>      &lt;!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node--&gt;<br>      &lt;supportedOS Id=&quot;{35138b9a-5d96-4fbd-8e2d-a2440225f93a}&quot;/&gt;<br><br>      &lt;!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node--&gt;<br>      &lt;supportedOS Id=&quot;{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}&quot;/&gt;<br><br>      &lt;!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node--&gt;<br>      &lt;supportedOS Id=&quot;{1f676c76-80e1-4239-95bb-83d0f6d0da78}&quot;/&gt;<br><br>      &lt;!-- This Id value indicates the application supports Windows Threshold functionality--&gt;<br>      &lt;supportedOS Id=&quot;{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}&quot;/&gt;<br>    &lt;/application&gt;<br>  &lt;/compatibility&gt;<br>&lt;/asmv1:assembly&gt;</pre><p>The second condition that is required is for the UAC settings to not be requiredAdministrator or highestAvailable. Another check by the System.Deployment DLL is it will look for the UAC settings and return errors if the disallowed values are set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpNnYFL1SPIbK1bUgJqJJg.png" /><figcaption>UAC Check in System.Deployment DLL</figcaption></figure><p>If UAC information exists, or it is set to ‘asInvoker’ the assembly will work as a ClickOnce deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*4riL-1p_n9FMm0wJap21Yg.png" /><figcaption>Assembly with No UAC Information</figcaption></figure><p>Since we are creating ClickOnce applications from scratch, we will have to create new manifests as opposed to our previous weaponization of modifying existing ClickOnce manifests. Microsoft has a utility that is used for this specific task which is called the Manifest Generation and Editing Tool (Mage). Microsoft makes two different tools that can be used, MageUI and Mage. Mage is a command line tool that comes part of the Windows SDK and for the purpose of this blog will be the one we cover.</p><p>Once you have gone through the process of identifying a .NET assembly that can be wrapped up as a ClickOnce deployment, you will want to create the directory structure of the assembly, dependencies, and extra files. As previously mentioned, there are two manifests that will need to be created with Mage — the deployment manifest and the application manifest. The application manifest can be created with the following command:</p><pre>&quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\mage.exe&quot; -New Application -Processor amd64 -ToFile AppVStreamingUX.exe.manifest -name &quot;TargetApp&quot; -Version 1.0.0.0 -FromDirectory .</pre><p>Next you will need to create the deployment manifest. This can be done with the following command:</p><pre>&quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\mage.exe&quot; -New Deployment -Processor amd64 -Install false -ProviderUrl &quot;http://localhost/dist/TargetApp.application&quot; -AppManifest TargetApp.exe.manifest -ToFile TargetApp.application</pre><p>The <em>ProviderUrl</em> argument is the location where the deployment manifest will be hosted since the primary method we’re covering is web-based applications. Once the manifests are created, you will see there are some signature values that are created with <em>Mage</em>. Just like what was covered when editing existing manifests, these values are not always required and can be removed. If any changes are made to the overall deployment, the signatures will be invalidated and will have to be regenerated which can lead to unnecessary troubleshooting. As mentioned previously, these values are:</p><ul><li><strong>&lt;publicKeyToken&gt;</strong>, required but can be nulled with 16 zeros</li><li><strong>&lt;hash&gt;</strong> block can be removed altogether and not required</li><li><strong>Publisher identity</strong> block can be removed altogether</li></ul><p>Now that we have identified an existing signed .NET assembly that can be deployed as a ClickOnce application, we can go through the same backdoor steps as the other technique. We will follow the code paths, identify called DLLs, and place our code inside of those DLLs. Finally, we can create the manifests with Mage and are ready for deployment.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCpuXgqvnNow%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCpuXgqvnNow&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCpuXgqvnNow%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c4555ae96ea40ccee7e867e36c16e9/href">https://medium.com/media/69c4555ae96ea40ccee7e867e36c16e9/href</a></iframe><p><strong>Identification of .NET Assemblies and ClickOnce Applications</strong></p><p>So far, we’ve covered the types of applications that can be weaponized, and now we want to discover potential targets. We have released two tools that will aid in the discovery of existing ClickOnce applications and .NET assemblies that can be weaponized for ClickOnce.</p><p>&gt; <a href="https://github.com/zyn3rgy/ClickonceHunter">ClickonceHunter</a></p><ul><li>searches online for existing ClickOnce published code</li><li>Google dorks, Github and others</li></ul><p>&gt; <a href="https://github.com/0xthirteen/AssemblyHunter">AssemblyHunter</a></p><ul><li>Searches file paths or files and looks for given criteria (signed, identity info, arch, UAC, etc.)</li><li>Helps identify target applications to weaponize</li></ul><p>ClickonceHunter will automate what can be done manually with Google or other related searches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*EVQ6ywi-HbyrzPmGZJDPow.png" /><figcaption>Dorking to Discover Third-Party ClickOnce Deployments</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TM8IzuskE7OYqqNR9uZu-g.png" /><figcaption>Github Searches for ClickOnce Projects (maybe with signed releases?)</figcaption></figure><p>While ClickonceHunter will go look through the internet for existing applications, AssemblyHunter will recursively search local file systems for assemblies that meet the criteria for a regular .NET assembly to be deployed as a ClickOnce application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1CBFIpwHUECuknPYDUUeA.png" /><figcaption>Usage for AssemblyHunter</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0EOR0MICEx2r3Vy6yuyn5g.png" /><figcaption>AssemblyHunter Discovering .NET Assembly</figcaption></figure><p>Using AssemblyHunter, we can quickly identify assemblies across a host’s filesystem and look for values that will be useful to us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8oYTvyI_mKMsrTY0Chnk5g.png" /><figcaption>AssemblyHunter Showing Assemblies that can be Weaponized</figcaption></figure><p>AssemblyHunter will also show us assemblies that are not useful to us if we would like to see them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEJGl4hNFfsZAmEE9SYLSA.png" /><figcaption>Example of anAssembly that Cannot be Weaponized</figcaption></figure><h3><strong>Detection and Prevention Opportunities</strong></h3><p>A major benefit to defenders who want to identify malicious ClickOnce deployments is that ClickOnce is not commonly used in many corporate environments. Defenders can baseline their environments to look for how prevalent they are and make detection or prevention decisions. Things we would consider looking for when identifying or preventing malicious ClickOnce use is:</p><p><strong>&gt; </strong>Monitoring <em>dfsvc.exe </em>process activity</p><ul><li>Monitoring child process activity (e.g. child processes with unsigned module loads)</li><li>Baseline required ClickOnce activity to whitelist applications with valid business use-cases</li><li>Monitoring activity associated with <em>dfshim.dll </em>(can also be used for launching ClickOnce deployments)</li></ul><p>&gt; Evaluate ETW telemetry associated with ClickOnce deployment execution</p><ul><li>Keep in mind ETW bypasses or <em>&lt;etwEnable&gt;</em> .NET config value</li></ul><p>&gt; Baseline the default ClickOnce installation directories</p><ul><li><em>%LOCALAPPDATA%\Apps\2.0\&lt;string&gt;</em></li></ul><p>&gt; Baseline of application that have never been seen making connections to the internet</p><p>&gt; <a href="https://learn.microsoft.com/en-us/visualstudio/deployment/how-to-configure-the-clickonce-trust-prompt-behavior?view=vs-2022&amp;tabs=csharp">Disable all ClickOnce installations from the internet, while still allowing from other trust zones</a></p><ul><li>Options include: Enabled, AuthenticodeRequired, and Disabled</li><li>Zones include: MyComputer, LocalIntranet, TrustedSites, Internet, UntrustedSites</li><li>To disable installation from internet: <em>\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Security\TrustManager\PromptingLevel — Internet:Disabled</em></li></ul><p>&gt; If an Application Control solution is deployed</p><ul><li>Prevent unreputable DLLs from being loaded</li></ul><p>If ClickOnce application execution from the internet is disabled using the registry key(s) mentioned above, a user will recieve a prompt that does not give them the option to run the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*dgkrmVkIsrJCCvZz35WRQQ.png" /><figcaption>Prevention of ClickOnce Installation from Internet Trust Zone</figcaption></figure><h3><strong>Closing</strong></h3><p>Based on all that was covered, we see ClickOnce as one of the best opportunities for initial access. There are still plenty of areas to dig into and additional potential for offensive use-cases. A few people we want to give thanks to and who paved the way for the work done are Lee Christensen (<a href="https://twitter.com/tifkin_">@tifkin_</a>), whose exploration of this technique wouldn’t have been possible without him, Casey Smith (<a href="https://twitter.com/subtee">@subTee</a>) for previous .NET research, and William Burke (<a href="https://twitter.com/0xF4B0">@0xF4B0</a>) for <a href="https://www.youtube.com/watch?v=4FtVwiuBtx4">previous ClickOnce research</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1446ea8051c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/specter-ops-posts/less-smartscreen-more-caffeine-ab-using-clickonce-for-trusted-code-execution-1446ea8051c5">Less SmartScreen More Caffeine: (Ab)Using ClickOnce for Trusted Code Execution</a> was originally published in <a href="https://medium.com/specter-ops-posts">Posts By SpecterOps Team Members</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proxy Windows Tooling via SOCKS]]></title>
            <link>https://medium.com/specter-ops-posts/proxy-windows-tooling-via-socks-c1af66daeef3?source=rss-e8d131c41615------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1af66daeef3</guid>
            <category><![CDATA[socks]]></category>
            <category><![CDATA[opsec]]></category>
            <category><![CDATA[red-teaming]]></category>
            <category><![CDATA[proxy]]></category>
            <dc:creator><![CDATA[Nick Powers]]></dc:creator>
            <pubDate>Thu, 10 Jun 2021 18:21:27 GMT</pubDate>
            <atom:updated>2021-10-30T20:34:51.603Z</atom:updated>
            <content:encoded><![CDATA[<p>Leveraging SOCKS to proxy tools from a Windows attacker machine through a compromised host is a topic that contains some nuance and room for confusion. This nuance stems from protocol requirements of common network traffic being proxied into a target network, as well as the tools (or lack thereof) available for Windows to facilitate proxying network traffic via SOCKS. However, there is significant value in the ability to proxy existing Windows tools and native utilities into a network from an offensive perspective. To that end, this post aims to step through:</p><ul><li>Clarity of material being covered vs. what is already well-documented</li><li>Value proposition of executing Windows tooling remotely vs. on-host</li><li>Network topology levelset and diagram for examples</li><li>Identification of a tool’s traffic to focus what is routed through SOCKS</li><li>The process of proxying Windows tools and utilities that rely on protocols such as DNS, RPC (DCOM/ WMI, MS-DRSR / DRSUAPI), Kerberos, LDAP, and SMB</li><li>Address nuances with common protocols an attacker would want to proxy, as well as Proxifier client specifics to maximize value for the offensive use case</li><li>Operational tips while proxying using this technique</li></ul><blockquote><strong>TLDR</strong>; Enable <a href="https://www.proxifier.com/docs/win-v4/dns.html">remote name resolution</a>, as well as <a href="https://www.proxifier.com/docs/win-v4/services.html">the proxying of Windows service / SYSTEM processes</a> within Proxifier to resolve DNS issues and also coerce traffic from SYSTEM processes / Kernel-initiated TCP through your SOCKS proxy. Skip to the <strong><em>Proxying Offensive Windows Tooling</em></strong> section<strong><em> </em></strong>for practical examples.</blockquote><h3><strong>Introduction</strong></h3><p>Proxying offensive tools into a network is not a new concept, from *nix-based or Windows operating systems. Pushing traffic associated with tools such as <a href="https://github.com/SecureAuthCorp/impacket">Impacket</a>, through utilities like <a href="https://github.com/haad/proxychains">Proxychains</a>, is a well-documented topic [<a href="https://www.crowdstrike.com/blog/staying-off-the-land-methodology/">1</a>][<a href="https://www.komodosec.com/post/bypassing-crowdstrike">2</a>][<a href="https://riccardoancarani.github.io/2020-05-10-hunting-for-impacket/">3</a>][<a href="https://bluescreenofjeff.com/2017-05-23-how-to-pass-the-ticket-through-ssh-tunnels/">4</a>] . This post will instead cover proxying Windows tooling through a compromised host via SOCKS, such as several of the C# and Powershell projects we’ve come to know and love, along with some of the nuances that come along with leveraging this technique. The idea is not to replace the resources and tools that already exist, but to extend usability of tools (largely Windows-based) that otherwise would have required some kind of on-host execution. Proxying traffic from Windows for offensive purposes has also been addressed previously [<a href="https://twitter.com/vysecurity/status/1312013229208543232">5</a>][<a href="https://twitter.com/NinjaParanoid/status/1401305665960767488">6</a>][<a href="https://www.trustedsec.com/blog/weaponizing-group-policy-objects-access/">7</a>][<a href="https://www.pentestpartners.com/security-blog/abusing-rdps-remote-credential-guard-with-rubeus-ptt/">8</a>] and this post will build on these resources by focusing on the protocols being proxied and address issues that may arise regarding configuration of SOCKS.</p><h3><strong>A Value Proposition</strong></h3><p>The value I wanted to stress with this post is the ability to proxy RPC traffic (and more) from Windows tools into a target network. What makes this beneficial? Not having to reinvent the wheel by reimplementing a specific protocol, or using a reimplementation that may not fit your specific needs. Using .NET, the Win32 API, or even the native Windows API, to handle interaction with protocols such as WMI, MS-DRSR (DRSUAPI), MS-SCMR, and more, can save a headache on this front.</p><p>Combining this with the ability to create a process and associated token in the context of a user within the target domain from a remote, non-domain-joined Windows machine, results in the ability to leverage native Windows functionality to proxy even more existing tools into a compromised network. Two ways to accomplish this would be to either simply use the <a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc771525(v=ws.11)">runas.exe binary</a>, or by using the <a href="https://github.com/gentilkiwi/mimikatz/wiki/module-~-sekurlsa#pth">mimikatz PTH</a> functionality in the instance of only having an NT hash for the target user. The underlying win32 API calls these tools rely on, such as <a href="https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprocesswithlogonw">CreateProcessWithLogonW</a> or <a href="https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa">CreateProcess</a> could also be used for the same purpose.</p><p>The perks of proxying your Windows tools into a network also align with many of the same benefits associated with proxying any other tool into a network. Several potential host-based indicators that would typically be taken into consideration to maintain OPSEC when conducting dynamic code execution or dropping to disk will not be created when using this proxying technique, such as:</p><ul><li><a href="https://docs.microsoft.com/en-us/windows/win32/amsi/antimalware-scan-interface-portal">AMSI</a> — assembly obfuscation for .NET 4.8+, Powershell, <a href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/wscript">WSH</a> (Windows Script Host)</li><li><a href="https://cobaltstrike.com/help-opsec">Fork&amp;Run</a> — behavioral considerations regarding parent-child process relationships</li><li>API Hooking — potentially remapping NTDLL, syscalls with dynamic ordinal resolution</li><li><a href="https://docs.microsoft.com/en-us/windows/win32/etw/event-tracing-portal">ETW</a> — patching in such a way that typical Assembly.Load functionality is less obvious</li><li>Kernel Callbacks — loading an EV-signed custom driver or exploiting a vulnerable one</li></ul><h4><strong>Situational Decision</strong></h4><p>There is a time and place for this technique. Some tools will require a significant amount of data transfer between agent and C2. Proxying your tools through C2 will likely increase the amount of network traffic egressing to the internet. If you cannot drop the sleep / jitter on your agent down to interactive (sleep of 0) then the timeouts associated with the protocol being proxied, the tool’s usage of that protocol, and the proxy client (in this case Proxifier), should all be taken into consideration. Veering off the beaten path, in terms of standard network traffic from specific processes, leaves room for behavioral and network-level detection opportunities. It would be beneficial to weigh these items against potential indicators generated from executing on-host as an alternative.</p><h3><strong>Infrastructure Topology Levelset</strong></h3><p>This is an example of how attacker infrastructure might look when proxying Windows tools into a network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YVl2Jywg53iKSoxZ" /></figure><p>For the purpose of the upcoming examples, the Windows Attacker Machine will be a Windows VM using Proxifier to route our tools’ traffic through a SOCKS proxy, in combination with runas.exe or mimikatz to conduct tool execution in the appropriate remote domain user context. C2 will be a Cobalt Strike teamserver listening with a SOCKS4A service. The Target Network is a compromised Active Directory environment where the Compromised Machine is running Cobalt Strike’s beacon and can route to a Target Workstation as well as Target Server, a Domain Controller.</p><blockquote><strong>Tip: </strong>When the Cobalt Strike server has its SOCKS service listening, it will bind to 0.0.0.0 by default. Securing this service in some way is essential to prevent unfettered access into your target network. Ensuring communication between your attacker machine and C2 is secured will also be an OPSEC consideration to ensure traffic such as cleartext RPC and NetNTLM hashes are not traversing the internet.</blockquote><p>The same outcome can be accomplished using several other techniques and tools, such as native OpenSSH (on the server-side of SOCKS, Compromised Machine) in Windows 10 1803 or later, or even using the Microsoft-signed SSH binary and its associated DLL dependency for older Windows versions (there’s backwards compatibility here). <a href="https://www.proxycap.com/">ProxyCap</a> is a viable alternative to Proxifier (on the client-side of SOCKS, Windows Attacker Machine). For demonstration purposes, we will stick to Cobalt Strike’s beacon in combination with Proxifier in the upcoming examples.</p><h3><strong>Proxifier Configuration</strong></h3><p>Several issues can arise while routing your tools through SOCKS from a Windows machine. Here are a few items that will hopefully help mitigate some potential issues:</p><ol><li>Ensure that service and/or system process traffic is routed through the proxy. This can be done by <a href="https://www.proxifier.com/docs/win-v4/services.html">enabling an option within </a><a href="https://www.proxifier.com/docs/win-v4/services.html">Services and Other Users in the GUI</a> or <a href="https://www.proxifier.com/docs/win-v4/service.html">Running Proxifier as a Windows Service</a>.</li><li>Enable remote hostname resolution so DNS resolves appropriately by <a href="https://www.proxifier.com/docs/win-v4/dns.html">selecting </a><a href="https://www.proxifier.com/docs/win-v4/dns.html">resolve hostnames through proxy option in Proxifier configuration</a>.</li></ol><blockquote><strong>Note: </strong>It was <a href="https://twitter.com/_ethicalchaos_">@_EthicalChaos_</a> responding to a conversation in Bloodhound Gang slack that prompted me to troubleshoot ensuring SYSTEM process traffic would be appropriately routed.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*-YKvmuduI02wrK4J" /></figure><p>In combination with the items listed above, you will need to configure a <a href="https://www.proxifier.com/docs/win-v4/proxy.html">proxy server</a> and <a href="https://www.proxifier.com/docs/win-v4/rules.html">proxification rules</a> (we’ll cover this in more detail later).</p><blockquote><strong>Tip: </strong>When configuring your proxy server to work with Cobalt Strike’s beacon, ensure the SOCKS Version 4 protocol is selected, in combination with checking the Use SOCKS 4A extension (remote hostname resolution) option.</blockquote><h3><strong>Identifying Traffic for Proxy Filtering</strong></h3><p>Knowing what processes generate what traffic when routing your tool’s through a SOCKS proxy will be important for a few reasons. With some protocols, the tool you are using is likely to rely on SYSTEM processes during communication with remote resources. As previously mentioned, this is relevant to how Proxifier is configured. Understanding how and why the traffic is generated will help you filter only essential traffic through your SOCKS proxy and into the target network. As an example, we will:</p><ul><li>Use `runas` to create a new process in the context of a domain user that has Local Administrator privileges on a target workstation routable from the compromised machine</li><li>Execute <a href="https://github.com/GhostPack/SharpWMI">SharpWMI</a> to enumerate environment variables on the target workstation</li><li>Monitor network traffic associated with SharpWMI by using <a href="https://docs.microsoft.com/en-us/sysinternals/">Sysinternal’s</a> Procmon</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0khLP88KJ0wKLdH2" /></figure><p>From the screenshot above, we can see that upon execution of SharpWMI, svchost.exe in the context of nt authority\network service conducts <a href="https://www.windows-security.org/windows-service/rpc-endpoint-mapper">RPC endpoint mapping</a> over port 135/tcp. This makes sense because WMI sits on top of <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dcom/4a893f3d-bd29-48cd-9f43-d9777a4415b0">DCOM</a>, which relies on RPC for remote communication capability. Once a high, dynamic port is determined for RPC communication (in this case port 49754/tcp), SharpWMI.exe wraps up and we receive the output from our WMI query. As an example of filtering to only route SharpWMI traffic through Proxifier, the following <a href="https://www.proxifier.com/docs/win-v4/rules.html">proxification rules</a> could be configured to route only SharpWMI-related traffic to the compromised host:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/0*HV--PxEV3X4jDbP3" /></figure><blockquote><strong>Note: </strong>The specific target port range for the sharpwmi rule shown above was set because this is the <a href="https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/service-overview-and-network-port-requirements">default ephemeral port range</a> used for RPC communication in modern Windows operating systems.</blockquote><h3><strong>Proxying Offensive Windows Tooling</strong></h3><p>With the information previously covered, we can identify traffic associated with a Windows utility to push through SOCKS, configure Proxifier accordingly, and start routing that tool’s traffic into your target network in the appropriate user context.</p><p>Reference the <strong>Infrastructure Topology Levelset</strong> section for where and how execution is happening in upcoming examples. Hostnames and IPs from the examples will align with the network diagram from that section. These tools will be executed and proxied from the Windows Attacker Machine, a non-domain-joined, remote Windows VM. Cobalt Strike’s beacon is running on WORKSTATIONA. From the C2 server in the network diagram, a SOCK4A service has been started with Cobalt Strike’s beacon. To demonstrate with commonly used tools, examples will include:</p><ul><li>RPC/DCOM (WMI) with Seatbelt &amp; WMIC</li><li>MS-DRSR (DCSync) with SharpKatz</li><li>SMB with native Windows functionality</li><li>LDAP with ADExplorer &amp; PowerView</li><li>Kerberos with Rubeus</li></ul><p><strong>RPC/DCOM (WMI) with Seatbelt &amp; WMIC</strong></p><p>From Windows Attacker Machine, a new process is spawned in the appropriate remote user context (CITADEL\jason) to access WORKSTATIONB with Local Administrator privileges through the proxy. The hostname of the remote target host is used in the seatbelt.exe arguments, and will resolve successfully because of the Proxifier configuration previously mentioned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iKB6lXcstpMLCuIQ" /></figure><p>The two proxification rules created, which can be seen in the Rule : Proxy column, were successfully triggered to route only our tool-specific traffic through the SOCKS server. Notice one of the svchost.exeprocesses conducting RPC endpoint mapping is executing in SYSTEM context. This would have failed unless the appropriate Proxifier option had been selected, as mentioned in the Proxifier Configuration section. Endpoint mapping for WMI is successful because seatbelt.exe opened a socket and conducted data transfer over an ephemeral port on WORKSTATIONB (49746/tcp in this case).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/0*2A8idKM1rzcXOjq2" /></figure><p>The native wmic.exe Windows binary can be used to achieve a similar outcome. WMI network traffic is proxied, so the same actions can be observed:</p><ul><li>RPC endpoint mapping on port 135/tcp</li><li>svchost.exe spawning as SYSTEM for a portion of RPC endpoint mapping</li><li>wmic.exe conducts the bulk of communication once an ephemeral port has been established</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRX4j7xeErvCH3xPZuZWrg.png" /></figure><p><strong>MS-DRSR (DCSync) with SharpKatz</strong></p><p>If you have the NT hash for the user you want to create an access token for, one way to create a process in the context of the user for which you have the hash is Mimikatz PTH functionality. Similar to runas.exe, Mimikatz spawns a new process in the context of a domain user, but instead of supplying a cleartext password, an NT hash was supplied.</p><p>The default Domain Administrator account and its NT hash are used to create a new process in the necessary user context to conduct a DCSync. SharpKatz is executed and MS-DRSR is utilized to conduct a DCSync of a specific user. Similarly to WMI, because this is an RPC-based protocol, we observe the endpoint mapping and high port traffic being routed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oTIjc3i2vCmbjJAv3Cdxdg.png" /></figure><blockquote><strong>Note:</strong> Notice the traffic originating from searchapp.exe. The proxification rule successfully routed this traffic unrelated to the DCSync directly to the internet, preventing unnecessary traffic from routing through our compromised host.</blockquote><p><strong>SMB with native Windows functionality</strong></p><p>With the appropriate user context, common utilities such as dir and redirection of stdout to a remote resource, as well as the SMB traffic associated with these actions, can be routed through a SOCKS proxy. This traffic is initiated from the kernel, which is demonstrated by traffic originating from the System process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tKSobTnz5G9Hrjzk" /></figure><p>The explorer.exe file browser can similarly be routed through the proxy, resulting in the ability to mount network drives and interact with contents of the remote file system, graphically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lBwbCjjDOO7K1oVj" /></figure><p>Native applications can also be used to interact with the contents of the remote file system that is now accessible via SOCKS. For example, a local text editor could be used to modify a text file on the remote machine directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnSCga7FKTIB4Lx-gbQbZA.png" /></figure><p><strong>LDAP with ADExplorer &amp; PowerView</strong></p><p>Providing the remote domain controller IP address and credentials to access the target domain on the other side of our SOCKS proxy, the Sysinternals ADExplorer64.exe is executed. Active Directory objects can be viewed and modified interactively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PIpcgl-GvwTQhGz8VOnSxA.png" /></figure><p>Mimikatz’s Pass-The-Hash (PTH) functionality was used to create a process in a domain user context. Any domain user within the target domain would work, because we only need permissions to conduct standard LDAP queries for this example. <a href="https://github.com/PowerShellMafia/PowerSploit/tree/dev/Recon">PowerView</a>’s Get-DomainUser function was executed and LDAP communication was properly routed to the target Domain Controller at the other end of the SOCKS tunnel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpvbSZ6sQTU38MBNKmxczw.png" /></figure><blockquote><strong>Note: </strong>When PowerView was downloaded with <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient?view=net-5.0">Web.Client</a>, our proxification rule properly routed the HTTPS traffic directly to the internet, instead of through our SOCKS tunnel.</blockquote><p><strong>Kerberos with Rubeus</strong></p><p>In this example, we will use a different domain user for spawning a process in the context of an authenticated user of the target domain on the other side of our SOCKS tunnel.</p><p>Rubeus is executed and attempts an ASREPRoast of all users in the target domain. ASREPRoast with Rubues only requires authenticated access to the target domain so any domain user would suffice (CITADEL\john used here). The proxification rule for routing traffic specific to the Rubeus process is triggered. LDAP (389/tcp) is proxied and queries for any users in the domain have the do not require Kerberos preauthentication attribute enabled. When a user with this attribute is identified, Kerberos (88/tcp) traffic is proxied to obtain the potentially crackable, encrypted TGT blob.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4trSqIJk9HNnPUMS" /></figure><blockquote><strong>Tip:</strong> Remember that it is important to have DNS configured correctly when interacting with Kerberos.</blockquote><p><strong>**Note about using TGTs**</strong></p><p>In all the above examples, either cleartext credentials or NT hashes were leveraged to proxy traffic into a network with the appropriate domain user context. You can also leverage forged or extracted TGTs with pass-the-ticket (PTT). To successfully authenticate to the remote Domain Controller via Kerberos:</p><ul><li>Ensure DNS is resolving remotely through the SOCKS proxy</li><li>Manually set your Kerberos realm as the target domain with the native Windows ksetup executable [<a href="https://www.pentestpartners.com/security-blog/abusing-rdps-remote-credential-guard-with-rubeus-ptt/">8</a>]</li></ul><h3><strong>Conclusion</strong></h3><p>Routing your Windows tooling through SOCKS can alleviate potential pain-points in a typical offensive workflow, such as OPSEC risks associated with on-host execution, as well as troubleshooting bugs associated with the usage of reimplemented protocols. Understanding what you’re routing, and how it is being routed, will help you determine when this technique might be an ideal alternative to your current code execution strategy.</p><h3><strong>References</strong></h3><ol><li><a href="https://www.crowdstrike.com/blog/staying-off-the-land-methodology/">https://www.crowdstrike.com/blog/staying-off-the-land-methodology/</a></li><li><a href="https://www.komodosec.com/post/bypassing-crowdstrike">https://www.komodosec.com/post/bypassing-crowdstrike</a></li><li><a href="https://riccardoancarani.github.io/2020-05-10-hunting-for-impacket/">https://riccardoancarani.github.io/2020-05-10-hunting-for-impacket/</a></li><li><a href="https://bluescreenofjeff.com/2017-05-23-how-to-pass-the-ticket-through-ssh-tunnels/">https://bluescreenofjeff.com/2017-05-23-how-to-pass-the-ticket-through-ssh-tunnels/</a></li><li><a href="https://twitter.com/vysecurity/status/1312013229208543232">https://twitter.com/vysecurity/status/1312013229208543232</a></li><li><a href="https://twitter.com/NinjaParanoid/status/1401305665960767488">https://twitter.com/NinjaParanoid/status/1401305665960767488</a></li><li><a href="https://www.trustedsec.com/blog/weaponizing-group-policy-objects-access/">https://www.trustedsec.com/blog/weaponizing-group-policy-objects-access/</a></li><li><a href="https://www.pentestpartners.com/security-blog/abusing-rdps-remote-credential-guard-with-rubeus-ptt/">https://www.pentestpartners.com/security-blog/abusing-rdps-remote-credential-guard-with-rubeus-ptt/</a></li><li><a href="https://github.com/haad/proxychains">https://github.com/haad/proxychains</a></li><li><a href="https://www.proxifier.com/docs/win-v4/">https://www.proxifier.com/docs/win-v4/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1af66daeef3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/specter-ops-posts/proxy-windows-tooling-via-socks-c1af66daeef3">Proxy Windows Tooling via SOCKS</a> was originally published in <a href="https://medium.com/specter-ops-posts">Posts By SpecterOps Team Members</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>