|
|
|
|
/* Copyright (C) 2025 Open Information Security Foundation
|
|
|
|
|
*
|
|
|
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
|
|
|
* the GNU General Public License version 2 as published by the Free
|
|
|
|
|
* Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* version 2 along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "suricata-common.h"
|
|
|
|
|
#include "util-lua-builtins.h"
|
|
|
|
|
#include "util-lua-base64lib.h"
|
|
|
|
|
#include "util-lua-dataset.h"
|
|
|
|
|
#include "util-lua-dnp3.h"
|
|
|
|
|
#include "util-lua-flowintlib.h"
|
|
|
|
|
#include "util-lua-flowvarlib.h"
|
|
|
|
|
#include "util-lua-http.h"
|
|
|
|
|
#include "util-lua-dns.h"
|
|
|
|
|
#include "util-lua-smtp.h"
|
|
|
|
|
#include "util-lua-ssh.h"
|
lua: add initial suricata.flow lib
Methods:
`get` creates the flow object.
`id` returns the flow id.
`has_alerts` returns a boolean indicating if the flow triggered alerts.
`app_layer_proto` returns various app-layer related fields as 5 strings:
alproto, alproto_ts, alproto_tc, alproto_orig, alproto_expect.
`stats` returns cnts for bytes and packets to sever and to client, as 4
numbers.
`tuple` -- returns various fields: srcip, dstip, proto, sp, dp.
`timestamps` returns time as 4 numbers: seconds and microseconds, for
first and last packet of the flow.
`timestring_legacy` returns the first packet from the flow's timestring
as a string (like fastlog).
`timestring_iso8601` returns the first packet from the flow's
timestring as an iso8601 compat timestring (like eve).
Example:
```
name = "lua-scflowstats.log"
local flow = require("suricata.flow")
function init(args)
local needs = {}
needs["type"] = "flow"
return needs
end
function setup(args)
filename = SCLogPath() .. "/" .. name
file = assert(io.open(filename, "a"))
SCLogInfo("lua SCFlowStats Log Filename " .. filename)
end
function log(args)
local f = flow.get()
timestring = f:timestring_legacy()
tscnt, tsbytes, tccnt, tcbytes = f:stats()
file:write ("[**] " .. timestring .. "\nSCFlowStats is\nPacket count to server: " .. tscnt .. "\nByte count to server: " .. tsbytes .. "\nPacket count to client: " .. tccnt .. "\nByte count to client: " .. tcbytes .. "\n[**]")
file:flush()
end
function deinit(args)
file:close(file)
end
```
Task #7489
2 years ago
|
|
|
#include "util-lua-flowlib.h"
|
|
|
|
|
#include "util-lua-hashlib.h"
|
|
|
|
|
#include "util-lua-tls.h"
|
lua: add initial suricata.packet lib
Example:
```
local packet = require "suricata.packet"
function init (args)
local needs = {}
return needs
end
function match (args)
p = packet.get()
payload = p:payload()
ts = p:timestring()
for line in payload:gmatch("([^\r\n]*)[\r\n]+") do
if line == "GET /index.html HTTP/1.0" then
ipver, srcip, dstip, proto, sp, dp = p:tuple()
SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line));
return 1
end
end
return 0
end
```
Methods:
`get` creates the packet object.
`payload` returns the packet payload as a buffer
`packet` returns the whole packet (includes headers)
`pcap_cnt` returns the `pcap_cnt` (pcap file mode only)
`tuple` returns various fields: srcip, dstip, proto, sp, dp
`sp` returns source port
`dp` returns destination port
`timestamp` returns time as 2 numbers: seconds and microseconds
`timestring_legacy` returns a timestamp as a string (like fastlog)
`timestring_iso8601` returns a iso8601 compat timestring (like eve)
Ticket: #7488.
2 years ago
|
|
|
#include "util-lua-packetlib.h"
|
|
|
|
|
#include "util-lua-rule.h"
|
|
|
|
|
#include "util-lua-ja3.h"
|
|
|
|
|
#include "util-lua-filelib.h"
|
|
|
|
|
|
|
|
|
|
#include "lauxlib.h"
|
|
|
|
|
|
|
|
|
|
static const luaL_Reg builtins[] = {
|
|
|
|
|
{ "suricata.base64", SCLuaLoadBase64Lib },
|
|
|
|
|
{ "suricata.dataset", LuaLoadDatasetLib },
|
|
|
|
|
{ "suricata.dnp3", SCLuaLoadDnp3Lib },
|
|
|
|
|
{ "suricata.dns", SCLuaLoadDnsLib },
|
|
|
|
|
{ "suricata.file", SCLuaLoadFileLib },
|
lua: add initial suricata.flow lib
Methods:
`get` creates the flow object.
`id` returns the flow id.
`has_alerts` returns a boolean indicating if the flow triggered alerts.
`app_layer_proto` returns various app-layer related fields as 5 strings:
alproto, alproto_ts, alproto_tc, alproto_orig, alproto_expect.
`stats` returns cnts for bytes and packets to sever and to client, as 4
numbers.
`tuple` -- returns various fields: srcip, dstip, proto, sp, dp.
`timestamps` returns time as 4 numbers: seconds and microseconds, for
first and last packet of the flow.
`timestring_legacy` returns the first packet from the flow's timestring
as a string (like fastlog).
`timestring_iso8601` returns the first packet from the flow's
timestring as an iso8601 compat timestring (like eve).
Example:
```
name = "lua-scflowstats.log"
local flow = require("suricata.flow")
function init(args)
local needs = {}
needs["type"] = "flow"
return needs
end
function setup(args)
filename = SCLogPath() .. "/" .. name
file = assert(io.open(filename, "a"))
SCLogInfo("lua SCFlowStats Log Filename " .. filename)
end
function log(args)
local f = flow.get()
timestring = f:timestring_legacy()
tscnt, tsbytes, tccnt, tcbytes = f:stats()
file:write ("[**] " .. timestring .. "\nSCFlowStats is\nPacket count to server: " .. tscnt .. "\nByte count to server: " .. tsbytes .. "\nPacket count to client: " .. tccnt .. "\nByte count to client: " .. tcbytes .. "\n[**]")
file:flush()
end
function deinit(args)
file:close(file)
end
```
Task #7489
2 years ago
|
|
|
{ "suricata.flow", LuaLoadFlowLib },
|
|
|
|
|
{ "suricata.flowint", LuaLoadFlowintLib },
|
|
|
|
|
{ "suricata.flowvar", LuaLoadFlowvarLib },
|
|
|
|
|
{ "suricata.hashlib", SCLuaLoadHashlib },
|
|
|
|
|
{ "suricata.http", SCLuaLoadHttpLib },
|
|
|
|
|
{ "suricata.ja3", SCLuaLoadJa3Lib },
|
lua: add initial suricata.packet lib
Example:
```
local packet = require "suricata.packet"
function init (args)
local needs = {}
return needs
end
function match (args)
p = packet.get()
payload = p:payload()
ts = p:timestring()
for line in payload:gmatch("([^\r\n]*)[\r\n]+") do
if line == "GET /index.html HTTP/1.0" then
ipver, srcip, dstip, proto, sp, dp = p:tuple()
SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line));
return 1
end
end
return 0
end
```
Methods:
`get` creates the packet object.
`payload` returns the packet payload as a buffer
`packet` returns the whole packet (includes headers)
`pcap_cnt` returns the `pcap_cnt` (pcap file mode only)
`tuple` returns various fields: srcip, dstip, proto, sp, dp
`sp` returns source port
`dp` returns destination port
`timestamp` returns time as 2 numbers: seconds and microseconds
`timestring_legacy` returns a timestamp as a string (like fastlog)
`timestring_iso8601` returns a iso8601 compat timestring (like eve)
Ticket: #7488.
2 years ago
|
|
|
{ "suricata.packet", LuaLoadPacketLib },
|
|
|
|
|
{ "suricata.rule", SCLuaLoadRuleLib },
|
|
|
|
|
{ "suricata.smtp", SCLuaLoadSmtpLib },
|
|
|
|
|
{ "suricata.ssh", SCLuaLoadSshLib },
|
|
|
|
|
{ "suricata.tls", SCLuaLoadTlsLib },
|
|
|
|
|
{ NULL, NULL },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Load a Suricata built-in module in a sand-boxed environment.
|
|
|
|
|
*/
|
|
|
|
|
bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
|
|
|
|
|
{
|
|
|
|
|
for (const luaL_Reg *lib = builtins; lib->name; lib++) {
|
|
|
|
|
if (strcmp(name, lib->name) == 0) {
|
|
|
|
|
lib->func(L);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Register Suricata built-in modules for loading in a
|
|
|
|
|
* non-sandboxed environment.
|
|
|
|
|
*/
|
|
|
|
|
void SCLuaRequirefBuiltIns(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
for (const luaL_Reg *lib = builtins; lib->name; lib++) {
|
|
|
|
|
luaL_requiref(L, lib->name, lib->func, 0);
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|