-1

This question already has an answer here:

I found some malicious code on my webserver which is exactly similar to this. My questions are:

  • How can I know from where this code was injected?
  • How can someone inject code on my server without my server credentials?
  • How to prevent future injections?

Note: I checked steps given on other similar answers but could not find a solution yet.

marked as duplicate by Matthew, Anders, Steffen Ullrich, techraf, S.L. Barth Feb 8 '17 at 12:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    It's not quite an exact duplicate, but the steps listed on that answer are what you need to do next - potentially along with having a professional security assessment of your system carried out, to find the hole and help you fix it. The general problem is that without performing detailed assessment, there are too many possible ways for us to identify which applies in your case. – Matthew Feb 8 '17 at 9:16
  • If you want to know how to remove it, the answer is in the duplicate: Nuke from orbit. If you want to know how the compromise happend and how to fix the hole, then your question is to broad since it is impossible for us to know without examining the server. – Anders Feb 8 '17 at 14:42
0

How can someone inject code on my server without my server credentials?

Using SSH stolen keys, FTP anonymous connection, or server-executed files (ie: PHP files that write in server's FS)

How can I know from where this code was injected?

See logs (bash/FTP/your server code logging system if there is one). You can seek for when it was written (using file's modification date or comparing backups), and check your server's access logs to find out what IP and how they injected code. Also, since servers are now bound to database, maybe it was a two-step injection: inject code in DB, and let another call (CRON or HTTP visit) write the DB content to a file.

How to prevent future injections?

Renew the server's credentials (including DB) and don't write any file from your executed code. Also, don't call any shell-execution function from your server code (ie: a PHP calling exec may write stuff to files). Favor community work (ie: open-source solutions) rather than custom stuff: they often are more secure.

Not the answer you're looking for? Browse other questions tagged or ask your own question.