2021-12-14 12:13:09 +03:00
|
|
|
## Supported versions
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
FreeBSD 11.x+ , OpenBSD 6.x+, partially MacOS Sierra+
|
|
|
|
|
2022-01-22 14:36:36 +03:00
|
|
|
Older versions may work or not.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
## BSD features
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
BSD does not have NFQUEUE. Similar mechanism - divert sockets.
|
|
|
|
In BSD compiling the source from nfq directory result in dvtws binary instead of nfqws.
|
|
|
|
dvtws shares most of the code with nfqws and offers almost identical parameters.
|
|
|
|
|
2021-03-10 21:49:58 +03:00
|
|
|
FreeBSD has 3 firewalls : IPFilter, ipfw and Packet Filter (PF). OpenBSD has only PF.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 15:13:51 +03:00
|
|
|
To compile sources in FreeBSD use `make`, in OpenBSD - use `make bsd`, in MacOS - use `make mac`.
|
2021-12-14 12:13:09 +03:00
|
|
|
|
|
|
|
Compile all programs : `make -C /opt/zapret`
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Divert sockets are internal type sockets in the BSD kernel. They have no relation to network addresses
|
2021-12-14 14:12:49 +03:00
|
|
|
or network packet exchange. They are identified by a port number `1..65535`. Its like queue number in NFQUEUE.
|
2021-03-04 14:30:38 +03:00
|
|
|
Traffic can be diverted to a divert socket using firewall rule.
|
2021-12-14 12:13:09 +03:00
|
|
|
If nobody listens on the specified divert port packets are dropped. Its similar to NFQUEUE without `--queue-bypass`.
|
|
|
|
|
|
|
|
`ipset/*.sh` scripts work with ipfw lookup tables if ipfw is present.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
ipfw table is analog to linux ipset. Unlike ipsets ipfw tables share v4 an v6 addresses and subnets.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
|
|
|
- If ipfw is absent scripts check LISTS_RELOAD config variable.
|
|
|
|
- If its present then scripts execute a command from LISTS_RELOAD.
|
|
|
|
- If LISTS_RELOAD=- scripts do not load tables even if ipfw exists.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
PF can load ip tables from a file. To use this feature with ipset/*.sh scripts disable gzip file creation
|
2021-12-14 12:13:09 +03:00
|
|
|
using `GZIP_LISTS=0` directive in the `/opt/zapret/config' file.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
BSD kernel doesn't implement splice syscall. tpws uses regular recv/send operations with data copying to user space.
|
|
|
|
Its slower but not critical.
|
|
|
|
tpws uses nonblocking sockets with linux specific epoll feature.
|
|
|
|
In BSD systems epoll is emulated by epoll-shim library on top of kqueue.
|
|
|
|
|
|
|
|
dvtws uses some programming HACKs, assumptions and knowledge of discovered bugs and limitations.
|
|
|
|
BSD systems have many limitations, version specific features and bugs in low level networking, especially for ipv6.
|
|
|
|
Many years have passed but BSD code still has 15-20 year artificial limiters in the code.
|
|
|
|
dvtws uses additinal divert socket(s) for layer 3 packet injection if raw sockets do not allow it.
|
|
|
|
It works for the moment but who knows. Such a usage is not very documented.
|
|
|
|
|
|
|
|
mdig and ip2net are fully compatible with BSD.
|
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
## FreeBSD
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Divert sockets require special kernel module 'ipdivert'.
|
|
|
|
Write the following to config files :
|
2021-12-14 12:13:09 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
/boot/loader.conf (create if absent) :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipdivert_load="YES"
|
|
|
|
net.inet.ip.fw.default_to_accept=1
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
/etc/rc.conf :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
firewall_enable="YES"
|
|
|
|
firewall_script="/etc/rc.firewall.my"
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
/etc/rc.firewall.my :
|
2021-12-14 12:13:09 +03:00
|
|
|
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipfw -q -f flush
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Later you will add ipfw commands to `/etc/rc.firewall.my` to be reapplied after reboot.
|
|
|
|
You can also run zapret daemons from there. Start them with `--daemon` options, for example :
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pkill ^dvtws$
|
|
|
|
/opt/zapret/nfq/dvtws --port=989 --daemon --dpi-desync=split2
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
To restart firewall and daemons run : `/etc/rc.d/ipfw restart`
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
Assume `LAN=em1`, `WAN="em0"`.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
tpws transparent mode quick start.
|
|
|
|
|
|
|
|
For all traffic:
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipfw delete 100
|
|
|
|
ipfw add 100 fwd 127.0.0.1,988 tcp from me to any 80,443 proto ip4 xmit em0 not uid daemon
|
|
|
|
ipfw add 100 fwd ::1,988 tcp from me to any 80,443 proto ip6 xmit em0 not uid daemon
|
|
|
|
ipfw add 100 fwd 127.0.0.1,988 tcp from any to any 80,443 proto ip4 recv em1
|
|
|
|
ipfw add 100 fwd ::1,988 tcp from any to any 80,443 proto ip6 recv em1
|
|
|
|
/opt/zapret/tpws/tpws --port=988 --user=daemon --bind-addr=::1 --bind-addr=127.0.0.1
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Process only table zapret with the exception of table nozapret :
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipfw delete 100
|
|
|
|
ipfw add 100 allow tcp from me to table\(nozapret\) 80,443
|
|
|
|
ipfw add 100 fwd 127.0.0.1,988 tcp from me to table\(zapret\) 80,443 proto ip4 xmit em0 not uid daemon
|
|
|
|
ipfw add 100 fwd ::1,988 tcp from me to table\(zapret\) 80,443 proto ip6 xmit em0 not uid daemon
|
|
|
|
ipfw add 100 allow tcp from any to table\(nozapret\) 80,443 recv em1
|
|
|
|
ipfw add 100 fwd 127.0.0.1,988 tcp from any to any 80,443 proto ip4 recv em1
|
|
|
|
ipfw add 100 fwd ::1,988 tcp from any to any 80,443 proto ip6 recv em1
|
|
|
|
/opt/zapret/tpws/tpws --port=988 --user=daemon --bind-addr=::1 --bind-addr=127.0.0.1
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Tables zapret, nozapret, ipban are created by ipset/*.sh scripts the same way as in Linux.
|
|
|
|
Its a good idea to update tables periodically :
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
crontab -e
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
|
|
|
write the line : `0 12 */2 * * /opt/zapret/ipset/get_config.sh`
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
When using ipfw tpws does not require special permissions for transparent mode.
|
|
|
|
However without root its not possible to bind to ports <1024 and change UID/GID. Without changing UID tpws
|
|
|
|
will run into recursive loop, and that's why its necessary to write ipfw rules with the right UID.
|
|
|
|
Redirecting to ports >=1024 is dangerous. If tpws is not running any unprivileged process can
|
|
|
|
listen to that port and intercept traffic.
|
|
|
|
|
|
|
|
|
|
|
|
dvtws quick start.
|
|
|
|
|
|
|
|
For all traffic:
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipfw delete 100
|
|
|
|
ipfw add 100 divert 989 tcp from any to any 80,443 out not diverted not sockarg xmit em0
|
|
|
|
/opt/zapret/nfq/dvtws --port=989 --dpi-desync=split2
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Process only table zapret with the exception of table nozapret :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ipfw delete 100
|
|
|
|
ipfw add 100 allow tcp from me to table\(nozapret\) 80,443
|
|
|
|
ipfw add 100 divert 989 tcp from any to table\(zapret\) 80,443 out not diverted not sockarg xmit em0
|
|
|
|
/opt/zapret/nfq/dvtws --port=989 --dpi-desync=split2
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Reinjection loop avoidance.
|
|
|
|
FreeBSD artificially ignores sockarg for ipv6 in the kernel.
|
|
|
|
This limitation is coming from the ipv6 early age. Code is still in "testing" state. 10-20 years. Everybody forgot about it.
|
|
|
|
dvtws sends ipv6 forged frames using another divert socket (HACK). they can be filtered out using 'diverted'.
|
|
|
|
ipv4 frames are filtered using 'sockarg'.
|
|
|
|
|
|
|
|
PF in FreeBSD:
|
|
|
|
The setup is similar to OpenBSD, but there are important nuances.
|
2022-01-23 23:11:11 +03:00
|
|
|
1) Don't forget to use special tpws parameter `--enable-pf`
|
2021-03-04 14:30:38 +03:00
|
|
|
2) It's not possible to redirect to ::1. Need to redirect to the link-local address of the incoming interface.
|
|
|
|
Look for fe80:... address in ifconfig and use it for redirection target.
|
|
|
|
3) pf.conf syntax is a bit different from OpenBSD.
|
|
|
|
4) How to set maximum table size : sysctl net.pf.request_maxcount=2000000
|
|
|
|
5) The word 'divert-packet' is absent in the pfctl binary, divert-packet rules are not working.
|
|
|
|
'divert-to' is not the same thing. Looks like its not possible to use dvtws with PF in FreeBSD.
|
2021-12-14 12:13:09 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
rdr pass on em1 inet6 proto tcp to port {80,443} -> fe80::31c:29ff:dee2:1c4d port 988
|
|
|
|
rdr pass on em1 inet proto tcp to port {80,443} -> 127.0.0.1 port 988
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2022-01-23 23:12:48 +03:00
|
|
|
/opt/zapret/tpws/tpws --port=988 --enable-pf --bind-addr=127.0.0.1 --bind-iface6=em1 --bind-linklocal=force
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Its not clear how to do rdr-to outgoing traffic. I could not make route-to scheme work.
|
|
|
|
|
|
|
|
|
2022-01-22 14:36:36 +03:00
|
|
|
## pfsense
|
|
|
|
|
|
|
|
pfsense is based on FreeBSD.
|
2022-01-23 11:37:40 +03:00
|
|
|
Binaries from `binaries/freebsd-x64` are compiled in FreeBSD 11 and should work. Use `install_bin.sh`.
|
2022-01-22 14:36:36 +03:00
|
|
|
pfsense uses pf firewall which does not support divert.
|
|
|
|
Fortunately ipfw and ipdivert modules are present and can be kldload-ed.
|
|
|
|
It's also necessary to change firewall order using sysctl commands.
|
|
|
|
Sometimes pf may limit dvtws abilities. It scrubs ip fragments disabling dvtws ipfrag2 desync mode.
|
|
|
|
|
2022-01-23 12:29:20 +03:00
|
|
|
There's autostart script example in `init.d/pfsense`. It should be placed to `/usr/local/etc/rc.d` and edited.
|
|
|
|
Write your ipfw rules and daemon start commands.
|
|
|
|
Because git is absent the most convinient way to copy files is ssh. curl is present by default.
|
|
|
|
|
2022-01-23 12:44:57 +03:00
|
|
|
Copy zip with zapret files to `/opt` and unpack there as it's done in other systems.
|
|
|
|
In this case run dvtws as `/opt/zapret/nfq/dvtws`. Or just copy `dvtws` to `/usr/local/sbin`. As you wish.
|
|
|
|
ipset scripts are working, cron is present. It's possible to renew lists.
|
|
|
|
|
2022-01-23 13:11:25 +03:00
|
|
|
If you dont like poverty of default repos its possible to enable FreeBSD repo.
|
2022-01-23 13:13:37 +03:00
|
|
|
Change `no` to `yes` in `/usr/local/etc/pkg/repos/FreeBSD.conf`.
|
2022-01-23 13:11:25 +03:00
|
|
|
Then it becomes possible to install all the required software including git to download zapret from github directly.
|
|
|
|
|
|
|
|
|
2022-01-22 14:36:36 +03:00
|
|
|
/usr/local/etc/rc.d/zapret.sh (chmod 755)
|
|
|
|
```
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
kldload ipfw
|
|
|
|
kldload ipdivert
|
|
|
|
sysctl net.inet.ip.pfil.outbound=ipfw,pf
|
|
|
|
sysctl net.inet.ip.pfil.inbound=ipfw,pf
|
|
|
|
sysctl net.inet6.ip6.pfil.outbound=ipfw,pf
|
|
|
|
sysctl net.inet6.ip6.pfil.inbound=ipfw,pf
|
2022-01-23 12:29:20 +03:00
|
|
|
ipfw delete 100
|
2022-01-23 18:27:38 +03:00
|
|
|
ipfw add 100 divert 989 tcp from any to any 80,443 out not diverted not sockarg xmit em0
|
2022-01-23 12:29:20 +03:00
|
|
|
pkill ^dvtws$
|
2022-01-22 14:36:36 +03:00
|
|
|
dvtws --daemon --port 989 --dpi-desync=split2
|
|
|
|
```
|
|
|
|
|
2022-01-23 18:27:38 +03:00
|
|
|
I could not make tpws work from ipfw. Looks like there's some conflict between two firewalls.
|
|
|
|
Only PF redirection works. PF does not allow to freely add and delete rules. Only anchors can be reloaded.
|
|
|
|
To make an anchor work it must be referred from the main ruleset. But its managed by pfsense scripts.
|
|
|
|
One possible solution would be to modify '/etc/inc/filter.inc' as follows :
|
|
|
|
```
|
|
|
|
$natrules .= "# TFTP proxy\n";
|
|
|
|
|
|
|
|
/* MOD */
|
|
|
|
$natrules .= "rdr-anchor \"zapret/*\"\n";
|
|
|
|
|
|
|
|
$natrules .= "rdr-anchor \"tftp-proxy/*\"\n";
|
|
|
|
```
|
|
|
|
|
|
|
|
Write the anchor code to '/etc/zapret.anchor':
|
|
|
|
```
|
|
|
|
rdr pass on em1 inet proto tcp to port {80,443} -> 127.0.0.1 port 988
|
|
|
|
rdr pass on em1 inet6 proto tcp to port {80,443} -> fe80::20c:29ff:5ae3:4821 port 988
|
|
|
|
```
|
|
|
|
|
|
|
|
Autostart '/usr/local/etc/rc.d/zapret.sh' :
|
|
|
|
```
|
|
|
|
pfctl -a zapret -f /etc/zapret.anchor
|
2022-01-23 23:11:11 +03:00
|
|
|
pkill ^tpws$
|
2022-01-23 23:17:52 +03:00
|
|
|
tpws --daemon --port=988 --enable-pf --split-http-req=method --split-pos=2
|
2022-01-23 18:27:38 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
After reboot check that anchor is created and referred from the main ruleset :
|
|
|
|
```
|
|
|
|
[root@pfSense /]# pfctl -s nat
|
|
|
|
no nat proto carp all
|
|
|
|
nat-anchor "natearly/*" all
|
|
|
|
nat-anchor "natrules/*" all
|
|
|
|
...................
|
|
|
|
no rdr proto carp all
|
|
|
|
rdr-anchor "zapret/*" all
|
|
|
|
rdr-anchor "tftp-proxy/*" all
|
|
|
|
rdr-anchor "miniupnpd" all
|
|
|
|
[root@pfSense /]# pfctl -s nat -a zapret
|
|
|
|
rdr pass on em1 inet proto tcp from any to any port = http -> 127.0.0.1 port 988
|
|
|
|
rdr pass on em1 inet proto tcp from any to any port = https -> 127.0.0.1 port 988
|
|
|
|
rdr pass on em1 inet6 proto tcp from any to any port = http -> fe80::20c:29ff:5ae3:4821 port 988
|
|
|
|
rdr pass on em1 inet6 proto tcp from any to any port = https -> fe80::20c:29ff:5ae3:4821 port 988
|
|
|
|
```
|
|
|
|
|
2022-01-22 14:36:36 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
## OpenBSD
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
In OpenBSD default tpws bind is ipv6 only. to bind to ipv4 specify --bind-addr=0.0.0.0
|
|
|
|
Use --bind-addr=0.0.0.0 --bind-addr=:: to achieve the same default bind as in others OSes.
|
|
|
|
|
|
|
|
tpws for forwarded traffic only :
|
|
|
|
|
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pass in quick on em1 inet proto tcp to port {80,443} rdr-to 127.0.0.1 port 988
|
|
|
|
pass in quick on em1 inet6 proto tcp to port {80,443} rdr-to ::1 port 988
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pfctl -f /etc/pf.conf
|
|
|
|
tpws --port=988 --user=daemon --bind-addr=::1 --bind-addr=127.0.0.1
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Its not clear how to do rdr-to outgoing traffic. I could not make route-to scheme work.
|
|
|
|
rdr-to support is done using /dev/pf, that's why transparent mode requires root.
|
|
|
|
|
|
|
|
dvtws for all traffic:
|
|
|
|
|
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-22 12:02:55 +03:00
|
|
|
pass in quick on em0 proto tcp from port {80,443} no state
|
|
|
|
pass out quick on em0 proto tcp to port {80,443} divert-packet port 989
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pfctl -f /etc/pf.conf
|
|
|
|
./dvtws --port=989 --dpi-desync=split2
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
dwtws only for table zapret with the exception of table nozapret :
|
|
|
|
|
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-22 12:02:55 +03:00
|
|
|
set limit table-entries 2000000
|
2021-03-04 14:30:38 +03:00
|
|
|
table <zapret> file "/opt/zapret/ipset/zapret-ip.txt"
|
|
|
|
table <zapret-user> file "/opt/zapret/ipset/zapret-ip-user.txt"
|
|
|
|
table <nozapret> file "/opt/zapret/ipset/zapret-ip-exclude.txt"
|
2021-03-22 12:02:55 +03:00
|
|
|
pass out quick on em0 inet proto tcp to <nozapret> port {80,443}
|
|
|
|
pass in quick on em0 inet proto tcp from <zapret> port {80,443} no state
|
|
|
|
pass out quick on em0 inet proto tcp to <zapret> port {80,443} divert-packet port 989 no state
|
|
|
|
pass in quick on em0 inet proto tcp from <zapret-user> port {80,443} no state
|
|
|
|
pass out quick on em0 inet proto tcp to <zapret-user> port {80,443} divert-packet port 989 no state
|
2021-03-04 14:30:38 +03:00
|
|
|
table <zapret6> file "/opt/zapret/ipset/zapret-ip6.txt"
|
|
|
|
table <zapret6-user> file "/opt/zapret/ipset/zapret-ip-user6.txt"
|
|
|
|
table <nozapret6> file "/opt/zapret/ipset/zapret-ip-exclude6.txt"
|
2021-03-22 12:02:55 +03:00
|
|
|
pass out quick on em0 inet6 proto tcp to <nozapret6> port {80,443}
|
|
|
|
pass in quick on em0 inet6 proto tcp from <zapret6> port {80,443} no state
|
|
|
|
pass out quick on em0 inet6 proto tcp to <zapret6> port {80,443} divert-packet port 989 no state
|
|
|
|
pass in quick on em0 inet6 proto tcp from <zapret6-user> port {80,443} no state
|
|
|
|
pass out quick on em0 inet6 proto tcp to <zapret6-user> port {80,443} divert-packet port 989 no state
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pfctl -f /etc/pf.conf
|
|
|
|
./dvtws --port=989 --dpi-desync=split2
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-03-22 12:02:55 +03:00
|
|
|
divert-packet automatically adds the reverse rule. By default also incoming traffic will be passwed to dvtws.
|
|
|
|
This is highly undesired because it is waste of cpu resources and speed limiter.
|
|
|
|
The trick with "no state" and "in" rules allows to bypass auto reverse rule.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
dvtws in OpenBSD sends all fakes through a divert socket because raw sockets have critical artificial limitations.
|
|
|
|
Looks like pf automatically prevent reinsertion of diverted frames. Loop problem does not exist.
|
|
|
|
|
|
|
|
OpenBSD forcibly recomputes tcp checksum after divert. Thats why most likely
|
|
|
|
dpi-desync-fooling=badsum will not work. dvtws will warn if you specify this parameter.
|
|
|
|
|
2021-12-14 12:18:23 +03:00
|
|
|
ipset scripts do not reload PF by default. To enable reload specify command in `/opt/zapret/config` :
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
LISTS_RELOAD="pfctl -f /etc/pf.conf"
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Newer pfctl versions can reload tables only :
|
|
|
|
```
|
|
|
|
pfctl -Tl -f /etc/pf.conf
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
But OpenBSD 6.8 pfctl is old enough and does not support that. Newer FreeBSD do.
|
2021-12-14 12:18:23 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Don't forget to disable gzip compression :
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
GZIP_LISTS=0
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
If some list files do not exist and have references in pf.conf it leads to error.
|
|
|
|
You need to exclude those tables from pf.conf and referencing them rules.
|
|
|
|
After configuration is done you can put ipset script :
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
crontab -e
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
|
|
|
then write the line : `0 12 */2 * * /opt/zapret/ipset/get_config.sh`
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
## MacOS
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
Initially, the kernel of this OS was based on BSD. That's why it is still BSD but a lot was modified by Apple.
|
|
|
|
As usual a mass commercial project priorities differ from their free counterparts.
|
|
|
|
Apple guys do what they want.
|
|
|
|
What everyone have updated long ago they keep old like a mammoth. But who cares ?
|
|
|
|
|
|
|
|
MacOS used to have ipfw but it was removed later and replaced by PF.
|
|
|
|
It looks like divert sockets are internally replaced with raw. Its possible to request a divert socket
|
|
|
|
but it behaves exactly as raw socket with all its BSD inherited + apple specific bugs and feature.
|
2021-12-14 14:12:49 +03:00
|
|
|
The fact is that divert-packet in `/etc/pf.conf` does not work. pfctl binary does not contain the word `divert`.
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
dvtws does compile but is useless.
|
|
|
|
|
|
|
|
After some efforts tpws works. Apple has removed some important stuff from their newer SDKs (DIOCNATLOOK) making
|
2021-12-14 14:12:49 +03:00
|
|
|
them undocumented and unsupported.
|
|
|
|
|
|
|
|
With important definitions copied from an older SDK it was possible to make
|
2021-03-04 14:30:38 +03:00
|
|
|
transparent mode working again. But this is not guaranteed to work in the future versions.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
|
|
|
Another MacOS unique feature is root requirement while polling `/dev/pf`.
|
|
|
|
|
|
|
|
By default tpws drops root. Its necessary to specify `--user=root` to stay with root.
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
In other aspects PF behaves very similar to FreeBSD and shares the same pf.conf syntax.
|
|
|
|
|
|
|
|
In MacOS redirection works both for passthrough and outgoing traffic. Outgoing redirection requires route-to rule.
|
|
|
|
Because tpws is forced to run as root to avoid loop its necessary to exempt root from the redirection.
|
|
|
|
That's why DPI bypass will not work for local requests from root.
|
|
|
|
|
|
|
|
If you do ipv6 routing you have to get rid of "secured" ipv6 address assignment.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
"secured" addresses are designed to be permanent and not related to the MAC address.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
And they really are. Except for link-locals.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
|
|
|
If you just reboot the system link-locals will not change. But next day they will change.Not necessary to wait so long.
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Just change the system time to tomorrow and reboot. Link-locals will change. (at least they change in vmware guest)
|
|
|
|
Looks like its a kernel bug. Link locals should not change. Its useless and can be harmful. Cant use LL as a gateway.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
The easiest solution is to disable "secured" addresses.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Outgoing connections prefer randomly generated temporary addressesas like in other systems.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
|
|
|
Put the string `net.inet6.send.opmode=0` to `/etc/sysctl.conf`. If not present - create it.
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Then reboot the system.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2022-01-23 17:38:49 +03:00
|
|
|
If you dont like this solution you can assign an additional static ipv6 address from `fc00::/7` range with `/128` prefix
|
2021-03-04 14:30:38 +03:00
|
|
|
to your LAN interface and use it as the gateway address.
|
|
|
|
|
2021-03-10 22:18:27 +03:00
|
|
|
tpws transparent mode only for outgoing connections.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
rdr pass on lo0 inet proto tcp from !127.0.0.0/8 to any port {80,443} -> 127.0.0.1 port 988
|
|
|
|
rdr pass on lo0 inet6 proto tcp from !::1 to any port {80,443} -> fe80::1 port 988
|
|
|
|
pass out route-to (lo0 127.0.0.1) inet proto tcp from any to any port {80,443} user { >root }
|
|
|
|
pass out route-to (lo0 fe80::1) inet6 proto tcp from any to any port {80,443} user { >root }
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pfctl -ef /etc/pf.conf
|
2021-03-10 22:18:27 +03:00
|
|
|
/opt/zapret/tpws/tpws --user=root --port=988 --bind-addr=127.0.0.1 --bind-iface6=lo0 --bind-linklocal=force
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-03-10 22:18:27 +03:00
|
|
|
tpws transparent mode for both passthrough and outgoing connections. en1 - LAN.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
ifconfig en1 | grep fe80
|
|
|
|
inet6 fe80::bbbb:bbbb:bbbb:bbbb%en1 prefixlen 64 scopeid 0x8
|
2021-12-14 14:12:49 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
/etc/pf.conf
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
rdr pass on en1 inet proto tcp from any to any port {80,443} -> 127.0.0.1 port 988
|
|
|
|
rdr pass on en1 inet6 proto tcp from any to any port {80,443} -> fe80::bbbb:bbbb:bbbb:bbbb port 988
|
|
|
|
rdr pass on lo0 inet proto tcp from !127.0.0.0/8 to any port {80,443} -> 127.0.0.1 port 988
|
|
|
|
rdr pass on lo0 inet6 proto tcp from !::1 to any port {80,443} -> fe80::1 port 988
|
|
|
|
pass out route-to (lo0 127.0.0.1) inet proto tcp from any to any port {80,443} user { >root }
|
|
|
|
pass out route-to (lo0 fe80::1) inet6 proto tcp from any to any port {80,443} user { >root }
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-12-14 12:18:23 +03:00
|
|
|
then
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
pfctl -ef /etc/pf.conf
|
2021-03-10 22:18:27 +03:00
|
|
|
/opt/zapret/tpws/tpws --user=root --port=988 --bind-addr=127.0.0.1 --bind-iface6=lo0 --bind-linklocal=force --bind-iface6=en1 --bind-linklocal=force
|
2021-12-14 12:18:23 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
Build from source : `make -C /opt/zapret mac`
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
`ipset/*.sh` scripts work.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
### MacOS easy install
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 12:18:23 +03:00
|
|
|
`install_easy.sh` supports MacOS
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
Shipped precompiled binaries are built for 64-bit MacOS with `-mmacosx-version-min=10.8` option.
|
2021-03-04 14:30:38 +03:00
|
|
|
They should run on all supported MacOS versions.
|
2021-12-14 14:12:49 +03:00
|
|
|
If no - its easy to build your own. Running `make` automatically installs developer tools.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
!! **Internet sharing is not supported** !!
|
2021-12-14 14:15:23 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
Routing is supported but only manually configured through PF.
|
|
|
|
If you enable internet sharing tpws stops functioning. When you disable internet sharing you may lose web site access.
|
2021-12-14 14:12:49 +03:00
|
|
|
|
2021-12-14 12:13:09 +03:00
|
|
|
To fix : `pfctl -f /etc/pf.conf`
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
If you need internet sharing use tpws socks mode.
|
|
|
|
|
2021-12-14 14:15:23 +03:00
|
|
|
launchd is used for autostart (`/Library/LaunchDaemons/zapret.plist`)
|
|
|
|
|
|
|
|
Control script : `/opt/zapret/init.d/macos/zapret`
|
|
|
|
|
|
|
|
The following commands fork with both tpws and firewall (if `INIT_APPLY_FW=1` in config)
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
/opt/zapret/init.d/macos/zapret start
|
|
|
|
/opt/zapret/init.d/macos/zapret stop
|
|
|
|
/opt/zapret/init.d/macos/zapret restart
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
Work with tpws only :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
/opt/zapret/init.d/macos/zapret start-daemons
|
|
|
|
/opt/zapret/init.d/macos/zapret stop-daemons
|
|
|
|
/opt/zapret/init.d/macos/zapret restart-daemons
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
Work with PF only :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
/opt/zapret/init.d/macos/zapret start-fw
|
|
|
|
/opt/zapret/init.d/macos/zapret stop-fw
|
|
|
|
/opt/zapret/init.d/macos/zapret restart-fw
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
Reloading PF tables :
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
/opt/zapret/init.d/macos/zapret reload-fw-tables
|
2021-12-14 12:13:09 +03:00
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
Installer configures `LISTS_RELOAD` in the config so `ipset/*.sh` scripts automatically reload PF tables.
|
2021-12-14 12:18:23 +03:00
|
|
|
Installer creates cron job for `ipset/get_config.sh`, as in OpenWRT.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
start-fw script automatically patches `/etc/pf.conf` inserting there `zapret` anchors.
|
2021-03-04 14:30:38 +03:00
|
|
|
Auto patching requires pf.conf with apple anchors preserved.
|
2021-12-14 14:12:49 +03:00
|
|
|
If your `pf.conf` is highly customized and patching fails you will see the warning. Do not ignore it.
|
|
|
|
In that case you need to manually insert "zapret" anchors to your `pf.conf` (keeping the right rule type ordering) :
|
|
|
|
```
|
2021-03-04 14:30:38 +03:00
|
|
|
rdr-anchor "zapret"
|
|
|
|
anchor "zapret"
|
|
|
|
unistall_easy.sh unpatches pf.conf
|
2021-12-14 14:12:49 +03:00
|
|
|
```
|
|
|
|
start-fw creates 3 anchor files in `/etc/pf.anchors` : zapret,zapret-v4,zapret-v6.
|
|
|
|
|
|
|
|
- Last 2 are referenced by anchor `zapret`.
|
|
|
|
- Tables `nozapret`,`nozapret6` belong to anchor `zapret`.
|
|
|
|
- Tables `zapret`,`zapret-user` belong to anchor `zapret-v4`.
|
|
|
|
- Tables `zapret6`,`apret6-user` belong to anchor `zapret-v6`.
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2021-12-14 14:12:49 +03:00
|
|
|
If an ip version is disabled then corresponding anchor is empty and is not referenced from the anchor `zapret`.
|
2021-03-04 14:30:38 +03:00
|
|
|
Tables are only created for existing list files in the ipset directory.
|