|
| 1 | +-- |
| 2 | +-- (C) 2019-24 - ntop.org |
| 3 | +-- |
| 4 | + |
| 5 | +-- ############################################## |
| 6 | + |
| 7 | +local flow_alert_keys = require "flow_alert_keys" |
| 8 | +local json = require "dkjson" |
| 9 | +local format_utils = require "format_utils" |
| 10 | +-- Import the classes library. |
| 11 | +local classes = require "classes" |
| 12 | +-- Make sure to import the Superclass! |
| 13 | +local alert = require "alert" |
| 14 | +-- Import Mitre Att&ck utils |
| 15 | +local mitre = require "mitre_utils" |
| 16 | + |
| 17 | +-- ############################################## |
| 18 | + |
| 19 | +local alert_s7comm_invalid_transition = classes.class(alert) |
| 20 | + |
| 21 | +-- ############################################## |
| 22 | + |
| 23 | +alert_s7comm_invalid_transition.meta = { |
| 24 | + alert_key = flow_alert_keys.flow_alert_s7comm_invalid_transition, |
| 25 | + i18n_title = "flow_checks.s7comm_invalid_transition", |
| 26 | + icon = "fas fa-fw fa-industry", |
| 27 | + |
| 28 | + -- Mitre Att&ck Matrix values |
| 29 | + mitre_values = { |
| 30 | + mitre_tactic = mitre.tactic.impact, |
| 31 | + mitre_technique = mitre.technique.data_manipulation, |
| 32 | + mitre_id = "T1565" |
| 33 | + }, |
| 34 | +} |
| 35 | + |
| 36 | +-- ############################################## |
| 37 | + |
| 38 | +-- @brief Prepare an alert table used to generate the alert |
| 39 | +-- @param last_error A string with the lastest influxdb error |
| 40 | +-- @return A table with the alert built |
| 41 | +function alert_s7comm_invalid_transition:init() |
| 42 | + -- Call the parent constructor |
| 43 | + self.super:init() |
| 44 | +end |
| 45 | + |
| 46 | +-- ############################################## |
| 47 | + |
| 48 | +local function function_code_to_string(function_id) |
| 49 | + -- S7Comm function codes |
| 50 | + if(function_id == 0x04) then return("Read Var (" .. function_id .. ")") end |
| 51 | + if(function_id == 0x05) then return("Write Var (" .. function_id .. ")") end |
| 52 | + if(function_id == 0xf0) then return("Setup Communication (" .. function_id .. ")") end |
| 53 | + if(function_id == 0x00) then return("CPU Services (" .. function_id .. ")") end |
| 54 | + if(function_id == 0x29) then return("PLC Control (" .. function_id .. ")") end |
| 55 | + if(function_id == 0x28) then return("PLC Stop (" .. function_id .. ")") end |
| 56 | + |
| 57 | + return(function_id) |
| 58 | +end |
| 59 | + |
| 60 | +-- ####################################################### |
| 61 | + |
| 62 | +-- @brief Format an alert into a human-readable string |
| 63 | +-- @param ifid The integer interface id of the generated alert |
| 64 | +-- @param alert The alert description table, including alert data such as the generating entity, timestamp, granularity, type |
| 65 | +-- @param alert_type_params Table `alert_type_params` as built in the `:init` method |
| 66 | +-- @return A human-readable string |
| 67 | +function alert_s7comm_invalid_transition.format(ifid, alert, alert_type_params) |
| 68 | + local from = function_code_to_string(alert_type_params.from) or alert_type_params.from or i18n('unknown') |
| 69 | + local to = function_code_to_string(alert_type_params.to) or alert_type_params.to or i18n('unknown') |
| 70 | + |
| 71 | + local rsp = from .. " -> ".. to |
| 72 | + |
| 73 | + -- tprint(alert_type_params) |
| 74 | + |
| 75 | + return(rsp) |
| 76 | +end |
| 77 | + |
| 78 | +-- ####################################################### |
| 79 | + |
| 80 | +return alert_s7comm_invalid_transition |
0 commit comments