I'm using Apache 2.4 as a reverse proxy and according to this post, I have no use for the HTTP CONNECT method. So I tried disabling proxy_connect module when I built Apache using configure (static) option.
$ ./apachectl -v
Server version: Apache/2.4.29 (Unix)
Server built: Feb 8 2018 12:40:42
$ ./apachectl -M
Loaded Modules:
core_module (static)
authn_core_module (static)
authz_host_module (static)
authz_core_module (static)
access_compat_module (static)
socache_shmcb_module (static)
so_module (static)
http_module (static)
mime_module (static)
log_config_module (static)
log_debug_module (static)
env_module (static)
headers_module (static)
setenvif_module (static)
proxy_module (static) ###########
proxy_http_module (static) ###########
proxy_balancer_module (static) ###########
slotmem_shm_module (static)
ssl_module (static)
lbmethod_byrequests_module (static)
lbmethod_bytraffic_module (static)
lbmethod_bybusyness_module (static)
lbmethod_heartbeat_module (static)
mpm_event_module (static)
unixd_module (static)
rewrite_module (static)
As you can see I have enabled only: proxy, proxy_http and proxy_balancer modules.
However, when I run nmap scan, it reports a 400 (Bad Request) for CONNECT when I was expecting 405 (Method Not Allowed).
$ nmap -p 443 --script http-methods --script-args 'http-methods.test-all=true,http-methods.retest=1' 10.x.x.xxx
Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-09 17:23 EST
Nmap scan report for serverA (10.x.x.xxx)
Host is up (0.00013s latency).
PORT STATE SERVICE
443/tcp open https
| http-methods:
| Supported Methods: TRACE GET HEAD POST CONNECT
| Potentially risky methods: TRACE CONNECT
| Status Lines:
| POST: HTTP/1.1 302 Moved Temporarily
| HEAD: HTTP/1.1 302 Moved Temporarily
| CONNECT: HTTP/1.1 400 Bad Request
| GET: HTTP/1.1 302 Moved Temporarily
|_ TRACE: HTTP/1.1 405 Method Not Allowed
Nmap done: 1 IP address (1 host up) scanned in 0.79 seconds
This is what I have at the beginning of apache/conf/extra/httpd-vhosts.conf:
<VirtualHost *:443>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)
RewriteRule .* - [R=405,L]
This is what is shown is Apache access log for the nmap scan:
[09/Feb/2018:17:29:47 -0500] "OPTIONS / HTTP/1.1" 405 225
[09/Feb/2018:17:29:47 -0500] "CBZF / HTTP/1.1" 405 222
[09/Feb/2018:17:29:47 -0500] "GET / HTTP/1.1" 302 109
[09/Feb/2018:17:29:47 -0500] "HEAD / HTTP/1.1" 302 -
[09/Feb/2018:17:29:47 -0500] "POST / HTTP/1.1" 302 109
[09/Feb/2018:17:29:47 -0500] "OPTIONS / HTTP/1.1" 405 225
[09/Feb/2018:17:29:47 -0500] "DELETE / HTTP/1.1" 405 224
[09/Feb/2018:17:29:47 -0500] "PUT / HTTP/1.1" 405 221
[09/Feb/2018:17:29:48 -0500] "CONNECT / HTTP/1.1" 400 226
[09/Feb/2018:17:29:48 -0500] "TRACE / HTTP/1.1" 405 223
I'm happy with everything except the 400 status for CONNECT.
Is there a way I can make Apache return 405 or 501 status for CONNECT?