Skip to content

Commit 3042359

Browse files
author
bol-van
committed
zapret-lib: detect_payload_str
1 parent 27ef67a commit 3042359

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ v0.6
7878
v0.6.1
7979

8080
* zapret-lib, zapret-auto: condition and stopif orchestrators
81+
* zapret-lib: detect_payload_str - sample lua payload detector

lua/zapret-lib.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ function posdebug(ctx,desync)
6161
DLOG(s)
6262
end
6363

64+
-- basic desync function
65+
-- set l7payload to 'arg.payload' if reasm.data or desync.dis.payload contains 'arg.pattern' substring
66+
-- NOTE : this does not set payload on C code side !
67+
-- NOTE : C code will not see payload change. --payload args take only payloads known to C code and cause error if unknown.
68+
-- arg: pattern - substring for search inside reasm_data or desync.dis.payload
69+
-- arg: payload - set desync.l7payload to this if detected
70+
-- arg: undetected - set desync.l7payload to this if not detected
71+
-- test case : nfqws2 --qnum 200 --debug --lua-init=@zapret-lib.lua --lua-init=@zapret-antidpi.lua --lua-init=@zapret-auto.lua --lua-desync=detect_payload_str:pattern=1234:payload=my --lua-desync=fake:blob=0x1234:payload=my
72+
function detect_payload_str(ctx, desync)
73+
if not desync.arg.pattern then
74+
error("detect_payload_str: missing 'pattern'")
75+
end
76+
local data = desync.reasm_data or desync.dis.payload
77+
local b = string.find(data,desync.arg.pattern,1,true)
78+
if b then
79+
DLOG("detect_payload_str: detected '"..desync.arg.payload.."'")
80+
if desync.arg.payload then desync.l7payload = desync.arg.payload end
81+
else
82+
DLOG("detect_payload_str: not detected '"..desync.arg.payload.."'")
83+
if desync.arg.undetected then desync.l7payload = desync.arg.undetected end
84+
end
85+
end
86+
87+
6488
-- this shim is needed then function is orchestrated. ctx services not available
6589
-- have to emulate cutoff in LUA using connection persistent table track.lua_state
6690
function instance_cutoff_shim(ctx, desync, dir)

0 commit comments

Comments
 (0)