Added unexpected SMTP plugin

This commit is contained in:
Daniele Zulberti 2020-10-09 16:30:02 +02:00
parent cff77b49cf
commit d74caa9d2b
5 changed files with 141 additions and 0 deletions

View file

@ -0,0 +1,75 @@
--
-- (C) 2019-20 - ntop.org
--
local user_scripts = require("user_scripts")
local flow_consts = require("flow_consts")
-- #################################################################
local script = {
-- Script category
category = user_scripts.script_categories.security,
-- Priority
prio = -20, -- Lower priority (executed after) than default 0 priority
-- NOTE: hooks defined below
hooks = {},
-- use this plugin only with this protocol
l7_proto_id = 3, -- 3 == SMTP
-- Specify the default value whe clicking on the "Reset Default" button
default_value = {
items = {},
},
-- The frequency for the periodicUpdate hook invocation. Must be
-- multiple of 30 seconds.
periodic_update_seconds = 30,
gui = {
i18n_title = "unexpected_smtp.unexpected_smtp_title",
i18n_description = "unexpected_smtp.unexpected_smtp_description",
input_builder = "items_list",
item_list_type = "string",
input_title = i18n("unexpected_smtp.title"),
input_description = i18n("unexpected_smtp.description"),
}
}
-- #################################################################
function script.hooks.protocolDetected(now, conf)
ok = 0
server_ip = flow.getServerKey()
-- the fortmat of the string returned by flow.geServerKey() is "x.x.x.x@0", :sub(1, -3) deletes "@0"
server_ip = server_ip:sub(1, -3)
for _, smtp_ip in pairs(conf.items or script.default_value.items) do
if server_ip == smtp_ip then
ok = 1
end
end
if ok == 0 then
flow.triggerStatus(
flow_consts.status_types.status_unexpected_smtp.create(
flow_consts.status_types.status_unexpected_smtp.alert_severity,
server_ip
),
100, -- flow_score
0, -- cli_score
100 --srv_score
)
end
end
-- #################################################################
return script