Code injection is a type of attack on a website where an attacker uploads a shell script PHP into your account either through a compromised password of an FTP account or by exploiting vulnerabilities in a software that does not was updated on time.
How to clean the website code in case of a Code Injection attack:
- Log in to your website using SSH
- Navigate to the public_html directory of the compromised website cd public_html
- Open the index.php file using the vim editor (the procedure will be repeated for all .php files)
- In most cases, malicious code sequences use the base64_decode function
- Copy the first characters from the script - eval (base64_decode - and the next 10 characters
- Now run the following command:
grep 'eval(base64_decode("sirul de caractere' ./ -Rl > malware.txt
- It will take a while for all the files in your website to be scanned and the filenames containing that character string will be saved to a file named malware.txt
- Using the malware.txt file, create copies for each file in that list using the suffix - Hacked
for FisierCompromis in `cat malware.txt`; do cp -frp $FisierCompromis $FisierCompromis"-HACKED"; done
- Use the sed command to replace the injected code for each file:
for FisierCompromis in `cat malware.txt`; do sed -i 's#<?php.*eval(base64_decode("siruldecaractere.*));#<?php#' $FisierCompromis; done
After running the commands, check if the website is functional.
It is important to note that this procedure may be inadequate for cleaning your website. Additional operations / checks may be required depending on the complexity of the malware.
Attention! - We recommend that you backup your website and database before attempting the above procedure.
TO REMEMBER! - HostX can provide you assistance (charged) in the process of cleaning your website.
