fox*_*337 5 apple nat routing pf ipfw
我需要破解 OS X pf 以将所有 ssh 连接从用户重定向到这台机器。我想要,在做的时候
$ ssh google.com
Run Code Online (Sandbox Code Playgroud)
得到相同的结果
$ ssh localhost
Run Code Online (Sandbox Code Playgroud)
即连接到我本地运行的 sshd。
在最近的 Linux 下,这将是:
# iptables -t nat -A OUTPUT -p tcp --dport 22 -m owner --uid-owner theuser -j REDIRECT
Run Code Online (Sandbox Code Playgroud)
在 OS X 10.8 下,似乎有 2 种方法 - ipfw 和 pf。两者都不起作用。ipfw:
# ipfw flush
# ipfw add 50 fwd 127.0.0.1,22 tcp from any to any 22 uid theuser
Run Code Online (Sandbox Code Playgroud)
如果我删除该uid theuser
部分,重定向将起作用,减去用户的东西。如果我把uid
指令留在那里,网络堆栈就会死掉,系统很快就会变得无法使用;没有了ipfw
,没有了ps
,没有了kill
。
根据手册页,不推荐使用 ipfw,因此应改用数据包过滤器:
# sysctl -w net.inet.ip.forwarding=1
Run Code Online (Sandbox Code Playgroud)
然后我加了
anchor "910.Custom/*"
load anchor "910.Custom" from "/etc/pf.anchors/910.Custom"
Run Code Online (Sandbox Code Playgroud)
在/etc/pf.anchors/com.apple
和
rdr on en1 proto TCP from any to any port 22 -> 127.0.0.1 port 22
Run Code Online (Sandbox Code Playgroud)
in /etc/pf.anchors/910.Custom
(请注意我在这里没有提到任何关于用户的内容,因为 pf 文档没有为 rdr 规则列出这样的选项)。
我跑后# pfctl -ef /etc/pf.anchors/com.apple
什么也没有发生。如果我向规则中添加垃圾/etc/pf.anchors/910.Custom
或者即使我敢user theuser
在rdr
规则之后添加,防火墙也会断断续续地抱怨语法错误。
OS X 内核甚至可以再执行 NAT 路由,还是 Apple 取消了该功能?如果可以,我是否遗漏了什么?
乐。固定iptables
语法
小智 10
你也可以用PF来做。但是,rdr
只接受传入的数据包。因此,您必须首先将这些数据包路由到 lo0,然后在rdr
那里添加一个-rule(它将捕获它们,因为它们将从“某处”路由进来)以将它们发送到您的本地 SSH 服务器。
顺序必须是:rdr
东西,然后过滤东西(如通过),但按时间顺序,第二条规则将首先命中(on $Out
),然后将激活第一个规则(on lo0
)。
# Output interface
Out = en0
# A macro to shorten rules below
Packets = "proto tcp from" $Out "to any port 22"
# Rule 1: Redirect those connections _after_ they were routed to lo0 below
rdr pass log on lo0 $Packets -> 127.0.0.1
# Rule 2: Route _first_ new IPv4 TCP connections leaving $Out to lo0
pass out on $Out route-to lo0 inet $Packets
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4869 次 |
最近记录: |