From 584d3b5925d44b736c7d4e05475e1364cc621f87 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 30 Jan 2026 16:37:19 +0300 Subject: [PATCH] zapret-obfs: synhide more magics --- lua/zapret-obfs.lua | 107 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 8 deletions(-) diff --git a/lua/zapret-obfs.lua b/lua/zapret-obfs.lua index da99815..cc57dac 100644 --- a/lua/zapret-obfs.lua +++ b/lua/zapret-obfs.lua @@ -260,16 +260,30 @@ end -- test case : -- client: -- --in-range=" administratively prohibited + x2 = 1 + end + + local kind + if desync.arg.kind then + kind = tonumber(desync.arg.kind) + -- do not allow noop and end + if kind<2 or kind>0xFF then + error("synhide: invalid kind value") + end + else + -- some firewalls allow only AECN bit (1). if reserved bits are !=0 => administratively prohibited + kind = 172 -- accurate ecn + end + + local opt + if desync.arg.opt then + opt = parse_hex(desync.arg.opt) + if not opt then + error("synhide: invalid opt value") + end + else + opt="" + end local function make_magic(client) local m @@ -290,13 +353,41 @@ function synhide(ctx, desync) return m end local function set_magic(client) - desync.dis.tcp.th_urp = make_magic(client) + if magic=="tsecr" then + desync.dis.tcp.options[tsidx].data = string.sub(desync.dis.tcp.options[tsidx].data,1,6) .. bu16(make_magic(client)) + elseif magic=="x2" then + desync.dis.tcp.th_x2 = bitor(desync.dis.tcp.th_x2, x2) + elseif magic=="urp" then + desync.dis.tcp.th_urp = make_magic(client) + elseif magic=="opt" then + table.insert(desync.dis.tcp.options, {kind=kind, data=opt}) + end end local function ver_magic(client) - return desync.dis.tcp.th_urp == make_magic(client) + if magic=="tsecr" then + return make_magic(client)==u16(string.sub(desync.dis.tcp.options[tsidx].data,7)) + elseif magic=="x2" then + return bitand(desync.dis.tcp.th_x2, x2)~=0 + elseif magic=="urp" then + return desync.dis.tcp.th_urp == make_magic(client) + elseif magic=="opt" then + local idx = find_tcp_option(desync.dis.tcp.options, kind) + return idx and desync.dis.tcp.options[idx].data == opt + end end local function clear_magic() - return desync.dis.tcp.th_urp == 0 + if magic=="tsecr" then + desync.dis.tcp.options[tsidx].data = string.sub(desync.dis.tcp.options[tsidx].data,1,6) .. "\x00\x00" + elseif magic=="x2" then + desync.dis.tcp.th_x2 = bitand(desync.dis.tcp.th_x2,bitnot(1)) + elseif magic=="urp" then + desync.dis.tcp.th_urp = 0 + elseif magic=="opt" then + local idx = find_tcp_option(desync.dis.tcp.options, kind) + if idx then + table.remove(desync.dis.tcp.options, idx) + end + end end if fl==TH_SYN then