Skip to content

lua: convert ssh function into suricata.ssh lib #13013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/userguide/lua/libs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ environment without access to additional modules.
hashlib
http
packetlib
ssh
91 changes: 91 additions & 0 deletions doc/userguide/lua/libs/ssh.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
SSH
---

SSH transaction details are exposes to Lua scripts with the
``suricata.ssh`` library, For example::

local ssh = require("suricata.ssh")

Setup
^^^^^

If your purpose is to create a logging script, initialize the buffer as:

::

function init (args)
local needs = {}
needs["protocol"] = "ssh"
return needs
end

If you are going to use the script for rule matching, choose one of
the available SSH buffers listed in :ref:`lua-detection` and follow
the pattern:

::

function init (args)
local needs = {}
needs["ssh.server_proto"] = tostring(true)
return needs
end

Transaction
~~~~~~~~~~~

SSH is transaction based, and the current transaction must be obtained before use::

local tx, err = ssh.get_tx()
if tx == err then
print(err)
end

All other functions are methods on the transaction table.

Transaction Methods
~~~~~~~~~~~~~~~~~~~

``server_proto()``
^^^^^^^^^^^^^^^^^^

Get the ``server_proto`` value as a string.

Example::

local tx = ssh.get_tx()
local proto = tx:server_proto();
print (proto)

``client_proto()``
^^^^^^^^^^^^^^^^^^

Get the ``client_proto`` value as a string.

Example::

local tx = ssh.get_tx()
local proto = tx:client_proto();
print (proto)

``server_software()``
^^^^^^^^^^^^^^^^^^^^^

Get the ``server_software`` value as a string.

Example::

local tx = ssh.get_tx()
local software = tx:server_software();
print (software)

``client_software()``
^^^^^^^^^^^^^^^^^^^^^

Get the ``client_software`` value as a string.

Example::

local tx = ssh.get_tx()
local software = tx:client_software();
print (software)
65 changes: 0 additions & 65 deletions doc/userguide/lua/lua-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,71 +481,6 @@ Initialize with:
return needs
end

SshGetServerProtoVersion
~~~~~~~~~~~~~~~~~~~~~~~~

Get SSH protocol version used by the server through SshGetServerProtoVersion.

Example:

::

function log (args)
version = SshGetServerProtoVersion()
if version == nil then
return 0
end
end

SshGetServerSoftwareVersion
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get SSH software used by the server through SshGetServerSoftwareVersion.

Example:

::

function log (args)
software = SshGetServerSoftwareVersion()
if software == nil then
return 0
end
end

SshGetClientProtoVersion
~~~~~~~~~~~~~~~~~~~~~~~~

Get SSH protocol version used by the client through SshGetClientProtoVersion.

Example:

::

function log (args)
version = SshGetClientProtoVersion()
if version == nil then
return 0
end
end

SshGetClientSoftwareVersion
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get SSH software used by the client through SshGetClientSoftwareVersion.

Example:

::

function log (args)
software = SshGetClientSoftwareVersion()
if software == nil then
return 0
end
end


HasshGet
~~~~~~~~

Expand Down
2 changes: 0 additions & 2 deletions src/detect-lua-extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "util-lua-dns.h"
#include "util-lua-ja3.h"
#include "util-lua-tls.h"
#include "util-lua-ssh.h"
#include "util-lua-hassh.h"
#include "util-lua-smtp.h"
#include "util-lua-dnp3.h"
Expand Down Expand Up @@ -552,7 +551,6 @@ int LuaRegisterExtensions(lua_State *lua_state)
LuaRegisterFunctions(lua_state);
LuaRegisterJa3Functions(lua_state);
LuaRegisterTlsFunctions(lua_state);
LuaRegisterSshFunctions(lua_state);
LuaRegisterHasshFunctions(lua_state);
LuaRegisterSmtpFunctions(lua_state);
return 0;
Expand Down
7 changes: 7 additions & 0 deletions src/detect-ssh-proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@ void DetectSshProtocolRegister(void)
DetectBufferTypeSetDescriptionByName(BUFFER_NAME, BUFFER_DESC);

g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);

/* register these generic engines for lua from here for now */
DetectAppLayerInspectEngineRegister(
"ssh_banner", ALPROTO_SSH, SIG_FLAG_TOSERVER, 1, DetectEngineInspectGenericList, NULL);
DetectAppLayerInspectEngineRegister(
"ssh_banner", ALPROTO_SSH, SIG_FLAG_TOCLIENT, 1, DetectEngineInspectGenericList, NULL);
DetectBufferTypeSetDescriptionByName("ssh_banner", "ssh banner");
}
2 changes: 0 additions & 2 deletions src/output-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "util-lua-dns.h"
#include "util-lua-ja3.h"
#include "util-lua-tls.h"
#include "util-lua-ssh.h"
#include "util-lua-hassh.h"
#include "util-lua-smtp.h"

Expand Down Expand Up @@ -593,7 +592,6 @@ static lua_State *LuaScriptSetup(const char *filename, LogLuaMasterCtx *ctx)
LuaRegisterFunctions(luastate);
LuaRegisterJa3Functions(luastate);
LuaRegisterTlsFunctions(luastate);
LuaRegisterSshFunctions(luastate);
LuaRegisterHasshFunctions(luastate);
LuaRegisterSmtpFunctions(luastate);

Expand Down
2 changes: 2 additions & 0 deletions src/util-lua-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "util-lua-dnp3.h"
#include "util-lua-http.h"
#include "util-lua-dns.h"
#include "util-lua-ssh.h"
#include "util-lua-flowlib.h"
#include "util-lua-hashlib.h"
#include "util-lua-packetlib.h"
Expand All @@ -37,6 +38,7 @@ static const luaL_Reg builtins[] = {
{ "suricata.hashlib", SCLuaLoadHashlib },
{ "suricata.http", SCLuaLoadHttpLib },
{ "suricata.packet", LuaLoadPacketLib },
{ "suricata.ssh", SCLuaLoadSshLib },
{ NULL, NULL },
};

Expand Down
Loading
Loading