mirror of
https://github.com/bol-van/zapret.git
synced 2025-05-17 10:52:58 +03:00
Compare commits
1 Commits
4c8fd9053b
...
a9cdf2e4f8
Author | SHA1 | Date | |
---|---|---|---|
|
a9cdf2e4f8 |
@ -3,8 +3,6 @@ custom_runner()
|
|||||||
# $1 - function name
|
# $1 - function name
|
||||||
# $2+ - params
|
# $2+ - params
|
||||||
|
|
||||||
[ "$DISABLE_CUSTOM" = 1 ] && return 0
|
|
||||||
|
|
||||||
local n script FUNC=$1
|
local n script FUNC=$1
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
@ -349,37 +349,27 @@ ipt_do_nfqws_in_out()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zapret_do_firewall_standard_tpws_rules_ipt()
|
zapret_do_firewall_standard_rules_ipt()
|
||||||
{
|
{
|
||||||
# $1 - 1 - add, 0 - del
|
# $1 - 1 - add, 0 - del
|
||||||
|
|
||||||
local f4 f6
|
local f4 f6
|
||||||
|
|
||||||
[ "$TPWS_ENABLE" = 1 -a -n "$TPWS_PORTS" ] && {
|
[ "$TPWS_ENABLE" = 1 -a -n "$TPWS_PORTS" ] &&
|
||||||
|
{
|
||||||
f4="-p tcp -m multiport --dports $TPWS_PORTS_IPT"
|
f4="-p tcp -m multiport --dports $TPWS_PORTS_IPT"
|
||||||
f6=$f4
|
f6=$f4
|
||||||
filter_apply_ipset_target f4 f6
|
filter_apply_ipset_target f4 f6
|
||||||
fw_tpws $1 "$f4" "$f6" $TPPORT
|
fw_tpws $1 "$f4" "$f6" $TPPORT
|
||||||
}
|
}
|
||||||
}
|
[ "$NFQWS_ENABLE" = 1 ] &&
|
||||||
zapret_do_firewall_standard_nfqws_rules_ipt()
|
{
|
||||||
{
|
|
||||||
# $1 - 1 - add, 0 - del
|
|
||||||
|
|
||||||
[ "$NFQWS_ENABLE" = 1 ] && {
|
|
||||||
ipt_do_nfqws_in_out $1 tcp "$NFQWS_PORTS_TCP_IPT" "$NFQWS_TCP_PKT_OUT" "$NFQWS_TCP_PKT_IN"
|
ipt_do_nfqws_in_out $1 tcp "$NFQWS_PORTS_TCP_IPT" "$NFQWS_TCP_PKT_OUT" "$NFQWS_TCP_PKT_IN"
|
||||||
ipt_do_nfqws_in_out $1 tcp "$NFQWS_PORTS_TCP_KEEPALIVE_IPT" keepalive "$NFQWS_TCP_PKT_IN"
|
ipt_do_nfqws_in_out $1 tcp "$NFQWS_PORTS_TCP_KEEPALIVE_IPT" keepalive "$NFQWS_TCP_PKT_IN"
|
||||||
ipt_do_nfqws_in_out $1 udp "$NFQWS_PORTS_UDP_IPT" "$NFQWS_UDP_PKT_OUT" "$NFQWS_UDP_PKT_IN"
|
ipt_do_nfqws_in_out $1 udp "$NFQWS_PORTS_UDP_IPT" "$NFQWS_UDP_PKT_OUT" "$NFQWS_UDP_PKT_IN"
|
||||||
ipt_do_nfqws_in_out $1 udp "$NFQWS_PORTS_UDP_KEEPALIVE_IPT" keepalive "$NFQWS_UDP_PKT_IN"
|
ipt_do_nfqws_in_out $1 udp "$NFQWS_PORTS_UDP_KEEPALIVE_IPT" keepalive "$NFQWS_UDP_PKT_IN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zapret_do_firewall_standard_rules_ipt()
|
|
||||||
{
|
|
||||||
# $1 - 1 - add, 0 - del
|
|
||||||
|
|
||||||
zapret_do_firewall_standard_tpws_rules_ipt $1
|
|
||||||
zapret_do_firewall_standard_nfqws_rules_ipt $1
|
|
||||||
}
|
|
||||||
|
|
||||||
zapret_do_firewall_rules_ipt()
|
zapret_do_firewall_rules_ipt()
|
||||||
{
|
{
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
standard_mode_tpws_socks()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
local opt
|
|
||||||
[ "$TPWS_SOCKS_ENABLE" = 1 ] && {
|
|
||||||
opt="--port=$TPPORT_SOCKS $TPWS_SOCKS_OPT"
|
|
||||||
filter_apply_hostlist_target opt
|
|
||||||
do_tpws_socks $1 2 "$opt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
standard_mode_tpws()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
local opt
|
|
||||||
[ "$TPWS_ENABLE" = 1 ] && check_bad_ws_options $1 "$TPWS_OPT" && {
|
|
||||||
opt="--port=$TPPORT $TPWS_OPT"
|
|
||||||
filter_apply_hostlist_target opt
|
|
||||||
do_tpws $1 1 "$opt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
standard_mode_nfqws()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
local opt
|
|
||||||
[ "$NFQWS_ENABLE" = 1 ] && check_bad_ws_options $1 "$NFQWS_OPT" && {
|
|
||||||
opt="--qnum=$QNUM $NFQWS_OPT"
|
|
||||||
filter_apply_hostlist_target opt
|
|
||||||
do_nfqws $1 3 "$opt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
standard_mode_daemons()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
|
|
||||||
standard_mode_tpws_socks $1
|
|
||||||
standard_mode_tpws $1
|
|
||||||
standard_mode_nfqws $1
|
|
||||||
}
|
|
||||||
zapret_do_daemons()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
|
|
||||||
standard_mode_daemons $1
|
|
||||||
custom_runner zapret_custom_daemons $1
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
zapret_run_daemons()
|
|
||||||
{
|
|
||||||
zapret_do_daemons 1 "$@"
|
|
||||||
}
|
|
||||||
zapret_stop_daemons()
|
|
||||||
{
|
|
||||||
zapret_do_daemons 0 "$@"
|
|
||||||
}
|
|
@ -640,31 +640,25 @@ nft_apply_nfqws_in_out()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zapret_apply_firewall_standard_tpws_rules_nft()
|
zapret_apply_firewall_standard_rules_nft()
|
||||||
{
|
{
|
||||||
local f4 f6
|
local f4 f6
|
||||||
|
|
||||||
[ "$TPWS_ENABLE" = 1 -a -n "$TPWS_PORTS" ] && {
|
[ "$TPWS_ENABLE" = 1 -a -n "$TPWS_PORTS" ] &&
|
||||||
|
{
|
||||||
f4="tcp dport {$TPWS_PORTS}"
|
f4="tcp dport {$TPWS_PORTS}"
|
||||||
f6=$f4
|
f6=$f4
|
||||||
nft_filter_apply_ipset_target f4 f6
|
nft_filter_apply_ipset_target f4 f6
|
||||||
nft_fw_tpws "$f4" "$f6" $TPPORT
|
nft_fw_tpws "$f4" "$f6" $TPPORT
|
||||||
}
|
}
|
||||||
}
|
[ "$NFQWS_ENABLE" = 1 ] &&
|
||||||
zapret_apply_firewall_standard_nfqws_rules_nft()
|
{
|
||||||
{
|
|
||||||
[ "$NFQWS_ENABLE" = 1 ] && {
|
|
||||||
nft_apply_nfqws_in_out tcp "$NFQWS_PORTS_TCP" "$NFQWS_TCP_PKT_OUT" "$NFQWS_TCP_PKT_IN"
|
nft_apply_nfqws_in_out tcp "$NFQWS_PORTS_TCP" "$NFQWS_TCP_PKT_OUT" "$NFQWS_TCP_PKT_IN"
|
||||||
nft_apply_nfqws_in_out tcp "$NFQWS_PORTS_TCP_KEEPALIVE" keepalive "$NFQWS_TCP_PKT_IN"
|
nft_apply_nfqws_in_out tcp "$NFQWS_PORTS_TCP_KEEPALIVE" keepalive "$NFQWS_TCP_PKT_IN"
|
||||||
nft_apply_nfqws_in_out udp "$NFQWS_PORTS_UDP" "$NFQWS_UDP_PKT_OUT" "$NFQWS_UDP_PKT_IN"
|
nft_apply_nfqws_in_out udp "$NFQWS_PORTS_UDP" "$NFQWS_UDP_PKT_OUT" "$NFQWS_UDP_PKT_IN"
|
||||||
nft_apply_nfqws_in_out udp "$NFQWS_PORTS_UDP_KEEPALIVE" keepalive "$NFQWS_UDP_PKT_IN"
|
nft_apply_nfqws_in_out udp "$NFQWS_PORTS_UDP_KEEPALIVE" keepalive "$NFQWS_UDP_PKT_IN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zapret_apply_firewall_standard_rules_nft()
|
|
||||||
{
|
|
||||||
zapret_apply_firewall_standard_tpws_rules_nft
|
|
||||||
zapret_apply_firewall_standard_nfqws_rules_nft
|
|
||||||
}
|
|
||||||
|
|
||||||
zapret_apply_firewall_rules_nft()
|
zapret_apply_firewall_rules_nft()
|
||||||
{
|
{
|
||||||
|
@ -417,9 +417,3 @@ v69.5
|
|||||||
|
|
||||||
nfqws,tpws: --dry-run
|
nfqws,tpws: --dry-run
|
||||||
install_easy: check tpws and nfqws options validity
|
install_easy: check tpws and nfqws options validity
|
||||||
|
|
||||||
v69.6
|
|
||||||
|
|
||||||
nfqws: set NETLINK_NO_ENOBUFS to fix possible nfq recv errors
|
|
||||||
init.d: unify custom scripts for linux
|
|
||||||
init.d: new custom scripts : 20-fw-extra, 50-wg4all
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# zapret v69.6
|
# zapret v69.5
|
||||||
|
|
||||||
# SCAMMER WARNING
|
# SCAMMER WARNING
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# zapret v69.6
|
# zapret v69.5
|
||||||
|
|
||||||
# ВНИМАНИЕ, остерегайтесь мошенников
|
# ВНИМАНИЕ, остерегайтесь мошенников
|
||||||
|
|
||||||
@ -1866,9 +1866,8 @@ custom скрипты - это маленькие shell программы, уп
|
|||||||
/opt/zapret/init.d/macos/custom.d
|
/opt/zapret/init.d/macos/custom.d
|
||||||
```
|
```
|
||||||
Директория будет просканирована в алфавитном порядке, и каждый скрипт будет применен.
|
Директория будет просканирована в алфавитном порядке, и каждый скрипт будет применен.
|
||||||
|
Рядом имеется `custom.d.examples`. Это готовые скрипты, которые можно копировать в `custom.d`.
|
||||||
В `init.d` имеется `custom.d.examples.linux`, в `init.d/macos` - `custom.d.examples`.
|
Их можно взять за основу для написания собственных.
|
||||||
Это готовые скрипты, которые можно копировать в `custom.d`. Их можно взять за основу для написания собственных.
|
|
||||||
|
|
||||||
***Для linux пишется код в функции***
|
***Для linux пишется код в функции***
|
||||||
```
|
```
|
||||||
@ -1886,9 +1885,9 @@ zapret_custom_firewall_v6
|
|||||||
```
|
```
|
||||||
|
|
||||||
zapret_custom_daemons поднимает демоны **nfqws**/**tpws** в нужном вам количестве и с нужными вам параметрами.
|
zapret_custom_daemons поднимает демоны **nfqws**/**tpws** в нужном вам количестве и с нужными вам параметрами.
|
||||||
В первом параметре передается код операции: 1 = запуск, 0 = останов.
|
Для систем традиционного linux (sysv) и MacOS в первом параметре передается код операции: 1 = запуск, 0 = останов.
|
||||||
|
Для openwrt логика останова отсутствует за ненадобностью.
|
||||||
Схема запуска демонов в openwrt отличается - используется procd.
|
Схема запуска демонов в openwrt отличается - используется procd.
|
||||||
Поэтому логика останова отсутствует за ненадобностью, останов никогда не вызывается.
|
|
||||||
|
|
||||||
zapret_custom_firewall поднимает и убирает правила `iptables`.
|
zapret_custom_firewall поднимает и убирает правила `iptables`.
|
||||||
В первом параметре передается код операции: 1 = запуск, 0 = останов.
|
В первом параметре передается код операции: 1 = запуск, 0 = останов.
|
||||||
@ -1914,8 +1913,8 @@ zapret_custom_firewall_nft поднимает правила nftables.
|
|||||||
В macos firewall-функции ничего сами никуда не заносят. Их задача - лишь выдать текст в stdout,
|
В macos firewall-функции ничего сами никуда не заносят. Их задача - лишь выдать текст в stdout,
|
||||||
содержащий правила для pf-якоря. Остальное сделает обертка.
|
содержащий правила для pf-якоря. Остальное сделает обертка.
|
||||||
|
|
||||||
Особо обратите внимание на номер демона в функциях `run_daemon` , `do_daemon`, `do_tpws`, `do_tpws_socks`, `do_nfqws` ,
|
Особо обратите внимание на номер демона в функциях `run_daemon` и `do_daemon`, номера портов **tpws**
|
||||||
номера портов **tpws** и очередей **nfqueue**.
|
и очередей `nfqueue`.
|
||||||
Они должны быть уникальными во всех скриптах. При накладке будет ошибка.
|
Они должны быть уникальными во всех скриптах. При накладке будет ошибка.
|
||||||
Поэтому используйте функции динамического получения этих значений из пула.
|
Поэтому используйте функции динамического получения этих значений из пула.
|
||||||
|
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
# this custom script runs standard mode with extra firewall rules
|
|
||||||
|
|
||||||
# config: use TPWS_ENABLE_OVERRIDE, NFQWS_ENABLE_OVERRIDE to enable standard mode daemons
|
|
||||||
# standard and override switches cannot be enabled simultaneously !
|
|
||||||
|
|
||||||
TPWS_ENABLE_OVERRIDE=${TPWS_ENABLE_OVERRIDE:-0}
|
|
||||||
NFQWS_ENABLE_OVERRIDE=${NFQWS_ENABLE_OVERRIDE:-0}
|
|
||||||
|
|
||||||
# config: some if these values must be set in config. not setting any of these makes this script meaningless.
|
|
||||||
# pre vars put ipt/nft code to the rule beginning
|
|
||||||
#FW_EXTRA_PRE_TPWS_IPT=
|
|
||||||
#FW_EXTRA_PRE_TPWS_NFT=
|
|
||||||
#FW_EXTRA_PRE_NFQWS_IPT="-m mark --mark 0x10000000/0x10000000"
|
|
||||||
#FW_EXTRA_PRE_NFQWS_NFT="mark and 0x10000000 != 0"
|
|
||||||
# post vars put ipt/nft code to the rule end
|
|
||||||
#FW_EXTRA_POST_TPWS_IPT=
|
|
||||||
#FW_EXTRA_POST_TPWS_NFT=
|
|
||||||
#FW_EXTRA_POST_NFQWS_IPT=
|
|
||||||
#FW_EXTRA_POST_NFQWS_NFT=
|
|
||||||
|
|
||||||
check_std_intersect()
|
|
||||||
{
|
|
||||||
[ "$TPWS_ENABLE_OVERRIDE" = 1 -a "$TPWS_ENABLE" = 1 ] && {
|
|
||||||
echo "ERROR ! both TPWS_ENABLE_OVERRIDE and TPWS_ENABLE are enabled"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
[ "$NFQWS_ENABLE_OVERRIDE" = 1 -a "$NFQWS_ENABLE" = 1 ] && {
|
|
||||||
echo "ERROR ! both NFQWS_ENABLE_OVERRIDE and NFQWS_ENABLE are enabled"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
zapret_custom_daemons()
|
|
||||||
{
|
|
||||||
# $1 - 1 - add, 0 - stop
|
|
||||||
|
|
||||||
check_std_intersect || return
|
|
||||||
|
|
||||||
local TPWS_SOCKS_ENABLE=0 TPWS_ENABLE=$TPWS_ENABLE_OVERRIDE NFQWS_ENABLE=$NFQWS_ENABLE_OVERRIDE
|
|
||||||
standard_mode_daemons "$1"
|
|
||||||
}
|
|
||||||
zapret_custom_firewall()
|
|
||||||
{
|
|
||||||
# $1 - 1 - run, 0 - stop
|
|
||||||
|
|
||||||
check_std_intersect || return
|
|
||||||
|
|
||||||
local FW_EXTRA_PRE FW_EXTRA_POST TPWS_ENABLE=$TPWS_ENABLE_OVERRIDE NFQWS_ENABLE=$NFQWS_ENABLE_OVERRIDE
|
|
||||||
FW_EXTRA_PRE="$FW_EXTRA_PRE_TPWS_IPT" FW_EXTRA_POST="$FW_EXTRA_POST_TPWS_IPT"
|
|
||||||
zapret_do_firewall_standard_tpws_rules_ipt $1
|
|
||||||
FW_EXTRA_PRE="$FW_EXTRA_PRE_NFQWS_IPT" FW_EXTRA_POST="$FW_EXTRA_POST_NFQWS_IPT"
|
|
||||||
zapret_do_firewall_standard_nfqws_rules_ipt $1
|
|
||||||
}
|
|
||||||
zapret_custom_firewall_nft()
|
|
||||||
{
|
|
||||||
# stop logic is not required
|
|
||||||
|
|
||||||
check_std_intersect || return
|
|
||||||
|
|
||||||
local FW_EXTRA_PRE FW_EXTRA_POST TPWS_ENABLE=$TPWS_ENABLE_OVERRIDE NFQWS_ENABLE=$NFQWS_ENABLE_OVERRIDE
|
|
||||||
FW_EXTRA_PRE="$FW_EXTRA_PRE_TPWS_NFT" FW_EXTRA_POST="$FW_EXTRA_POST_TPWS_NFT"
|
|
||||||
zapret_apply_firewall_standard_tpws_rules_nft
|
|
||||||
FW_EXTRA_PRE="$FW_EXTRA_PRE_NFQWS_NFT" FW_EXTRA_POST="$FW_EXTRA_POST_NFQWS_NFT"
|
|
||||||
zapret_apply_firewall_standard_nfqws_rules_nft
|
|
||||||
}
|
|
38
init.d/openwrt/custom.d.examples/50-dht4all
Normal file
38
init.d/openwrt/custom.d.examples/50-dht4all
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# this custom script runs desync to DHT packets with udp payload length 101..399 , without ipset/hostlist filtering
|
||||||
|
|
||||||
|
# can override in config :
|
||||||
|
NFQWS_OPT_DESYNC_DHT="${NFQWS_OPT_DESYNC_DHT:---dpi-desync=tamper}"
|
||||||
|
|
||||||
|
alloc_dnum DNUM_DHT4ALL
|
||||||
|
alloc_qnum QNUM_DHT4ALL
|
||||||
|
|
||||||
|
zapret_custom_daemons()
|
||||||
|
{
|
||||||
|
# stop logic is managed by procd
|
||||||
|
|
||||||
|
local opt="--qnum=$QNUM_DHT4ALL $NFQWS_OPT_BASE $NFQWS_OPT_DESYNC_DHT"
|
||||||
|
run_daemon $DNUM_DHT4ALL $NFQWS "$opt"
|
||||||
|
}
|
||||||
|
zapret_custom_firewall()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
local f uf4 uf6
|
||||||
|
local first_packet_only="$ipt_connbytes 1:1"
|
||||||
|
|
||||||
|
f='-p udp -m length --length 109:407 -m u32 --u32'
|
||||||
|
uf4='0>>22&0x3C@8>>16=0x6431'
|
||||||
|
uf6='48>>16=0x6431'
|
||||||
|
fw_nfqws_post $1 "$f $uf4 $first_packet_only" "$f $uf6 $first_packet_only" $QNUM_DHT4ALL
|
||||||
|
|
||||||
|
}
|
||||||
|
zapret_custom_firewall_nft()
|
||||||
|
{
|
||||||
|
# stop logic is not required
|
||||||
|
|
||||||
|
local f
|
||||||
|
local first_packet_only="$nft_connbytes 1"
|
||||||
|
|
||||||
|
f="meta length 109-407 meta l4proto udp @th,64,16 0x6431"
|
||||||
|
nft_fw_nfqws_post "$f $first_packet_only" "$f $first_packet_only" $QNUM_DHT4ALL
|
||||||
|
}
|
75
init.d/openwrt/custom.d.examples/50-discord
Normal file
75
init.d/openwrt/custom.d.examples/50-discord
Normal file
File diff suppressed because one or more lines are too long
89
init.d/openwrt/custom.d.examples/50-tpws-ipset
Normal file
89
init.d/openwrt/custom.d.examples/50-tpws-ipset
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
# this custom script demonstrates how to launch extra tpws instance limited by ipset
|
||||||
|
|
||||||
|
# can override in config :
|
||||||
|
TPWS_MY1_OPT="${TPWS_MY1_OPT:---oob --split-pos=midsld}"
|
||||||
|
TPWS_MY1_PORTS=${TPWS_MY1_PORTS:-$TPWS_PORTS}
|
||||||
|
TPWS_MY1_SUBNETS4="${TPWS_MY1_SUBNETS4:-142.250.0.0/15 64.233.160.0/19 172.217.0.0/16 173.194.0.0/16 108.177.0.0/17 74.125.0.0/16 209.85.128.0/17 216.58.192.0/19}"
|
||||||
|
TPWS_MY1_SUBNETS6="${TPWS_MY1_SUBNETS6:-2607:F8B0::/32 2a00:1450:4000::/37}"
|
||||||
|
|
||||||
|
TPWS_MY1_IPSET_SIZE=${TPWS_MY1_IPSET_SIZE:-4096}
|
||||||
|
TPWS_MY1_IPSET_OPT="${TPWS_MY1_IPSET_OPT:-hash:net hashsize 8192 maxelem $TPWS_MY1_IPSET_SIZE}"
|
||||||
|
|
||||||
|
alloc_dnum DNUM_TPWS_MY1
|
||||||
|
alloc_tpws_port PORT_TPWS_MY1
|
||||||
|
TPWS_MY1_NAME4=my1tpws4
|
||||||
|
TPWS_MY1_NAME6=my1tpws6
|
||||||
|
|
||||||
|
zapret_custom_daemons()
|
||||||
|
{
|
||||||
|
# stop logic is managed by procd
|
||||||
|
|
||||||
|
local opt="--port=$PORT_TPWS_MY1 $TPWS_MY1_OPT"
|
||||||
|
run_tpws $DNUM_TPWS_MY1 "$opt"
|
||||||
|
}
|
||||||
|
|
||||||
|
zapret_custom_firewall()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
local f4 f6 subnet
|
||||||
|
local PORTS_IPT=$(replace_char - : $TPWS_MY1_PORTS)
|
||||||
|
local dest_set="-m set --match-set $TPWS_MY1_NAME4 dst"
|
||||||
|
|
||||||
|
[ "$1" = 1 -a "$DISABLE_IPV4" != 1 ] && {
|
||||||
|
ipset create $TPWS_MY1_NAME4 $TPWS_MY1_IPSET_OPT family inet 2>/dev/null
|
||||||
|
ipset flush $TPWS_MY1_NAME4
|
||||||
|
for subnet in $TPWS_MY1_SUBNETS4; do
|
||||||
|
echo add $TPWS_MY1_NAME4 $subnet
|
||||||
|
done | ipset -! restore
|
||||||
|
}
|
||||||
|
[ "$1" = 1 -a "$DISABLE_IPV6" != 1 ] && {
|
||||||
|
ipset create $TPWS_MY1_NAME6 $TPWS_MY1_IPSET_OPT family inet6 2>/dev/null
|
||||||
|
ipset flush $TPWS_MY1_NAME6
|
||||||
|
for subnet in $TPWS_MY1_SUBNETS6; do
|
||||||
|
echo add $TPWS_MY1_NAME6 $subnet
|
||||||
|
done | ipset -! restore
|
||||||
|
}
|
||||||
|
|
||||||
|
f4="-p tcp -m multiport --dports $PORTS_IPT -m set --match-set"
|
||||||
|
f6="$f4 $TPWS_MY1_NAME6 dst"
|
||||||
|
f4="$f4 $TPWS_MY1_NAME4 dst"
|
||||||
|
fw_tpws $1 "$f4" "$f6" $PORT_TPWS_MY1
|
||||||
|
|
||||||
|
[ "$1" = 1 ] || {
|
||||||
|
ipset destroy $TPWS_MY1_NAME4 2>/dev/null
|
||||||
|
ipset destroy $TPWS_MY1_NAME6 2>/dev/null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zapret_custom_firewall_nft()
|
||||||
|
{
|
||||||
|
local f4 f6 subnet
|
||||||
|
|
||||||
|
[ "$DISABLE_IPV4" != 1 ] && {
|
||||||
|
make_comma_list subnets $TPWS_MY1_SUBNETS4
|
||||||
|
nft_create_set $TPWS_MY1_NAME4 "type ipv4_addr; size $TPWS_MY1_IPSET_SIZE; auto-merge; flags interval;"
|
||||||
|
nft_flush_set $TPWS_MY1_NAME4
|
||||||
|
nft_add_set_element $TPWS_MY1_NAME4 "$subnets"
|
||||||
|
}
|
||||||
|
[ "$DISABLE_IPV6" != 1 ] && {
|
||||||
|
make_comma_list subnets $TPWS_MY1_SUBNETS6
|
||||||
|
nft_create_set $TPWS_MY1_NAME6 "type ipv6_addr; size $TPWS_MY1_IPSET_SIZE; auto-merge; flags interval;"
|
||||||
|
nft_flush_set $TPWS_MY1_NAME6
|
||||||
|
nft_add_set_element $TPWS_MY1_NAME6 "$subnets"
|
||||||
|
}
|
||||||
|
|
||||||
|
f4="tcp dport {$TPWS_MY1_PORTS}"
|
||||||
|
f6="$f4 ip6 daddr @$TPWS_MY1_NAME6"
|
||||||
|
f4="$f4 ip daddr @$TPWS_MY1_NAME4"
|
||||||
|
nft_fw_tpws "$f4" "$f6" $PORT_TPWS_MY1
|
||||||
|
}
|
||||||
|
|
||||||
|
zapret_custom_firewall_nft_flush()
|
||||||
|
{
|
||||||
|
# this function is called after all nft fw rules are deleted
|
||||||
|
# however sets are not deleted. it's desired to clear sets here.
|
||||||
|
|
||||||
|
nft_del_set $TPWS_MY1_NAME4 2>/dev/null
|
||||||
|
nft_del_set $TPWS_MY1_NAME6 2>/dev/null
|
||||||
|
}
|
30
init.d/openwrt/custom.d.examples/50-wg4all
Normal file
30
init.d/openwrt/custom.d.examples/50-wg4all
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# this custom script runs desync to all wireguard handshake initiation packets
|
||||||
|
|
||||||
|
# can override in config :
|
||||||
|
NFQWS_OPT_DESYNC_WG="${NFQWS_OPT_DESYNC_WG:---dpi-desync=fake}"
|
||||||
|
|
||||||
|
alloc_dnum DNUM_WG4ALL
|
||||||
|
alloc_qnum QNUM_WG4ALL
|
||||||
|
|
||||||
|
zapret_custom_daemons()
|
||||||
|
{
|
||||||
|
# stop logic is managed by procd
|
||||||
|
|
||||||
|
local opt="--qnum=$QNUM_WG4ALL $NFQWS_OPT_BASE $NFQWS_OPT_DESYNC_WG"
|
||||||
|
run_daemon $DNUM_WG4ALL $NFQWS "$opt"
|
||||||
|
}
|
||||||
|
# size = 156 (8 udp header + 148 payload) && payload starts with 0x01000000
|
||||||
|
zapret_custom_firewall()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
local f='-p udp -m u32 --u32'
|
||||||
|
fw_nfqws_post $1 "$f 0>>22&0x3C@4>>16=0x9c&&0>>22&0x3C@8=0x01000000" "$f 44>>16=0x9c&&48=0x01000000" $QNUM_WG4ALL
|
||||||
|
}
|
||||||
|
zapret_custom_firewall_nft()
|
||||||
|
{
|
||||||
|
# stop logic is not required
|
||||||
|
|
||||||
|
local f="udp length 156 @th,64,32 0x01000000"
|
||||||
|
nft_fw_nfqws_post "$f" "$f" $QNUM_WG4ALL
|
||||||
|
}
|
@ -10,7 +10,6 @@ ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
|
|||||||
. "$ZAPRET_BASE/common/ipt.sh"
|
. "$ZAPRET_BASE/common/ipt.sh"
|
||||||
. "$ZAPRET_BASE/common/nft.sh"
|
. "$ZAPRET_BASE/common/nft.sh"
|
||||||
. "$ZAPRET_BASE/common/linux_fw.sh"
|
. "$ZAPRET_BASE/common/linux_fw.sh"
|
||||||
. "$ZAPRET_BASE/common/linux_daemons.sh"
|
|
||||||
. "$ZAPRET_BASE/common/list.sh"
|
. "$ZAPRET_BASE/common/list.sh"
|
||||||
. "$ZAPRET_BASE/common/custom.sh"
|
. "$ZAPRET_BASE/common/custom.sh"
|
||||||
CUSTOM_DIR="$ZAPRET_RW/init.d/openwrt"
|
CUSTOM_DIR="$ZAPRET_RW/init.d/openwrt"
|
||||||
|
@ -81,10 +81,6 @@ run_tpws()
|
|||||||
}
|
}
|
||||||
run_daemon $1 "$TPWS" "$OPT $2"
|
run_daemon $1 "$TPWS" "$OPT $2"
|
||||||
}
|
}
|
||||||
do_tpws()
|
|
||||||
{
|
|
||||||
[ "$1" = 0 ] || { shift; run_tpws "$@"; }
|
|
||||||
}
|
|
||||||
run_tpws_socks()
|
run_tpws_socks()
|
||||||
{
|
{
|
||||||
[ "$DISABLE_IPV4" = "1" ] && [ "$DISABLE_IPV6" = "1" ] && return 0
|
[ "$DISABLE_IPV4" = "1" ] && [ "$DISABLE_IPV6" = "1" ] && return 0
|
||||||
@ -94,10 +90,13 @@ run_tpws_socks()
|
|||||||
tpws_apply_socks_binds opt
|
tpws_apply_socks_binds opt
|
||||||
run_daemon $1 "$TPWS" "$opt $2"
|
run_daemon $1 "$TPWS" "$opt $2"
|
||||||
}
|
}
|
||||||
do_tpws_socks()
|
|
||||||
|
stop_tpws()
|
||||||
{
|
{
|
||||||
[ "$1" = 0 ] || { shift; run_tpws_socks "$@"; }
|
stop_daemon $1 "$TPWS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tpws_apply_socks_binds()
|
tpws_apply_socks_binds()
|
||||||
{
|
{
|
||||||
local o
|
local o
|
||||||
@ -106,27 +105,39 @@ tpws_apply_socks_binds()
|
|||||||
[ "$DISABLE_IPV6" = "1" ] || o="$o --bind-addr=::1"
|
[ "$DISABLE_IPV6" = "1" ] || o="$o --bind-addr=::1"
|
||||||
|
|
||||||
for lan in $OPENWRT_LAN; do
|
for lan in $OPENWRT_LAN; do
|
||||||
network_get_device DEVICE $lan
|
network_get_device DEVICE $lan
|
||||||
[ -n "$DEVICE" ] || continue
|
[ -n "$DEVICE" ] || continue
|
||||||
[ "$DISABLE_IPV4" = "1" ] || o="$o --bind-iface4=$DEVICE $TPWS_WAIT"
|
[ "$DISABLE_IPV4" = "1" ] || o="$o --bind-iface4=$DEVICE $TPWS_WAIT"
|
||||||
[ "$DISABLE_IPV6" = "1" ] || o="$o --bind-iface6=$DEVICE --bind-linklocal=unwanted $TPWS_WAIT_SOCKS6"
|
[ "$DISABLE_IPV6" = "1" ] || o="$o --bind-iface6=$DEVICE --bind-linklocal=unwanted $TPWS_WAIT_SOCKS6"
|
||||||
done
|
done
|
||||||
eval $1="\"\$$1 $o\""
|
eval $1="\"\$$1 $o\""
|
||||||
}
|
}
|
||||||
|
|
||||||
run_nfqws()
|
|
||||||
|
standard_mode_daemons()
|
||||||
{
|
{
|
||||||
run_daemon $1 "$NFQWS" "$NFQWS_OPT_BASE $2"
|
local opt
|
||||||
}
|
[ "$TPWS_ENABLE" = 1 ] && check_bad_ws_options 1 "$TPWS_OPT" && {
|
||||||
do_nfqws()
|
opt="--port=$TPPORT $TPWS_OPT"
|
||||||
{
|
filter_apply_hostlist_target opt
|
||||||
[ "$1" = 0 ] || { shift; run_nfqws "$@"; }
|
run_tpws 1 "$opt"
|
||||||
|
}
|
||||||
|
[ "$TPWS_SOCKS_ENABLE" = 1 ] && {
|
||||||
|
opt="--port=$TPPORT_SOCKS $TPWS_SOCKS_OPT"
|
||||||
|
filter_apply_hostlist_target opt
|
||||||
|
run_tpws_socks 2 "$opt"
|
||||||
|
}
|
||||||
|
[ "$NFQWS_ENABLE" = 1 ] && check_bad_ws_options 1 "$NFQWS_OPT" && {
|
||||||
|
opt="--qnum=$QNUM $NFQWS_OPT_BASE $NFQWS_OPT"
|
||||||
|
filter_apply_hostlist_target opt
|
||||||
|
run_daemon 3 "$NFQWS" "$opt"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start_daemons_procd()
|
start_daemons_procd()
|
||||||
{
|
{
|
||||||
standard_mode_daemons 1
|
standard_mode_daemons
|
||||||
custom_runner zapret_custom_daemons 1
|
custom_runner zapret_custom_daemons
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,4 @@ pfctl -d ; pfctl -e
|
|||||||
ipfw delete 100
|
ipfw delete 100
|
||||||
ipfw add 100 divert 989 tcp from any to any 80,443 out not diverted not sockarg
|
ipfw add 100 divert 989 tcp from any to any 80,443 out not diverted not sockarg
|
||||||
pkill ^dvtws$
|
pkill ^dvtws$
|
||||||
dvtws --daemon --port 989 --dpi-desync=multisplit
|
dvtws --daemon --port 989 --dpi-desync=split2
|
||||||
|
@ -8,7 +8,7 @@ alloc_qnum QNUM_DHT4ALL
|
|||||||
|
|
||||||
zapret_custom_daemons()
|
zapret_custom_daemons()
|
||||||
{
|
{
|
||||||
# $1 - 1 - add, 0 - stop
|
# stop logic is managed by procd
|
||||||
|
|
||||||
local opt="--qnum=$QNUM_DHT4ALL $NFQWS_OPT_DESYNC_DHT"
|
local opt="--qnum=$QNUM_DHT4ALL $NFQWS_OPT_DESYNC_DHT"
|
||||||
do_nfqws $1 $DNUM_DHT4ALL "$opt"
|
do_nfqws $1 $DNUM_DHT4ALL "$opt"
|
@ -8,7 +8,7 @@ alloc_qnum QNUM_WG4ALL
|
|||||||
|
|
||||||
zapret_custom_daemons()
|
zapret_custom_daemons()
|
||||||
{
|
{
|
||||||
# $1 - 1 - add, 0 - stop
|
# stop logic is managed by procd
|
||||||
|
|
||||||
local opt="--qnum=$QNUM_WG4ALL $NFQWS_OPT_DESYNC_WG"
|
local opt="--qnum=$QNUM_WG4ALL $NFQWS_OPT_DESYNC_WG"
|
||||||
do_nfqws $1 $DNUM_WG4ALL "$opt"
|
do_nfqws $1 $DNUM_WG4ALL "$opt"
|
@ -10,7 +10,6 @@ ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"}
|
|||||||
. "$ZAPRET_BASE/common/ipt.sh"
|
. "$ZAPRET_BASE/common/ipt.sh"
|
||||||
. "$ZAPRET_BASE/common/nft.sh"
|
. "$ZAPRET_BASE/common/nft.sh"
|
||||||
. "$ZAPRET_BASE/common/linux_fw.sh"
|
. "$ZAPRET_BASE/common/linux_fw.sh"
|
||||||
. "$ZAPRET_BASE/common/linux_daemons.sh"
|
|
||||||
. "$ZAPRET_BASE/common/list.sh"
|
. "$ZAPRET_BASE/common/list.sh"
|
||||||
. "$ZAPRET_BASE/common/custom.sh"
|
. "$ZAPRET_BASE/common/custom.sh"
|
||||||
CUSTOM_DIR="$ZAPRET_RW/init.d/sysv"
|
CUSTOM_DIR="$ZAPRET_RW/init.d/sysv"
|
||||||
@ -276,3 +275,45 @@ create_ipset()
|
|||||||
echo "Creating ip list table (firewall type $FWTYPE)"
|
echo "Creating ip list table (firewall type $FWTYPE)"
|
||||||
"$IPSET_CR" "$@"
|
"$IPSET_CR" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
standard_mode_daemons()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
local opt
|
||||||
|
|
||||||
|
[ "$TPWS_ENABLE" = 1 ] && check_bad_ws_options $1 "$TPWS_OPT" && {
|
||||||
|
opt="--port=$TPPORT $TPWS_OPT"
|
||||||
|
filter_apply_hostlist_target opt
|
||||||
|
do_tpws $1 1 "$opt"
|
||||||
|
}
|
||||||
|
[ "$TPWS_SOCKS_ENABLE" = 1 ] && {
|
||||||
|
opt="--port=$TPPORT_SOCKS $TPWS_SOCKS_OPT"
|
||||||
|
filter_apply_hostlist_target opt
|
||||||
|
do_tpws_socks $1 2 "$opt"
|
||||||
|
}
|
||||||
|
[ "$NFQWS_ENABLE" = 1 ] && check_bad_ws_options $1 "$NFQWS_OPT" && {
|
||||||
|
opt="--qnum=$QNUM $NFQWS_OPT"
|
||||||
|
filter_apply_hostlist_target opt
|
||||||
|
do_nfqws $1 3 "$opt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zapret_do_daemons()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
standard_mode_daemons $1
|
||||||
|
custom_runner zapret_custom_daemons $1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
zapret_run_daemons()
|
||||||
|
{
|
||||||
|
zapret_do_daemons 1 "$@"
|
||||||
|
}
|
||||||
|
zapret_stop_daemons()
|
||||||
|
{
|
||||||
|
zapret_do_daemons 0 "$@"
|
||||||
|
}
|
||||||
|
@ -394,7 +394,7 @@ copy_openwrt()
|
|||||||
mkdir "$2/tpws" "$2/nfq" "$2/ip2net" "$2/mdig" "$2/binaries" "$2/binaries/$ARCH" "$2/init.d" "$2/tmp" "$2/files"
|
mkdir "$2/tpws" "$2/nfq" "$2/ip2net" "$2/mdig" "$2/binaries" "$2/binaries/$ARCH" "$2/init.d" "$2/tmp" "$2/files"
|
||||||
cp -R "$1/files/fake" "$2/files"
|
cp -R "$1/files/fake" "$2/files"
|
||||||
cp -R "$1/common" "$1/ipset" "$2"
|
cp -R "$1/common" "$1/ipset" "$2"
|
||||||
cp -R "$1/init.d/openwrt" "$1/init.d/custom.d.examples.linux" "$2/init.d"
|
cp -R "$1/init.d/openwrt" "$2/init.d"
|
||||||
cp "$1/config" "$1/config.default" "$1/install_easy.sh" "$1/uninstall_easy.sh" "$1/install_bin.sh" "$1/install_prereq.sh" "$1/blockcheck.sh" "$2"
|
cp "$1/config" "$1/config.default" "$1/install_easy.sh" "$1/uninstall_easy.sh" "$1/install_bin.sh" "$1/install_prereq.sh" "$1/blockcheck.sh" "$2"
|
||||||
cp "$BINDIR/tpws" "$BINDIR/nfqws" "$BINDIR/ip2net" "$BINDIR/mdig" "$2/binaries/$ARCH"
|
cp "$BINDIR/tpws" "$BINDIR/nfqws" "$BINDIR/ip2net" "$BINDIR/mdig" "$2/binaries/$ARCH"
|
||||||
}
|
}
|
||||||
|
17
nfq/nfqws.c
17
nfq/nfqws.c
@ -192,7 +192,7 @@ static bool nfq_init(struct nfq_handle **h,struct nfq_q_handle **qh)
|
|||||||
|
|
||||||
DLOG_CONDUP("binding this socket to queue '%u'\n", params.qnum);
|
DLOG_CONDUP("binding this socket to queue '%u'\n", params.qnum);
|
||||||
*qh = nfq_create_queue(*h, params.qnum, &nfq_cb, ¶ms);
|
*qh = nfq_create_queue(*h, params.qnum, &nfq_cb, ¶ms);
|
||||||
if (!*qh) {
|
if (!qh) {
|
||||||
DLOG_PERROR("nfq_create_queue()");
|
DLOG_PERROR("nfq_create_queue()");
|
||||||
goto exiterr;
|
goto exiterr;
|
||||||
}
|
}
|
||||||
@ -238,15 +238,18 @@ static int nfq_main(void)
|
|||||||
int fd,e;
|
int fd,e;
|
||||||
ssize_t rd;
|
ssize_t rd;
|
||||||
|
|
||||||
|
#ifndef __CYGWIN__
|
||||||
sec_harden();
|
sec_harden();
|
||||||
|
|
||||||
if (params.droproot && !droproot(params.uid, params.gid))
|
if (params.droproot && !droproot(params.uid, params.gid))
|
||||||
return 1;
|
goto exiterr;
|
||||||
|
|
||||||
print_id();
|
print_id();
|
||||||
|
#endif
|
||||||
|
|
||||||
pre_desync();
|
pre_desync();
|
||||||
|
|
||||||
if (!nfq_init(&h,&qh))
|
nfq_init(&h,&qh);
|
||||||
return 1;
|
|
||||||
|
|
||||||
fd = nfq_fd(h);
|
fd = nfq_fd(h);
|
||||||
do
|
do
|
||||||
@ -269,7 +272,13 @@ static int nfq_main(void)
|
|||||||
} while(e==ENOBUFS);
|
} while(e==ENOBUFS);
|
||||||
|
|
||||||
nfq_deinit(&h,&qh);
|
nfq_deinit(&h,&qh);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
exiterr:
|
||||||
|
if (qh) nfq_destroy_queue(qh);
|
||||||
|
if (h) nfq_close(h);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(BSD)
|
#elif defined(BSD)
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#define TLS_PARTIALS_ENABLE true
|
#define TLS_PARTIALS_ENABLE true
|
||||||
|
|
||||||
|
#define Q_RCVBUF (128*1024) // in bytes
|
||||||
|
#define Q_SNDBUF (64*1024) // in bytes
|
||||||
#define RAW_SNDBUF (64*1024) // in bytes
|
#define RAW_SNDBUF (64*1024) // in bytes
|
||||||
|
|
||||||
#define Q_MAXLEN 1024 // in packets
|
#define Q_MAXLEN 1024 // in packets
|
||||||
|
Loading…
x
Reference in New Issue
Block a user