There are several questions here.
Who has been writing to the files
The operating system does not log this information, but there are some clues:
- The modification date
- The file permissions
Use the files' modification date to narrow down your search of your Apache access logs. Check at the very least for any POST
requests and logins from around that time. For example this would show all login attempts:
zgrep 'POST /wp-login.php' /var/log/apache2/*access*
You can then filter the output by the time range you got from the files' modification time.
If the files that have been modified are only writable by certain system users, then you can be reasonably certain that they were modified by those system users.
What process(es) are pegging the CPU
This information is not logged by default. If it impractical to try to monitor the server "live" -- for example with top -- then there are various logging tools you can use. Here is a serverfault question where various tools are recommended for this purpose.
Determining if you have been hacked
This a larger topic, but the place I would start, since you mentioned modifications to the WordPress files, is to determine if these modifications are malicious. Run a WordPress malware scanner, and/or look for malicious patterns such as eval(base64_decode(
, php web shells, and so on. If you're unsure, be persistent, be thorough, post more questions if you need to.
Determining how an attacker gained access
If you are reasonably certain that the site or sites were hacked, you can try to determine how the attacker gained access. The two most likely ways this could have happened are via login to an admin user account, or via a vulnerability. In most cases, it is difficult to determine with a high degree of certainty. But if you have been running software with a known vulnerability, especially one with a public exploit and that allows remote code execution, then this is a very likely possibility. And if a WordPress admin user has weak credentials, or their credentials were leaked, then this is a very likely possibility.
Further hardening
If you believe that the server has been compromised, then you should refer to the canonical answer on the subject.