wordpress cleanup

Cleaning a WordPress site

The website of our non-profit organization was compromised. This document describes the measures taken and also discusses suggestions for further action. It also points out critical tooling and hosting decisions for a small organization.

Starting point: beginning of July

The site was created around 2016 with the help of a friendly it-media company that supported the goals of our environmental organization. All support was based on personal friendships. This worked for a few years until changes in the leadership of the organization showed the first problem points. The new editor was not familiar with Divi and changed back to the standard editor for posts. There was a significant decrease in the number of posts. The pages were already getting outdated and were in need of a re-design.

More than a year back a copyright issue led to a fine and there was a potential for further violations hidden in the site. This led to the site being put “under construction” until the content could be cleaned – which would obviously a major effort. At the beginning of July I started working on two things: a) getting a backup for the club and b) updating the layout of the site. I had two wordpress sites previously but had little to no knowledge about wordpress internals. A backup was performed with the provider and downloaded locally. Until then, the club had not maintained its own data backup. The theme and plugin software was outdated, and the provider had not responded to attempts to contact them for months. In retrospect, this backup turned out to be infected with malware in the form of plugins which was not rally a surprise given the lack of maintenance. Furthermore, it turned out that the posts and pages had extensively used PDF copies of articles from daily newspapers and other copyrighted documents.

After the initial backup, I began transferring the layout from the new sample page (which the provider had promised us as a "template") to the other pages. However, it was only a sample homepage that still needed to be adjusted in several places (English names, etc.) and not actually a layout template. The provider offered to do this for €7000. This was too expensive for us. Therefore, the only remaining option was to transfer the design elements used in the example page (which was created by a professional designer) to the other pages in a meaningful way. This required learning Divi 4. At that time, no one realized the ultimate consequences of using a powerful editor like Divi or Elementor. The decision had been made long ago, forcing all potential editors to learn the editor. Cleaning up the website revealed further major problems, as there was no clear separation between content and layout; Divi mixed everything together, allowed embedded HTML, and thus created ample space for malware in the tables.

Professional Divi specialists and designers would first create a template for each project, club, etc., and then adapt the other pages. In our example, due to a lack of knowledge, the layout was simply copied and adapted page by page, and only with a better understanding of Divi were individual templates created, e.g., for the footer, newsletter, etc. Links to illegal copies, especially in the posts but also on the pages, have been replaced and the media removed from the site.

As of early August

On August 1st and 2nd, the site was subjected to a massive attack, resulting in the registration of unauthorized administrators and the transmission of significant traffic via XML-RPC and REST API. The exact details of the attack remain unclear. It is suspected that it was carried out using WP2SHELL. This is because the site wasn't updated to the emergency version in time. The "under construction" plugin may also have prevented an automatic update. The only remaining option was to have the website shut down by the provider, as a high volume of traffic was detected via XML-RPC and the REST API. The "Homepage" directory contains the attack logs, while the "Jail" directory contains the loaded malicious code, various backups, scripts, and an investigation into the attack and its consequences.

Subsequently, it turned out that the provider – who had meanwhile withdrawn from the online business – was unable to further support us in this matter. Another problem was that most of the work on layout and content had happened in the last two weeks but a backup was only done when the attack had already started.

Note

Lesson learned: During active work on the site daily backups and exports are needed as an attack can happen any time.

Failure 1: First test environment WP-Local

Following the attack, backups were downloaded from the live site to avoid losing the work on the new site layout. An initial attempt to set up a test environment with WP-local proved problematic, as WP-local does not allow true isolation of the WordPress site, thus creating a risk of malware spreading to the local laptop (running Linux)

Note

WP Local ist NOT a safe environment for malware detection despite other rumors on the net. It does NOT provide save isolation.

Failure 2: New attempt (end of August)

For a test, a new version of the site was created based on the current database. Many plugins were new. Posts and pages had been exported via WP-XML and scanned for malware keywords. Nothing was found. After the provider made a new WordPress version available, an attempt was made to bring the site back online using this cleaned-up version (only the database, some plugins (where the provider had provided licenses), uploads (checked for .php files), and Divi4 were retained). Upon login by another administrator, illegal upload attempts immediately resumed. It was then clear that the site was completely infected with malware: user sessions, user data, WordPress cron jobs, etc., and most importantly, two plugins. I realized that a much better understanding of how wordpress works was needed. The provider then explained that switching to a specialized WordPress host would probably be the right thing to do. The company itself had shifted away from hosting and was no longer able to clean up the website in preparation for the annual general meeting. During my subsequent vacation, there was no communication between the provider and the association (approximately 3 weeks).

Emergency solution for the general meeting

Meanwhile, the date of the meeting was drawing ever closer. As a temporary solution, a static page containing the most important information about the members' meeting was sent to the provider, and the website remained offline. The static pages included the invitation, the agenda, and a note about the problems with the website.

Setting up an isolated development environment

To safely clean the infected WordPress instance, a local, isolated QEMU/KVM instance was set up. Using small nft-scripts, the instance could be quickly isolated from the network, and WordPress could be shut down by disabling Apache. An Ubuntu 24.4 cloud server version was installed as the guest operating system. Regular scans were also performed using Thor Lite Linux 64 from Nextron Systems. This software also scans the browser's process memory for malware. ClamAV and Maldet were also used for scans. The vmnet tool toggles the firewall settings for necessary updates or installations on the guest operating system. MariaDB, Apache, and WordPress were installed on the guest server. Security measures were immediately implemented in Apache to disable or restrict XML-RPC and REST API calls, and the CSP was enabled. Specific .htaccess files protect, for example, the uploads directory from code execution. Equally important is securing against the extraction of user IDs. Access to the WordPress instance was gained via a browser outside the VM, whose RAM was scanned with Thor-Lite. To safely test the real website a docker-based firefox was installed in the ubuntu cloud server guest. This browser can be accessed from a regular firefox tab in the host browser via port 5800. It prevents malware from reaching the host system. Future backups of the live-site can be checked in this environment safely.

Note

Important: These security measures are for the Apache web server! They must be adapted for Nginx on the target platform!

Cleanup Process

We began our own attempts to clean the site and ordered the new Divi 5 theme. It turned out that the old Divi 4 theme from July 7th was not infected; it was only infected during the attack at the end of August. Three cleaning strategies were evaluated: 1. Only use the pages and posts exported via XML export. 2. Extract the pages and posts from the database backup of the last version. 3. Save all pages via the Divi layouts and export them as JSON using the Divi export function. In any case, the exported files would need to be subsequently scanned for malware keywords, base64-encoded malware, etc. A running WordPress system was not required for this. The evaluation revealed that Strategy 1 unfortunately did not export the Divi content correctly, and as a result, the pages were not displayed correctly upon re-import. The reason lies in the way Divi stores its information. This is a fundamental problem with all complex themes and editors. So the steep learning curve is not the only problem! With strategy 3, it was unclear whether Divi would export only the layouts or also the content of the pages correctly, and furthermore, the infected database would have had to be re-imported into a running WordPress system.

The following strategy (2) was used for cleaning: - downloaded new Divi4 and Divi5, wordpress etc. into the ubuntu cloud server guest. - Malware plugins removed - web research for critical code tags frequently used in malware (script, eval, decode etc.) - From the database backup, only wp_posts and wp_postmeta were extracted (the backup was imported into a new database and the tables extracted) and then scanned for malware using various Linux tools, specifically for dangerous PHP or script commands. The images and PDFs were also scanned with various tools, cleaned (e.g., data at the end of images was removed, active content in PDF files was removed), and re-encoded to neutralize encrypted malware (using ImageMagick). Claude collected several of those operations in python files which made the whole process much easier.

Note

I did not rely only on Claude generated scanners. Instead, using Linux tools I checked everything for well known tags and also checked base64 encoded pieces. I also added some of them on purpose in the sql dumps to verify that the python scanners work.

Copyrighted articles were also removed directly from the uploads as .pdf files, as well as all uploads that were no longer referenced in the database. The entire cleanup process was located in the directory cleanup_process. This includes scripts, original uploads, the database, and new versions. In some places, Claude (free version) was used to detect various forms of injected malware directly within the .sql files.

Note

Claude was very efficient in dealing with the proper wordpress tables in an automated process.

No user data, session data, options, etc., were imported from the database. Only a few key Divi settings (__et_) were extracted from wp_options, scanned for malware, and imported. A new version of WordPress with new plugins was installed, and the site data were imported. Initially, Divi 4 was chosen for backword compatibility reasons. Subsequently, the site was migrated to Divi 5. This version was then handed over for testing on November 4th.

Hosting, plugins and securing availability

We have the full range of options, from self-hosting (a VPS at Hetzner), a general provider like All-inkl.de, which provides WordPress and Apache, to a specialized WordPress provider like IONOS or HOSTPRESS. In any case, the domain name must be transferred there, or you can take the name to a dedicated domain registrar (recommended). Then you can transfer it to another provider yourself at any time. The most convenient option is certainly a specialized provider. I would recommend choosing one specializing in no-plugin security, which ensures security directly below WordPress and can also perform malware removal in case of emergency. Ideally, the club's email address can also be migrated to this provider. This is possible with Hostpress. And in any case, robust SSH access must be available. This is also the case with Hostpress – which btw. Also has a strong focus on no-plugin-security. Cost approx. €35/ month. Special rate for clubs. The most flexible option is certainly self-hosting. Of course, this means you have to do everything yourself, such as ensuring regular updates, securing the server, etc. The risk here is what happens if we can no longer do this ourselves, for example, due to health reasons. Regular hosting providers offer some convenience but no concrete WordPress help in case of emergency, but they are very cheap.

Thoughts on security

Among the “lessons learned” is the realization that powerful access to one's own site must be guaranteed at all times via SSH, and also that the access of all users must be carefully protected.

1. All registered users MUST use two-factor authentication or passkeys.
2. There are only two administrators. These administrators do NOT edit pages or posts in their admin role. Two author or editor roles are set up for them, just like for the other users.
3. Security begins on the server: Enforce additional user authentication in Apache, disable XML-RPC and restrict REST API access to authenticated users. Enable user login restrictions (fail2ban, etc.). No-plugin-security is the keyword here!!
4. Set the correct permissions for directories and files and block the upload directory with Apache to prevent code execution.
6. Download backups immediately to a secure environment, preferably encrypted.
8. Plugins are entry points for malware. Every plugin must be absolutely necessary before it is installed. Inactive plugins are uninstalled immediately.
10. Ensuring availability Should your platform or main administrator fail, you may need to quickly switch to a new platform. The key to this is having backups. A backup created with Updraft Plus can be quickly installed on another platform. Backups also serve as a fallback in case of a future site compromise. We can only detect an attack if we scan regularly. Furthermore, backups must be regularly uploaded to a new platform and their functionality verified. A backup is only a backup if it works. Specifically, this means the club needs cloud space where backups can be stored.

To-Dos

Review and test the forms. Is there any spam? If so, adjust or replace the CAPTCHA mechanism. What other form of consent is required? - Adapt the privacy policy to the plugins ultimately used. IMPORTANT: Many plugins require a data processing agreement with the developer! Don't simply install plugins that "phone home." Jetpack is particularly problematic. With WP-Forms, care was taken to ensure that messages and forms are forwarded directly via email and do not end up in the website database. With the statistics plugin, emphasis was placed on anonymizing IP addresses. - Request the domain transfer - Be sure to perform the hardening measures on the server and WordPress before going live! - Define backup procedures: how often, where to store data, how to test.

Concluding remarks

It was a lot of work to modernize the site and clean it up again. I enjoy writing posts for the site from time to time. But I'm not going to be a full-time WordPress admin. See the next point. Lessons learned

Note

The most important lesson: It's no longer possible to simply run a website on the side without much further attention. And if something happens, deeper know-how becomes a requirement. Doing all this for just a single site of a small organization just does not scale. I recommend using a professional hosting service with automatic scans, no-plugin-security in place and a team to help in case of infections.

As soon as your site is up, attacks start coming in. Make sure there are no old session tokens in the DB and have all hardening measures in place before you go live. Only then start apache/nginx. AI is taking its toll mercilessly. Bruce Schneier just mentioned in his cryptogram of November 2026 that the last month had 3% of all vulnerabilities EVER DISCOVERED (we are talking 40-50 years here). Normal would be around 0.25% per month or in other words we are seeing a 12-fold increase in detected vulnerabilities! During active work on the site daily backups and exports are needed as an attack can happen any time. For a regular small organization backups are the only safety line finally – so keep them in a safe place and test them regularly. Cleaning up is hard!