【问题标题】:Lua Script in suricata to detect the change in filesuricata中的Lua脚本来检测文件的变化
【发布时间】:2021-09-02 17:08:10
【问题描述】:

我是 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;)


【问题讨论】:

  • 您创建此帖子时单击的按钮标有“”。我在这里没有看到任何问题。
  • 你能指定你是否使用linux发行版吗?

标签: lua suricata


【解决方案1】:

除非你有一些其他的 open 函数现在显示在你的 sn-p 中,否则 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的内容。但这只是我个人的看法。

【讨论】:

  • 感谢您的回答。您能否指导我如何获取正在下载的文件。正如你所说,init() 将返回表格。
  • 对不起,我不知道 Surricata。类似的信息可以在 surricata 手册中找到。抱歉,没时间为您阅读。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-20
  • 2019-02-19
  • 1970-01-01
  • 2010-11-29
  • 1970-01-01
相关资源
最近更新 更多