0x01 背景


0x02 端口映射

1. 修改/etc/pf.conf文件

通过sudo vi打开/etc/pf.conf文件,在rdr-anchor "*"这一句后面添加如下命令:

rdr on lo0 inet proto tcp from any to port 80 -> port 10080


# Default PF configuration file.
# This file contains the main ruleset, which gets automatically loaded
# at startup.  PF will not be automatically enabled, however.  Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8).  That will ensure that PF
# is disabled only when the last enable reference is released.
# Care must be taken to ensure that the main ruleset does not get flushed,
# as the nested anchors rely on the anchor point defined here. In addition,
# to the anchors loaded by this file, some system services would dynamically 
# insert anchors into the main ruleset. These anchors will be added only when
# the system service is used and would removed on termination of the service.
# See pf.conf(5) for syntax.

# anchor point
scrub-anchor "*"
nat-anchor "*"
rdr-anchor "*"
rdr on lo0 inet proto tcp from any to port 80 -> port 10080
dummynet-anchor "*"
anchor "*"
load anchor "" from "/etc/pf.anchors/"

2. 配置文件检查

检查配置文件,以防手抖配错了 [此步骤非必须]

$ sudo pfctl -vnf /etc/pf.conf

3. 转发生效

$ sudo pfctl -f /etc/pf.conf

4. 启动pf防火墙

$ sudo pfctl -e

5. 启动端口对应服务


0x03 开机自启动

1. 创建脚本

  • 脚本路径
$ sudo vi /usr/local/bin/
  • 脚本内容

sleep 10
/sbin/pfctl -ef /etc/pf.conf
  • 修改脚本权限
$ sudo chmod 755 /usr/local/bin/

2. 创建plist

  • plist路径
$ sudo vi /Library/LaunchDaemons/cn.matz.pfctl.plist
  • plist内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

3. 其他


声明:PowerMatz | 版权所有,违者必究 | 如未注明,均为原创 | 本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - macOS配置80端口映射

Stay hungry. Stay foolish.