WordPress sites being filled with random PHP files

First steps:

  • Take the server offline, if you can access it directly. – The chance of your server being part of a larger scheme at this point is pretty high.
  • If you can’t take it offline, check your authorized_keys files in ~/.ssh/authorized_keys and remove entries that don’t belong to you. (Repeat this step for every user, where ~ is their home-directory. Changing the port only is not sufficient at all – would prob. only take seconds to find the new one.

Recommended:

  • Nuke the server completely and restore a backup from before this occured
  • Check for available updates on the server + the wordpress installation and make sure you’re not using deprecated addons/php-code.
  • Have a look at linux-hardening and especially your wordpress installation.
  • Check the authorized_keys files as well as other ssh-configuration files (f.e. /etc/ssh/sshd_config on some systems like debian).

Without finding the root cause for this, it’s very likely to happen again in the future, so make sure to secure it, monitor ssh connections/only allow from your IP, etc.

Without further information, there is not much more detail to provide. – Feel free to leave OS information/software information if you need further assistance.

EDIT: Disable root login via password if activated and use in general a non-root user for setup. Sudo is way better in those regards.