Dav*_*lie 9 linux firewall iptables voip sip
(移自 SO)
我有 iptables 保护 sip 服务器。除了我特别打开的 IP 之外,它会阻止所有 IP,并且它似乎对几乎所有人都有效。我已经从许多未列入白名单的 IP 地址进行了测试,它们都被删除了。
但是,我找到了一个似乎能够绕过 iptables 规则的“黑客”。他试探性的邀请成功了,我不知道是怎么做到的,或者甚至是可能的。10 年来,我从未见过这种情况。
我想这一定是我做过的事情,但我看不到它。
像这样创建的 iptables(在顶部定义的 MYIP - 已编辑):
iptables -F
iptables -X
iptables -N ALLOWEDSIP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -d $MYIP --dport 22 -j ACCEPT
iptables -t filter -A INPUT -j ALLOWEDSIP
# This is my white list.
iptables -A ALLOWEDSIP -j RETURN
Run Code Online (Sandbox Code Playgroud)
现在,由于 ALLOWEDSIP 中没有任何内容,我应该能够做的就是 SSH(我可以)。如果我给它打电话,他们都会掉线。但是wireshark向我展示了这个(我的ip已编辑):
89.163.146.25 -> x.x.x.x SIP/SDP 805 Request: INVITE sip:521088972597572280@x.x.x.x |
x.x.x.x -> 89.163.146.25 SIP 417 Status: 100 Giving a try |
x.x.x.x -> 89.163.146.25 SIP 875 Status: 407 Proxy Authentication Required |
Run Code Online (Sandbox Code Playgroud)
他的电话打了我的开关,虽然最终被 ACL 拒绝,但他们永远不应该到达那里。没有其他东西通过。拉我的头发。有人知道吗?
为了完整起见,这是 iptables -L 的结果:
# iptables -L --line-numbers -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 10 640 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
2 0 0 ACCEPT all -- lo any anywhere anywhere
3 0 0 ACCEPT tcp -- any any anywhere <redacted>.com tcp dpt:6928
4 0 0 ALLOWEDSIP all -- any any anywhere anywhere
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 6 packets, 544 bytes)
num pkts bytes target prot opt in out source destination
Chain ALLOWEDSIP (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 RETURN all -- any any anywhere anywhere
Run Code Online (Sandbox Code Playgroud)
编辑:刚刚从wireshark看到这个。他们会不会做一些可怕的事情,比如以其他方式建立起来然后按照既定规则进行游戏?也许他们在 RELATED 的某个洞打球?
89.163.146.25 -> <redacted> RTCP 806 Source port: tag-pm Destination port: sip
Run Code Online (Sandbox Code Playgroud)
编辑 2:UDP 是这里的关键。当我将 OpenSIPS 设置为仅侦听 TCP 时,问题似乎消失了。尽管他们发送了更多的“tag-pm”消息,但他们的尝试都没有通过。没有解释为什么数据包甚至会到达opensips。iptables 应该先阻止它们。很想知道我在这里做错了什么。
编辑 3:如果我删除 RELATED,我将停止回复他们,所以这与此有关。但我想我需要相关的。有关解决方法的任何提示?
rem*_*guy -3
你可以空路由。这应该绕过 iptables。
route add 89.163.146.25 gw 127.0.0.1 lo
Run Code Online (Sandbox Code Playgroud)
核实
netstat -nr
Run Code Online (Sandbox Code Playgroud)
或者
route -n
Run Code Online (Sandbox Code Playgroud)