Go to the documentation of this file.
69 void *state,
void *txv,
const Signature *s,
73 static void DetectLuaRegisterTests(
void);
76 static int g_lua_ja3_list_id = 0;
77 static int g_lua_ja3s_list_id = 0;
111 #define FLAG_DATATYPE_PACKET BIT_U32(0)
112 #define FLAG_DATATYPE_PAYLOAD BIT_U32(1)
113 #define FLAG_LIST_JA3 BIT_U32(3)
114 #define FLAG_LIST_JA3S BIT_U32(4)
115 #define FLAG_ERROR_LOGGED BIT_U32(23)
116 #define FLAG_BLOCKED_FUNCTION_LOGGED BIT_U32(24)
117 #define FLAG_INSTRUCTION_LIMIT_LOGGED BIT_U32(25)
118 #define FLAG_MEMORY_LIMIT_LOGGED BIT_U32(26)
120 #define DEFAULT_LUA_ALLOC_LIMIT 500000
121 #define DEFAULT_LUA_INSTRUCTION_LIMIT 500000
126 int size = lua_gettop(state);
127 printf(
"%s: size %d\n", prefix, size);
129 for (
int i = 1; i <= size; i++) {
130 int type = lua_type(state, i);
131 printf(
"- %s: Stack size=%d, level=%d, type=%d, ", prefix, size, i,
type);
135 printf(
"function %s", lua_tostring(state, i));
138 printf(
"bool %s", lua_toboolean(state, i) ?
"true" :
"false");
141 printf(
"number %g", lua_tonumber(state, i));
144 printf(
"string `%s'", lua_tostring(state, i));
147 printf(
"table `%s'", lua_tostring(state, i));
150 printf(
"other %s", lua_typename(state,
type));
162 static int DetectLuaRunMatch(
168 if (lua_pcall(tlua->
luastate, 1, 1, 0) != 0) {
169 const char *reason = lua_tostring(tlua->
luastate, -1);
180 reason =
"memory limit exceeded";
188 if (!(tlua->
flags & flag)) {
189 SCLogWarning(
"Lua script failed to run successfully: %s", reason);
194 while (lua_gettop(tlua->
luastate) > 0) {
203 if (lua_gettop(tlua->
luastate) > 0) {
205 if (lua_type(tlua->
luastate, 1) == LUA_TNUMBER) {
206 lua_Integer script_ret = lua_tointeger(tlua->
luastate, 1);
212 SCLogDebug(
"Unsupported datatype returned from Lua script");
223 while (lua_gettop(tlua->
luastate) > 0) {
236 if (buffer == NULL || buffer_len == 0)
255 lua_getglobal(tlua->
luastate,
"match");
258 lua_pushliteral(tlua->
luastate,
"offset");
269 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
302 flags = STREAM_TOSERVER;
304 flags = STREAM_TOCLIENT;
319 lua_getglobal(tlua->
luastate,
"match");
325 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
351 lua_getglobal(tlua->
luastate,
"match");
357 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
376 void *state,
void *txv,
const Signature *s,
379 return DetectLuaAppMatchCommon(det_ctx,
f,
flags, state, s,
ctx);
385 static const char *ut_script = NULL;
388 static void *DetectLuaThreadInit(
void *data,
bool allow_restricted_functions)
414 if (allow_restricted_functions) {
425 if (ut_script != NULL) {
426 status = luaL_loadbuffer(t->
luastate, ut_script, strlen(ut_script),
"unittest");
446 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
452 lua_getglobal(t->
luastate,
"thread_init");
453 if (lua_isfunction(t->
luastate, -1)) {
455 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
456 SCLogError(
"couldn't run script 'thread_init' function: %s",
473 static void *DetectLuaThreadRestrictedInit(
void *data)
475 return DetectLuaThreadInit(data,
false);
478 static void *DetectLuaThreadAllowInit(
void *data)
480 return DetectLuaThreadInit(data,
true);
483 static void DetectLuaThreadFree(
void *
ctx)
527 if (strlen(
str) &&
str[0] ==
'!') {
541 DetectLuaFree(
de_ctx, lua);
546 int allow_restricted_functions)
555 if (luastate == NULL)
557 if (allow_restricted_functions) {
558 luaL_openlibs(luastate);
567 if (ut_script != NULL) {
568 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
570 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
575 status = luaL_loadfile(luastate, ld->
filename);
577 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
588 if (lua_pcall(luastate, 0, 0, 0) != 0) {
589 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
593 lua_getglobal(luastate,
"init");
594 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
601 lua_pushlightuserdata(luastate, (
void *)s);
605 if (lua_pcall(luastate, 1, 1, 0) != 0) {
606 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
613 if (lua_gettop(luastate) == 0) {
614 SCLogError(
"init function in script should return table, nothing returned");
617 if (lua_type(luastate, 1) != LUA_TTABLE) {
618 SCLogError(
"init function in script should return table, returned is not table");
622 lua_pushnil(luastate);
624 while (lua_next(luastate, -2)) {
628 if (lua_type(luastate, -2) != LUA_TSTRING) {
629 lua_pop(luastate, 1);
632 k = lua_tostring(luastate, -2);
635 if (strcmp(k,
"flowvar") == 0) {
636 if (lua_istable(luastate, -1)) {
637 lua_pushnil(luastate);
638 while (lua_next(luastate, -2) != 0) {
640 const char *value = lua_tostring(luastate, -1);
643 lua_pop(luastate, 1);
657 lua_pop(luastate, 1);
659 }
else if (strcmp(k,
"flowint") == 0) {
660 if (lua_istable(luastate, -1)) {
661 lua_pushnil(luastate);
662 while (lua_next(luastate, -2) != 0) {
664 const char *value = lua_tostring(luastate, -1);
667 lua_pop(luastate, 1);
681 lua_pop(luastate, 1);
685 bool required = lua_toboolean(luastate, -1);
686 lua_pop(luastate, 1);
691 if (strcmp(k,
"ja3") == 0) {
693 }
else if (strcmp(k,
"ja3s") == 0) {
695 }
else if (strcmp(k,
"packet") == 0) {
697 }
else if (strcmp(k,
"payload") == 0) {
699 }
else if (strcmp(k,
"buffer") == 0) {
705 }
else if (strcmp(k,
"stream") == 0) {
712 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
713 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
714 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
715 SCLogError(
"data type %s no longer supported, use rule hooks", k);
725 lua_pop(luastate, 1);
749 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
750 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
761 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
762 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
765 if (lua_alloc_limit < 0) {
766 SCLogError(
"security.lua.max-bytes must be non-negative (got %" PRIdMAX
"), "
767 "use 0 for no limit",
774 int allow_restricted_functions = 0;
775 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
777 if (DetectLuaSetupPrime(
de_ctx, lua, s, allow_restricted_functions) == -1) {
781 void *cb = DetectLuaThreadRestrictedInit;
782 if (allow_restricted_functions) {
783 cb = DetectLuaThreadAllowInit;
793 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
811 list = g_lua_ja3_list_id;
813 list = g_lua_ja3s_list_id;
825 DetectLuaFree(
de_ctx, lua);
844 for (uint16_t i = 0; i < lua->
flowints; i++) {
847 for (uint16_t i = 0; i < lua->
flowvars; i++) {
850 for (uint16_t i = 0; i < lua->
bytevars; i++) {
864 static int LuaMatchTest01(
void)
868 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
869 "function init (args)\n"
870 " flowvarlib.register(\"cnt\")\n"
873 "function thread_init (args)\n"
874 " cnt = flowvarlib.get(\"cnt\")\n"
877 "function match(args)\n"
880 " a = tostring(tonumber(a)+1)\n"
889 " print (\"pre check: \" .. (a))\n"
890 " if tonumber(a) == 2 then\n"
897 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
900 "POST / HTTP/1.1\r\n"
901 "Host: www.emergingthreats.net\r\n\r\n";
903 "POST / HTTP/1.1\r\n"
904 "Host: www.openinfosecfoundation.org\r\n\r\n";
905 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
906 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
918 memset(&
f, 0,
sizeof(
f));
919 memset(&
ssn, 0,
sizeof(
ssn));
990 static int LuaMatchTest01a(
void)
992 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
993 "function init (args)\n"
994 " flowvarlib.register(\"cnt\")\n"
997 "function thread_init (args)\n"
998 " cnt = flowvarlib.get(\"cnt\")\n"
1001 "function match(args)\n"
1002 " a = cnt:value(0)\n"
1004 " a = tostring(tonumber(a)+1)\n"
1008 " a = tostring(1)\n"
1013 " print (\"pre check: \" .. (a))\n"
1014 " if tonumber(a) == 2 then\n"
1015 " print \"match\"\n"
1021 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1023 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1024 "Host: www.emergingthreats.net\r\n\r\n";
1025 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1026 "Host: www.openinfosecfoundation.org\r\n\r\n";
1027 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1028 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1040 memset(&
f, 0,
sizeof(
f));
1041 memset(&
ssn, 0,
sizeof(
ssn));
1113 static int LuaMatchTest02(
void)
1115 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1116 "function init (args)\n"
1117 " flowvarlib.register(\"cnt\")\n"
1118 " local needs = {}\n"
1119 " needs[\"payload\"] = tostring(true)\n"
1122 "function thread_init (args)\n"
1123 " cnt = flowvarlib.get(\"cnt\")\n"
1126 "function match(args)\n"
1127 " a = cnt:value()\n"
1129 " a = tostring(tonumber(a)+1)\n"
1133 " a = tostring(1)\n"
1138 " print (\"pre check: \" .. (a))\n"
1139 " if tonumber(a) == 2 then\n"
1140 " print \"match\"\n"
1146 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1147 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1148 "Host: www.emergingthreats.net\r\n\r\n";
1149 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1150 "Host: www.openinfosecfoundation.org\r\n\r\n";
1151 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1152 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1162 memset(&
f, 0,
sizeof(
f));
1163 memset(&
ssn, 0,
sizeof(
ssn));
1225 static int LuaMatchTest02a(
void)
1227 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1228 "function init (args)\n"
1229 " flowvarlib.register(\"cnt\")"
1230 " local needs = {}\n"
1231 " needs[\"payload\"] = tostring(true)\n"
1234 "function thread_init (args)\n"
1235 " cnt = flowvarlib.get(\"cnt\")"
1238 "function match(args)\n"
1239 " a = cnt:value()\n"
1241 " a = tostring(tonumber(a)+1)\n"
1245 " a = tostring(1)\n"
1250 " print (\"pre check: \" .. (a))\n"
1251 " if tonumber(a) == 2 then\n"
1252 " print \"match\"\n"
1258 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1259 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1260 "Host: www.emergingthreats.net\r\n\r\n";
1261 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1262 "Host: www.openinfosecfoundation.org\r\n\r\n";
1263 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1264 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1274 memset(&
f, 0,
sizeof(
f));
1275 memset(&
ssn, 0,
sizeof(
ssn));
1335 static int LuaMatchTest03(
void)
1337 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1338 "function init (args)\n"
1339 " flowvarlib.register(\"cnt\")\n"
1340 " local needs = {}\n"
1341 " needs[\"packet\"] = tostring(true)\n"
1345 "function thread_init (args)\n"
1346 " cnt = flowvarlib.get(\"cnt\")\n"
1349 "function match(args)\n"
1350 " a = cnt:value()\n"
1352 " a = tostring(tonumber(a)+1)\n"
1356 " a = tostring(1)\n"
1361 " print (\"pre check: \" .. (a))\n"
1362 " if tonumber(a) == 2 then\n"
1363 " print \"match\"\n"
1369 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1370 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1371 "Host: www.emergingthreats.net\r\n\r\n";
1372 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1373 "Host: www.openinfosecfoundation.org\r\n\r\n";
1374 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1375 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1385 memset(&
f, 0,
sizeof(
f));
1386 memset(&
ssn, 0,
sizeof(
ssn));
1445 static int LuaMatchTest03a(
void)
1447 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1448 "function init (args)\n"
1449 " flowvarlib.register(\"cnt\")\n"
1450 " local needs = {}\n"
1451 " needs[\"packet\"] = tostring(true)\n"
1455 "function thread_init (args)\n"
1456 " cnt = flowvarlib.get(\"cnt\")\n"
1459 "function match(args)\n"
1460 " a = cnt:value()\n"
1462 " a = tostring(tonumber(a)+1)\n"
1466 " a = tostring(1)\n"
1471 " print (\"pre check: \" .. (a))\n"
1472 " if tonumber(a) == 2 then\n"
1473 " print \"match\"\n"
1479 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1480 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1481 "Host: www.emergingthreats.net\r\n\r\n";
1482 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1483 "Host: www.openinfosecfoundation.org\r\n\r\n";
1484 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1485 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1495 memset(&
f, 0,
sizeof(
f));
1496 memset(&
ssn, 0,
sizeof(
ssn));
1555 static int LuaMatchTest04(
void)
1557 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1558 "function init (args)\n"
1559 " flowintlib.register(\"cnt\")\n"
1563 "function thread_init (args)\n"
1564 " cnt = flowintlib.get(\"cnt\")\n"
1567 "function match(args)\n"
1568 " print \"inspecting\""
1569 " a = cnt:value()\n"
1576 " a = cnt:value()\n"
1578 " print \"match\"\n"
1584 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1586 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1587 "Host: www.emergingthreats.net\r\n\r\n";
1588 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1589 "Host: www.openinfosecfoundation.org\r\n\r\n";
1590 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1591 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1603 memset(&
f, 0,
sizeof(
f));
1604 memset(&
ssn, 0,
sizeof(
ssn));
1673 static int LuaMatchTest04a(
void)
1675 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1676 "function init (args)\n"
1677 " flowintlib.register(\"cnt\")\n"
1681 "function thread_init (args)\n"
1682 " cnt = flowintlib.get(\"cnt\")\n"
1685 "function match(args)\n"
1686 " print \"inspecting\""
1687 " a = cnt:value()\n"
1694 " a = cnt:value()\n"
1696 " print \"match\"\n"
1702 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1704 uint8_t httpbuf1[] =
1705 "POST / HTTP/1.1\r\n"
1706 "Host: www.emergingthreats.net\r\n\r\n";
1707 uint8_t httpbuf2[] =
1708 "POST / HTTP/1.1\r\n"
1709 "Host: www.openinfosecfoundation.org\r\n\r\n";
1710 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1711 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1723 memset(&
f, 0,
sizeof(
f));
1724 memset(&
ssn, 0,
sizeof(
ssn));
1793 static int LuaMatchTest05(
void)
1795 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1796 "function init (args)\n"
1797 " flowintlib.register(\"cnt\")\n"
1801 "function thread_init (args)\n"
1802 " cnt = flowintlib.get(\"cnt\")\n"
1805 "function match(args)\n"
1806 " print \"inspecting\""
1809 " print \"match\"\n"
1815 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1817 uint8_t httpbuf1[] =
1818 "POST / HTTP/1.1\r\n"
1819 "Host: www.emergingthreats.net\r\n\r\n";
1820 uint8_t httpbuf2[] =
1821 "POST / HTTP/1.1\r\n"
1822 "Host: www.openinfosecfoundation.org\r\n\r\n";
1823 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1824 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1836 memset(&
f, 0,
sizeof(
f));
1837 memset(&
ssn, 0,
sizeof(
ssn));
1906 static int LuaMatchTest05a(
void)
1908 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1909 "function init (args)\n"
1910 " flowintlib.register(\"cnt\")\n"
1914 "function thread_init (args)\n"
1915 " cnt = flowintlib.get(\"cnt\")\n"
1918 "function match(args)\n"
1919 " print \"inspecting\""
1922 " print \"match\"\n"
1928 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1930 uint8_t httpbuf1[] =
1931 "POST / HTTP/1.1\r\n"
1932 "Host: www.emergingthreats.net\r\n\r\n";
1933 uint8_t httpbuf2[] =
1934 "POST / HTTP/1.1\r\n"
1935 "Host: www.openinfosecfoundation.org\r\n\r\n";
1936 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1937 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1949 memset(&
f, 0,
sizeof(
f));
1950 memset(&
ssn, 0,
sizeof(
ssn));
2021 static int LuaMatchTest06(
void)
2023 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2024 "function init (args)\n"
2025 " flowintlib.register(\"cnt\")\n"
2029 "function thread_init (args)\n"
2030 " cnt = flowintlib.get(\"cnt\")\n"
2033 "function match(args)\n"
2034 " print \"inspecting\""
2035 " a = cnt:value()\n"
2036 " if a == nil then\n"
2037 " print \"new var set to 2\""
2042 " print \"match\"\n"
2048 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2050 uint8_t httpbuf1[] =
2051 "POST / HTTP/1.1\r\n"
2052 "Host: www.emergingthreats.net\r\n\r\n";
2053 uint8_t httpbuf2[] =
2054 "POST / HTTP/1.1\r\n"
2055 "Host: www.openinfosecfoundation.org\r\n\r\n";
2056 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2057 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2069 memset(&
f, 0,
sizeof(
f));
2070 memset(&
ssn, 0,
sizeof(
ssn));
2139 static int LuaMatchTest06a(
void)
2141 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2142 "function init (args)\n"
2143 " flowintlib.register(\"cnt\")\n"
2147 "function thread_init (args)\n"
2148 " cnt = flowintlib.get(\"cnt\")\n"
2151 "function match(args)\n"
2152 " print \"inspecting\""
2153 " a = cnt:value()\n"
2154 " if a == nil then\n"
2155 " print \"new var set to 2\""
2160 " print \"match\"\n"
2166 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2168 uint8_t httpbuf1[] =
2169 "POST / HTTP/1.1\r\n"
2170 "Host: www.emergingthreats.net\r\n\r\n";
2171 uint8_t httpbuf2[] =
2172 "POST / HTTP/1.1\r\n"
2173 "Host: www.openinfosecfoundation.org\r\n\r\n";
2174 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2175 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2187 memset(&
f, 0,
sizeof(
f));
2188 memset(&
ssn, 0,
sizeof(
ssn));
2256 void DetectLuaRegisterTests(
void)
void LuaStateSetTX(lua_State *luastate, void *txptr, const uint64_t tx_id)
#define FLAG_MEMORY_LIMIT_LOGGED
void LuaStateSetPacket(lua_State *luastate, Packet *p)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void LuaStateSetInvocationGen(lua_State *luastate, uint64_t *gen)
publish the state's invocation counter (once, at state init)
SigTableElmt * sigmatch_table
void SCLuaSbUpdateBytesLimit(lua_State *L)
void(* Free)(DetectEngineCtx *, void *)
#define FLAG_BLOCKED_FUNCTION_LOGGED
uint64_t SCLuaSbResetBytesLimit(lua_State *L)
void * DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
const Signature * signature
SCLuaSbState * SCLuaSbGetContext(lua_State *L)
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
#define FLAG_INSTRUCTION_LIMIT_LOGGED
main detection engine ctx
#define DEFAULT_LUA_INSTRUCTION_LIMIT
void LuaStateSetDetectLuaData(lua_State *luastate, DetectLuaData *ld)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
#define DETECT_LUA_MAX_FLOWVARS
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
#define FLOW_PKT_TOSERVER
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
uint32_t flowvar[DETECT_LUA_MAX_FLOWVARS]
void LuaStateSetFlow(lua_State *luastate, Flow *f)
set a flow pointer in the lua state
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
StatsCounterId lua_instruction_limit_errors
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
#define SIG_FLAG_TOCLIENT
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FLAG_DATATYPE_PACKET
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
struct lua_State lua_State
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
#define FLOW_INITIALIZE(f)
#define SIG_FLAG_TOSERVER
uint32_t VarNameStoreLookupByName(const char *name, const enum VarTypes type)
find name for id+type at packet time. As the active store won't be modified, we don't need locks.
#define PASS
Pass the test.
void SCLuaSbRestoreBytesLimit(lua_State *L, const uint64_t cfg_limit)
StatsCounterId lua_memory_limit_errors
uint64_t instruction_limit
void LuaStateSetFile(lua_State *luastate, File *file)
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
AppLayerParserThreadCtx * alp_tctx
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Per thread variable structure.
void DetectLuaRegister(void)
Registration function for keyword: lua.
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
#define DETECT_LUA_MAX_FLOWINTS
#define FLAG_DATATYPE_PAYLOAD
#define SCLogWarning(...)
Macro used to log WARNING messages.
int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, const uint8_t *buffer, uint32_t buffer_len, uint32_t offset, Flow *f)
@ SIGNATURE_HOOK_TYPE_NOT_SET
StatsCounterId lua_rule_errors
DetectLuaDataBytevarEntry bytevar[DETECT_LUA_MAX_BYTEVARS]
void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx)
void SCLuaSbStateClose(lua_State *L)
uint32_t flowint[DETECT_LUA_MAX_FLOWINTS]
#define FLAG_ERROR_LOGGED
SignatureInitData * init_data
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
bool blocked_function_error
#define FLOW_PKT_TOCLIENT
void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngineThreadCtx *det_ctx, Flow *f, Packet *p, const Signature *s, uint8_t flags)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void LuaDumpStack(lua_State *state, const char *prefix)
dump stack from lua state to screen
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
int SCConfSetFinal(const char *name, const char *val)
Set a final configuration value.
void StatsThreadInit(StatsThreadContext *stats)
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
void SCLuaSbLoadLibs(lua_State *L)
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
int DetectBufferTypeRegister(const char *name)
void StreamTcpFreeConfig(bool quiet)
int DetectRegisterThreadCtxFuncs(DetectEngineCtx *de_ctx, const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *), int mode)
Register Thread keyword context Funcs.
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
union FlowVar_::@121 data
#define DEFAULT_LUA_ALLOC_LIMIT
void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa)
enum SignatureHookType type
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
void SCLuaSbResetInstructionCounter(lua_State *L)
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
#define SCLogError(...)
Macro used to log ERROR messages.
#define FLOW_PKT_ESTABLISHED
DetectEngineCtx * DetectEngineCtxInit(void)
bool instruction_count_error
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
lua_State * SCLuaSbStateNew(uint64_t alloclimit, uint64_t instructionlimit)
Allocate a new Lua sandbox.
FlowVar * FlowVarGet(Flow *f, uint32_t idx)
get the flowvar with index 'idx' from the flow
int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *de_ctx, void *data, const char *name)
Remove Thread keyword context registration.
AppProto alproto
application level protocol
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
void StatsThreadCleanup(StatsThreadContext *stats)
void LuaStateSetSignature(lua_State *luastate, const Signature *s)
StatsCounterId lua_blocked_function_errors
void(* RegisterTests)(void)
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.