Products
GG网络技术分享 2025-03-18 16:14 3
首先申明这是一篇技术文章,不愿意看技术文章的朋友可以略过!
最近在用wordpress搭建一个美食类网站,由于很久不做站,php语言也忘得差不多,所以为了图简单,用wordpress搭建了一个cms网站,发现漏洞很多,分享一下。
做为站长和博主,我们总在担心我们的博客网站是否安全,同时我也一直再找一个比较好的安全防护方法。我们一直都以为黑客们不知道我们网站的用户名,就算知道后台登陆地址也没事,直到今天才发现,使用WordPress建站的博主们的用户名都是可见的,除非采取了其他措施来保护。
大部分博主的后台路径都是:http://网站地址/wp-login.php。
大部分博主的后台登陆用户名都可以这样查看到:http://网站地址/?author=1,多用户的可以把1变为2、3、4、5等,就可以在地址栏查看到各个用户名。
知道了后台登陆地址和用户名后,剩下的就是用暴力破解密码了,如果没有任何防护的话,成功指数相当高。
为了保障我们的后台安全,建议安装一个Limit Login Attempts插件,来限制强行登陆的次数,同时修改后台登陆地址和隐藏我们的用户名。
修改后台登陆地址:
我在网上找了很多方法,大部分就是在所用主题的functions.php文件的?>前面添加以下代码即可实现。
add_action(‘login_enqueue_scripts’,’login_protection’);
function login_protection(){
if($_GET[‘word‘] != ‘press’)header(‘Location: http://网站地址/’);
}
但经本人测试,在本地WIN主机测试是成功的,但是上传到Linux服务器却发生错误:Cannot modify header information,据说是因为header()要求太苛刻。
本人觉得既然是header()出错,而且它只是用来跳转而已,何不用JS实现跳转呢,于是修改为:
function login_protection(){
if($_GET[‘word’] != ‘press’){
$url = “http://网站地址”;
echo “<script language=’javascript’ type=’text/javascript’>”;
echo “window.location.href=’$url’”;
echo “</script>”;
}
}
add_action(‘login_enqueue_scripts’,’login_protection’);
上传到服务器一测试,果然成功了,登陆http://网站地址/wp-login.php会直接跳转到我们指定的页面,要登录必须是http://网站地址/wp-login.php?word=press才行,而word、press、跳转的页面都是我们自己设置的,而且word、press只有自己知道,大大提高了其安全性。
隐藏用户名:
这个也同样道理,直接将“作者文章列表(?author=1)”跳转到指定的页面,这样就可以做到隐藏用户名的目的。
同样在所用主题的functions.php文件的?>前面添加以下代码:
add_filter( ‘author_link’, ‘my_author_link’ );
function my_author_link() {
return home_url( ‘/’ );
}
其中home_url( ‘/’ )是跳转到主页,这里也可以设置为指定的页面,比如grda页面,可以为home_url( ‘grda’ )。
安装了限制强行登录次数的插件、修改了后台登陆的地址和隐藏了用户名,我相信这个时候的系统应该还是挺安全的。
写给哪些用wordpress程序做站的朋友们,为了你的网站安全,千万不要错过看了!
- - - - - - -
关注作者
↓↓↓↓↓↓↓↓↓↓
微信公众账号:zimeiti_110阿牛个人微信:seoniu
/* 评论作者和谐,使昵称部分隐藏,例如:ad**n 。*/function cut_str($string, $sublen, $start = 0, $code = \'UTF-8\')
{
if($code == \'UTF-8\')
{
$pa = \"/[\\x01-\\x7f]|[\\xc2-\\xdf][\\x80-\\xbf]|\\xe0[\\xa0-\\xbf][\\x80-\\xbf]|[\\xe1-\\xef][\\x80-\\xbf][\\x80-\\xbf]|\\xf0[\\x90-\\xbf][\\x80-\\xbf][\\x80-\\xbf]|[\\xf1-\\xf7][\\x80-\\xbf][\\x80-\\xbf][\\x80-\\xbf]/\";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join(\'\', array_slice($t_string[0], $start, $sublen));
return join(\'\', array_slice($t_string[0], $start, $sublen));
}
else
{
$start = $start*2;
$sublen = $sublen*2;
$strlen = strlen($string);
$tmpstr = \'\';
for($i=0; $i< $strlen; $i++)
{
if($i>=$start && $i< ($start+$sublen))
{
if(ord(substr($string, $i, 1))>129)
{
$tmpstr.= substr($string, $i, 2);
}
else
{
$tmpstr.= substr($string, $i, 1);
}
}
if(ord(substr($string, $i, 1))>129) $i++;
}
//if(strlen($tmpstr)< $strlen ) $tmpstr.= \"...\";
return $tmpstr;
}
}
//替换评论作者
function my_get_comment_author_link() {
$url = get_comment_author_url( $comment_ID );
$author = cut_str(get_comment_author( $comment_ID ), 2, 0).\'***\'.cut_str(get_comment_author( $comment_ID ), 1, -1);
if ( empty( $url ) || \'http://\' == $url )
return $author;
else
return \"<a target=\'_blank\' href=\'$url\' rel=\'external nofollow\' class=\'url\'>$author</a>\";
}
add_filter(\'get_comment_author_link\', \'my_get_comment_author_link\');
Demand feedback