问题原文
原帖链接 · Bama · CC BY-SA 4.0
I am trying to harden an Apache 2.4 Web server running 2 wordpress sites with separate vhost settings. Deployed on Windows 2012 r2. I was hacked a few weeks ago and the server was completely lost. On the new server they are still trying to hack the site with post request injections/code executions. I'm having trouble trying to block all POST request that are not sent by the server on submission.
Things I have tried include
<Location>,<Directory>,<Limit>tags with their attributes likeGET,PUT,POST PUT DELETEtrying varied combos with variousRequirestatements ie.local,ip,host, andorder allow, denypatterns.Allow all from<Directory "/">,<Location >,<LimitExcept >Tags including attributes such asGET,POSTand combos.Various
<if >statementsAllowMethodStatementsWhitelisting Directories in the
.htacess
Placing attempts in different file context. Such as httpd.conf, Vhost.conf, .htaccess. Any file I found referenced in Apache docs related to the directive context. Even placed it where it should not work for giggles. Nothing, I read in the docs or on stack overflow seemed to work.
All auth Modules loaded like mod_auth, mod_host etc. Just assume Modules are fine.
What I would like to achieve is to deny or <Limit POST> request. Strictly allowing them in a dynamic <Directory "/.*"> or ` being responded to only when the server submits the Request using the server IP. Therefore the IP:port of the request should be the "remote address" because the apache local service sends the request method via PHP. I believe this to be correct logic.
The last thing I had time to try before leaving work, is the below code attempting a dynamic `<Directory "/.*"> tag I do not want to dig through Wordpress for every form and create a tag for each directory.
Thank you for the help, please include a code example with your answer.
<Directory "/.*">
<if "%{REQUEST_METHOD} == 'POST'">
<Limit POST PUT DELETE>
Require req, http %{REMOTE_ADDR} == 'xx.xx.xx.xx:xx'
</Limit>
</if>
</Directory>
Now I tried
<Directory "/">
<if "($_SERVER['%{REMOTE_ADDR}'] == 'xx.xx.xx.xx'">
<Limit POST>
allow from all
</Limit>
</if>
</Directory>
<Directory "/">
<if "($_SERVER['REMOTE_ADDR'] == 'xx.xx.xx.xx'">
<Limit POST>
allow from all
</Limit>
</if>
</Directory>
No plugin, No nginx,E xpress, Or IIS Suggestions. Only relevant solutions to this config.
已采纳解答
原帖链接 · Gerard H. Pille · CC BY-SA 4.0
The POST is done by the user's browser. If Apache's access logs show you that the request is coming from the same system, then maybe some other software is the first in line on that system, like eg. a webcache as Varnish, or HaProxy. Check if the header X-Forwarded-For contains the user's IP address. If you want to protect Wordpress from hacking, which is not easy, you need to work on Wordpress itself. Change the name of the login page, give admin a password, impossible to guess or brute force, and last but not least, keep Wordpress up to date, so the known vulnerabilities are patched.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
