Home WordpressWordPress cơ bản Hướng dẫn một số bảo mật trong wordpress

Hướng dẫn một số bảo mật trong wordpress

by admincp

Hiện nay càng được nhiều người sử dụng WordPress do tính linh hoạt và dễ sử dụng, tuy nhiên vấn đề bảo mật về mã nguồn này không hẳn đã tốt so với các mã nguồn mở khác.
wordpress security issue hoangweb
Sau đây là một số gợi ý cho bạn bảo mật website wordpress.

Đặt mật khó khó đoán:

không được chọn mật khẩu dễ đoán và quen thuộc ví dụ: admin, 123456..
*Luôn cập nhật wordpress: việc nâng cấp wordpress từ wordpress.org cũng là một giải pháp, vì các bản mới ra luôn tốt hơn bản cũ.

Để Ẩn thông số phiên bản wordpress ở footer:

khi đăng nhập vào wordpress, bạn nhìn ở phía góc phải dưới cùng sẽ hiển ra chỉ số phiên bản wordpress, để ẩn thông số này bằng cách Copy dòng sau vào functions.php

add_filter('the_generator', 'wp_remove_version');
function wp_remove_version(){
	return '';
}

Change File Permissions

Thiết lập đúng File Permissions để bảo vệ các files code khỏi bị tấn công sửa đổi là rất quan trọng. Mình khuyên các bạn thiết lập giới hạn truy cập , thiết lập CHMOD=744 chỉ đọc (read-only) trừ quyền admin là bạn. Mở trương trình FTP chuột phải vào folder hoặc file -> chọn File Permissions. Nếu đó là 777 thì bạn đã yên tâm vì trước đó chưa bị tấn công, bạn chuyển CHMOD thành 744, và full access cho “owner”.

Banning a WordPress Spammer With .htaccess

Chặn địa chỉ IP có dấu hiệu spam website của bạn, thêm dòng sau vào .htaccess. Thay đổi IP bạn muốn chặn , nếu chặn nhiều IP thì nhân bản dòng deny from.

<limit GET POST>
order allow,deny
deny from 200.49.176.139
allow from all
</limit>

Bảo mật Form

Sử dụng wp_verify_nonce để verify form submit, tránh request form nhiều lần mang tính spam dữ liệu từ bên ngoài. Tham khảo đoạn code sau:

< ?php
/*
The nonce is generated based on the current time, the $action argument, and the current user ID.
In this simple example, we create an nonce and use it as one of the GET query parameters in a URL for a link.
When the user clicks the link they are directed to a page where a certain action will be performed (for example, a post might be deleted).
On the target page the nonce is verified to insure that the request was valid (this user really clicked the link and really wants to perform this action).
*/ 
// Create an nonce for a link.
// We pass it as a GET parameter.
// The target page will perform some action based on the 'do_something' parameter.
$nonce = wp_create_nonce( 'my-nonce' );
?>
<a href="https://www.hoangweb.com/wordpress/myplugin.php?do_something=some_action&_wpnonce=<?php echo $nonce; ?>">Do some action</a>
 
< ?php 
// This code would go in the target page.
// We need to verify the nonce.
$nonce = $_REQUEST['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'my-nonce' ) ) {
    // This nonce is not valid.
    die( 'Security check' ); 
} else {
    // The nonce was valid.
    // Do stuff here.
}
?>
< ?php
//For example, if we were to create an nonce that would be part of a request to delete a post, we might call it 'delete_post'. Then to make it more specific, we could append the ID of the particular post that the nonce was for. For example 'delete_post-5' for the post with ID 5.
wp_create_nonce( 'delete_post-' . $post_id );
 
//Then we would verify the nonce like this:
wp_verify_nonce( $nonce, 'delete_post-' . $_REQUEST['post_id'] );
?>

Giới hạn truy cập độc lập vào file

Chèn đoạn kiểm tra để đảm bảo truy cập vào ứng dụng có môi trường wordpress.

//nếu truy cập trực tiếp vào file của plugin sẽ k có biến wp
if(!defined('ABSPATH')) exit('hacked :D');

Sử dụng plugins bảo mật

WP safely disable directory browsing.

Để nhận được bài viết mới vui lòng đăng ký kênh kiến thức WordPress từ A-Z ở Form bên dưới. Bạn cũng có thể nhận được sự trợ giúp trên TwitterFacebook

Liên hệ

Công ty chuyên Thiết kế website uy tín nhất Miền Bắc: http://vinastar.net

Hotline tư vấn: 0989 48 3456

Nguồn: Sưu tầm trên internet

You may also like

Leave a Comment