Hassan.
← Writing

C2 Development from Scratch · Part 4

Implementing VLESS, REALITY, and uTLS in a Go C2 (and What Wireshark Still Catches)

November 30, 2026 · 25 min read
offensive-securityred-teamc2gotlsnetwork-securitydistributed-systemsVLESSREALITYuTLS

Introduction

In my previous post, I explored three technologies that I originally came across while learning about internet censorship: VLESS, REALITY, and uTLS. What started as a completely unrelated rabbit hole eventually became one of the more interesting networking projects I’ve worked on. I wanted to understand these technologies beyond what I could read in documentation and research papers, and see what integrating them into an existing application would actually involve.

I ended that post with a plan. I wanted to implement the new transport, keep the Go agent reasonably compact, and eventually validate my assumptions through actual network observations.

Implementing it turned out to be a different story from researching it, mostly because of how much of the existing framework I ended up revisiting along the way. What was supposed to be a networking feature turned into a much larger exercise in authentication, distributed systems, data integrity, and reliability. The implementation is now running in my controlled lab environment, with successful runtime testing on both Windows and Linux.

Revisiting the Original Problem

Before getting into the implementation, it’s worth revisiting where I left off. The framework already supported two communication methods: direct HTTP and HTTPS with certificate pinning. The application also had its own encryption layer using AES-256-GCM.

However, encrypting application data and understanding how network traffic is identified are two completely different problems. A network analyst doesn’t need to decrypt a connection to learn something about it. Connection timing, destinations, protocol characteristics, and TLS handshake metadata can all provide useful information.

This was the main subject of my previous article, and it’s also where I want to make an important distinction. Implementing a technology that changes certain characteristics of network traffic does not automatically mean that the traffic becomes indistinguishable from legitimate activity. That’s a hypothesis that requires evidence. Understanding that distinction became increasingly important throughout this project.

From the Original Plan to the Final Architecture

Evaluating the Dependencies

One of my concerns from the beginning was the size of the compiled Go binary. Go binaries aren’t small to begin with. Adding an entire networking framework introduces additional dependencies, functionality, and maintenance considerations.

During my initial investigation, I experimented with different libraries and recorded some preliminary binary sizes.

Experiment Preliminary size
Original Go agent Approximately 2-3 MB
Standalone REALITY library experiment 4.07 MB
Xray-core experiment 13.7 MB

These were preliminary experiments, not controlled benchmarks of the final implementation. I’ll include a proper comparison later in this post.

The research also made me reconsider my original idea of implementing everything independently. Existing protocol implementations contain a significant amount of engineering work, and reimplementing cryptographic protocols unnecessarily introduces opportunities for mistakes. The final implementation includes adapted upstream code from Xray-core. The relevant attribution and Mozilla Public License 2.0 notice are included in the project documentation.

Understanding the Three Components

Before looking at the architecture, it helps to understand why these three technologies exist separately.

uTLS: A Go library that provides additional control over the TLS ClientHello. A ClientHello is essentially the opening message of a TLS connection, containing information about the capabilities and preferences of the connecting client.

REALITY: A technology developed within the internet censorship circumvention ecosystem. It introduces its own authentication model and changes how connections are handled by the receiving service.

VLESS: A proxy protocol responsible for identifying clients and communicating routing information. It relies on the underlying transport for encryption rather than providing its own encryption layer.

Each of these technologies has a different responsibility. Treating them as one large protocol would make it much harder to tell where a specific behavior or failure originates.

The Architectural Decision I’m Most Happy With

One thing I wanted to avoid was having three completely different application implementations just because there were three different communication methods. The application already had a protocol for exchanging information with the server. It had its own authentication, encryption, message formats, and state management. None of those responsibilities should need to change simply because the underlying connection changes.

This is the benefit of separating the application protocol from the network transport. Think about how a web application can work over either HTTP or HTTPS. The application shouldn’t need separate business logic for each transport. The underlying communication changes, while the application continues to process the same information. That was the architectural principle I wanted to preserve here.

Original architecture with direct HTTP and pinned HTTPS Figure 1: Original architecture with direct HTTP and pinned HTTPS.

Updated architecture with REALITY as a third transport option Figure 2: Updated architecture with REALITY as a third transport option.

The final architecture retains the original transport options while introducing Xray as a separate component for the new transport. Keeping these responsibilities separate was probably the engineering decision I was most satisfied with throughout this project.

Changes to the Dashboard

Adding another transport also meant reconsidering how the dashboard represents application configuration. Previously, the configuration interface was relatively straightforward. The new architecture introduced settings that were relevant to one transport but not another. I didn’t want the interface to simply display every possible configuration field at once. The updated dashboard presents transport-specific configuration options, validates inputs, and records additional metadata about each build.

Something that became apparent during development was the difference between configuration metadata and observed behavior. Showing that a binary was built with REALITY enabled is not the same thing as confirming it actually checked in over REALITY, so the UI needed to keep build config separate from live session state. This sounds like a small UI consideration, but it becomes increasingly important when troubleshooting distributed applications.

The Project Within the Project

This was originally supposed to be a transport implementation. During the development and review process, I started finding problems that had very little to do with REALITY itself. Some were security issues, some were reliability issues, and others were simply problems I hadn’t considered when building the earlier versions.

Authentication and Trust

One of the changes involved revisiting how the server authenticates its users and connected clients. The earlier dashboard handled authentication partly through browser-side JavaScript. The updated architecture introduces a server-side login boundary.

I also revisited the distinction between sharing an encryption key and verifying the identity of an individual agent. Knowing the AES key only proves a client came from the same build, not which specific agent is talking, so I separated per-agent identity checks from payload encryption.

The same gap existed for replay attacks. A previously valid encrypted message doesn’t become invalid just because somebody sends it a second time, so the server needed explicit replay checks to reject resubmitted ciphertexts.

The Problem With Delivery Guarantees

When an agent sends a request to the server, the server can receive it, process it, and send back a response, only for the connection to drop before that response arrives. From the agent’s perspective the request failed, while on the server everything succeeded, leaving no reliable way to tell what actually happened.

This is one of the more interesting problems I encountered throughout the project. You can know that you sent something, without knowing whether the other side received or processed it. Automatically repeating an operation isn’t always the right answer either. If the original request succeeded, repeating it could cause the same operation to happen twice.

I originally considered a more complicated delivery model involving leases and additional timers. Eventually, I decided that the additional complexity wasn’t justified for this project. Sometimes the most accurate thing a distributed application can tell you is that the outcome is uncertain. I wanted the dashboard to reflect that uncertainty rather than display a misleading success or failure message.

The Result Outbox

The result outbox was probably the hardest part of the project from a design perspective. The problem itself is a fairly common one in distributed systems: how do you preserve information when a connection fails at an inconvenient moment?

When an agent finishes a task and sends the output back, a dropped connection before the acknowledgement arrives leaves the agent stuck. It has no way to know whether the server stored the result or never received it, and even an HTTP 200 isn’t proof on its own that the specific payload was accepted.

Designing around these uncertainties forced me to think a lot more carefully about data durability, acknowledgement integrity, and what an application can realistically guarantee.

Message delivery uncertainty when a server acknowledgement is lost Figure 3: Message delivery uncertainty when a server acknowledgement is lost.

It also made me appreciate how much complexity exists underneath features that users take for granted. We expect applications to survive temporary network failures and restarts without losing information. Building something that holds up under those conditions is a lot harder than getting the happy path working.

Database and Filesystem Integrity

Several other problems came up during testing. For example, what happens when an application writes a file successfully but fails to create the corresponding database record? What happens when two requests attempt to create a file with the same name? What happens when a write is interrupted halfway through?

These aren’t the most exciting problems when you first start a project. They’re also the kinds of problems that eventually make an otherwise functional application unreliable.

The review uncovered issues involving file naming collisions, incomplete writes, database transactions, file permissions, and certificate management. A significant amount of development went into improving these areas and testing failure conditions rather than only testing successful operations.

Dashboard Race Conditions

Another interesting problem was the behavior of asynchronous requests in the dashboard. If you select one agent, wait for its details or task history to load, and click another agent before the first request finishes, the slower response can overwrite the view for the agent you currently have open.

The server might be working perfectly, and both responses can be valid, yet the interface ends up displaying the wrong agent’s data.

Several variations of this problem appeared throughout the dashboard during development. It was a good reminder that a successful API response doesn’t automatically mean the UI should still render it.

Passing Tests vs. Live Deployment

This was easily the most frustrating part of the project. By the time I started testing the complete environment, the repository already had a substantial automated test suite. The individual components worked, the project compiled, and the local tests were passing.

I started the Windows VM, ran the agent, opened the dashboard, and got nothing back. There were no useful errors in the application, the Xray logs, or the Flask console. I had a system that looked completely healthy from the outside but wasn’t actually communicating end to end.

Looking in the Wrong Place

My first assumption was that I had made a mistake with the authentication configuration. I checked the credentials multiple times. I reconsidered parts of the implementation and questioned whether I had misunderstood something about the protocol.

Another thing that confused me was observing the Xray server communicating with an external HTTPS service. I initially interpreted this as evidence that authentication had failed. That interpretation turned out to be wrong. I was drawing conclusions about the entire connection from one observation without fully understanding what that observation represented.

The Clock Problem

To make things worse, the clock on my VPS was several weeks off. I was looking at logs that appeared to be from a month earlier, trying to figure out whether they were relevant to a connection I had initiated minutes ago. Some of the information I needed was already in front of me. I was dismissing it because the timestamps didn’t make sense.

It’s a relatively simple infrastructure problem, but it wasted a surprising amount of debugging time. Accurate time synchronization is something I had taken for granted until I needed to correlate events across multiple services.

The Actual Problem

Eventually, the problem turned out to be related to the version of Xray-core running on the VPS. A newer release introduced a default destination protection policy that restricted proxy clients from reaching private services on the host. The connection was getting further through the system than I initially realized, but the final application connection was being prevented by that policy.

From a security perspective, the restriction makes sense. A client authorized to use a proxy should not automatically gain unrestricted access to other services running on the same machine.

My mistake was assuming that because the application-level implementation was correct, the infrastructure underneath it would behave the way I expected.

What I Learned From Debugging This

There were three assumptions I made that turned out to be wrong:

  • No visible errors meant the system was working.
  • Log timestamps could be trusted without checking the underlying clocks.
  • Passing automated tests meant the complete deployment would work.

The third one is embarrassing because my own documentation explicitly stated that live integration had not yet been verified. I should have listened to my own README.

On November 24, 2026, I recorded the first successful end-to-end session. I’ve since confirmed basic runtime operation on both Windows and Linux.

Testing the Implementation

Automated Testing

The project went through several rounds of automated testing and regression reviews during development. Before moving to live testing, I ran a full test and regression pass on September 28:

Test suite Result
Python tests 64 passed
Dashboard JavaScript tests 40 passed
Go unit tests Passed
Go race detector Passed
Go vet Passed
Windows cross-compilation Passed
macOS cross-compilation Passed
Chromium layout and navigation checks Passed

These results establish a useful development baseline, but they should not be confused with live integration results. A unit test validates a specific piece of behavior. Cross-compilation establishes that the code can be compiled for another platform. Neither guarantees that the complete application will work correctly in its actual environment. That distinction became fairly obvious during my own deployment experience.

Live Environment

All live testing was conducted using infrastructure I control.

Component Environment
Server Debian 13 VPS
Xray-core 26.10.29
Windows endpoint Windows 11 virtual machine
Linux endpoint Linux 7.2.15
Go version 1.27.3
Python version 3.13.5

Final Binary Sizes

One of the things I promised in the previous article was a comparison of binary sizes before and after the implementation. Note that the pre-REALITY baseline here is larger than the rough 2-3 MB figure from my early experiments because the agent accumulated additional features and standard build settings before this transport was added.

Build Previous size Current size Difference
Windows amd64 6.9 MB 8.4 MB 1.5 MB
Linux amd64 6.6 MB 8.1 MB 1.5 MB

Network Analysis and Defensive Observations

Up until this point, I’ve only established that the implementation works. The agent communicates with the server, tasks are processed, and the framework runs on both Windows and Linux. However, getting it to work was only half of the goal. This project started with a specific question: if a network defender could previously identify the agent from its traffic alone, how much does the new transport actually change when someone is watching the wire?

To find out, I wanted to look at the communication the way a network monitor would, using packet captures alone rather than application logs or source code.

Experimental Setup

I collected three packet captures using Wireshark inside the same Windows 11 virtual machine, on the same interface, from the same endpoint. Keeping the operating system and network environment constant leaves the TLS client itself as the main variable between the captures.

Capture Application Transport Capture duration
Browser reference Google Chrome TCP/TLS 6.4 seconds
Non-browser reference curl TCP/TLS 30.6 seconds
Framework REALITY agent TCP/TLS 100.8 seconds

Chrome and curl were both used to access example.com. I disabled QUIC in Chrome for the TCP capture, since HTTP/3 runs over UDP and would have introduced another variable.

The captures were collected on November 27 and November 30, 2026, using Wireshark 4.6.10 and examined with tshark 4.7.4. All three contained unrelated Windows background traffic (such as Windows Update and Edge services), which I filtered out before quoting any per-connection numbers. It’s also worth noting one limitation up front: curl is not a direct stand-in for Go’s native crypto/tls stack. It simply serves as a reference for what a non-browser TLS client looks like on the wire.

TLS Fingerprinting and the Baseline

When a client opens a TLS connection, its ClientHello advertises its cryptographic capabilities, such as cipher suites, extensions, signature algorithms, key shares, and the hostname it expects to reach. Tools like JA3 and JA4 hash selected parts of that message into an identifier that network monitoring tools can use to classify clients. When a connection claims to be Chrome in its HTTP headers but produces a ClientHello shaped like a default Go or curl stack, that mismatch is fairly easy to spot.

To establish a baseline, I captured two legitimate connections to the same website from the same machine:

Chrome TLS ClientHello Figure 4: ClientHello generated by Google Chrome over TCP.

curl TLS ClientHello Figure 5: ClientHello generated by curl over TCP.

Characteristic Chrome curl
JA4 t13d1517h2_8daaf6152771_cb7bf5808d99 t13d2013h1_2b729b4bf6f3_e24568c0d440
Cipher suites 16 20
Extensions 17 + 2 GREASE 13
ClientHello record size 1,946 bytes 453 bytes
ECH, ALPS, certificate compression present absent

Even with the same website, operating system, and endpoint, a fingerprinting tool can easily tell these two clients apart. Any JA4 allowlist that permits Chrome would flag curl right away, and it would have flagged the agent’s original Go TLS stack for the same reason.

One detail worth noting is that Chrome-family browsers shuffle their extension order on every connection. Because JA3 hashes that order, real Chrome produces a different JA3 hash each time, whereas JA4 sorts the extensions before hashing and stays stable. A client claiming to be Chrome with a fixed extension order would stand out on its own, so the shuffle also has to be reproduced.

Does the Agent Look Like Chrome?

TLS ClientHello from the REALITY transport Figure 6: TLS connection establishment observed during the live REALITY session.

With the baseline in place, I compared the agent’s ClientHello against the Chrome capture collected on the same machine a few hours apart:

Field Chrome REALITY agent Match
JA4 cipher hash 8daaf6152771 8daaf6152771 identical
Cipher suites 15 named + GREASE identical list identical
Extensions 17 + 2 GREASE 16 + 2 GREASE 16 of 17 shared
GREASE values randomized per connection randomized per connection yes
ECH present, length varies per connection present, length varies per connection yes
Key shares GREASE + X25519MLKEM768 + x25519 GREASE + X25519MLKEM768 + x25519 identical
Extension order shuffled per connection shuffled per connection yes
ALPN h2, http/1.1 h2, http/1.1 identical
Session ID 32 bytes 32 bytes identical

Every field a passive monitor can inspect without decrypting the connection matches the Chromium family, including the per-connection extension shuffle reproduced by uTLS. The agent’s JA4 (t13d1516h2_8daaf6152771_d8a2da3f94cd) isn’t an unusual or synthetic value; public fingerprint databases list that exact fingerprint for Chrome-family clients of that generation. From the perspective of a JA4 allowlist, a fingerprinting appliance, or an analyst looking at the capture in Wireshark, the handshake looks like a browser connecting to an ordinary HTTPS site.

There are two specific differences worth pointing out. The installed Chrome (152+) sends a trust_anchors extension (0xCA34, 186 bytes) that the uTLS preset does not include, and it prepends a GREASE value along with three ML-DSA signature algorithms to its signature-algorithm list, which the preset also lacks. Both differences come from version drift rather than a flaw in the implementation. The uTLS preset mimics a roughly 148-generation Chrome, while the installed browser is more than three releases newer, and Chrome 152 changed Chrome’s JA4 across the board by adding those fields. In practice, keeping a spoofed fingerprint byte-for-byte identical to the latest Chrome release is an ongoing maintenance task. You either keep updating with every browser release or accept family-level matching with known, specific differences, which is what this transport provides.

As for server identity, all fourteen agent connections in the capture carry the decoy domain in the SNI field. The C2 server’s hostname never appears in the handshake, so a monitor watching for the infrastructure by domain name only sees traffic directed at a legitimate public site.

Looking Beyond the ClientHello

The server’s response makes up the other half of the handshake.

Chrome TLS ServerHello Figure 7: ServerHello from the Chrome HTTPS connection.

curl TLS ServerHello Figure 8: ServerHello from the curl HTTPS connection.

Characteristic Chrome connection curl connection
Negotiated version TLS 1.3 TLS 1.3
Selected cipher suite AES-128-GCM-SHA256 AES-256-GCM-SHA384
Key exchange X25519MLKEM768 X25519

The Chrome connection negotiated the hybrid post-quantum key exchange, whereas curl only offered classical x25519 and negotiated x25519 in return.

TLS ServerHello from the REALITY transport Figure 9: ServerHello observed during the REALITY connection.

The REALITY edge responded to the agent with the same parameters Chrome negotiated against example.com: TLS 1.3, AES-128-GCM, and the hybrid X25519MLKEM768 key share. That confirms the agent’s post-quantum offer was actually negotiated rather than silently falling back to classical x25519. From the server side of the handshake as well, the connection looks consistent with a browser talking to a normal site.

Because TLS 1.3 encrypts everything after the ServerHello (including the certificate, EncryptedExtensions, and the negotiated application protocol), there is a limit to what passive captures can show. They cannot directly display REALITY’s certificate mechanism, where the forged leaf carries an ed25519 key and an HMAC-SHA512 signature that the client verifies, silently retrying if it receives a genuine decoy certificate instead. That part is verified through the implementation and live runtime behavior rather than from the packet captures. The same encryption also means the absence of TLS-in-TLS isn’t directly visible on the wire, though observing a single handshake per cycle carrying plaintext HTTP/1.1 inside VLESS reflects the architecture working as intended.

What Still Stands Out

While the handshake itself looks like a browser, the surrounding traffic behavior still gives it away.

In the Chrome reference capture, the browser resolves example.com, opens a single TCP connection, transfers 7.6 kB in 93 milliseconds, and finishes. Over the course of the agent’s capture, it makes fourteen fresh connections to the same destination, each performing a full TLS handshake across nine check-in cycles spaced 9.5 to 15.4 seconds apart, matching the build’s jitter window. Each connection carries nearly identical traffic volumes: 25-31 packets, roughly 6.5-7.1 kB outbound and 3.4-4.6 kB inbound. Real browsers typically reuse connections and transfer data in uneven bursts, whereas the agent’s traffic is repetitive and predictable. Given enough observation time, the bounded jitter range could be identified statistically without decrypting a single byte. It’s fair to point out that my Chrome capture is only a single page load rather than a full browsing session, though even that is enough to show how different the connection patterns look.

The second signal is DNS. Both Chrome and curl resolved example.com before connecting. The agent never sent a DNS query for either the edge server or the decoy domain; it connects directly to the IP address and puts the decoy domain in the SNI field. TLS connections with no preceding DNS lookup are a common beaconing indicator, and many detection workflows treat bare-IP flows as suspicious on their own. Even after addressing that, there’s still a practical limitation: the destination IP belongs to a datacenter rather than the decoy’s CDN, which an analyst pivoting on the IP would notice.

Both of these are behavioral problems rather than cryptographic ones, and they are the next areas I plan to look at: replacing bounded jitter with long-tailed timing distributions, and resolving the decoy domain at connection time the way a browser would.

What About Active Probing and Enterprise Proxies?

Because these captures are passive, they don’t directly test active probing. However, active probing did come up during live deployment debugging when an IP address (which I’m assuming was an internet scanner of some sort) connected to the listener. Xray transparently relayed the session to the real decoy site, the scanner completed a genuine TLS handshake with the legitimate domain, and the server journal logged the rejected authentication. That showed REALITY behaving as designed: probing the listener returns the decoy’s real certificate and site rather than exposing the C2.

The enterprise proxy limitation from Part 1, where an explicit forward proxy performing TLS interception cannot complete the X25519-based REALITY handshake, remains reasoned analysis. I didn’t have an enterprise interception proxy available to test against, so I don’t want to present that as an observed test result.

What Did This Experiment Actually Establish?

  • Against passive TLS fingerprinting, which was the original problem, the transport works as intended. Every ClientHello field a passive monitor can observe matches the captured Chrome baseline from the same machine, aside from the two documented version-drift differences.
  • The baseline comparison confirms the “before” state as well. curl differs from Chrome on every measured field, and a JA4 allowlist would separate them immediately. Closing that gap is the main benefit of this implementation.
  • The C2 hostname never appears on the wire. All fourteen connections use the decoy domain as SNI, and the server side of the handshake matches Chrome, including the hybrid post-quantum key exchange.
  • Probing the listener redirects to the real decoy site, which was observed live during deployment even though it isn’t part of these passive captures.
  • Behavioral detection remains an open problem. The regular check-in timing and the absence of DNS queries are both measurable, and a defender looking at connection patterns rather than handshakes could still spot the traffic.

Against the two threats that motivated this project (passive fingerprinting and active listener scanning), the implementation produces a measurable improvement. It moves detection from something a TLS fingerprinting appliance can flag immediately to something that requires behavioral analysis over time. That doesn’t make the traffic invisible, and I wouldn’t claim that it does, but it meaningfully narrows the detection surface compared to the framework’s earlier transports.

The original packet captures have been retained privately alongside my research notes. The screenshots included in this article are selected excerpts, with sensitive infrastructure information removed. This limits independent reproduction of the analysis from the published material alone.

What I Would Do Differently

If I were starting this implementation again, the first thing I would do is validate the complete network path before spending time polishing the rest of the application. I left live integration until relatively late in development. That meant I encountered several infrastructure problems at the same time, after already investing a significant amount of effort into other components.

I would also prioritize observability earlier. Applications need meaningful diagnostics, especially when they depend on multiple independently configured services. Without them, simple problems take much longer to isolate.

There are also architectural limitations that I would reconsider. Some parts of the current design are more tightly coupled to the infrastructure than I would ideally like, and request timeout handling remains an area that needs further attention. These are things that only became apparent once the system was running outside its automated test environment.

Final Thoughts

The most interesting part of this project wasn’t the implementation itself. It’s been seeing how closely offensive and defensive security research relate to one another. Every time I learn about a new networking technique, I end up learning about another defensive mechanism. Understanding why a technology behaves a certain way often requires understanding the systems designed to inspect, restrict, or identify it. You hear early on how closely offensive and defensive work mirror each other, but watching your own transport get dissected in a packet capture makes that relationship a lot clearer.

I’ve also become more careful about the difference between implementing something and proving something. Before this project, I probably would have been much more comfortable making conclusions based on what a technology was designed to accomplish. Now I’m more interested in what I can actually demonstrate, where my assumptions fail, and what the evidence tells me. That’s probably the biggest thing I’ve taken away from this entire experience.

This project was developed for educational and authorized security research purposes.