Страница 1 из 1

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-24 22:01:17
DuoMorph
На серваке ip адрес интерфейса внутренней сетевухи используемой для внутренней сети = 172.22.22.1. Так же на том же серваке стоит апач и соответственно случает порты 80 и 443. Проблема заключает в том, что при обращеннии с того самого же сервера, на свой же ip адрес присвоенный одной из сетевух - порты 80 и 443 являются filtered (по терминологии Nmap). Проблема решается, если убрать правило block in all в packet filter'e.

Привожу логи работы:
Список моих правил PF'a без правила block in all:

Код: Выделить всё

root@serv:/home/adm # pfctl -s rules
scrub in all fragment reassemble
scrub out all random-id fragment reassemble
scrub on tun0 all max-mss 1450 fragment reassemble
scrub on tun5 all max-mss 1450 fragment reassemble
scrub on tun8 all max-mss 1450 fragment reassemble

pass inet from 172.22.22.0/24 to any flags S/SA keep state
pass on tun8 inet from 10.8.11.0/24 to any flags S/SA keep state
pass in all flags S/SA keep state
pass out all flags S/SA keep state
pass quick from any to <blockedip> flags S/SA keep state rtable 1
pass proto tcp from any to any port = http flags S/SA keep state
pass proto tcp from any to any port = https flags S/SA keep state
pass proto tcp from any to any port = 31322 flags S/SA keep state
pass on tun8 inet proto icmp all icmp-type echoreq keep state
pass on tun8 proto udp from any to any port 33433 >< 33626 keep state
Провожу сканирование порта nmap'om:

Код: Выделить всё

root@serv:/home/adm # nmap -sT -p 443 -n -Pn -sV --script http-title 172.22.22.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-04-25 00:46 +07
Nmap scan report for 172.22.22.1
Host is up (0.00011s latency).
PORT    STATE SERVICE   VERSION
443/tcp open  ssl/https Apache/2.4.25 (FreeBSD) OpenSSL/1.0.1s-freebsd PHP/5.6.30
|_http-server-header: Apache/2.4.25 (FreeBSD) OpenSSL/1.0.1s-freebsd PHP/5.6.30
|_http-title: Site doesn't have a title (text/html).

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.48 seconds
Порт открыт, все ок.

Вывод ifconfig интерфейса которому присвоен ip 172.22.22.1:

Код: Выделить всё

root@serv:/home/adm # ifconfig em0
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        description: IntNet
        options=4219b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,WOL_MAGIC,VLAN_HWTSO>
        ether 00:1b:21:53:7c:f8
        inet 172.22.22.1 netmask 0xffffff00 broadcast 172.22.22.255
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
Далее, меняем правила на правильные - добавляем block in all перед разрешающими правилами:

Код: Выделить всё

root@serv:/home/adm # pfctl -s rules
scrub in all fragment reassemble
scrub out all random-id fragment reassemble
scrub on tun0 all max-mss 1450 fragment reassemble
scrub on tun5 all max-mss 1450 fragment reassemble
scrub on tun8 all max-mss 1450 fragment reassemble

block return in log all

pass inet from 172.22.22.0/24 to any flags S/SA keep state
pass on tun8 inet from 10.8.11.0/24 to any flags S/SA keep state
pass in all flags S/SA keep state
pass out all flags S/SA keep state
pass quick from any to <blockedip> flags S/SA keep state rtable 1
pass proto tcp from any to any port = http flags S/SA keep state
pass proto tcp from any to any port = https flags S/SA keep state
pass proto tcp from any to any port = 31322 flags S/SA keep state
pass on tun8 inet proto icmp all icmp-type echoreq keep state
pass on tun8 proto udp from any to any port 33433 >< 33626 keep state
Сканируем ещё раз нмапом 443 порт:

Код: Выделить всё

root@serv:/home/adm # nmap -sT -p 443 -n -Pn -sV --script http-title 172.22.22.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-04-25 00:48 +07
Nmap scan report for 172.22.22.1
Host is up.
PORT    STATE    SERVICE VERSION
443/tcp filtered https

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 2.48 seconds
Куда копать, как дебажить, почему так происходит... Подскажите, коллеги.

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 6:36:24
Neus
по-моему не хватает:
set skip on lo0

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 14:46:47
DuoMorph
Neus писал(а):по-моему не хватает:
set skip on lo0
В конфиге имеется подобная запись. Весь конфиг: https://pastebin.com/DnJdBuD9

Ситуация немного изменилась: В конфиге опция block in log all установлена, останавлиаю апач, запускаю ncat -l -p 443, сканирую nmapом - вуаля - порт открыт...
Запустил tcpdump для мониторинга pflog0. В итоге: При сканировании открытого 443 порта ncatом - все ок, tcpdump ничего не ловит. При сканировании открытого 443 порта апачем - tcpdump сообщает следующее:

Код: Выделить всё

18:41:24.339497 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 35090, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.50798: Flags [S.], cksum 0x845d (incorrect -> 0x2a7a), seq 2996189261, ack 3306225897, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 552793345 ecr 67831356], length 0
18:41:25.358979 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 3717, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.49377: Flags [S.], cksum 0x845d (incorrect -> 0xab49), seq 2543515240, ack 4149584623, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 1015538371 ecr 67832376], length 0
18:41:27.350622 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 44864, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.50798: Flags [S.], cksum 0x845d (incorrect -> 0x2a7a), seq 2996189261, ack 3306225897, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 552793345 ecr 67831356], length 0
18:41:28.401995 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 1590, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.49377: Flags [S.], cksum 0x845d (incorrect -> 0xab49), seq 2543515240, ack 4149584623, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 1015538371 ecr 67832376], length 0
18:41:30.358915 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 39171, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.50798: Flags [S.], cksum 0x845d (incorrect -> 0x2a7a), seq 2996189261, ack 3306225897, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 552793345 ecr 67831356], length 0
18:41:31.431089 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 33070, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.49377: Flags [S.], cksum 0x845d (incorrect -> 0xab49), seq 2543515240, ack 4149584623, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 1015538371 ecr 67832376], length 0
18:41:33.380596 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 42941, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.50798: Flags [S.], cksum 0x845d (incorrect -> 0x2a7a), seq 2996189261, ack 3306225897, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 552793345 ecr 67831356], length 0
18:41:34.452916 rule 0..16777216/0(match): block in on em0: (tos 0x0, ttl 64, id 6779, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.49377: Flags [S.], cksum 0x845d (incorrect -> 0xab49), seq 2543515240, ack 4149584623, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 1015538371 ecr 67832376], length 0
Переместил старые логи апача в одельную диру (чтобы они не мешали). Делаю рестарт апача, запускаю - в логах тишина...

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 14:58:54
Sadok123
DuoMorph писал(а):

Код: Выделить всё

443/tcp filtered https
Где ж он открыт то?

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 15:13:55
Neus
DuoMorph писал(а): В конфиге имеется подобная запись.
в конфиге имеется "set skip on lo"
man pf.conf
set skip on <ifspec>
List interfaces for which packets should not be filtered. Packets
passing in or out on such interfaces are passed as if pf was dis-
abled, i.e. pf does not process them in any way. This can be use-
ful on loopback and other virtual interfaces, when packet filtering
is not desired and can have unexpected effects. For example:

set skip on lo0
номер интерфейса забыл указать

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 17:19:08
DuoMorph
Neus писал(а): номер интерфейса забыл указать
Если честно, не помню, почему у меня так указано в конфиге, я тоже обратил на это внимание и разумеется протестил с skip lo0, но результат одинаков. К тому же как я уже писал выше - когда открываю порт другой тулзой (ncat'om) фаер ничего не лочит, следовательно, дело не в этой опции.
Sadok123 писал(а): Где ж он открыт то?
Вы видимо, чтото недопоняли из моего изложения, конкретизируйте, в каком моменте я говорил, что он открыт и это не являлось таковым, а я поясню. Возможно так будет понятней:

Код: Выделить всё

root@serv:/var/log/httpd # apachectl status
apache24 is running as pid 16305.
root@serv:/var/log/httpd # nmap -sT -p 443 -Pn -n 172.22.22.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-04-25 21:17 +07
Nmap scan report for 172.22.22.1
Host is up.
PORT    STATE    SERVICE
443/tcp filtered https

Nmap done: 1 IP address (1 host up) scanned in 2.07 seconds
root@serv:/var/log/httpd # apachectl stop
Stopping apache24.
Waiting for PIDS: 16305.
root@serv:/var/log/httpd # ncat -l -p 443 &
[1] 16446
root@serv:/var/log/httpd # nmap -sT -p 443 -Pn -n 172.22.22.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-04-25 21:18 +07
Nmap scan report for 172.22.22.1
Host is up (0.00011s latency).
PORT    STATE SERVICE
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
root@serv:/var/log/httpd #
Чесно говоря не понимаю, с чем может быть связано такое поведение...

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 22:32:50
Sadok123
А с ncat ACK, SYN+ACK, ACK в обе стороны (по портам) пролетают? А с апчем?

И снова PF. Не работают правила после block in all.

Добавлено: 2017-04-25 23:54:00
DuoMorph
Sadok123 писал(а):А с ncat ACK, SYN+ACK, ACK в обе стороны (по портам) пролетают? А с апчем?
Сканирование нмапом (два раза) на открытый 443 порт ncat:

Код: Выделить всё

root@serv:/usr/local/etc/apache24 # tcpdump -vvv -n -e -i lo0 '( dst host 172.22.22.1 and src host 172.22.22.1 )'
tcpdump: listening on lo0, link-type NULL (BSD loopback), capture size 65535 bytes
03:10:15.984209 AF IPv4 (2), length 64: (tos 0x0, ttl 255, id 3738, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->e8f2)!)
    172.22.22.1.26258 > 172.22.22.1.443: Flags [S], cksum 0x845d (incorrect -> 0x0a0c), seq 1471206217, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 98363001 ecr 0], length 0
03:10:15.984242 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 3739, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->a7f2)!)
    172.22.22.1.443 > 172.22.22.1.26258: Flags [S.], cksum 0x845d (incorrect -> 0x8ebd), seq 2167338367, ack 1471206218, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 35127927 ecr 98363001], length 0
03:10:15.984259 AF IPv4 (2), length 56: (tos 0x0, ttl 255, id 3740, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->e8f8)!)
    172.22.22.1.26258 > 172.22.22.1.443: Flags [.], cksum 0x8455 (incorrect -> 0xf78a), seq 1, ack 1, win 39, options [nop,nop,TS val 98363001 ecr 35127927], length 0
03:10:15.984281 AF IPv4 (2), length 56: (tos 0x0, ttl 255, id 3741, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->e8f7)!)
    172.22.22.1.26258 > 172.22.22.1.443: Flags [R.], cksum 0x8455 (incorrect -> 0xf786), seq 1, ack 1, win 39, options [nop,nop,TS val 98363001 ecr 35127927], length 0
03:10:40.206399 AF IPv4 (2), length 64: (tos 0x0, ttl 255, id 4072, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->e7a4)!)
    172.22.22.1.34896 > 172.22.22.1.443: Flags [S], cksum 0x845d (incorrect -> 0xb2a2), seq 1182579594, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 98387223 ecr 0], length 0
03:10:40.206431 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 4073, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->a6a4)!)
    172.22.22.1.443 > 172.22.22.1.34896: Flags [S.], cksum 0x845d (incorrect -> 0x0357), seq 1040925120, ack 1182579595, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 1108012388 ecr 98387223], length 0
03:10:40.206447 AF IPv4 (2), length 56: (tos 0x0, ttl 255, id 4074, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->e7aa)!)
    172.22.22.1.34896 > 172.22.22.1.443: Flags [.], cksum 0x8455 (incorrect -> 0x6c24), seq 1, ack 1, win 39, options [nop,nop,TS val 98387223 ecr 1108012388], length 0
03:10:40.206468 AF IPv4 (2), length 56: (tos 0x0, ttl 255, id 4075, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->e7a9)!)
    172.22.22.1.34896 > 172.22.22.1.443: Flags [R.], cksum 0x8455 (incorrect -> 0x6c20), seq 1, ack 1, win 39, options [nop,nop,TS val 98387223 ecr 1108012388], length 0
Сканирование nmapом (один раз) на откртый 443 порт apache:

Код: Выделить всё

03:11:34.159003 AF IPv4 (2), length 64: (tos 0x0, ttl 255, id 4987, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->e411)!)
    172.22.22.1.41310 > 172.22.22.1.443: Flags [S], cksum 0x845d (incorrect -> 0x60e0), seq 1483411342, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 98441176 ecr 0], length 0
03:11:34.159067 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 60746, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.41310: Flags [S.], cksum 0x845d (incorrect -> 0x9838), seq 2876641109, ack 1483411343, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 3688852495 ecr 98441176], length 0
03:11:34.159081 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 4989, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a314)!)
    172.22.22.1.41310 > 172.22.22.1.443: Flags [R.], cksum 0x65c1 (correct), seq 1, ack 1, win 0, length 0
03:11:35.167277 AF IPv4 (2), length 64: (tos 0x0, ttl 255, id 5020, offset 0, flags [DF], proto TCP (6), length 60, bad cksum 0 (->e3f0)!)
    172.22.22.1.42601 > 172.22.22.1.443: Flags [S], cksum 0x845d (incorrect -> 0x2ae8), seq 2025921588, win 65535, options [mss 16344,nop,wscale 11,sackOK,TS val 98442185 ecr 0], length 0
03:11:35.167304 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 43601, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.42601: Flags [S.], cksum 0x845d (incorrect -> 0xe126), seq 1657782172, ack 2025921589, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 28925871 ecr 98442185], length 0
03:11:35.167319 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5022, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a2f3)!)
    172.22.22.1.42601 > 172.22.22.1.443: Flags [R.], cksum 0xcc19 (correct), seq 1, ack 1, win 0, length 0
03:11:37.164755 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 20971, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.41310: Flags [S.], cksum 0x845d (incorrect -> 0x9838), seq 2876641109, ack 1483411343, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 3688852495 ecr 98441176], length 0
03:11:37.164772 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5039, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a2e2)!)
    172.22.22.1.41310 > 172.22.22.1.443: Flags [R.], cksum 0x65c1 (correct), seq 1, ack 1, win 0, length 0
03:11:38.172053 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 38569, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.42601: Flags [S.], cksum 0x845d (incorrect -> 0xe126), seq 1657782172, ack 2025921589, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 28925871 ecr 98442185], length 0
03:11:38.172074 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5055, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a2d2)!)
    172.22.22.1.42601 > 172.22.22.1.443: Flags [R.], cksum 0xcc19 (correct), seq 1, ack 1, win 0, length 0
03:11:40.175047 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 53133, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.41310: Flags [S.], cksum 0x845d (incorrect -> 0x9838), seq 2876641109, ack 1483411343, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 3688852495 ecr 98441176], length 0
03:11:40.175062 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5095, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a2aa)!)
    172.22.22.1.41310 > 172.22.22.1.443: Flags [R.], cksum 0x65c1 (correct), seq 1, ack 1, win 0, length 0
03:11:41.171856 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 59033, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.42601: Flags [S.], cksum 0x845d (incorrect -> 0xe126), seq 1657782172, ack 2025921589, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 28925871 ecr 98442185], length 0
03:11:41.171871 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5109, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a29c)!)
    172.22.22.1.42601 > 172.22.22.1.443: Flags [R.], cksum 0xcc19 (correct), seq 1, ack 1, win 0, length 0
03:11:43.194803 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 17299, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.41310: Flags [S.], cksum 0x845d (incorrect -> 0x9838), seq 2876641109, ack 1483411343, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 3688852495 ecr 98441176], length 0
03:11:43.194824 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5130, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a287)!)
    172.22.22.1.41310 > 172.22.22.1.443: Flags [R.], cksum 0x65c1 (correct), seq 1, ack 1, win 0, length 0
03:11:44.181044 AF IPv4 (2), length 64: (tos 0x0, ttl 64, id 30616, offset 0, flags [DF], proto TCP (6), length 60)
    172.22.22.1.443 > 172.22.22.1.42601: Flags [S.], cksum 0x845d (incorrect -> 0xe126), seq 1657782172, ack 2025921589, win 65535, options [mss 1460,nop,wscale 11,sackOK,TS val 28925871 ecr 98442185], length 0
03:11:44.181057 AF IPv4 (2), length 44: (tos 0x10, ttl 64, id 5143, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->a27a)!)
    172.22.22.1.42601 > 172.22.22.1.443: Flags [R.], cksum 0xcc19 (correct), seq 1, ack 1, win 0, length 0
Да, забыл уточнить на всякий случай:
1. Другие тачки из сетки 172.22.22.0/24 с апачем работают нормально (для них порт открыт и апач возвращает страницы).
2. При сканировании нмапом на локалхост (127.0.0.1) порт апача открыт (что в принципе логично т.к. установлена опция set skip lo0)

Отправлено спустя 29 минут 26 секунд:
Все. Отбой мужики, как и ожидалось - я тупанул) но ковырялся до поста тут уже N дней... а может и с неделю.
Когдато я добавлял себе дополнительную табилицу маршрутизации и была необходимость, чтобы апач работал в рамках именно той таблицы маршрутизации, собственно в чем и заключалась проблема:
в rc.conf: apache24_fib="2"

Извиняюсь за беспокойство :) Всем спасибо.