pwn.sc Back to journal

Pen-testing my own license service: what held and what fell over

Investigation log · Licensing & Trust · 10 min read · By Maxed

I run a small licensing service: a Go server, and a Windows desktop client that signs in, fetches a protected program and starts it. In early November I had it attacked. My own code, my own server, white box, and nothing destructive against production. Four days later, after a penetration test, a full source audit and two rounds of checking the fixes, there was no remote hole in the report. Nearly everything on the list was something I had built on purpose.

That is the part I want to write down. The cryptography was fine. What failed were a cache with a ceiling, a key that could come from a config file, and a database column nothing ever wrote to.

How the review ran

The first pass was a penetration test with the source open: the server, the client, the deployment files, and non-destructive checks against the live service. Anything that could take the service down was confirmed in code and left alone. The second pass, two days later, was a full read of a later release: about 9,500 lines of client C++, 16,000 lines of server Go and 1,800 lines of web front end, split into separate reads of the server, the client and the admin pages. After that came two rounds of checking the fixes against the code and the test suite.

One rule held through all of it. A finding only counted once it pointed at a line. "This looks risky" did not go in the report.

What held

Passwords are hashed with PBKDF2-SHA256 at 600,000 iterations, compared in constant time, with a dummy hash for names that do not exist. Admin requests are protected against cross-site forgery three ways, and two of them were tested live: a request without the custom header got a 403, and so did one with the wrong origin. Every SQL statement is parameterized. The content security policy allows no inline script. Webhooks resolve the hostname, refuse private and reserved ranges, connect to the checked address and follow no redirects. The service runs unprivileged behind systemd hardening, and its port is not reachable from outside.

None of that was interesting to test, which is how it should be.

The limiter that could lock everyone out

The server kept two structures in memory to slow attackers down. One held short-lived challenges for the encrypted request channel. The other counted requests per key. Both had a hard ceiling, and both answered the ceiling the same way: when full, refuse.

The challenge cache stopped at 4,096 entries and then returned 429 to every caller. The endpoint that fills it was exempt from the global per-address limit and had its own, 180 requests a minute, with entries living for two minutes. So one address could hold 360 slots, and about a dozen addresses could hold all of them. Native clients are required to use the encrypted channel, so from that moment no real customer could sign in, download or renew. The counter table had the same shape at 16,384 keys, and part of each key was a username the caller could choose.

The login limit had a quieter version of the same mistake. It was keyed on the username alone: eight attempts a minute, and successful logins counted too. I tried it on the live service with a made-up name. Attempts one to eight returned 401. The ninth returned 429 with a retry time of 51 seconds. Anyone who knew the admin's username could keep the admin out all day with a loop and a sleep.

I had written both as defenses. A limit that fails closed for everybody is a denial-of-service feature with good intentions.

The fix was to make the limiter cheap to overflow. Counters now live in a fixed block of memory and the oldest challenges are evicted when it fills. Failed logins are counted per source address together with the username. A correct password is no longer a failure. The admin console got one-time codes on top of the password.

The same pass found the origin server answering directly, around the CDN in front of it. The reason was almost funny. A certificate had once been issued for the bare address, and certificate transparency logs are public and permanent. The firewall now only accepts the CDN's ranges. The address itself stays in the log. You cannot take that one back.

An elevated client that trusted its own folder

The desktop client relaunched itself as administrator on start. The only step that really needs that is setting up the TPM key. But it meant everything the client started inherited an administrator token: the updater, the helper, and the customer's program.

With that in mind, three ordinary things became one serious thing:

Release builds still honored a development switch in the client's config file. With the switch on, the client took its server address and its signing key from that file and accepted plain HTTP on loopback. Any process running as the user could write a config pointing at its own fake server, with its own key, and the elevated client would download whatever that server signed and run it.

The updater was copied into a folder the user could write to, the handle was closed, and the file was then started by path with administrator rights. Between the hash check and the launch there was a gap.

The decrypted program was written to a temporary folder owned by the user and started from there, elevated.

None of this let anyone steal a license or decrypt a product they had not paid for. It let any program already running as the user become administrator without a prompt, which is the one thing the prompt exists to stop.

The development path is now compiled out of release builds, and the public key is a compile-time constant. Helper binaries are checked against a signed manifest and held locked until they start. Only the TPM helper elevates. The launcher, the updater and the product run with normal rights. The saved password became a random token that is bound to the device, expires, and can be revoked on the server.

One limit stays, and I would rather say it than hide it. A customer who is allowed to run a program can still read it out of memory while it runs. Nothing in a client changes that.

The ban that nothing could write

This is the finding that stung. The plan for abuse was simple: every device proves it holds a real TPM, the server remembers the endorsement key, and a machine that misbehaves gets banned as a machine, whatever account it tries next.

The audit went looking for the code that performs the ban. There was a revoked column on two tables. The only statement in the whole tree that ever set it was in a test. No admin route wrote it. The identity rows were keyed by account, so the same TPM registered under a second account was a stranger. And devices that had proved themselves through the cloud attestation path had no endorsement key recorded at all, so there was nothing to ban them by.

I had a policy and a column. I did not have a feature.

It took two releases to make it real. There is now a global table of banned endorsement keys, checked at every place where the server decides to trust a device. A device key is linked to an endorsement key only after credential activation and a TPM certification of the device key have both passed, and a second link to a different key is refused. In the release after that, an endorsement-key identity became mandatory for every product load and every renewal, and a ban could be placed from a verified proof even if the device had never been enrolled under any account.

Two smaller things came out of the same read. A session with the right password on the wrong device, which the server calls a candidate, could still write identity records into the account it was knocking on. It gained no access, but it left a stranger's hardware in the account's history, and that history is what I would look at when deciding who to ban. Candidates now write nothing to the trust tables.

The other was a comparison I had left to a library. When the TPM certifies a key, the certificate names the key it covers, and that name has to match the public key the client presented. The library I use is supposed to check it. My code did not, and my tests had no case where the signature was valid and the key was the wrong one. Both exist now.

Fresh revocation or working software

The first version cached a verified endorsement key for up to thirty days and skipped the revocation check while the cache was warm. If a TPM vendor revoked a certificate, I would only notice by accident.

The fix tied the cache to the freshness of the revocation answer and capped it at six hours. The next pass pointed at the other end of that decision. Every device now has to complete a full check against the vendor's revocation service at least every six hours. If that service is unreachable for longer, nobody can load anything, and programs that are already running lose their lease at the next renewal. There is no grace period.

I traded a stale-revocation window for a dependency on someone else's uptime. The option on the table is to accept the last good answer for up to a day when the vendor cannot be reached, never when the answer is "revoked", and to log every time that happens. I have not decided.

What is still open

The shipped executable is not signed. The protector around it has its own tamper checks, and whether it tolerates a signature appended to the file had not been tested when the review ended.

The native TPM path reaches a raw TPM2_Certify through platform interfaces that are not documented. It works today. A Windows update could change that, and since the last release nothing else can stand in for it.

The first enrollment of a real endorsement key on the production server had not happened yet. Everything that passed, passed against a synthetic certificate chain and retained evidence.

And some things were never tried. The denial-of-service paths were not fired at production. Cross-tenant access was reviewed in code and not tested with real accounts. The protected binary was only examined statically. On the last pass the server suite stood at 258 passed, none failed and four skipped, and the four need private hardware fixtures.

Evidence note: based on the retained penetration-test and audit reports for my own service, written between November 4 and 7, 2026. Hostnames, addresses, account names and product names are left out on purpose. The denial-of-service paths were confirmed in code and never triggered against production. Nothing was rerun for this article, and it describes the state at the end of that review, not today's deployment.