大网数据广告活动
服务器运维问答

How Apache Limit POST are set to accept Strictly local service Request?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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 like GET,PUT, POST PUT DELETE trying varied combos with various Require statements ie. local, ip, host, and order allow, deny patterns. Allow all from

  • <Directory "/">, <Location >,<LimitExcept > Tags including attributes such as GET,POST and combos.

  • Various <if > statements

  • AllowMethod Statements

  • Whitelisting 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。