Running The Mystery File Charged Every Customer
Someone found a file called pay.pl on a server and ran it to see what it did. Thousands of a client's customers were charged on the spot. Years later, someone else did the same thing with a different file.
At a company I worked for, someone was poking around on a server and found a file named something like pay.pl.
So what is the first thing you do when you find a random file on a server? You run it before reading it, of course.
Or not.
Thousands Of Charges At Once
The moment it ran, thousands of a client’s customers were charged on their credit cards.
That is what the file did. It went through the customers and billed every one of them. Whatever it had been written for, it still worked perfectly.
One Person, An EFTPOS Machine And A Printout
This was a long time ago, and there was no easy way to refund people in bulk. No button to reverse a batch. No portal.
So it came down to one person, an EFTPOS machine, and a printout of every transaction. They went through the list one line at a time, refunding each charge by hand.
Thousands of them.
The file was deleted. Apologies went out to the customers. We made sure it would never happen again.
Until It Happened Again
Years later, someone else found a random PHP file on a server. They also decided to run it.
Once again, people got charged.
This time it was not as bad. Most of the cards on file had expired, so those charges never went through. For the ones that did, we were able to refund them through a payment portal instead of a person working through a printout.
It happened twice, by two different people.
That is the part that has always stuck with me. It was not one careless person having a bad day. Two different people, years apart, found a file they did not recognise and both decided the way to find out what it did was to run it.
It has made me think about code like this ever since, and there are four things I keep coming back to.
Never Run Code You Don’t Understand
The first one is the obvious one. Never run code when you don’t know what it does.
A file sitting on a server is not harmless just because nobody remembers it. If you don’t know what it does, read it. A script called pay is a fairly strong hint that it is worth reading first.
Should The Code Still Exist?
The second is whether code like this should exist at all once it has been used for its purpose.
Both of these files had done their job at some point. Someone wrote them, ran them, and got what they needed. Then they were left where they were, fully working, waiting for the next person to come along.
If a script was a one-off, it should not still be sitting on the server ready to go.
There Should Be A Dry Run
The third is dry run flags.
A dry run is a mode where the script goes through all the motions and reports what it would do, without actually doing it. For anything that touches money, that should be the default. Running the file with no arguments should print a list of who would be charged, not charge them. Actually charging people should take a deliberate flag that you have to type on purpose.
Either of these files running in dry run mode by default would have turned both incidents into someone reading a list on their screen.
One Line At The Top
The fourth is the simplest of all. If the code really must be kept around, put an exit on the first line.
<?php
exit;
That is it. Anyone who runs the file gets nothing. Anyone who wants to run it for real has to open it, read it, and remove that line, which means they have looked at it first.
A single exit; on the first line would have stopped both of these.