fast.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. -- This is a simple example script to show what you can do with lua output scripts.
  2. -- It prints logs similar to the ones produced by the builtin fast.log output
  3. -- faciltiy to stdout, hence its name.
  4. -- In the init() function we tell suricata, that we want the log function to be
  5. -- called for every packet that produces an alert (see needs variable)
  6. -- Then in the log() function we get various informations about this packet via
  7. -- SCRuleMsg() and all the other API functions and print them to stdout with print()
  8. -- To learn more about all the API functions suricata provides for your lua scripts
  9. -- and the lua output extension in general see:
  10. -- http://suricata.readthedocs.io/en/latest/output/lua-output.html
  11. function init()
  12. local needs = {}
  13. needs["type"] = "packet"
  14. needs["filter"] = "alerts"
  15. return needs
  16. end
  17. function setup()
  18. alert_count = 0
  19. end
  20. function log()
  21. timestring = SCPacketTimeString()
  22. sid, rev, gid = SCRuleIds()
  23. msg = SCRuleMsg()
  24. class, priority = SCRuleClass()
  25. ip_version, src_ip, dst_ip, protocol, src_port, dst_port = SCPacketTuple()
  26. if class == nil then
  27. class = "unknown"
  28. end
  29. print (timestring .. " [**] [" .. gid .. ":" .. sid .. ":" .. rev .. "] " ..
  30. msg .. " [**] [Classification: " .. class .. "] [Priority: " ..
  31. priority .. "] {" .. protocol .. "} " ..
  32. src_ip .. ":" .. src_port .. " -> " .. dst_ip .. ":" .. dst_port)
  33. alert_count = alert_count + 1;
  34. end
  35. function deinit()
  36. print ("Alerted " .. alert_count .. " times");
  37. end