Skip to content Are you an AI agent? QIO facts, prices and requests are here

4 min read

How to check a website for malicious code and what to do about an infection

An infected website rarely looks broken: the pages still open, yet unknown URLs appear in search results, mobile visitors are sent to ads and the hosting provider sends a notice. We explain how to check a site for malicious code from the outside and on the server itself. We also cover what to do when an infection is confirmed.

How to check a website for malicious code and what to do about an infection

Signs of infection and external checks

Malicious code can steal form data or create doorway pages, spam pages that send visitors to someone else's site. Compare the search results for site:yourdomain with the pages you know are on the site. Note which device and which path showed visitors a redirect. In Yandex Webmaster (Russia's analogue of Google Search Console), open "Site optimisation" → "Security and violations"; in Google Search Console, open "Security issues". Google's Safe Browsing service also shows the status of a public URL. Such checks help you find a warning or a suspicious page. Identifying the infected file requires access to the server.

Finding malicious code on the server and in the database

Leave this check to the hosting administrator or the developer. They will need the hosting control panel or SSH, secure command-line access to the server using credentials or a key. Ask them to run a server-side antivirus and compare suspicious PHP files with a clean version. The eval and base64_decode functions also appear in legitimate code. A single match is not enough to delete a file.

Check recent changes, upload folders, scheduled tasks (crontab), web server settings (.htaccess) and PHP settings (.user.ini). In a WordPress or 1C-Bitrix (a popular Russian CMS) database, check records and settings for foreign code insertions, and the administrator list for unfamiliar accounts. If a web shell remains, a script for remote control of the site, an attacker can restore deleted spam pages.

Check levelWhat is examinedWhat it gives
External signs and webmaster panelsUnknown pages in search, redirects, browser warningsWarnings and visible consequences
Files on the serverRecently modified PHP files, upload folders, crontab, .htaccess, .user.iniInfected files and persistence points
WordPress and 1C-Bitrix databaseRecords, settings, administrator listForeign code insertions that a file search would miss, and unknown administrators

What to do after an infection is found

Do not delete what you find straight away. The order is:

  1. Save copies of the files and the database (a dump), as well as event logs. The snapshot is needed to investigate the incident and may itself contain malicious code.
  2. For cleaning, take the core and extension files of the same version from the official distribution or from a known-clean backup. Check your own code, templates and database separately.
  3. Eliminate the cause of the intrusion: update the vulnerable plugin or revoke the compromised access.
  4. After cleaning, change passwords, keys and tokens. A remaining backdoor, a hidden way to log in again, will let the attacker keep access even after the password is changed.
  5. Run a control comparison of the cleaned core and extensions against the clean files of the corresponding version.
  6. Request a review in the security section of the search engine that issued the warning. Monitor the status in the same section.

Prevention is simple: update the CMS and extensions, limit access rights and keep backups off the main server. If an infection is found late, a copy will help you recover.

Check from the top down, from search results to the server

External signs and webmaster panels suggest that something is wrong with the site, but only an examination of the files and database on the server gives a precise answer. If you run the site yourself and notice unknown pages in search or redirects from mobile devices, start with a copy of the files and a database dump, then look for the persistence points through which the malicious code returns.

If the site brings in enquiries and you have no server experience, it is better to show the investigation to a security specialist.

Questions and answers

What signs suggest a website may be infected?

Unknown pages may appear in search, redirects may occur when visiting from mobile internet or from search, and the browser may show warnings. You can check the site in incognito mode.

Can an external check identify the infected file?

An external check shows warnings and examples of affected URLs. A server-side check will help identify the specific file.

What should I check on the server and in the database?

On the server, check recently modified PHP files, upload folders, crontab, .htaccess and .user.ini, and run a server-side antivirus. In WordPress and 1C-Bitrix databases, check records, settings and the administrator list.

What should I do before deleting malicious code?

Save a copy of the files, a copy of the database and event logs to investigate the cause of the infection.

When should I change passwords and keys after an infection?

After cleaning the site and eliminating the cause of the compromise. If a hidden entry point remains, the attacker can use it again.

Follow the journal

New pieces on websites, SEO and AI come out in the QIO journal. Follow in Google, by RSS or in Telegram to get them first.

Read next

How can we help?
Discuss a project