使用 Lua 脚本检查 Cisco AnyConnect

我们正在尝试为 Cisco AnyConnect 客户端部署动态访问策略 (DAP),以检查最终用户的计算机是否已安装并运行反病毒软件、防火墙是否已启用并运行,并且具有某些 Windows 更新 (KB)。 Cisco 有一个漂亮的网站,展示了这些不同的脚本,但是我们想将这三个脚本合并成一个。

以下是代码和显示反病毒软件和防火墙检查的 Lua 脚本的网站。请帮助我将此脚本与 Hotfix KB 检查合并。 https://www.cisco.com/c/en/us/support/docs/security/asa-5500-x-series-next-generation-firewalls/115947-dap-adv-functions-00.html#anc9

预先感谢

        assert(function()
    function checkav(antix)
        if (type(antix) == "table") then
            for k,v in pairs(antix) do
                if (EVAL(v.activescan, "EQ", "ok", "string") and EVAL (v.lastupdate, "LT", "2592000", "integer")) then
                    return true
                end
            end
        end
        return false
    end
    function checkfw(antix)
        if (type(antix) == "table") then
            for k,v in pairs(antix) do
                if (EVAL(v.enabled, "EQ", "ok", "string")) then
                    return true
                end
            end
        end
        return false
    end
    return (checkav(endpoint.av) and checkfw(endpoint.fw))
end)()
    assert(function ()
    local pattern = "KB944"
    local true_on_match = true
    local match = false
    for k,v in pairs(endpoint.os.hotfix) do
        print(k)
        match = string.find(k, pattern)
        if (match) then
            if (true_on_match) then
                return true
            else return (false)
            end
        end
    end
end)()
点赞
用户4403144
用户4403144

前进的方向:分离功能。然后,您可以调用断言并使用逻辑“and”组合调用:

热补丁 KB 检查:

function hotfixKb()
    local pattern = "KB944"
    local true_on_match = true
    local match = false
    for k,v in pairs(endpoint.os.hotfix) do
        print(k)
        match = string.find(k, pattern)
        if (match) then
            if (true_on_match) then
                return true
            else
                return (false)
            end
        end
    end
end

杀毒软件检查:

function checkAntiVirus(antix)
    if (type(antix) == "table") then
        for k,v in pairs(antix) do
            if (EVAL(v.activescan, "EQ", "ok", "string") and EVAL (v.lastupdate, "LT", "2592000", "integer")) then
                return true
            end
        end
    end

    return false
end

防火墙检查:

function checkFireWall(antix)
    if (type(antix) == "table") then
        for k,v in pairs(antix) do
            if (EVAL(v.enabled, "EQ", "ok", "string")) then
                return true
            end
        end
    end

    return false
end

然后:

assert(hotfixKb() and checkAntiVirus() and checkFireWall())
2018-07-19 03:01:14