如果想要wordpress当做一个cms来使用,那下面的安全配置是必须要看的了。
1、去掉wordpress版本号信息
wp-includes/general-template.php第2204行 $gen = ‘<meta name=”generator” content=”WordPress ‘ . get_bloginfo( ‘version’ ) . ‘” 去掉里面所有版本号信息
2、删除下面文件里面的版本信息
wp-admin/includes/export.php 这里是订阅页面,还要删除wp-includes/general-template.php里面的所有信息,否则一样显示
wp-admin/admin-footer.php <p id=”footer-upgrade”><?php echo $upgrade; ?></p>
3、禁止访问wp-includes文件夹和wp-admin文件夹
apache的用户,可通过.htaccess来实现,其他用户可通过在该文件夹下面建立一个空白html文件,再加上rewrite规则实现。
4、删除掉所有插件的附带信息,避免有心人利用插件漏洞来入侵,最好也禁止访问wp-content下面的plugins文件夹和themes文件夹,方法如上一步。
5、删除后台首页版本号和主题信息
wp-admin/includes/dashboard.php,删除掉下面这段代码
echo “/n/t”.’<div>’;
$ct = current_theme_info();
echo “/n/t<p>”;
if ( !empty($wp_registered_sidebars) ) {
$sidebars_widgets = wp_get_sidebars_widgets();
$num_widgets = 0;
foreach ( (array) $sidebars_widgets as $k => $v ) {
if ( ‘wp_inactive_widgets’ == $k )
continue;
if ( is_array($v) )
$num_widgets = $num_widgets + count($v);
}
$num = number_format_i18n( $num_widgets );
$switch_themes = $ct->title;
if ( current_user_can( ‘switch_themes’) ) {
echo ‘<a href=”themes.php”>’ . __(‘Change Theme’) . ‘</a>’;
$switch_themes = ‘<a href=”themes.php”>’ . $switch_themes . ‘</a>’;
}
if ( current_user_can( ‘edit_theme_options’ ) ) {
printf(_n(‘Theme <span>%1$s</span> with <span><a href=”widgets.php”>%2$s Widget</a></span>’, ‘Theme <span>%1$s</span> with <span><a href=”widgets.php”>%2$s Widgets</a></span>’, $num_widgets), $switch_themes, $num);
} else {
printf(_n(‘Theme <span>%1$s</span> with <span>%2$s Widget</span>’, ‘Theme <span>%1$s</span> with <span>%2$s Widgets</span>’, $num_widgets), $switch_themes, $num);
}
} else {
if ( current_user_can( ‘switch_themes’ ) ) {
echo ‘<a href=”themes.php”>’ . __(‘Change Theme’) . ‘</a>’;
printf( __(‘Theme <span><a href=”themes.php”>%1$s</a></span>’), $ct->title );
} else {
printf( __(‘Theme <span>%1$s</span>’), $ct->title );
}
}
echo ‘</p>’;
update_right_now_message();
echo “/n/t”.’<br /></div>’;
6、登陆页装上login-lockdown插件,避免暴力破解用户密码,如果开放会员注册功能,请按下面的方法修改登陆页,否则请把根目录下面的wp-login.php改名后,丢到其他你自己知道的文件夹里面,然后修改这个登陆文件相关地址,很简单,一般直接用你的新地址全部替换wp-login.php这个地址差不多了。最后还要修改wp-includes/general-template.php第215行,这里是后台点退出后跳转到的地址,修改成登陆页新地址。
开放会员注册,就要防止其他用户恶意修改密码。在找回密码的页面,要求同时输入用户名和邮箱,这样比较保险。方法如下:
wp-login.php 第391行,多加一行。
<p>
<label><?php _e(‘Username’) ?><br />
<input type=”text” name=”user_login” id=”user_login” value=”" size=”20″ tabindex=”10″ /></label>
</p>
<p>
<label><?php _e(‘E-mail:’) ?><br />
<input type=”text” name=”user_login” id=”user_login” value=”" size=”20″ tabindex=”10″ controlName=”email” dataType=”user_login” /></label>
</p>
传递方式后面加上method=”post” onsubmit=”return validator(this);”
上面加上检测email脚本
<script language=”javascript” type=”text/javascript”>
String.prototype.isEmpty = function () {
return !(/.?[^/s ]+/.test(this));
}
String.prototype.isBetween = function (val, min, max) {
return isNaN(val) == false && val >= min && val <= max;
}
String.prototype.getBetweenVal = function (what) {
var val = this.split(‘,’);
var min = val[0];
var max = val[1] == null ? val[0] : val[1];
if (parseInt(min) > parseInt(max)) {
min = max;
max = val[0];
}
return what == ‘min’ ? (isNaN(min) ? null : min) : (isNaN(max) ? null : max);
}
var validator = function (formObj) {
this.allTags = formObj.getElementsByTagName(‘*’);
this.reg = new Object();
this.reg.user_login = /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/;
this.tip = new Object();
this.tip.user_login = ‘ Is not a valid e-mail format’;
this.getControlName = function ()
{
return this.element.getAttribute(‘controlName’) == null
? ‘The value of the specified control’
: this.element.getAttribute(‘controlName’);
}
this.setFocus = function (ele) {
try {
ele.focus();
} catch (e){}
}
this.setBorderColor = function (ele) {
var borderColor = ele.currentStyle ?
ele.currentStyle.borderColor :
document.defaultView.getComputedStyle(ele, null)['borderColor'];
ele.style.borderColor = ‘#ff9900′;
ele.onkeyup = function () {
this.style.borderColor = borderColor;
}
}
//输出错误反馈信息
this.feedback = function (type) {
try {
var msg = eval(‘this.tip.’ + type) == undefined ?
type :
this.getControlName() + eval(‘this.tip.’ + type);
} catch (e) {
msg = type;
}
this.setBorderColor(this.element);
alert(msg);
this.setFocus(this.element);
};
this.validate = function () {
var v = this.element.value;
var dataType = this.element.getAttribute(‘dataType’);
if (!v.isEmpty() && dataType != null && dataType.toLowerCase() != ‘password’) {
dataType = dataType.toLowerCase();
try {
if (!(eval(‘this.reg.’ + dataType)).test(v)) {
this.feedback(dataType);
return false;
}
} catch(e) {
this.feedback(‘unknow’);
return false;
}
}
return true;
};
this.init = function () {
for (var i=0; i<this.allTags.length; i++) {
if (this.allTags[i].tagName.toUpperCase() == ‘INPUT’
this.allTags[i].tagName.toUpperCase() == ‘SELECT’
this.allTags[i].tagName.toUpperCase() == ‘TEXTAREA’)
{
this.element = allTags[i];
if (!this.validate())
return false;
}
}
};
return this.init();
}
</script>
如果有心人浏览器禁用js脚本,那就只能通过修改php程序来实现了。
7、必须要尽全力保护好wp-config.php这个文件
先要先禁止搜索引擎收录wp-开头的文件和文件夹,尤其要记得这一步,否则在你配置服务器的时候,如果php环境不能立即配置好,那别人访问的时候,很可能直接显示wp-config.php的代码,你的网站数据库信息被搜索引擎收录,你说是好还是坏呢?
其次要禁止访问这个文件,可通过.htaccess或rewrite实现,有能力的最好改名,然后丢到一个别人不知道的文件夹里面。
8、开始安装wordpress的时候,不要使用数据库默认前缀和admin用户名。
9、即时跟进更新,包括插件更新。
本文来自:站长特效网,遵守行业道德,转载请注明出处。