Bug #9243
closedlua: block string.dump in sandbox
Description
Summary¶
The Lua sandbox that rule scripts run under replaces every non-allowlisted
library function with a stub that raises "Blocked Lua function called:
<name>". The allowlist is per-module in "IsAllowed()"
("src/util-lua-sandbox.c"); every "string" table entry except "dump" is
blocked. "string.dump" stayed on the allowlist, so it is the one blocked
category that a rule script can still call.
What string.dump does¶
"string.dump(f)" serializes a function object to its compiled bytecode
(portable Lua bytecode format, the inverse of the blocked "load" /
"loadstring"). The resulting blob contains, for the dumped function:
- the full prototype: parameter list and compiled instruction stream
- every embedded constant (strings, numbers) and the debug constants
(chunk name, local and upvalue names) - the upvalue structure (which slots are captured)
Why that is harmful in a rule script¶
Rule scripts are less trusted than the operator: in managed or
multi-tenant deployments third parties author rules that execute on the
sensor. The sandbox's block list exists to keep such scripts limited to
the inspection APIs. With "string.dump" allowed:
- Information leak / exfiltration. A script can serialize any
function it can name (its own functions, stdlib functions, library
closures in its environment), and move the resulting plain string out
through whatever output path the script legitimately has (Lua logging
to eve/alert output, the file library). The blob is portable, so it
can be taken off the sensor and inspected or re-loaded in any
external Lua 5.4 interpreter. - It is the "code to bytes" half of "load". "load" / "loadstring"
are blocked precisely to keep "bytes in, code executed" out of reach;
"string.dump" is the inverse direction. Left open, the pair is
separated by a single stub, and any future weakening of the load side
turns dump output directly into code execution. - It breaks the block-list contract. Every probed sibling raises
"Blocked Lua function called: X"; one silently working entry reads
as an oversight, not a decision, and undermines the block list's
credibility for anyone enumerating the sandbox.
Reproduction¶
pre. alert tcp any any -> any any (msg:"dump"; flow:to_server; lua:"dump.lua"; sid:1; rev:1;)
with "dump.lua":
local f = function() return 42 end
local blob, err = string.dump(f)
lua.log("dump ok", tostring(blob ~= nil))
On an unfixed engine "string.dump" returns the bytecode string (no
error). On the fixed engine the call raises "Blocked Lua function
called: dump" like every other blocked function, and the error is
counted in the ".transform.lua.blocked_function_errors" counter.
Fix¶
Remove "dump" from the "string" allowlist in "IsAllowed()"
("src/util-lua-sandbox.c") so the sandbox installs the block stub for
it. A call then raises like its siblings and is counted in
".transform.lua.blocked_function_errors". No legitimate rule serializes
functions, so no supported behaviour changes.