SSH --- SSH事务的详细信息通过 ``suricata.ssh`` 库暴露给Lua脚本。例如:: local ssh = require("suricata.ssh") 如需使用hassh功能,可在suricata.yaml中设置 ``app-layer.protocols.ssh.hassh`` 为true, 或在Lua脚本的 ``init`` 函数中调用 ``ssh.enable_hassh()`` 来启用:: function init (args) ssh.enable_hassh() return {} end 用于规则匹配时,规则必须**挂钩**到SSH事务状态。可用状态见 :ref:`ssh-hooks`。 例如: .. container:: example-rule alert ssh::example-rule-emphasis:`response_banner_done` any any -> any any (... 配置 ^^^^^ 若需创建日志脚本,按如下方式初始化缓冲区:: function init (args) local needs = {} return needs end 若将脚本用于规则匹配,请选择 :ref:`lua-detection` 中列出的可用SSH缓冲区, 并按以下模式操作:: function init (args) local needs = {} return needs end 事务 ~~~~~~~~~~~ SSH基于事务机制,使用前需获取当前事务:: local tx, err = ssh.get_tx() if tx == err then print(err) end 其他所有函数均为事务表的方法。 事务方法 ~~~~~~~~~~~~~~~~~~~ ``server_proto()`` ^^^^^^^^^^^^^^^^^^ 获取字符串类型的 ``server_proto`` 值。 示例:: local tx = ssh.get_tx() local proto = tx:server_proto(); print (proto) ``client_proto()`` ^^^^^^^^^^^^^^^^^^ 获取字符串类型的 ``client_proto`` 值。 示例:: local tx = ssh.get_tx() local proto = tx:client_proto(); print (proto) ``server_software()`` ^^^^^^^^^^^^^^^^^^^^^ 获取字符串类型的 ``server_software`` 值。 示例:: local tx = ssh.get_tx() local software = tx:server_software(); print (software) ``client_software()`` ^^^^^^^^^^^^^^^^^^^^^ 获取字符串类型的 ``client_software`` 值。 示例:: local tx = ssh.get_tx() local software = tx:client_software(); print (software) ``client_hassh()`` ^^^^^^^^^^^^^^^^^^ 需配合 ``ssh.enable_hassh()`` 使用。 通过client_hassh获取客户端使用的hassh算法MD5值。 示例:: local tx = ssh.get_tx() local h = tx:client_hassh(); print (h) ``client_hassh_string()`` ^^^^^^^^^^^^^^^^^^^^^^^^^ 需配合 ``ssh.enable_hassh()`` 使用。 通过client_hassh_string获取客户端使用的hassh算法字符串。 示例:: local tx = ssh.get_tx() local h = tx:client_hassh_string(); print (h) ``server_hassh()`` ^^^^^^^^^^^^^^^^^^ 需配合 ``ssh.enable_hassh()`` 使用。 通过server_hassh获取服务端使用的hassh算法MD5值。 示例:: local tx = ssh.get_tx() local h = tx:server_hassh(); print (h) ``server_hassh_string()`` ^^^^^^^^^^^^^^^^^^^^^^^^^ 需配合 ``ssh.enable_hassh()`` 使用。 通过server_hassh_string获取服务端使用的hassh算法字符串。 示例:: local tx = ssh.get_tx() local h = tx:server_hassh_string(); print (h)