Laravel site hacked.
I got a call
I got a call from a friend that one of his sites was hacked.
This is a PHP/Laravel site and it wasn't responding as expected.
I'm not going into a lot of specfics here but I want to document the basics.
Several PHP files had code injected which was heavily obfuscated.
It appeared to be SEO spam which was lucky because they could have done much worse.
There were numerous version of the same files or similar files everywhere.
In addition, it launched a process that would periodically send out an email with the url of where to attack.
What it installed was a web shell and some mechanisms to respond with sitemaps.
What did I do?
First, I copied all the files to my local so I could look at them later.
Then the files were removed. I also looked for errant processes and shut those down.
I uses the firewall (ufw) to shut off the ports that were in use.
I updated apache so that it would only run index.php, and no other php files.
I then used SandFly to scan the entire server looking for other intrusions.
How did the files get there?
It turns out this was an application issue. This application allowed users to upload profile pics.
But it didn't prevent the upload of any file, including PHP files.
This was remidies with two approaches.
The application was updated to only allow JPG and PNG files.
The upload process also double checked the file to make sure it really is a PNG or JPG.
I reconfigure apache not to allow PHP execution in the upload folder.
Finally
I created two applications to help with monitoring.
webtaser - this scans the web server logs and looks for known and obvious attempts to do malicious things. Then it blocks the IP address for an hour.
filepat - this continually scans all the PHP files looking for malicious patterns and reports them.
All systems are up and running now. No site is ultimately secure. But I definitely closed the door on this attack.