SecurityGuide

Card-testing attack on your payment gateway: how we proved it bypassed the website, and what stopped it

Card testers use stolen card numbers to find the ones that still work, a few dollars at a time. If they have your gateway's API key, they do not need your website at all, and no checkout CAPTCHA will slow them down.

Author

CrpyByte Engineering

Published

Reading time

3 min read

A client noticed odd orders in their payment gateway dashboard: names like "Test Customer" and "John Customer", descriptions such as TEST SALE and LIVE CHECK, and amounts from zero to about $13. The first question was the obvious one: is someone abusing our checkout page?

The answer was no, and finding that out early changed the whole fix.

What card testing is

Criminals buy lists of stolen card numbers. Most are dead. To find the live ones, they run tiny charges or authorisations through a merchant account that is not theirs. A card that is approved is worth far more on resale. The merchant gets the fees, the declines, the chargeback risk and sometimes a suspended account.

Step 1: prove whether the website was used

Every real order on the site went through one endpoint, the script that sends the payment to the gateway. So we counted two things for the first day of the attack:

SourceFirst day
Transactions recorded by the gateway16
Requests to the website's order endpoint (access log)1, a genuine customer

Fifteen transactions never touched the website. They were sent straight to the gateway's API, which is only possible with the merchant's API login and transaction key. The fraudulent rows also carried fields the real checkout never sent, such as an invoice number in a fixed pattern and a customer IP address, which gave us a clean fingerprint to separate them from real orders.

How the key leaked

The key was written directly into two PHP files inside the website's public folder. The same server had been infected with web shells more than once that year. A web shell can read any file the website can read, so the key was almost certainly copied during one of those infections.

Step 2: rotate the key, and disable the old one immediately

Attackers rotated their IP addresses within hours, so blocking IPs was a losing game. The only real fix was a new transaction key with the old one disabled at once, not after the usual grace period. After that, the attacker's requests failed authentication and never created a transaction.

Before the rotation, the attack escalated: three charges with real cards were approved, for $5.50 to $12.90. All three ended up voided and nothing settled, so no money moved and there were no chargebacks. Over the first two days there had been 31 attempts. After the rotation there were none.

  1. Generate the new key in the gateway portal and choose to disable the old one immediately.
  2. Find every place the old key is used. In this case it was in three places, not two. A search of the code for the old value is the only reliable way.
  3. Test with one real small order, then void it, to confirm the site still takes payments.
  4. Re-check the transaction list a few hours later for anything with the attack's fingerprint.

Step 3: make the next one loud

  • Move keys out of the public web folder into a config file or environment variable the code reads. It does not stop a web shell, but it stops casual exposure through backups, file listings and misconfigured servers.
  • Turn on the gateway's fraud filters: transactions per IP, per hour, and a minimum amount. They are usually off by default.
  • Alert on the fingerprint. A daily job that emails you when a transaction does not look like your real checkout catches the next attack on day one, not day three.
  • Rotate keys on a schedule, for example every 90 days, so a key copied months ago stops working on its own.
  • Fix the original break-in. A new key protects you only until the next web shell reads it.

If you think your site has been compromised as well, start with our first-hour checklist for a hacked website, or contact us and we will help you work out where the attack came from.

Written by

CrpyByte EngineeringEngineering team

The team that designs and builds CrpyByte client systems and tools. We write about the parts of the work worth writing down.

Have a process worth improving?

Let's build the system behind it. Tell us what the process is and where it breaks — the first conversation is about constraints, not technology.