fix: zapret2 fixes and xray update
This commit is contained in:
11 files changed
+217
-39
No files matched your search
@@ -326,7 +326,9 @@ blocked\. When off, only ` zapret2.domains ` and ` proxy-ctl zapret auto add ` a
|
|||||||
Learn with proxy-suite’s detector instead of nfqws2’s\. It also learns sites blocked
|
Learn with proxy-suite’s detector instead of nfqws2’s\. It also learns sites blocked
|
||||||
only some of the time (a working connection no longer clears the failures before it),
|
only some of the time (a working connection no longer clears the failures before it),
|
||||||
downloads that stall partway (the 16 KB cutoff), and requests that never get an
|
downloads that stall partway (the 16 KB cutoff), and requests that never get an
|
||||||
answer\. Learned sites are logged with ` strategyLog `\. Only with the source’s own
|
answer\. It also follows learned sites past the first 4 KB a strategy is judged on:
|
||||||
|
one whose downloads keep stalling keeps the proxy’s route (` zapret.directSync `)\.
|
||||||
|
Learned sites are logged with ` strategyLog `\. Only with the source’s own
|
||||||
` profiles `, and for TLS: nfqws2-keenetic no longer learns plain HTTP sites\.
|
` profiles `, and for TLS: nfqws2-keenetic no longer learns plain HTTP sites\.
|
||||||
|
|
||||||
**Type:** boolean\
|
**Type:** boolean\
|
||||||
@@ -409,9 +411,11 @@ Extra fake payloads by name (blob=\<name>): a file in zapret2’s files/fake, or
|
|||||||
## services\.proxy-suite\.zapret\.zapret2\.cutoff\.enable
|
## services\.proxy-suite\.zapret\.zapret2\.cutoff\.enable
|
||||||
|
|
||||||
Work around ISPs that cut TLS to some hosting networks after about 16 KB, which no
|
Work around ISPs that cut TLS to some hosting networks after about 16 KB, which no
|
||||||
strategy fixes\. A daily probe finds the affected networks and a whitelisted name that
|
strategy fixes\. A daily probe finds the affected networks, and with
|
||||||
gets through for each\. Only with ` strategySource = "z2k" `\. Each run makes thousands of
|
` strategySource = "z2k" ` (and its own ` profiles `) a whitelisted name that gets
|
||||||
short direct connections\. ` proxy-ctl zapret cutoff ` shows the results\.
|
through for each, which z2k puts into a fake ClientHello\. Otherwise no name is
|
||||||
|
searched for, and every affected network is left to ` proxyFallback `\. Each run makes
|
||||||
|
thousands of short direct connections\. ` proxy-ctl zapret cutoff ` shows the results\.
|
||||||
|
|
||||||
**Type:** boolean\
|
**Type:** boolean\
|
||||||
**Default:** `true`
|
**Default:** `true`
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ in
|
|||||||
Learn with proxy-suite's detector instead of nfqws2's. It also learns sites blocked
|
Learn with proxy-suite's detector instead of nfqws2's. It also learns sites blocked
|
||||||
only some of the time (a working connection no longer clears the failures before it),
|
only some of the time (a working connection no longer clears the failures before it),
|
||||||
downloads that stall partway (the 16 KB cutoff), and requests that never get an
|
downloads that stall partway (the 16 KB cutoff), and requests that never get an
|
||||||
answer. Learned sites are logged with `strategyLog`. Only with the source's own
|
answer. It also follows learned sites past the first 4 KB a strategy is judged on:
|
||||||
|
one whose downloads keep stalling keeps the proxy's route (`zapret.directSync`).
|
||||||
|
Learned sites are logged with `strategyLog`. Only with the source's own
|
||||||
`profiles`, and for TLS: nfqws2-keenetic no longer learns plain HTTP sites.
|
`profiles`, and for TLS: nfqws2-keenetic no longer learns plain HTTP sites.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -173,9 +175,11 @@ in
|
|||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Work around ISPs that cut TLS to some hosting networks after about 16 KB, which no
|
Work around ISPs that cut TLS to some hosting networks after about 16 KB, which no
|
||||||
strategy fixes. A daily probe finds the affected networks and a whitelisted name that
|
strategy fixes. A daily probe finds the affected networks, and with
|
||||||
gets through for each. Only with `strategySource = "z2k"`. Each run makes thousands of
|
`strategySource = "z2k"` (and its own `profiles`) a whitelisted name that gets
|
||||||
short direct connections. `proxy-ctl zapret cutoff` shows the results.
|
through for each, which z2k puts into a fake ClientHello. Otherwise no name is
|
||||||
|
searched for, and every affected network is left to `proxyFallback`. Each run makes
|
||||||
|
thousands of short direct connections. `proxy-ctl zapret cutoff` shows the results.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,22 @@ for f in asn.txt sni.txt asn.new sni.new proxy.json proxy.json.tmp egress ts for
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
touch asn.txt sni.txt
|
touch asn.txt sni.txt
|
||||||
|
# The rule-set from the maps as they stand, rewritten only when it changes: sing-box
|
||||||
|
# reloads it on every rename.
|
||||||
|
rules() {
|
||||||
|
@proxyRules@ asn.txt sni.txt @lists@/tcp16_nets.txt >proxy.json.tmp
|
||||||
|
if cmp -s proxy.json.tmp proxy.json; then
|
||||||
|
rm -f proxy.json.tmp
|
||||||
|
else
|
||||||
|
mv -f proxy.json.tmp proxy.json
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Names no profile puts in fix nothing: none kept from when one did, so every cut-off
|
||||||
|
# network goes to the proxy now, not after the next probe.
|
||||||
|
if [ @names@ = 0 ] && [ -s sni.txt ]; then
|
||||||
|
: >sni.txt
|
||||||
|
rules
|
||||||
|
fi
|
||||||
force=0
|
force=0
|
||||||
if [ -e requests/force ] || [ -L requests/force ]; then
|
if [ -e requests/force ] || [ -L requests/force ]; then
|
||||||
force=1
|
force=1
|
||||||
@@ -59,8 +75,13 @@ z2k-detect tcp16 -targets @lists@/tcp16_targets.txt -parallel 50 -asn-out asn.ne
|
|||||||
case "$rc" in
|
case "$rc" in
|
||||||
1)
|
1)
|
||||||
rc=0
|
rc=0
|
||||||
|
# No profile puts a name in: the cut-off networks are all there is to know.
|
||||||
|
if [ @names@ = 0 ]; then
|
||||||
|
: >sni.new
|
||||||
|
else
|
||||||
z2k-detect tcp16 -targets @lists@/tcp16_targets.txt -scan @lists@/sni_wl_candidates.txt \
|
z2k-detect tcp16 -targets @lists@/tcp16_targets.txt -scan @lists@/sni_wl_candidates.txt \
|
||||||
-per-asn -batch 5 -parallel 50 -sni-out sni.new || rc=$?
|
-per-asn -batch 5 -parallel 50 -sni-out sni.new || rc=$?
|
||||||
|
fi
|
||||||
# 2: no network took any name; the list of cut-off networks still stands.
|
# 2: no network took any name; the list of cut-off networks still stands.
|
||||||
if [ "$rc" != 0 ] && [ "$rc" != 2 ]; then
|
if [ "$rc" != 0 ] && [ "$rc" != 2 ]; then
|
||||||
rm -f asn.new sni.new
|
rm -f asn.new sni.new
|
||||||
@@ -84,8 +105,7 @@ changed=0
|
|||||||
{ cmp -s asn.new asn.txt && cmp -s sni.new sni.txt; } || changed=1
|
{ cmp -s asn.new asn.txt && cmp -s sni.new sni.txt; } || changed=1
|
||||||
mv -f asn.new asn.txt
|
mv -f asn.new asn.txt
|
||||||
mv -f sni.new sni.txt
|
mv -f sni.new sni.txt
|
||||||
@proxyRules@ asn.txt sni.txt @lists@/tcp16_nets.txt >proxy.json.tmp
|
rules
|
||||||
mv -f proxy.json.tmp proxy.json
|
|
||||||
printf '%s\n' "$egress" >egress
|
printf '%s\n' "$egress" >egress
|
||||||
printf '%s\n' "$now" >ts
|
printf '%s\n' "$now" >ts
|
||||||
echo "cut-off networks: $(grep -c '^[0-9]' asn.txt || true), with a name: $(grep -c '^[0-9]' sni.txt || true)"
|
echo "cut-off networks: $(grep -c '^[0-9]' asn.txt || true), with a name: $(grep -c '^[0-9]' sni.txt || true)"
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ let
|
|||||||
# The z2k flake.lock holds, whatever `z2k` the consumer passes (pkgs/z2k-detect.nix).
|
# The z2k flake.lock holds, whatever `z2k` the consumer passes (pkgs/z2k-detect.nix).
|
||||||
z2kDetect = packages.z2k-detect;
|
z2kDetect = packages.z2k-detect;
|
||||||
|
|
||||||
|
# Only z2k's own profiles put the name in (z2k-tcp16.lua, ahead of rotation; ahead of
|
||||||
|
# the nfqws2-keenetic strategies it broke hosts, sources.nix). Elsewhere a name found
|
||||||
|
# fixes nothing: every cut-off network goes to the proxy, and no name is searched for.
|
||||||
|
namesApply = cfg.zapret.zapret2.strategySource == "z2k" && cfg.zapret.zapret2.profiles == null;
|
||||||
|
|
||||||
# $1 asn.txt, $2 sni.txt, $3 AS-to-prefix map; prints a sing-box source rule-set
|
# $1 asn.txt, $2 sni.txt, $3 AS-to-prefix map; prints a sing-box source rule-set
|
||||||
# with the prefixes of every cut-off network that no whitelisted name fixes.
|
# with the prefixes of every cut-off network that no whitelisted name fixes.
|
||||||
proxyRules = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
proxyRules = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||||
@@ -59,6 +64,7 @@ let
|
|||||||
z2kDetect
|
z2kDetect
|
||||||
];
|
];
|
||||||
dir = lib.escapeShellArg dir;
|
dir = lib.escapeShellArg dir;
|
||||||
|
names = if namesApply then "1" else "0";
|
||||||
inherit lists proxyRules;
|
inherit lists proxyRules;
|
||||||
restartUnits = lib.escapeShellArgs restartUnits;
|
restartUnits = lib.escapeShellArgs restartUnits;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@
|
|||||||
-- "kind<TAB>name<TAB>proto<TAB>note<TAB>time" (the last line per name and proto wins), for
|
-- "kind<TAB>name<TAB>proto<TAB>note<TAB>time" (the last line per name and proto wins), for
|
||||||
-- direct-sync.template.sh and proxy-ctl:
|
-- direct-sync.template.sh and proxy-ctl:
|
||||||
-- - works <site> tcp|udp: a strategy got through; only then does a learned site go direct;
|
-- - works <site> tcp|udp: a strategy got through; only then does a learned site go direct;
|
||||||
-- - stalls <host> cutoff: learned from transfers cut short (the 16 KB cutoff); such a site
|
-- - stalls <host> cutoff: learned from transfers cut short (the 16 KB cutoff), or learned
|
||||||
-- keeps the proxy's route whatever "works" says, as success is judged on the first 4 KB;
|
-- otherwise and cut short since (ps_watch); such a site keeps the proxy's route whatever
|
||||||
|
-- "works" says, as success is judged on the first 4 KB;
|
||||||
-- - unfixable <site> tcp|udp: every strategy failed in turn; the proxy carries it;
|
-- - unfixable <site> tcp|udp: every strategy failed in turn; the proxy carries it;
|
||||||
-- - blocked <ip> ip: connections to it go unanswered (blocked by address, ps_syn), and
|
-- - blocked <ip> ip: connections to it go unanswered (blocked by address, ps_syn), and
|
||||||
-- reachable <ip> ip once one is answered again;
|
-- reachable <ip> ip once one is answered again;
|
||||||
@@ -355,6 +356,30 @@ local function feed(st, data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- The server's next segment: fed in order, one that came early held until the gap fills.
|
||||||
|
local function receive(st, desync, payload)
|
||||||
|
local s = pos_get(desync, "s")
|
||||||
|
if s == st.next then
|
||||||
|
feed(st, payload)
|
||||||
|
st.next = s + #payload
|
||||||
|
while st.pending[st.next] do
|
||||||
|
local p = st.pending[st.next]
|
||||||
|
st.pending[st.next] = nil
|
||||||
|
feed(st, p)
|
||||||
|
st.next = st.next + #p
|
||||||
|
end
|
||||||
|
elseif s > st.next then
|
||||||
|
st.pending[s] = payload
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The server went quiet inside a TLS record, while the window still showed its packets.
|
||||||
|
-- Past the NFQUEUE window nothing more is seen: no telling a stall from the rest.
|
||||||
|
local function cut_short(st, arg)
|
||||||
|
if st.done or st.notls or st.inpk >= (tonumber(arg.win) or 15) then return false end
|
||||||
|
return st.need > 0 or #st.hdr > 0 or next(st.pending) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
-- nfqws2's own fast fail: a reset to the client retransmitting into silence, so it
|
-- nfqws2's own fast fail: a reset to the client retransmitting into silence, so it
|
||||||
-- gives up (and tries again) instead of waiting out its timeouts.
|
-- gives up (and tries again) instead of waiting out its timeouts.
|
||||||
local function reset_client(desync)
|
local function reset_client(desync)
|
||||||
@@ -377,9 +402,7 @@ end
|
|||||||
|
|
||||||
function ps_learn_stall(_, data)
|
function ps_learn_stall(_, data)
|
||||||
local st = data.st
|
local st = data.st
|
||||||
-- Past the NFQUEUE window nothing more is seen: no telling a stall from the rest.
|
if cut_short(st, data.arg) then
|
||||||
if st.done or st.notls or st.inpk >= (tonumber(data.arg.win) or 15) then return end
|
|
||||||
if st.need > 0 or #st.hdr > 0 or next(st.pending) then
|
|
||||||
failure(st, data.arg, "transfer stalled after " .. math.floor((st.next - 1) / 1024) .. " KB", true)
|
failure(st, data.arg, "transfer stalled after " .. math.floor((st.next - 1) / 1024) .. " KB", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -419,19 +442,7 @@ function ps_learn(_, desync)
|
|||||||
end
|
end
|
||||||
if #payload > 0 then
|
if #payload > 0 then
|
||||||
st.answered = true
|
st.answered = true
|
||||||
local s = pos_get(desync, "s")
|
receive(st, desync, payload)
|
||||||
if s == st.next then
|
|
||||||
feed(st, payload)
|
|
||||||
st.next = s + #payload
|
|
||||||
while st.pending[st.next] do
|
|
||||||
local p = st.pending[st.next]
|
|
||||||
st.pending[st.next] = nil
|
|
||||||
feed(st, p)
|
|
||||||
st.next = st.next + #p
|
|
||||||
end
|
|
||||||
elseif s > st.next then
|
|
||||||
st.pending[s] = payload
|
|
||||||
end
|
|
||||||
if st.name then
|
if st.name then
|
||||||
-- Replacing the timer restarts its countdown: it fires once the server goes quiet.
|
-- Replacing the timer restarts its countdown: it fires once the server goes quiet.
|
||||||
timer_set("psls_" .. st.name, ps_learn_stall, STALL_MS, true, { st = st, arg = desync.arg })
|
timer_set("psls_" .. st.name, ps_learn_stall, STALL_MS, true, { st = st, arg = desync.arg })
|
||||||
@@ -440,6 +451,56 @@ function ps_learn(_, desync)
|
|||||||
if bitand(flags, TH_FIN) ~= 0 then st.done = true end
|
if bitand(flags, TH_FIN) ~= 0 then st.done = true end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- --- learned sites cut off ---------------------------------------------------------------
|
||||||
|
|
||||||
|
-- A learned site goes direct once a strategy gets it through, judged on the first 4 KB,
|
||||||
|
-- which the 16 KB cutoff lets through; a site learned for another failure (a ClientHello
|
||||||
|
-- retransmitted) carries no "stalls" verdict from ps_learn, which sees no listed site.
|
||||||
|
-- ps_watch, ahead of rotation in the profile that takes the learned sites, follows each
|
||||||
|
-- transfer on: one cut short `fails` times within `time` seconds is a "stalls" verdict,
|
||||||
|
-- and the site keeps the proxy's route.
|
||||||
|
|
||||||
|
function ps_watch_stall(_, data)
|
||||||
|
local st = data.st
|
||||||
|
if not cut_short(st, data.arg) then return end
|
||||||
|
st.done = true
|
||||||
|
local n, need = tally("cut " .. st.host, tonumber(data.arg.time) or 300), tonumber(data.arg.fails) or 3
|
||||||
|
if data.arg.log then
|
||||||
|
say(st.host .. ": transfer stalled after " .. math.floor((st.next - 1) / 1024) .. " KB (" .. n .. "/" .. need .. " to keep it on the proxy)")
|
||||||
|
end
|
||||||
|
if n >= need then
|
||||||
|
if status[st.host .. " cutoff"] ~= "stalls" then say(st.host .. ": its transfers are cut short, the proxy carries it") end
|
||||||
|
verdict("stalls", st.host, "cutoff", "transfers cut short")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ps_watch(_, desync)
|
||||||
|
local track, dis = desync.track, desync.dis
|
||||||
|
if not (track and dis and dis.tcp) or not track.hostname or track.hostname_is_ip then return end
|
||||||
|
local st = track.lua_state.ps_watch
|
||||||
|
if not st then
|
||||||
|
st = { host = track.hostname:lower(), next = 1, need = 0, hdr = "", pending = {}, inpk = 0 }
|
||||||
|
track.lua_state.ps_watch = st
|
||||||
|
end
|
||||||
|
if st.done then return end
|
||||||
|
local flags = dis.tcp.th_flags
|
||||||
|
-- A client that hangs up mid-transfer (a cancelled page) says nothing of the site.
|
||||||
|
if bitand(flags, TH_RST) ~= 0 or (desync.outgoing and bitand(flags, TH_FIN) ~= 0) then
|
||||||
|
st.done = true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if desync.outgoing then return end
|
||||||
|
st.inpk = pos_get(desync, "n") or (st.inpk + 1)
|
||||||
|
local payload = dis.payload or ""
|
||||||
|
if #payload > 0 then
|
||||||
|
receive(st, desync, payload)
|
||||||
|
-- Named by the server's direction, the one it is reset by.
|
||||||
|
st.name = st.name or dis_timer_name(dis)
|
||||||
|
timer_set("psws_" .. st.name, ps_watch_stall, STALL_MS, true, { st = st, arg = desync.arg })
|
||||||
|
end
|
||||||
|
if bitand(flags, TH_FIN) ~= 0 then st.done = true end
|
||||||
|
end
|
||||||
|
|
||||||
-- --- addresses blocked outright ------------------------------------------------------------
|
-- --- addresses blocked outright ------------------------------------------------------------
|
||||||
|
|
||||||
-- No strategy helps where the connection itself goes unanswered: the address is blocked,
|
-- No strategy helps where the connection itself goes unanswered: the address is blocked,
|
||||||
|
|||||||
@@ -70,11 +70,13 @@ let
|
|||||||
|
|
||||||
# lib.trim drops string context: without it the source's list paths are no build input,
|
# lib.trim drops string context: without it the source's list paths are no build input,
|
||||||
# so lazy trees never materialize them and the closure omits them.
|
# so lazy trees never materialize them and the closure omits them.
|
||||||
|
# <STALLWATCH>: where the source's profile for learned sites takes stallWatch.
|
||||||
renderProfile =
|
renderProfile =
|
||||||
profile:
|
profile:
|
||||||
lib.replaceStrings hostlistMarkers (map (
|
lib.replaceStrings (hostlistMarkers ++ [ "<STALLWATCH> " ]) (
|
||||||
marker: marker + withSpaces staticListArgs
|
map (marker: marker + withSpaces staticListArgs) hostlistMarkers
|
||||||
) hostlistMarkers) (lib.addContextFrom profile (lib.trim profile));
|
++ [ (lib.optionalString (stallWatch != "") (stallWatch + " ")) ]
|
||||||
|
) (lib.addContextFrom profile (lib.trim profile));
|
||||||
|
|
||||||
# detect.lua learns in place of nfqws2's autohostlist, in a last TLS profile of its
|
# detect.lua learns in place of nfqws2's autohostlist, in a last TLS profile of its
|
||||||
# own: z2k-profiles.template.sh puts it there, tailProfiles for nfqws2-keenetic.
|
# own: z2k-profiles.template.sh puts it there, tailProfiles for nfqws2-keenetic.
|
||||||
@@ -97,8 +99,25 @@ let
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# detect.lua's ps_watch, ahead of every other instance of the profile that takes the
|
||||||
|
# learned sites, so rotation (an orchestrator: it runs the instances after it) leaves it
|
||||||
|
# be; it sees the server's bytes past what rotation judges a success on, and the
|
||||||
|
# profile's filters are back at nfqws2's defaults after it.
|
||||||
|
stallWatch = lib.optionalString learnLua (
|
||||||
|
"--in-range=-s65536 --payload=all --lua-desync=ps_watch:"
|
||||||
|
+ lib.concatStringsSep ":" (
|
||||||
|
[
|
||||||
|
"fails=${toString autoCfg.failThreshold}"
|
||||||
|
"time=${toString autoCfg.failTime}"
|
||||||
|
"win=${toString packetWindow.tcpIn}"
|
||||||
|
]
|
||||||
|
++ lib.optional zapret2Cfg.strategyLog "log"
|
||||||
|
)
|
||||||
|
+ " --in-range=x --payload=all"
|
||||||
|
);
|
||||||
|
|
||||||
z2kGenerated = sources.z2k.mkProfiles {
|
z2kGenerated = sources.z2k.mkProfiles {
|
||||||
inherit learnArgs;
|
inherit learnArgs stallWatch;
|
||||||
hostlistSuffix = withSpaces staticListArgs;
|
hostlistSuffix = withSpaces staticListArgs;
|
||||||
# z2k's category profiles filter on their own lists, not on a marker.
|
# z2k's category profiles filter on their own lists, not on a marker.
|
||||||
excludeSuffix = withSpaces ([ "--hostlist-exclude=${excludeHostlistFile}" ] ++ excludeDomainArgs);
|
excludeSuffix = withSpaces ([ "--hostlist-exclude=${excludeHostlistFile}" ] ++ excludeDomainArgs);
|
||||||
|
|||||||
@@ -83,9 +83,12 @@ let
|
|||||||
# No 16 KB cutoff name step: its fake ClientHello ahead of these strategies
|
# No 16 KB cutoff name step: its fake ClientHello ahead of these strategies
|
||||||
# broke every host on a line where the strategies alone work. Its HTTP strategy
|
# broke every host on a line where the strategies alone work. Its HTTP strategy
|
||||||
# has no strategy=N, so circular must not take http_req: it would skip it.
|
# has no strategy=N, so circular must not take http_req: it would skip it.
|
||||||
|
# <STALLWATCH>: it takes the learned sites (runtime.nix). ps_watch there makes
|
||||||
|
# circular the profile's second instance: keyed as nfqws2 named it before
|
||||||
|
# (<func>_<profile>_<nth instance>), its sites keep the strategies remembered.
|
||||||
"${
|
"${
|
||||||
patch "NFQWS_ARGS" "${tcpPayload} ${circular}"
|
patch "NFQWS_ARGS" "${tcpPayload} ${circular}"
|
||||||
"--in-range=-s5556 ${tcpPayload},tls_server_hello,empty,unknown ${circular} --in-range=x ${tcpPayload}"
|
"<STALLWATCH> --in-range=-s5556 ${tcpPayload},tls_server_hello,empty,unknown ${circular}:key=circular_3_1 --in-range=x ${tcpPayload}"
|
||||||
(args "NFQWS_ARGS")
|
(args "NFQWS_ARGS")
|
||||||
} <HOSTLIST> ${lists}"
|
} <HOSTLIST> ${lists}"
|
||||||
];
|
];
|
||||||
@@ -166,6 +169,7 @@ let
|
|||||||
hostlistSuffix,
|
hostlistSuffix,
|
||||||
excludeSuffix,
|
excludeSuffix,
|
||||||
learnArgs ? "",
|
learnArgs ? "",
|
||||||
|
stallWatch ? "",
|
||||||
}:
|
}:
|
||||||
pkgs.runCommand "proxy-suite-zapret2-z2k-profiles" {
|
pkgs.runCommand "proxy-suite-zapret2-z2k-profiles" {
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
@@ -176,7 +180,12 @@ let
|
|||||||
gnugrep
|
gnugrep
|
||||||
gnused
|
gnused
|
||||||
];
|
];
|
||||||
inherit hostlistSuffix excludeSuffix learnArgs;
|
inherit
|
||||||
|
hostlistSuffix
|
||||||
|
excludeSuffix
|
||||||
|
learnArgs
|
||||||
|
stallWatch
|
||||||
|
;
|
||||||
} (fillTemplate ./z2k-profiles.template.sh { z2k = src; });
|
} (fillTemplate ./z2k-profiles.template.sh { z2k = src; });
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -44,11 +44,14 @@ grep -q -- '--lua-desync=circular' raw || { echo "z2k generator produced no prof
|
|||||||
# instead, in the same last place. It cannot ride along on the autohostlist profile:
|
# instead, in the same last place. It cannot ride along on the autohostlist profile:
|
||||||
# nfqws2 applies nothing there to a host in no list, Lua included. It writes the
|
# nfqws2 applies nothing there to a host in no list, Lua included. It writes the
|
||||||
# same auto list and reads the same excludes, which it checks itself.
|
# same auto list and reads the same excludes, which it checks itself.
|
||||||
|
#
|
||||||
|
# $stallWatch (detect.lua's ps_watch) goes first among the instances of the profile
|
||||||
|
# that takes the learned sites, ahead of its in-profile filters, which it resets after.
|
||||||
awk -v disc="--hostlist=$root/lists/discovered-domains.txt" \
|
awk -v disc="--hostlist=$root/lists/discovered-domains.txt" \
|
||||||
-v wl="--hostlist-exclude=$root/lists/whitelist.txt" \
|
-v wl="--hostlist-exclude=$root/lists/whitelist.txt" \
|
||||||
-v yt="--hostlist-exclude=$root/extra_strats/TCP/YT/List.txt --hostlist-exclude=$root/extra_strats/TCP/YT_GV/List.txt" \
|
-v yt="--hostlist-exclude=$root/extra_strats/TCP/YT/List.txt --hostlist-exclude=$root/extra_strats/TCP/YT_GV/List.txt" \
|
||||||
-v hsuf="$hostlistSuffix" -v esuf="$excludeSuffix" \
|
-v hsuf="$hostlistSuffix" -v esuf="$excludeSuffix" \
|
||||||
-v learn="$learnArgs" -v wlfile="$root/lists/whitelist.txt" '
|
-v learn="$learnArgs" -v wlfile="$root/lists/whitelist.txt" -v watch="$stallWatch" '
|
||||||
{
|
{
|
||||||
for (i = 1; i <= NF; i++) {
|
for (i = 1; i <= NF; i++) {
|
||||||
t = $i
|
t = $i
|
||||||
@@ -57,9 +60,18 @@ awk -v disc="--hostlist=$root/lists/discovered-domains.txt" \
|
|||||||
} else if (t ~ /^--filter-tcp=/ && !(prof in ports)) {
|
} else if (t ~ /^--filter-tcp=/ && !(prof in ports)) {
|
||||||
ports[prof] = substr(t, 14)
|
ports[prof] = substr(t, 14)
|
||||||
}
|
}
|
||||||
|
pre = ""
|
||||||
|
if (t ~ /^--(in-range|out-range|payload|lua-desync)=/) {
|
||||||
|
if (watch != "" && seen && prof == learner && !watched++) pre = watch " "
|
||||||
|
filtered[prof] = 1
|
||||||
|
}
|
||||||
if (t == disc) {
|
if (t == disc) {
|
||||||
t = "<HOSTLIST_NOAUTO>" hsuf
|
t = "<HOSTLIST_NOAUTO>" hsuf
|
||||||
if (!seen++) { t = t " " yt; learner = prof }
|
if (!seen++) {
|
||||||
|
t = t " " yt
|
||||||
|
learner = prof
|
||||||
|
if (prof in filtered) { print "z2k general TLS profile: hostlist after its instances" > "/dev/stderr"; exit 1 }
|
||||||
|
}
|
||||||
} else if (t == wl) {
|
} else if (t == wl) {
|
||||||
t = t esuf
|
t = t esuf
|
||||||
} else if (t ~ /^--lua-desync=circular:/) {
|
} else if (t ~ /^--lua-desync=circular:/) {
|
||||||
@@ -68,11 +80,12 @@ awk -v disc="--hostlist=$root/lists/discovered-domains.txt" \
|
|||||||
for (j = 1; j <= n; j++)
|
for (j = 1; j <= n; j++)
|
||||||
if (p[j] !~ /^(retrans|maxseq|inseq)=/ && p[j] != "reset") t = t ":" p[j]
|
if (p[j] !~ /^(retrans|maxseq|inseq)=/ && p[j] != "reset") t = t ":" p[j]
|
||||||
}
|
}
|
||||||
printf "%s%s", (i > 1 ? " " : ""), t
|
printf "%s%s%s", (i > 1 ? " " : ""), pre, t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
if (!seen || !(learner in ports)) { print "z2k general TLS profile not found" > "/dev/stderr"; exit 1 }
|
if (!seen || !(learner in ports)) { print "z2k general TLS profile not found" > "/dev/stderr"; exit 1 }
|
||||||
|
if (watch != "" && !watched) { print "z2k general TLS profile has no instances" > "/dev/stderr"; exit 1 }
|
||||||
if (learn == "")
|
if (learn == "")
|
||||||
printf " --new --filter-tcp=%s --filter-l7=tls %s%s <HOSTLIST>%s", ports[learner], wl, esuf, hsuf
|
printf " --new --filter-tcp=%s --filter-l7=tls %s%s <HOSTLIST>%s", ports[learner], wl, esuf, hsuf
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ let
|
|||||||
daemonStart = zapret2Global.config.systemd.services.${globalService}.serviceConfig.ExecStart;
|
daemonStart = zapret2Global.config.systemd.services.${globalService}.serviceConfig.ExecStart;
|
||||||
cutoffProbe =
|
cutoffProbe =
|
||||||
zapret2Global.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart;
|
zapret2Global.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart;
|
||||||
|
z2kCutoffProbe =
|
||||||
|
zapret2Z2k.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart;
|
||||||
socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart;
|
socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart;
|
||||||
directSync = builtins.head (
|
directSync = builtins.head (
|
||||||
lib.splitString " " zapret2Global.config.systemd.services.proxy-suite-zapret2-direct.serviceConfig.ExecStart
|
lib.splitString " " zapret2Global.config.systemd.services.proxy-suite-zapret2-direct.serviceConfig.ExecStart
|
||||||
@@ -319,6 +321,13 @@ in
|
|||||||
# nfqws2-keenetic learns with detect.lua too: its own profile only reads the auto list.
|
# nfqws2-keenetic learns with detect.lua too: its own profile only reads the auto list.
|
||||||
grep -qE -- " --new --filter-tcp=443 --filter-l7=tls --in-range=-s65536 --out-range=-s32768 --payload=all --lua-desync=ps_learn:auto=[^ ]+:exclude=[^ ]+/etc/nfqws2/lists/exclude.list,[^ ]+zapret-hosts-user-exclude.txt:" "${globalRuntime}/config"
|
grep -qE -- " --new --filter-tcp=443 --filter-l7=tls --in-range=-s65536 --out-range=-s32768 --payload=all --lua-desync=ps_learn:auto=[^ ]+:exclude=[^ ]+/etc/nfqws2/lists/exclude.list,[^ ]+zapret-hosts-user-exclude.txt:" "${globalRuntime}/config"
|
||||||
test "$(grep -oF -- '<HOSTLIST>' "${globalRuntime}/config" | wc -l)" = 0
|
test "$(grep -oF -- '<HOSTLIST>' "${globalRuntime}/config" | wc -l)" = 0
|
||||||
|
# The profile that takes the learned sites follows their transfers ahead of rotation,
|
||||||
|
# its filters back at their defaults after; circular keeps its name for its sites.
|
||||||
|
grep -qE -- " --in-range=-s65536 --payload=all --lua-desync=ps_watch:fails=3:time=300:win=32:log --in-range=x --payload=all --in-range=-s5556 [^ ]+ --lua-desync=circular:[^ ]*:key=circular_3_1:" "${globalRuntime}/config"
|
||||||
|
grep -qE -- " --lua-desync=ps_watch:fails=3:time=300:win=32:log --in-range=x --payload=all --out-range=-s34228 --in-range=-s5556 --lua-desync=z2k_sni_pick:[^ ]*:key=rkn_tcp:" "${z2kRuntime}/config"
|
||||||
|
test "$(grep -oF -- 'ps_watch:' "${z2kRuntime}/config" | wc -l)" = 1
|
||||||
|
if grep -qF -- 'ps_watch' "${tunedRuntime}/config"; then exit 1; fi
|
||||||
|
if grep -qF -- '<STALLWATCH>' "${tunedRuntime}/config"; then exit 1; fi
|
||||||
# Counted failures and switches, named by circular key and host; the switch
|
# Counted failures and switches, named by circular key and host; the switch
|
||||||
# is the one that stuck, after the state layer's revert.
|
# is the one that stuck, after the state layer's revert.
|
||||||
LOG=$(grep -oE '/nix/store/[^ ]+-strategy-log\.lua' "${z2kRuntime}/config") lua -e '
|
LOG=$(grep -oE '/nix/store/[^ ]+-strategy-log\.lua' "${z2kRuntime}/config") lua -e '
|
||||||
@@ -456,6 +465,11 @@ in
|
|||||||
printf '24940\t300.ya.ru\n14061\tad.adriver.ru\n' >sni.txt
|
printf '24940\t300.ya.ru\n14061\tad.adriver.ru\n' >sni.txt
|
||||||
test "$("$rules" asn.txt sni.txt nets.txt)" = '{"version":1,"rules":[]}'
|
test "$("$rules" asn.txt sni.txt nets.txt)" = '{"version":1,"rules":[]}'
|
||||||
|
|
||||||
|
# A name helps only where z2k's profiles put it in: elsewhere none is searched for,
|
||||||
|
# one kept from before is dropped, and every cut-off network goes to the proxy.
|
||||||
|
grep -qF -- 'if [ 0 = 0 ] && [ -s sni.txt ]; then' ${cutoffProbe}
|
||||||
|
grep -qF -- 'if [ 1 = 0 ] && [ -s sni.txt ]; then' ${z2kCutoffProbe}
|
||||||
|
|
||||||
# The probe is built from z2k's source and knows its tcp16 mode.
|
# The probe is built from z2k's source and knows its tcp16 mode.
|
||||||
detect=$(grep -o '/nix/store/[^:]*-z2k-detect-[^:/]*/bin' ${cutoffProbe} | head -n1)
|
detect=$(grep -o '/nix/store/[^:]*-z2k-detect-[^:/]*/bin' ${cutoffProbe} | head -n1)
|
||||||
"$detect/z2k-detect" tcp16 -h 2>/dev/null
|
"$detect/z2k-detect" tcp16 -h 2>/dev/null
|
||||||
|
|||||||
@@ -235,6 +235,34 @@ end
|
|||||||
assert(verdicts()["149.154.167.99 ip"] == "blocked" and not verdicts()["192.168.1.1 ip"], "blocked by address")
|
assert(verdicts()["149.154.167.99 ip"] == "blocked" and not verdicts()["192.168.1.1 ip"], "blocked by address")
|
||||||
syn("149.154.167.99", true)
|
syn("149.154.167.99", true)
|
||||||
assert(verdicts()["149.154.167.99 ip"] == "reachable", "an answer clears it")
|
assert(verdicts()["149.154.167.99 ip"] == "reachable", "an answer clears it")
|
||||||
|
-- A learned site a strategy got through, cut short past the first 4 KB since: three cut
|
||||||
|
-- transfers keep it on the proxy. Finished ones, ones the client hung up on, and ones
|
||||||
|
-- past the queue window say nothing.
|
||||||
|
local function watch(track, outgoing, opts) ps_watch(nil, packet(track, outgoing, opts)) end
|
||||||
|
for i = 1, 3 do
|
||||||
|
local t = flow("i.scdn.co")
|
||||||
|
watch(t, true, { l7 = "tls_client_hello", payload = "hello" })
|
||||||
|
watch(t, false, { s = 1, payload = record(16000) .. string.rep("x", 6000), n = 5 })
|
||||||
|
watch(t, false, { s = 6006, payload = string.rep("x", 2000), n = 7 })
|
||||||
|
fire("psws_")
|
||||||
|
assert((verdicts()["i.scdn.co cutoff"] == "stalls") == (i == 3), "stalls after three cut transfers")
|
||||||
|
end
|
||||||
|
for _, case in ipairs({ "whole", "hangup", "big" }) do
|
||||||
|
for _ = 1, 3 do
|
||||||
|
local t = flow(case .. ".example")
|
||||||
|
if case == "whole" then
|
||||||
|
watch(t, false, { s = 1, payload = record(3) .. "abc", n = 2 })
|
||||||
|
elseif case == "hangup" then
|
||||||
|
watch(t, false, { s = 1, payload = record(16000) .. "x", n = 2 })
|
||||||
|
watch(t, true, { flags = TH_FIN + 16 })
|
||||||
|
else
|
||||||
|
watch(t, false, { s = 1, payload = record(60000) .. "z", n = 32 })
|
||||||
|
end
|
||||||
|
fire("psws_")
|
||||||
|
end
|
||||||
|
assert(not verdicts()[case .. ".example cutoff"], case .. ": no verdict")
|
||||||
|
end
|
||||||
|
|
||||||
-- A wildcard domain whose every fresh name resets: past its share of the list, the site
|
-- A wildcard domain whose every fresh name resets: past its share of the list, the site
|
||||||
-- itself is learned, which covers the rest, rather than one more name of it.
|
-- itself is learned, which covers the rest, rather than one more name of it.
|
||||||
local f2 = io.open(auto, "a")
|
local f2 = io.open(auto, "a")
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
version = "26.10.10";
|
version = "26.10.21";
|
||||||
base =
|
base =
|
||||||
if lib.versionAtLeast pkgs.xray.version version then
|
if lib.versionAtLeast pkgs.xray.version version then
|
||||||
pkgs.xray
|
pkgs.xray
|
||||||
@@ -23,7 +23,7 @@ let
|
|||||||
owner = "XTLS";
|
owner = "XTLS";
|
||||||
repo = "Xray-core";
|
repo = "Xray-core";
|
||||||
rev = "v${finalAttrs.version}";
|
rev = "v${finalAttrs.version}";
|
||||||
hash = "sha256-M6biUT2RgP4xNGj9RUAVG7rrGNm65+sWL7pRQpbpWFI=";
|
hash = "sha256-1FwcB/qZaH7W9b+GSe+CG/s+uStaDjz792OxDc3uAyg=";
|
||||||
};
|
};
|
||||||
vendorHash = "sha256-XfTEpPMKyIhaoG53omH5rewI86QFNc9pnzhvZvxgFp0=";
|
vendorHash = "sha256-XfTEpPMKyIhaoG53omH5rewI86QFNc9pnzhvZvxgFp0=";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user