[message long, mais j'ai réfléchi et avancé en répondant aux questions, il substite la question du promiscuous, voir à la fin]
Ce n'est pas forcément une réponse précise que j'attendais mais des questions à me poser et une direction... (vu que je patauge et m'embrouille). Les questions permettent d'avoir une vision plus claire (je dis à mes élèves: Poser la bonne question c'est y répondre, mais là je patauge qd même, même si je vois plus précisement où est le pbm, voir plus bas en gras mon erreur stupide, et le pbm réel à la fin)
Sur la structure du réseau, l'interface eth1 du bridge est UP mais non branchée finalement (j'avais mis en place ce bridge pour connecter directement la machine à la box et avoir une ligne à 1 Gb/s et mettre eth1 sur un switch à 100Mb/s pour la suite du réseau, où je mettais les autres machines et l'imprimante, le DHCP ne passait pas donc j'ai laissé tomber sans chercher, mais c'est (peut être) un autre problème).
Bref: machine visée -> une interface filaire, machine routeur ---> un bridge br0 associant eth0 up et branchée et eth1 up et non branchéee, WAN ---> freebox en mode réseau assurant le DHCP sur le réseau.
Code : Tout sélectionner
[WAN] <---> | eth0, pontée avec eth1 .
v-----------> | machine en DMZ
machine |
visée
root@hermes:/home/francois# ip route show
default via 192.168.160.254 dev br0
169.254.0.0/16 dev br0 scope link metric 1000
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.160.0/24 dev br0 proto kernel scope link src 192.168.160.1
root@hermes:/home/francois#
Machine visée 192.168.160.7
Routeur: 192.168.160.1
(règles iptables complètes à la fin)
Trafic routé où tout se passe bien:
Code : Tout sélectionner
machine routeur:
listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes
09:05:10.825869 IP 129.199.129.80.48390 > 192.168.160.7.40000: Flags [S], seq 1176844576, win 64240, options [mss 1460,sackOK,TS val 1618973149 ecr 0,nop,wscale 7], length 0
09:05:10.826029 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [S], seq 1176844576, win 64240, options [mss 1460,sackOK,TS val 1618973149 ecr 0,nop,wscale 7], length 0
09:05:10.826975 IP 192.168.160.7.40000 > 129.199.129.80.48390: Flags [S.], seq 2202264238, ack 1176844577, win 65160, options [mss 1460,sackOK,TS val 1169284080 ecr 1618973149,nop,wscale 7], length 0
09:05:10.827062 IP 192.168.160.1.40000 > 129.199.129.80.48390: Flags [S.], seq 2202264238, ack 1176844577, win 65160, options [mss 1460,sackOK,TS val 1169284080 ecr 1618973149,nop,wscale 7], length 0
09:05:10.829805 IP 129.199.129.80.48390 > 192.168.160.7.40000: Flags [.], ack 1, win 502, options [nop,nop,TS val 1618973153 ecr 1169284080], length 0
09:05:10.829891 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 2202264239, win 502, options [nop,nop,TS val 1618973153 ecr 1169284080], length 0
09:05:10.833371 IP 192.168.160.7.40000 > 129.199.129.80.48390: Flags [P.], seq 1:8, ack 1, win 510, options [nop,nop,TS val 1169284086 ecr 1618973153], length 7
09:05:10.833445 IP 192.168.160.1.40000 > 129.199.129.80.48390: Flags [P.], seq 1:8, ack 1, win 510, options [nop,nop,TS val 1169284086 ecr 1618973153], length 7
09:05:10.833947 IP 192.168.160.7.40000 > 129.199.129.80.48390: Flags [FP.], seq 8:32, ack 1, win 510, options [nop,nop,TS val 1169284087 ecr 1618973153], length 24
09:05:10.834016 IP 192.168.160.1.40000 > 129.199.129.80.48390: Flags [FP.], seq 8:32, ack 1, win 510, options [nop,nop,TS val 1169284087 ecr 1618973153], length 24
09:05:10.836230 IP 129.199.129.80.48390 > 192.168.160.7.40000: Flags [.], ack 8, win 502, options [nop,nop,TS val 1618973160 ecr 1169284086], length 0
09:05:10.836306 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 8, win 502, options [nop,nop,TS val 1618973160 ecr 1169284086], length 0
09:05:10.877186 IP 129.199.129.80.48390 > 192.168.160.7.40000: Flags [.], ack 33, win 502, options [nop,nop,TS val 1618973201 ecr 1169284087], length 0
09:05:10.877293 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 33, win 502, options [nop,nop,TS val 1618973201 ecr 1169284087], length 0
09:05:26.595760 IP 129.199.129.80.48390 > 192.168.160.7.40000: Flags [F.], seq 1, ack 33, win 502, options [nop,nop,TS val 1618988919 ecr 1169284087], length 0
09:05:26.595895 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [F.], seq 0, ack 33, win 502, options [nop,nop,TS val 1618988919 ecr 1169284087], length 0
09:05:26.596754 IP 192.168.160.7.40000 > 129.199.129.80.48390: Flags [.], ack 2, win 510, options [nop,nop,TS val 1169299849 ecr 1618988919], length 0
09:05:26.596882 IP 192.168.160.1.40000 > 129.199.129.80.48390: Flags [.], ack 2, win 510, options [nop,nop,TS val 1169299849 ecr 1618988919], length 0
machine visée:
9:05:10.823267 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [S], seq 1176844576, win 64240, options [mss 1460,sackOK,TS val 1618973149 ecr 0,nop,wscale 7], length 0
09:05:10.823332 IP 192.168.160.7.40000 > 192.168.160.1.48390: Flags [S.], seq 2202264238, ack 1176844577, win 65160, options [mss 1460,sackOK,TS val 1169284080 ecr 1618973149,nop,wscale 7], length 0
09:05:10.826900 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 1, win 502, options [nop,nop,TS val 1618973153 ecr 1169284080], length 0
09:05:10.829737 IP 192.168.160.7.40000 > 192.168.160.1.48390: Flags [P.], seq 1:8, ack 1, win 510, options [nop,nop,TS val 1169284086 ecr 1618973153], length 7
09:05:10.830298 IP 192.168.160.7.40000 > 192.168.160.1.48390: Flags [FP.], seq 8:32, ack 1, win 510, options [nop,nop,TS val 1169284087 ecr 1618973153], length 24
09:05:10.833159 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 8, win 502, options [nop,nop,TS val 1618973160 ecr 1169284086], length 0
09:05:10.874326 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [.], ack 33, win 502, options [nop,nop,TS val 1618973201 ecr 1169284087], length 0
09:05:26.592852 IP 192.168.160.1.48390 > 192.168.160.7.40000: Flags [F.], seq 1, ack 33, win 502, options [nop,nop,TS val 1618988919 ecr 1169284087], length 0
09:05:26.592907 IP 192.168.160.7.40000 > 192.168.160.1.48390: Flags [.], ack 2, win 510, options [nop,nop,TS val 1169299849 ecr 1618988919], length 0
Module:
Code : Tout sélectionner
root@hermes:/home/francois# lsmod | grep filter
br_netfilter 24576 0
bridge 126976 1 br_netfilter
root@hermes:/home/francois# cat /proc/sys/net/bridge/bridge-nf-call-iptables
1
root@hermes:/home/francois#
Un nouvel essai en enlevant le mode promiscuous ne change rien (!?!)
Essai en rajoutant le port 40003
Code : Tout sélectionner
root@hermes:/home/francois# iptables-save
# Generated by xtables-save v1.8.2 on Sat Oct 8 09:26:01 2022
*filter
*nat
:PREROUTING ACCEPT [1912499:144008717]
:INPUT ACCEPT [1787241:135839485]
:POSTROUTING ACCEPT [24663:1872429]
:OUTPUT ACCEPT [24665:1872549]
:DOCKER - [0:0]
-A PREROUTING -i br0 -p tcp -m tcp --dport 40003 -j DNAT --to-destination 192.168.160.7:40003
-A PREROUTING -i br0 -p tcp -m tcp --dport 40000 -j DNAT --to-destination 192.168.160.7:40000
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -d 192.168.160.7/32 -p tcp -m tcp --dport 40003 -j MASQUERADE
-A POSTROUTING -d 192.168.160.7/32 -p tcp -m tcp --dport 40000 -j MASQUERADE
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sat Oct 8 09:26:01 2022
Le trafic obtenu sur la machine routeur:
Code : Tout sélectionner
09:25:41.013075 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620203336 ecr 0,nop,wscale 7], length 0
09:25:41.013010 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620203336 ecr 0,nop,wscale 7], length 0
09:25:42.037385 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620204361 ecr 0,nop,wscale 7], length 0
09:25:42.037315 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620204361 ecr 0,nop,wscale 7], length 0
09:25:44.053437 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620206377 ecr 0,nop,wscale 7], length 0
09:25:44.053374 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620206377 ecr 0,nop,wscale 7], length 0
09:25:48.309290 IP 129.199.129.80.56844 > 192.168.160.7.40003: Flags [S], seq 256311811, win 64240, options [mss 1460,sackOK,TS val 1620210633 ecr 0,nop,wscale 7], length 0
^C
tcpdump sur la machine visée ne donne aucun trafic
Essai en jouant sur /bridge-nf-call-iptables (ne change rien)
Code : Tout sélectionner
root@hermes:/home/francois# echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables
root@hermes:/home/francois# tcpdump -n -i br0 port 40003
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes
09:32:44.117860 IP 129.199.129.80.53422 > 192.168.160.1.40003: Flags [S], seq 534824854, win 64240, options [mss 1460,sackOK,TS val 1620626441 ecr 0,nop,wscale 7], length 0
09:32:45.141202 IP 129.199.129.80.53422 > 192.168.160.1.40003: Flags [S], seq 534824854, win 64240, options [mss 1460,sackOK,TS val 1620627465 ecr 0,nop,wscale 7], length 0
09:32:47.157224 IP 129.199.129.80.53422 > 192.168.160.1.40003: Flags [S], seq 534824854, win 64240, options [mss 1460,sackOK,TS val 1620629481 ecr 0,nop,wscale 7], length 0
09:32:51.225203 IP 129.199.129.80.53422 > 192.168.160.1.40003: Flags [S], seq 534824854, win 64240, options [mss 1460,sackOK,TS val 1620633549 ecr 0,nop,wscale 7], length 0
^C
4 packets captured
5 packets received by filter
0 packets dropped by kernel
root@hermes:/home/francois# echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
root@hermes:/home/francois# tcpdump -n -i br0 port 40003
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes
09:33:08.038640 IP 129.199.129.80.40444 > 192.168.160.7.40003: Flags [S], seq 3461557266, win 64240, options [mss 1460,sackOK,TS val 1620650362 ecr 0,nop,wscale 7], length 0
09:33:08.038552 IP 129.199.129.80.40444 > 192.168.160.7.40003: Flags [S], seq 3461557266, win 64240, options [mss 1460,sackOK,TS val 1620650362 ecr 0,nop,wscale 7], length 0
09:33:09.045222 IP 129.199.129.80.40444 > 192.168.160.7.40003: Flags [S], seq 3461557266, win 64240, options [mss 1460,sackOK,TS val 1620651369 ecr 0,nop,wscale 7], length 0
09:33:09.045146 IP 129.199.129.80.40444 > 192.168.160.7.40003: Flags [S], seq 3461557266, win 64240, options [mss 1460,sackOK,TS val 1620651369 ecr 0,nop,wscale 7], length 0
Log des règles:
Code : Tout sélectionner
root@hermes:/home/francois# iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 2026K packets, 152M bytes)
pkts bytes target prot opt in out source destination
29 1740 DNAT tcp -- br0 any anywhere anywhere tcp dpt:40003 to:192.168.160.7:40003
10 600 DNAT tcp -- br0 any anywhere anywhere tcp dpt:40002 to:192.168.160.7:22
50 2992 DNAT tcp -- br0 any anywhere anywhere tcp dpt:40000 to:192.168.160.7:40000
2022K 152M DOCKER all -- any any anywhere anywhere ADDRTYPE match dst-type LOCAL
Chain INPUT (policy ACCEPT 1893K packets, 144M bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 26195 packets, 1988K bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE tcp -- any any anywhere challenge tcp dpt:40003
0 0 MASQUERADE tcp -- any any anywhere challenge tcp dpt:ssh
34 2032 MASQUERADE tcp -- any any anywhere challenge tcp dpt:40000
0 0 MASQUERADE all -- any !docker0 172.17.0.0/16 anywhere
Chain OUTPUT (policy ACCEPT 26197 packets, 1988K bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER all -- any any anywhere !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
Chain DOCKER (2 references)
pkts bytes target prot opt in out source destination
0 0 RETURN all -- docker0 any anywhere anywhere
root@hermes:/home/francois#
L'intéressant est
0 0 MASQUERADE tcp -- any any anywhere challenge tcp dpt:40003
34 2032 MASQUERADE tcp -- any any anywhere challenge tcp dpt:40000
qui montre que c'est la règle POSTROUTING induisant le masquerade qui ne s'applique pas (mais on verrait les paquets sur la machine visée) ou qui n'est pas atteinte (ce qui me parait plus conforme à ce que je vois).
Etat exact des règles iptables à ce moment là:
Code : Tout sélectionner
root@hermes:/home/francois# iptables-save
# Generated by xtables-save v1.8.2 on Sat Oct 8 09:34:21 2022
*filter
:INPUT ACCEPT [4438230:440577898]
:FORWARD DROP [57:3420]
:OUTPUT ACCEPT [2868635:1765158018]
:f2b-sshd - [0:0]
:f2b-postfix-sasl - [0:0]
:DOCKER - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-USER - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:f2b-dovecot - [0:0]
-A INPUT -s 195.178.120.188/32 -j DROP
-A INPUT -p tcp -m multiport --dports 110,995,143,993,587,465,4190 -j f2b-dovecot
-A INPUT -p tcp -m multiport --dports 25,465,587,143,993,110,995 -j f2b-postfix-sasl
-A INPUT -p tcp -m multiport --dports 22 -j f2b-sshd
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -p tcp -m tcp --dport 40000 -j ACCEPT
-A f2b-sshd -s 157.230.98.148/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-sshd -s 117.102.113.50/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-sshd -s 20.70.152.170/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-sshd -s 61.7.142.185/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-sshd -j RETURN
-A f2b-postfix-sasl -s 5.34.207.246/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-postfix-sasl -s 5.34.207.23/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-postfix-sasl -s 212.70.149.22/32 -j REJECT --reject-with icmp-port-unreachable
-A f2b-postfix-sasl -j RETURN
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-USER -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A f2b-dovecot -j RETURN
COMMIT
# Completed on Sat Oct 8 09:34:21 2022
# Generated by xtables-save v1.8.2 on Sat Oct 8 09:34:21 2022
*nat
:PREROUTING ACCEPT [1927319:145113612]
:INPUT ACCEPT [1801030:136878875]
:POSTROUTING ACCEPT [24784:1881501]
:OUTPUT ACCEPT [24786:1881621]
:DOCKER - [0:0]
-A PREROUTING -i br0 -p tcp -m tcp --dport 40003 -j DNAT --to-destination 192.168.160.7:40003
-A PREROUTING -i br0 -p tcp -m tcp --dport 40002 -j DNAT --to-destination 192.168.160.7:22
-A PREROUTING -i br0 -p tcp -m tcp --dport 40000 -j DNAT --to-destination 192.168.160.7:40000
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -d 192.168.160.7/32 -p tcp -m tcp --dport 40003 -j MASQUERADE
-A POSTROUTING -d 192.168.160.7/32 -p tcp -m tcp --dport 22 -j MASQUERADE
-A POSTROUTING -d 192.168.160.7/32 -p tcp -m tcp --dport 40000 -j MASQUERADE
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sat Oct 8 09:34:21 2022
Modules chargés me paraissant en rapport:
Code : Tout sélectionner
Module Size Used by
xt_REDIRECT 16384 0
xt_state 16384 0
nfnetlink_queue 20480 0
nfnetlink_log 20480 0
bluetooth 425984 0
drbg 28672 1
ansi_cprng 16384 0
ecdh_generic 32768 1 bluetooth
xt_nat 16384 1
xt_tcpudp 16384 1
veth 24576 0
ipt_MASQUERADE 16384 1
nf_conntrack_netlink 36864 0
xfrm_user 36864 1
xfrm_algo 16384 1 xfrm_user
nft_chain_nat_ipv4 16384 4
nf_nat_ipv4 16384 2 nft_chain_nat_ipv4,ipt_MASQUERADE
xt_addrtype 16384 1
xt_conntrack 16384 1
nf_nat 28672 3 xt_nat,nf_nat_ipv4,xt_REDIRECT
nf_conntrack 106496 8 xt_state,xt_nat,ipt_MASQUERADE,nf_conntrack_netlink,xt_conntrack,nf_nat_ipv4,xt_REDIRECT,nf_nat
nf_defrag_ipv6 16384 1 nf_conntrack
nf_defrag_ipv4 16384 1 nf_conntrack
libcrc32c 16384 2 nf_conntrack,nf_nat
br_netfilter 24576 0
overlay 86016 0
ipt_REJECT 16384 1
nf_reject_ipv4 16384 1 ipt_REJECT
xt_multiport 16384 1
nft_compat 20480 29
nft_counter 16384 38
nf_tables 98304 116 nft_chain_nat_ipv4,nft_compat,nft_counter
nfnetlink 16384 6 nfnetlink_log,nft_compat,nfnetlink_queue,nf_conntrack_netlink,nf_tables
tun 36864 0
bridge 126976 1 br_netfilter
stp 16384 1 bridge
llc 16384 2 bridge,stp
[...]
[...]
ip_tables 20480 0
x_tables 24576 11 xt_state,xt_multiport,ipt_REJECT,xt_nat,ip_tables,nft_compat,xt_tcpudp,ipt_MASQUERADE,xt_addrtype,xt_conntrack,xt_REDIRECT
[...]
Constatation: Le mode promiscuous ne change plus rien. Or c'est en le mettant à on que j'ai réussi à faire router le port 40000 une première fois. On dirait que la règle PREROUTING est appliqué et que netfilter paume le paquet qui n'atteint pas le POSTROUTING.
Hum, ce serait un problème de FORWARDING (de mémoire PREROUTING -> FORWARD -> POSTROUTING...
Exact je suis un crétin, je rajoute le ACCEPT pour le port 40003
Je teste. et là c'est l'apothéose:
La redirection marche, mais que si je met le mode promiscuous à on, où si je trace le trafic avec tcpdump (qui met l'interface en mode promiscuous). Donc la partie stupide du pbm (règle FORWARD manquante est correcte), mais le coeur du pbm est toujours là.