0

我是lua编程的新手。我正在寻找一个 lua 脚本,它可以读取通过 Suricata 从 Internet 下载的文件并检测文件是否已更改。任何帮助,将不胜感激。提前致谢。

像这样的东西:

function init(args)
    return {http.response_body = tostring(true)}
end

local function read_file(path)
    local file = open(path, "rb") -- r read mode and b binary mode
    if not file then return nil end
    local content = file:read "*a" -- *a or *all reads the whole file
    file:close()
    return content
end

local fileContent = read_file(path-to-where-previous-file-is-stored);
local fileContent2 = read_file(init());

if fileContent != fileContent2:
     print("File changed")

如果内容相同则阻塞

drop http any any -> any any (msg:"NVISO PDF file lua"; flow:established,to_client; luajit:pdfcheckname.lua; classtype:policy-violation; sid:1000000; rev:1;)


4

1 回答 1

0

除非您有一些其他open功能现在显示在您的代码段中,local file = open(path, "rb")否则应替换为local file = io.open(path, "rb")

local fileContent2 = read_file(init());将导致问题,因为init()将返回一个表,而不是路径字符串。这样调用的时候会报错io.open

if fileContent != fileContent2:
     print("File changed")

语法不正确。

将其替换为

if fileContent != fileContent2 then
  print("File Changed")
end

类似的名称file2Content也更有意义,因为它不是文件的第二个内容,而是文件 2 的内容。但这只是我个人的看法。

于 2021-09-02T09:02:39.407 回答