Chặn Tấn Công Vào Tệp xmlrpc.php Trong WordPress Trên Directadmin

1 20.06.2024

Xin Chào!!! Bài viết này ZHOST sẽ hướng dẫn bạn cách chặn các cuộc tấn công vào tệp xmlrpc.php bằng cách chỉnh sửa các tệp cấu hình trên 3 WebServer :Apache, Nginx và OpenLiteSpeed, khi sử dụng DirectAdmin.

Vì sao phải làm vậy???
Tệp xmlrpc.php này thường bị khai thác trong các cuộc tấn công vào website. Và chúng ta chặn truy cập vào nó nhằm tăng cường bảo mật cho website WordPress của mình.

I. Chặn Tấn công Với Apache + Directadmin

  1. Truy cập vào Server với quyền root qua SSH
  2. Đi tới đường dẫn lưu trữ các tệp mẫu tùy chỉnh (khi bạn chỉnh sửa hoặc tạo mới các mẫu cấu hình cho DirectAdmin, bạn có thể lưu chúng vào thư mục này để đảm bảo rằng các thay đổi của bạn không bị ghi đè bởi các cập nhật hệ thống hoặc DirectAdmin.)
    Zhost Tutorial
    cd /usr/local/directadmin/data/templates/custom/
  3. Tạo các tệp trống để chứa cấu hình tùy chỉnh
    Zhost Tutorial
    touch virtual_host2.conf.CUSTOM.4.post virtual_host2_secure.conf.CUSTOM.4.post 
    touch virtual_host2_secure_sub.conf.CUSTOM.4.post virtual_host2_sub.conf.CUSTOM.4.post
    chmod 644 virtual_host2.conf.CUSTOM.4.post virtual_host2_secure.conf.CUSTOM.4.post 
    chmod 644 virtual_host2_secure_sub.conf.CUSTOM.4.post virtual_host2_sub.conf.CUSTOM.4.post
  4. Mở từng tệp và thêm đoạn code sau ở cuối file
    Zhost Tutorial
    <Location ~ "/xmlrpc.php">
        Order allow,deny
        Deny from all
        ErrorDocument 403 "Sorry, you are not allowed to view this page!"
    </Location>
    Khởi động lại hệ thống
    Zhost Tutorial
    sudo systemctl restart apache2
  5. Sao chép nội dung của tệp đầu tiên vào các tệp khác:
    Zhost Tutorial
    cp -p virtual_host2.conf.CUSTOM.4.post virtual_host2_secure.conf.CUSTOM.4.post
    cp -p virtual_host2.conf.CUSTOM.4.post virtual_host2_secure_sub.conf.CUSTOM.4.post
    cp -p virtual_host2.conf.CUSTOM.4.post virtual_host2_sub.conf.CUSTOM.4.post
  6. Áp dụng các thay đổi và tái tạo lại cấu hình cho tất cả các virtual host hiện có
    Zhost Tutorial
    cd /usr/local/directadmin/custombuild/
    ./build rewrite_confs
  7. Hãy đảm bảo rằng Apache của bạn đã khởi động lại, sau đó thử truy cập vào linkhttp://www.domain.com/xmlrpc.php=> Bạn sẽ thấy thông báo “Sorry, you are not allowed to view this page!”.

II. Chặn Tấn công Với Nginx + Directadmin

  1. Truy cập vào Server với quyền root qua SSH
  2. Đi tới đường dẫn lưu trữ các tệp mẫu tùy chỉnh (khi bạn chỉnh sửa hoặc tạo mới các mẫu cấu hình cho DirectAdmin, bạn có thể lưu chúng vào thư mục này để đảm bảo rằng các thay đổi của bạn không bị ghi đè bởi các cập nhật hệ thống hoặc DirectAdmin.)
    Zhost Tutorial
    cd /usr/local/directadmin/data/templates/custom/
  3. Tạo các tệp trống để chứa cấu hình tùy chỉnh
    Zhost Tutorial
    touch nginx_server.conf.CUSTOM.4.post nginx_server_secure.conf.CUSTOM.4.post 
    touch nginx_server_secure_sub.conf.CUSTOM.4.post nginx_server_sub.conf.CUSTOM.4.post
    chmod 644 nginx_server.conf.CUSTOM.4.post nginx_server_secure.conf.CUSTOM.4.post
    chmod 644 nginx_server_secure_sub.conf.CUSTOM.4.post nginx_server_sub.conf.CUSTOM.4.post
  4. Mở từng tệp và thêm đoạn code sau ở cuối file
    Zhost Tutorial
    location =/xmlrpc.php 
    {
        deny all;
    }
    Lưu tệp cấu hình và kiểm tra cú pháp của tệp cấu hình Nginx để đảm bảo không có lỗi
    Zhost Tutorial
    sudo nginx -t
    Khởi động lại hệ thống
    Zhost Tutorial
    sudo systemctl restart nginx
  5. Sao chép nội dung của tệp đầu tiên vào các tệp khác
    Zhost Tutorial
    cp -p nginx_server.conf.CUSTOM.4.post nginx_server_secure.conf.CUSTOM.4.post
    cp -p nginx_server_secure.conf.CUSTOM.4.post nginx_server_secure_sub.conf.CUSTOM.4.post
    cp -p nginx_server_secure_sub.conf.CUSTOM.4.post nginx_server_sub.conf.CUSTOM.4.post
  6. Áp dụng các thay đổi và tái tạo lại cấu hình
    Zhost Tutorial
    cd /usr/local/directadmin/custombuild/
    ./build rewrite_confs
  7. Hãy đảm bảo rằng Nginx của bạn đã khởi động lại, sau đó thử truy cập vào linkhttp://www.domain.com/xmlrpc.php=> Bạn sẽ thấy lỗi 403: “403 Forbidden”.

III. Chặn Tấn công Với OpenLiteSpeed + Directadmin

  1. Truy cập vào Server với quyền root qua SSH
  2. Đi tới đường dẫn lưu trữ các tệp mẫu tùy chỉnh (khi bạn chỉnh sửa hoặc tạo mới các mẫu cấu hình cho DirectAdmin, bạn có thể lưu chúng vào thư mục này để đảm bảo rằng các thay đổi của bạn không bị ghi đè bởi các cập nhật hệ thống hoặc DirectAdmin.)
    Zhost Tutorial
    cd /usr/local/directadmin/data/templates/custom/
  3. Tạo các tệp trống để chứa cấu hình tùy chỉnh
    Zhost Tutorial
    touch openlitespeed_vhost.conf.CUSTOM.5.post
    chown diradmin:diradmin openlitespeed_vhost.conf.CUSTOM.5.post
  4. Mở tệp và thêm dòng code sau ở cuối file
    Zhost Tutorial
    RewriteRule ^/(xmlrpc|wp-trackback)\.php - [F,L,NC]
    Khởi động lại hệ thống
    Zhost Tutorial
    sudo systemctl restart lsws
  5. Áp dụng các thay đổi và tái tạo lại cấu hình
    Zhost Tutorial
    cd /usr/local/directadmin/custombuild/
    ./build rewrite_confs
  6. Hãy đảm bảo rằng OpenLiteSpeed của bạn đã khởi động lại, sau đó thử truy cập vào linkhttp://www.domain.com/xmlrpc.php=> Bạn sẽ thấy lỗi 403: “403 Forbidden”.

Hoàn Tất Cấu Hình Từ Chối Truy Cập Vào Tệp xmlrpc.php.