消除xmlrpc的最佳方法是什么。当你不需要的时候从WordPress下载php文件?
消除xmlrpc.php的最佳方法是什么?
自WordPress 3.5以来,此选项(XML-RPC
)默认情况下已启用,并且可以从WordPress中关闭它dashboard
不见了。
添加此代码段以在中使用functions.php
:
// Disable use XML-RPC
add_filter( \'xmlrpc_enabled\', \'__return_false\' );
// Disable X-Pingback to header
add_filter( \'wp_headers\', \'disable_x_pingback\' );
function disable_x_pingback( $headers ) {
unset( $headers[\'X-Pingback\'] );
return $headers;
}
虽然它是照它说的做的,但当一个站点受到攻击时,它会变得非常密集您最好在
.htaccess
文件# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order allow,deny
deny from all
</Files>
或使用此选项禁用对xmlrpc.php
来自NGINX服务器块的文件。# nginx block xmlrpc.php requests
location /xmlrpc.php {
deny all;
}
请注意,禁用也会影响通过手机登录。如果我是正确的WordPress移动应用程序确实需要这个请参见Codex 有关使用的更多信息
XML-RPC
.请在编辑/添加之前始终备份文件
Edit/Update
@Prosti,-你完全正确-关于RESTful API
将为WordPress提供
我忘了提这个。它应该已经集成到core(WordPress 4.1版)中,而这在当时是不可能的。但看起来,它将是WordPress 4.5的核心
目前的替代方案是此插件:WordPress REST API (Version 2)
您可以一直使用到Restful API
也是WordPress的核心
Target date for release of WordPress 4.5. (April 12, 2016 (+3w))
对于那些对RESTful
, 在…上Stackoverflow 是一个非常好的社区维基。
When you have the ability to block it via your web server\'s configuration, @Charles\' suggestions are good.
If you can only disable it using php, the xmlrpc_enabled
filter is not the right way.
Like documented here:
https://developer.wordpress.org/reference/hooks/xmlrpc_enabled/
it only disables xml rpc methods that require authentication.
Instead use the xmlrpc_methods
filter to disable all methods:
<?php
// Disable all xml-rpc endpoints
add_filter(\'xmlrpc_methods\', function () {
return [];
}, PHP_INT_MAX);
You can test if it\'s working by sending a POST request to xmlrpc.php with the following content:
<methodCall>
<methodName>system.listMethods</methodName>
</methodCall>
If the filter is working, there should only be 3 methods left:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<string>system.multicall</string>
</value>
<value>
<string>system.listMethods</string>
</value>
<value>
<string>system.getCapabilities</string>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
you can quickly test it with curl:
curl -X POST \\
-H \'Cache-Control: no-cache\' \\
-H \'Content-Type: application/xml\' \\
-d \'<methodCall><methodName>system.listMethods</methodName></methodCall>\' \\
https://your-wordpress-site.com/xmlrpc.php
我们正在使用htaccess文件来保护它免受黑客攻击。
# BEGIN protect xmlrpc.php
<files xmlrpc.php>
order allow,deny
deny from all
</files>
# END protect xmlrpc.php
最好的做法是禁用xmlrpc.php
与插件一起运行,而不是删除或禁用文件本身。该文件本身将在WordPress核心更新时被替换,而插件将在核心更新后以及更改主题时将其禁用。
看见https://wordpress.org/plugins/search.php?q=disable+xml-rpc 对于不同的插件。它们都有细微的差别。
这些插件与添加到主题的functions.php
文件或添加order,allow deny
规则到。htaccess(如其他答案中所述),区别在于插件或函数禁用调用xmlrpc.php
通过PHP,以及中的规则。htaccess通过在webserver(即Apache或Nginx)中利用mod\\u重写来工作。在现代服务器上使用PHP和mod\\u重写之间没有明显的性能差异。
对于在IIS中托管WordPress的极少数人,可以使用IIS URL重写模块执行类似htaccess的限制。下面的示例假设真正的客户端IP位于X-Forwarded-For标头中,已知的白名单IP为55.55.555.555,并且您希望使用HTTP 404响应非白名单IP。
<rule name="wordpress-restrictions" enabled="true" stopProcessing="true">
<match url="(^xmlrpc.php)|(^wp-admin)|(^wp-login.php)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_X_FORWARDED_FOR}" pattern="(^55\\.55\\.555\\.555$)" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="404" subStatusCode="44" statusReason="File or directory not found" statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
</rule>
最好的方法是使用。htaccess文件通过添加
# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
allow from 1.1.1.1
</Files>
到文件末尾but 如果你想要easiest 使用方式Disable XML-RPC-API 插件将完成这项工作。我最近安装了Wordfence,从版本6.3.12开始,它能够阻止对任何位置的直接访问。正在放置/xmlrpc。“立即阻止访问这些URL的IP”列表中选项页上的php现在显示,大约每15分钟就有一次尝试被阻止。
这还有一个优点,就是可以阻止URL,以躲避那些讨厌的机器人,因为它们一次又一次地以不同的IP地址返回。
我不知道它是否允许使用xmlrpc。php通过应用程序进行有效操作。
起初,我在服务器上遇到了一些问题,产生了504个超时和502个坏网关错误,但似乎已经解决了。
到目前为止,这个结果给人留下了非常深刻的印象,在安装Wordfence之前,该网站遭到黑客攻击,尽管总是有最新版本的WordPress和插件,但它还是产生了一个有价值的清理概要文件。
我为nginx使用这个小代码,它100%工作
location ~* (/wp-content/.*\\.php|/wp-includes/.*\\.php|/xmlrpc\\.php$|/(?:uploads|files)/.*\\.php$) {
deny all;
access_log off;
log_not_found off;
return 444;
}