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 DELETE
trying varied combos with variousRequire
statements ie.local
,ip
,host
, andorder allow, deny
patterns.Allow all from
<Directory "/">
,<Location >
,<LimitExcept >
Tags including attributes such asGET
,POST
and combos.Various
<if >
statementsAllowMethod
StatementsWhitelisting 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.