How to Remove Malware From Website

How to Remove Malware From Website Malware on a website is one of the most serious threats a website owner can face. Unlike a simple broken link or slow loading time, malware can compromise user data, damage your brand reputation, get your site blacklisted by search engines, and even lead to legal consequences. Malware—short for malicious software—is designed to infiltrate, damage, or gain unautho

Nov 6, 2025 - 08:00
Nov 6, 2025 - 08:00
 1

How to Remove Malware From Website

Malware on a website is one of the most serious threats a website owner can face. Unlike a simple broken link or slow loading time, malware can compromise user data, damage your brand reputation, get your site blacklisted by search engines, and even lead to legal consequences. Malwareshort for malicious softwareis designed to infiltrate, damage, or gain unauthorized access to systems. When it infects a website, it can manifest as hidden iframes, redirect scripts, phishing forms, crypto-mining code, or backdoors that allow attackers to maintain persistent control.

Removing malware from a website is not just about deleting a few suspicious filesits a comprehensive process that involves detection, eradication, hardening, and prevention. Many website owners attempt quick fixes, such as reinstalling their CMS or deleting one infected file, only to find the malware returns days later. This happens because the root causesuch as an outdated plugin, weak password, or unpatched vulnerabilityis never addressed.

This guide provides a complete, step-by-step roadmap to identify, remove, and prevent malware from infecting your website. Whether youre managing a WordPress blog, an e-commerce store built on Shopify or Magento, or a custom-coded site, these methods are universally applicable. By the end of this tutorial, youll understand how to clean your site thoroughly, restore its integrity, and implement safeguards to prevent future infections.

Step-by-Step Guide

Step 1: Confirm the Infection

Before taking any action, verify that your website is actually infected. Malware doesnt always announce itself with obvious symptoms. Sometimes, it operates silently in the background. Start by checking for these common signs:

  • Unexplained redirects to unfamiliar or malicious sites
  • Pop-ups or ads appearing on your site that you didnt place
  • Google Search Console alerts stating This site may be hacked
  • Browser warnings (e.g., Chromes Dangerous site warning)
  • Unexpected changes to your sites content or structure
  • Unusual spikes in server resource usage or traffic from unknown sources

Use automated tools to validate your suspicions. Googles Safe Browsing Diagnostic Tool and SiteCheckers Malware Scanner can scan your site and return detailed reports. If either tool flags your site, proceed immediately to cleanup.

Additionally, manually inspect your site using a browsers developer tools. Right-click on your homepage and select Inspect. Navigate to the Network tab, reload the page, and look for external scripts loading from unknown domains. Suspicious domains often contain random strings (e.g., xq8j3k[.]com or cdn[.]malware[.]xyz) or mimic legitimate services like Google Analytics or Cloudflare.

Step 2: Isolate the Infected Site

Once infection is confirmed, immediately isolate your website to prevent further damage. This includes:

  • Temporarily disabling public access by placing the site in maintenance mode
  • Blocking access via .htaccess or server firewall rules if you have SSH access
  • Notifying your hosting provider so they can monitor for malicious outbound traffic

Isolation prevents your site from serving malware to visitors or becoming a relay point for attacks on other websites. It also stops search engines from further indexing malicious content, which helps preserve your SEO rankings during cleanup.

If youre using a CMS like WordPress, Joomla, or Drupal, disable all plugins and themes temporarily. Malware often hides in third-party extensions. You can do this by renaming the plugin folder via FTP or your hosting file manager (e.g., change wp-content/plugins to wp-content/plugins.disabled). This immediately neutralizes many infection vectors.

Step 3: Take a Full Backup (Before Cleaning)

Before you begin removing files or editing code, create a full backup of your website. This includes:

  • All files in your public_html or www directory
  • Your database (SQL dump)
  • Configuration files (e.g., wp-config.php, .env, settings.php)

Store this backup offline or on a secure, isolated drive. Do not store it on the same server. Why? Because malware may be embedded in files you think are clean. Having a clean, pre-infection backup allows you to restore if something goes wrong during cleanup.

Use your hosting providers backup tool, or manually create one via SSH using the following command:

tar -czvf website-backup.tar.gz /var/www/html/

mysqldump -u username -p database_name > database-backup.sql

Label the backup with the date and time. This will be critical for later forensic analysis.

Step 4: Scan Files for Malware

Manual inspection of thousands of files is impractical. Use specialized malware scanners to identify compromised code. Here are the most effective tools:

  • Wordfence (for WordPress): Scans core files, themes, plugins, and databases for known malware signatures and obfuscated code.
  • Sucuri SiteCheck: Free online scanner that checks for blacklisting, malware, out-of-date software, and suspicious code.
  • ClamAV: Open-source antivirus engine for Linux servers. Can be run via command line to scan entire directories.
  • Malwarebytes: Offers a web scanner that detects JavaScript-based malware and hidden redirects.

Run multiple scanners. Each tool uses different detection algorithms. A file missed by one may be flagged by another.

Pay special attention to:

  • Files with names like tmp_, cache_, or _old that were not created by your CMS
  • PHP files in image directories (e.g., /wp-content/uploads/2024/01/shell.php)
  • Base64-encoded strings or eval() functions in JavaScript and PHP files
  • Files modified recently with timestamps matching the suspected infection date

For advanced users, search for common malware patterns using grep via SSH:

grep -r "eval(" /var/www/html/

grep -r "base64_decode" /var/www/html/

grep -r "file_put_contents" /var/www/html/

These commands reveal scripts that dynamically execute codea hallmark of malware.

Step 5: Clean or Remove Infected Files

Once malware is identified, you have two options: clean the file or delete and replace it.

Option A: Clean the File

Only attempt cleaning if the file is essential (e.g., your themes functions.php or a custom script). Open the file in a code editor and look for injected code. Malware often appears at the top or bottom of files, disguised as legitimate code. Common examples:

<?php eval(base64_decode("aWYoZnVuY3Rpb25fZXhpc3RzKCdvcGVuX2RpcicpKSB7ICRvID0gb3Blbl9kaXIoJy4uJyk7ICRmID0gZGlybmFtZSgkbyk7IGVjaG8gJGZbMF07IH0gPz4="); ?>

Remove the entire malicious block. Be careful not to delete legitimate code. If unsure, compare the file against a clean version from your original CMS download or a trusted backup.

Option B: Replace the File

For core files, plugins, or themes, deletion and replacement is safer. Download clean versions from official sources:

Replace infected files with clean ones. Do not overwrite configuration files like wp-config.php or .htaccess unless youre certain theyre compromised. Instead, compare them with known-good versions from your backup.

For custom code, manually audit each line. Look for:

  • Obfuscated functions (base64_decode, gzinflate, eval)
  • Remote file inclusion (fopen, file_get_contents) pointing to external URLs
  • Hidden admin panels or backdoors (e.g., a file named wp-login.php in /uploads/)

Step 6: Clean the Database

Malware doesnt always live in files. It often hides in your databaseespecially in WordPress, where posts, options, and user meta tables are common targets.

Use phpMyAdmin or Adminer to access your database. Look for:

  • Unusual entries in the wp_posts table with titles like SEO Tools or Google Analytics containing hidden iframes
  • Malicious scripts inserted into the wp_options table under siteurl, home, or template
  • Unknown users with administrator privileges

Search for suspicious code using SQL queries:

SELECT * FROM wp_posts WHERE post_content LIKE '%eval(%';

SELECT * FROM wp_options WHERE option_value LIKE '%base64_decode%';

SELECT * FROM wp_users WHERE user_login NOT IN ('admin', 'administrator');

Delete or sanitize any malicious entries. Always back up your database before running these queries.

If your site uses forms (contact, registration, etc.), check for injected spam content or malicious redirects in form submissions. Clean the database thoroughlyeven a single malicious entry can reinfect your site.

Step 7: Check Server-Level Infections

Malware can persist at the server level. If youre on a shared host, your account may be compromised, but the server itself might also be infected. Check for:

  • Unauthorized cron jobs: Run crontab -l to list scheduled tasks
  • Hidden files in /tmp, /var/tmp, or /home directories
  • Unusual processes running on the server: Use ps aux | grep -i php
  • SSH keys added to authorized_keys files without your knowledge

Malware often creates hidden backdoors using cron jobs to re-infect your site daily. Remove any unfamiliar entries. If youre unsure about a cron job, disable it temporarily and monitor your site for recurrence.

Also check your server logs for suspicious access patterns:

grep "POST" /var/log/apache2/access.log | grep -v "wp-admin" | grep -v "wp-login" | tail -n 50

This reveals POST requests to non-admin filescommon for malware uploads.

Step 8: Change All Passwords

Assume all credentials have been compromised. Change passwords for:

  • Your hosting account
  • Your CMS admin panel (WordPress, Joomla, etc.)
  • Your database user
  • Your FTP/SFTP/SSH accounts
  • Your domain registrar account
  • Any third-party integrations (payment gateways, analytics, email services)

Use strong, unique passwords for each. A password manager like Bitwarden or 1Password can help generate and store them securely. Enable two-factor authentication (2FA) wherever possible.

Also, review active sessions in your CMS. In WordPress, plugins like User Session Control or WP Security Audit Log can show you whos logged in. Log out all unknown sessions.

Step 9: Update Everything

Most malware infections occur due to outdated software. Update:

  • Your CMS (WordPress, Drupal, etc.) to the latest version
  • All plugins and themesremove any that are abandoned or no longer used
  • Your servers operating system and software stack (PHP, MySQL, Apache/Nginx)
  • Any third-party libraries (e.g., jQuery, Bootstrap)

Use the following checklist:

  • Remove unused plugins and themes
  • Replace nulled or pirated themes/plugins with official versions
  • Ensure PHP is updated to a supported version (7.4 or higher)
  • Disable directory listing via .htaccess: Options -Indexes

Outdated software is the

1 reason malware returns. Dont skip this step.

Step 10: Re-Scan and Test

After cleaning, scan your site again using multiple tools:

  • Sucuri SiteCheck
  • Google Safe Browsing
  • Quttera Web Malware Scanner
  • Wordfence (if applicable)

Test your site manually:

Also test form submissions, login pages, and media uploads to ensure no backdoors remain.

Step 11: Request Re-Review from Search Engines

If your site was flagged by Google or Bing, submit it for re-review:

  • Google Search Console: Go to Security & Manual Actions > Security Issues > Request a Review
  • Bing Webmaster Tools: Navigate to Malware section and click Request Reconsideration

Include a detailed note explaining what you did to clean the site. Search engines take this seriously and often approve clean sites within 2472 hours.

Step 12: Monitor for Recurrence

Malware often returns. Set up continuous monitoring:

  • Enable real-time malware scanning with Sucuri or Wordfence
  • Set up file integrity monitoring (e.g., Tripwire or AIDE on Linux)
  • Configure email alerts for file changes
  • Check Google Search Console weekly for new security alerts

Regular monitoring is your best defense against reinfection.

Best Practices

1. Keep Software Updated

Outdated software is the leading cause of website compromise. Enable automatic updates for your CMS, plugins, and themes whenever possible. For critical sites, schedule weekly manual checks.

2. Use Strong Authentication

Use long, complex passwords with a mix of uppercase, lowercase, numbers, and symbols. Avoid dictionary words. Enable two-factor authentication (2FA) for all administrative accounts. Use authenticator apps like Google Authenticator or Authynever SMS, which is vulnerable to SIM swapping.

3. Limit File Uploads

If your site allows user uploads (e.g., profile pictures, documents), restrict file types to images only (.jpg, .png, .gif). Block executable files (.php, .exe, .bat). Store uploads outside the web root if possible. Scan uploaded files with ClamAV or a dedicated plugin.

4. Use a Web Application Firewall (WAF)

A WAF filters malicious traffic before it reaches your server. Cloudflare, Sucuri, and Wordfence offer WAF services that block SQL injection, XSS, brute force attacks, and malware uploads. Configure rules to block known malicious IPs and user agents.

5. Regular Backups

Perform daily automated backups and store them offsite. Use versioned backups so you can restore to a point before infection. Test your restore process quarterly to ensure it works.

6. Disable File Editing in CMS

In WordPress, add this line to wp-config.php:

define('DISALLOW_FILE_EDIT', true);

This prevents attackers from editing theme or plugin files via the WordPress dashboardeven if they gain admin access.

7. Use Secure Hosting

Choose a reputable hosting provider with built-in security features: automatic updates, malware scanning, DDoS protection, and daily backups. Avoid cheap shared hosts with poor security practices.

8. Monitor User Accounts

Regularly audit user roles. Remove inactive users. Never grant administrator access to freelancers or contractors unless absolutely necessary. Use temporary roles like editor instead.

9. Secure Your Local Environment

Malware can enter your site through an infected computer. Use antivirus software on your workstation. Never upload files from untrusted devices. Use SFTP instead of FTP for file transfers.

10. Educate Your Team

If multiple people manage your site, train them on security basics: recognizing phishing emails, avoiding pirated plugins, and reporting suspicious activity.

Tools and Resources

Malware Scanners

  • Sucuri SiteCheck Free online scanner for malware, blacklisting, and vulnerabilities
  • Wordfence Comprehensive WordPress security plugin with real-time scanning
  • Quttera AI-powered malware detection with detailed reports
  • ClamAV Open-source antivirus engine for server-level scanning
  • Malwarebytes Detects JavaScript and PHP-based malware

Security Plugins (WordPress)

  • Wordfence Security
  • Sucuri Security
  • iThemes Security
  • All In One WP Security & Firewall

Server Security Tools

  • AIDE File integrity monitoring
  • Fail2Ban Blocks brute force login attempts
  • ModSecurity Web application firewall for Apache/Nginx
  • OSSEC Host-based intrusion detection system

Online Utilities

  • Google Safe Browsing Check if your site is flagged
  • VirusTotal Scan URLs and files with 70+ antivirus engines
  • Redirect Checker Detect hidden redirects
  • SSL Labs Test your SSL/TLS configuration
  • SecurityHeaders.io Analyze HTTP security headers

Learning Resources

Real Examples

Example 1: WordPress Site Redirecting to Fake Antivirus

A small business website began redirecting visitors to windows-security-center[.]net, a fake antivirus scam. The client noticed a drop in traffic and Google warnings.

Investigation revealed:

  • A compromised plugin (a free SEO Analyzer from an untrusted source)
  • Malicious code injected into the themes footer.php
  • A hidden admin user created in the database

Resolution:

  • Deleted the malicious plugin and replaced the theme with a clean version
  • Removed the fake admin user and reset all passwords
  • Updated WordPress and all plugins
  • Installed Wordfence and enabled real-time scanning

The site was cleared by Google within 48 hours. Traffic returned to normal.

Example 2: E-Commerce Site Injecting Crypto-Miners

An online stores server CPU usage spiked to 95%. Visitors reported slow loading, but no redirects were visible.

Analysis showed:

  • A hidden JavaScript file loaded from /wp-content/uploads/2024/03/miner.js
  • The file contained Coinhive (now defunct) or XMRig code to mine Monero using visitor CPU
  • The file was uploaded via a vulnerable WooCommerce plugin

Resolution:

  • Deleted the miner.js file and all similar files in /uploads/
  • Updated WooCommerce and all extensions
  • Blocked JavaScript execution from /uploads/ via .htaccess
  • Enabled WAF to block mining scripts

Server load returned to normal. No data was stolen, but the sites performance and user trust were restored.

Example 3: Custom PHP Site with Backdoor Shell

A custom-built PHP site was used to send spam emails. The hosting provider suspended the account.

Discovery:

  • A file named upload.php in the root directory with a web shell interface
  • The attacker had full control: could upload files, run commands, access databases
  • Multiple cron jobs re-uploaded the shell every hour

Resolution:

  • Removed all shell files and cron jobs
  • Rebuilt the entire site from clean source code
  • Implemented input validation and file upload restrictions
  • Switched to a VPS with dedicated security monitoring

This case highlights why custom code requires extra scrutinythere are no automatic updates or plugin security audits.

FAQs

How do I know if my website has malware?

Signs include browser warnings, unexpected redirects, pop-ups, slow performance, Google Search Console alerts, or unusual server resource usage. Use tools like Sucuri SiteCheck or Google Safe Browsing to confirm.

Can malware be removed without technical skills?

Yes, but with limitations. Plugins like Wordfence or Sucuri can scan and clean WordPress sites automatically. However, for complex infections or custom sites, technical knowledge is essential. If unsure, hire a professional security expert.

Will cleaning malware restore my SEO rankings?

Yesif you request a review from Google Search Console and Bing Webmaster Tools after cleaning. Rankings may take days to recover, but they will return if the site is fully clean and secure.

How long does malware removal take?

Simple infections (one infected plugin) can be fixed in under an hour. Complex infections involving server-level backdoors or database corruption may take 48 hours or more. Always allow time for testing and verification.

Can antivirus software on my computer remove website malware?

No. Antivirus software protects your local machine, not your website. Website malware requires server-side scanning and cleaning.

Is it safe to use free themes and plugins?

Only if they come from official repositories (WordPress.org, Joomla Extensions Directory). Pirated or nulled themes/plugins often contain hidden malware. Always download from trusted sources.

Whats the most common way websites get infected?

Outdated software (CMS, plugins, themes), weak passwords, and vulnerable file uploads are the top three causes. Never ignore software updates.

How often should I scan my website for malware?

Weekly for high-traffic or e-commerce sites. Monthly for small blogs. Enable real-time scanning if possible.

Should I delete my website and rebuild it from scratch?

Only if the infection is severe, the source code is compromised, or you lack confidence in cleaning it. Rebuilding is time-consuming but guarantees a clean slate. Always restore from a known-clean backup first.

Can malware spread to other websites on the same server?

Yes, especially on shared hosting. If one site is infected, attackers can use it as a launchpad to compromise neighboring sites. Isolate and clean immediately.

Conclusion

Removing malware from a website is not a one-time taskits an ongoing security discipline. The steps outlined in this guide provide a complete framework to detect, eradicate, and prevent malware infections. From scanning files and cleaning databases to updating software and implementing monitoring, each action builds a stronger defense.

Many website owners underestimate the sophistication of modern malware. What appears to be a simple redirect may be the tip of a much larger icebergbackdoors, data exfiltration, and server compromise are common. Treating malware as a superficial issue leads to repeated infections.

By adopting the best practices in this guidestrong authentication, regular updates, file integrity monitoring, and WAF protectionyou transform your website from a vulnerable target into a hardened asset. Security is not about fear; its about preparedness.

Remember: The best time to secure your website was yesterday. The second-best time is now. Take action today. Scan your site. Update your software. Change your passwords. Monitor your logs. Your visitors, your brand, and your search engine rankings depend on it.