Go to the documentation of this file.
70 void *state,
void *txv,
const Signature *s,
74 static void DetectLuaRegisterTests(
void);
77 static int g_lua_ja3_list_id = 0;
78 static int g_lua_ja3s_list_id = 0;
112 #define FLAG_DATATYPE_PACKET BIT_U32(0)
113 #define FLAG_DATATYPE_PAYLOAD BIT_U32(1)
114 #define FLAG_DATATYPE_STREAM BIT_U32(2)
115 #define FLAG_LIST_JA3 BIT_U32(3)
116 #define FLAG_LIST_JA3S BIT_U32(4)
117 #define FLAG_DATATYPE_BUFFER BIT_U32(22)
118 #define FLAG_ERROR_LOGGED BIT_U32(23)
119 #define FLAG_BLOCKED_FUNCTION_LOGGED BIT_U32(24)
120 #define FLAG_INSTRUCTION_LIMIT_LOGGED BIT_U32(25)
121 #define FLAG_MEMORY_LIMIT_LOGGED BIT_U32(26)
123 #define DEFAULT_LUA_ALLOC_LIMIT 500000
124 #define DEFAULT_LUA_INSTRUCTION_LIMIT 500000
129 int size = lua_gettop(state);
130 printf(
"%s: size %d\n", prefix, size);
132 for (
int i = 1; i <= size; i++) {
133 int type = lua_type(state, i);
134 printf(
"- %s: Stack size=%d, level=%d, type=%d, ", prefix, size, i,
type);
138 printf(
"function %s", lua_tostring(state, i));
141 printf(
"bool %s", lua_toboolean(state, i) ?
"true" :
"false");
144 printf(
"number %g", lua_tonumber(state, i));
147 printf(
"string `%s'", lua_tostring(state, i));
150 printf(
"table `%s'", lua_tostring(state, i));
153 printf(
"other %s", lua_typename(state,
type));
164 lua_pushlightuserdata(state, (
void *)data);
165 lua_settable(state, LUA_REGISTRYINDEX);
172 static int DetectLuaRunMatch(
178 if (lua_pcall(tlua->
luastate, 1, 1, 0) != 0) {
179 const char *reason = lua_tostring(tlua->
luastate, -1);
190 reason =
"memory limit exceeded";
198 if (!(tlua->
flags & flag)) {
199 SCLogWarning(
"Lua script failed to run successfully: %s", reason);
204 while (lua_gettop(tlua->
luastate) > 0) {
213 if (lua_gettop(tlua->
luastate) > 0) {
215 if (lua_type(tlua->
luastate, 1) == LUA_TNUMBER) {
216 lua_Integer script_ret = lua_tointeger(tlua->
luastate, 1);
222 SCLogDebug(
"Unsupported datatype returned from Lua script");
233 while (lua_gettop(tlua->
luastate) > 0) {
246 if (buffer == NULL || buffer_len == 0)
261 lua_getglobal(tlua->
luastate,
"match");
264 lua_pushliteral(tlua->
luastate,
"offset");
272 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
302 flags = STREAM_TOSERVER;
304 flags = STREAM_TOCLIENT;
315 lua_getglobal(tlua->
luastate,
"match");
318 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
337 lua_getglobal(tlua->
luastate,
"match");
340 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
356 void *state,
void *txv,
const Signature *s,
359 return DetectLuaAppMatchCommon(det_ctx, f,
flags, state, s,
ctx);
365 static const char *ut_script = NULL;
368 static void *DetectLuaThreadInit(
void *data)
395 LuaStateSetDetectLuaData(t->
luastate, lua);
399 if (ut_script != NULL) {
400 status = luaL_loadbuffer(t->
luastate, ut_script, strlen(ut_script),
"unittest");
417 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
423 lua_getglobal(t->
luastate,
"thread_init");
424 if (lua_isfunction(t->
luastate, -1)) {
425 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
426 SCLogError(
"couldn't run script 'thread_init' function: %s",
443 static void DetectLuaThreadFree(
void *
ctx)
471 if (strlen(
str) &&
str[0] ==
'!') {
485 DetectLuaFree(
de_ctx, lua);
494 if (luastate == NULL)
497 luaL_openlibs(luastate);
502 LuaStateSetDetectLuaData(luastate, ld);
506 if (ut_script != NULL) {
507 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
509 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
514 status = luaL_loadfile(luastate, ld->
filename);
516 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
524 if (lua_pcall(luastate, 0, 0, 0) != 0) {
525 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
529 lua_getglobal(luastate,
"init");
530 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
537 lua_pushlightuserdata(luastate, (
void *)s);
539 if (lua_pcall(luastate, 1, 1, 0) != 0) {
540 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
545 if (lua_gettop(luastate) == 0) {
546 SCLogError(
"init function in script should return table, nothing returned");
549 if (lua_type(luastate, 1) != LUA_TTABLE) {
550 SCLogError(
"init function in script should return table, returned is not table");
554 lua_pushnil(luastate);
556 while (lua_next(luastate, -2)) {
557 k = lua_tostring(luastate, -2);
562 if (strcmp(k,
"flowvar") == 0) {
563 if (lua_istable(luastate, -1)) {
564 lua_pushnil(luastate);
565 while (lua_next(luastate, -2) != 0) {
567 const char *value = lua_tostring(luastate, -1);
570 lua_pop(luastate, 1);
584 lua_pop(luastate, 1);
586 }
else if (strcmp(k,
"flowint") == 0) {
587 if (lua_istable(luastate, -1)) {
588 lua_pushnil(luastate);
589 while (lua_next(luastate, -2) != 0) {
591 const char *value = lua_tostring(luastate, -1);
594 lua_pop(luastate, 1);
608 lua_pop(luastate, 1);
612 bool required = lua_toboolean(luastate, -1);
613 lua_pop(luastate, 1);
618 if (strcmp(k,
"ja3") == 0) {
620 }
else if (strcmp(k,
"ja3s") == 0) {
622 }
else if (strcmp(k,
"packet") == 0) {
624 }
else if (strcmp(k,
"payload") == 0) {
626 }
else if (strcmp(k,
"buffer") == 0) {
634 }
else if (strcmp(k,
"stream") == 0) {
643 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
644 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
645 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
646 SCLogError(
"data type %s no longer supported, use rule hooks", k);
656 lua_pop(luastate, 1);
680 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
681 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
692 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
693 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
697 int allow_restricted_functions = 0;
698 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
701 if (DetectLuaSetupPrime(
de_ctx, lua, s) == -1) {
706 DetectLuaThreadInit, (
void *)lua,
707 DetectLuaThreadFree, 0);
713 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
731 list = g_lua_ja3_list_id;
733 list = g_lua_ja3s_list_id;
745 DetectLuaFree(
de_ctx, lua);
764 for (uint16_t i = 0; i < lua->
flowints; i++) {
767 for (uint16_t i = 0; i < lua->
flowvars; i++) {
770 for (uint16_t i = 0; i < lua->
bytevars; i++) {
784 static int LuaMatchTest01(
void)
788 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
789 "function init (args)\n"
790 " flowvarlib.register(\"cnt\")\n"
793 "function thread_init (args)\n"
794 " cnt = flowvarlib.get(\"cnt\")\n"
797 "function match(args)\n"
800 " a = tostring(tonumber(a)+1)\n"
809 " print (\"pre check: \" .. (a))\n"
810 " if tonumber(a) == 2 then\n"
817 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
820 "POST / HTTP/1.1\r\n"
821 "Host: www.emergingthreats.net\r\n\r\n";
823 "POST / HTTP/1.1\r\n"
824 "Host: www.openinfosecfoundation.org\r\n\r\n";
825 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
826 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
836 memset(&th_v, 0,
sizeof(th_v));
837 memset(&f, 0,
sizeof(f));
838 memset(&ssn, 0,
sizeof(ssn));
845 f.
proto = IPPROTO_TCP;
909 static int LuaMatchTest01a(
void)
911 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
912 "function init (args)\n"
913 " flowvarlib.register(\"cnt\")\n"
916 "function thread_init (args)\n"
917 " cnt = flowvarlib.get(\"cnt\")\n"
920 "function match(args)\n"
921 " a = cnt:value(0)\n"
923 " a = tostring(tonumber(a)+1)\n"
932 " print (\"pre check: \" .. (a))\n"
933 " if tonumber(a) == 2 then\n"
940 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
942 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
943 "Host: www.emergingthreats.net\r\n\r\n";
944 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
945 "Host: www.openinfosecfoundation.org\r\n\r\n";
946 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
947 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
957 memset(&th_v, 0,
sizeof(th_v));
958 memset(&f, 0,
sizeof(f));
959 memset(&ssn, 0,
sizeof(ssn));
966 f.
proto = IPPROTO_TCP;
1031 static int LuaMatchTest02(
void)
1033 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1034 "function init (args)\n"
1035 " flowvarlib.register(\"cnt\")\n"
1036 " local needs = {}\n"
1037 " needs[\"payload\"] = tostring(true)\n"
1040 "function thread_init (args)\n"
1041 " cnt = flowvarlib.get(\"cnt\")\n"
1044 "function match(args)\n"
1045 " a = cnt:value()\n"
1047 " a = tostring(tonumber(a)+1)\n"
1051 " a = tostring(1)\n"
1056 " print (\"pre check: \" .. (a))\n"
1057 " if tonumber(a) == 2 then\n"
1058 " print \"match\"\n"
1064 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1065 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1066 "Host: www.emergingthreats.net\r\n\r\n";
1067 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1068 "Host: www.openinfosecfoundation.org\r\n\r\n";
1069 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1070 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1078 memset(&th_v, 0,
sizeof(th_v));
1079 memset(&f, 0,
sizeof(f));
1080 memset(&ssn, 0,
sizeof(ssn));
1087 f.
proto = IPPROTO_TCP;
1142 static int LuaMatchTest02a(
void)
1144 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1145 "function init (args)\n"
1146 " flowvarlib.register(\"cnt\")"
1147 " local needs = {}\n"
1148 " needs[\"payload\"] = tostring(true)\n"
1151 "function thread_init (args)\n"
1152 " cnt = flowvarlib.get(\"cnt\")"
1155 "function match(args)\n"
1156 " a = cnt:value()\n"
1158 " a = tostring(tonumber(a)+1)\n"
1162 " a = tostring(1)\n"
1167 " print (\"pre check: \" .. (a))\n"
1168 " if tonumber(a) == 2 then\n"
1169 " print \"match\"\n"
1175 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1176 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1177 "Host: www.emergingthreats.net\r\n\r\n";
1178 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1179 "Host: www.openinfosecfoundation.org\r\n\r\n";
1180 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1181 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1189 memset(&th_v, 0,
sizeof(th_v));
1190 memset(&f, 0,
sizeof(f));
1191 memset(&ssn, 0,
sizeof(ssn));
1198 f.
proto = IPPROTO_TCP;
1251 static int LuaMatchTest03(
void)
1253 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1254 "function init (args)\n"
1255 " flowvarlib.register(\"cnt\")\n"
1256 " local needs = {}\n"
1257 " needs[\"packet\"] = tostring(true)\n"
1261 "function thread_init (args)\n"
1262 " cnt = flowvarlib.get(\"cnt\")\n"
1265 "function match(args)\n"
1266 " a = cnt:value()\n"
1268 " a = tostring(tonumber(a)+1)\n"
1272 " a = tostring(1)\n"
1277 " print (\"pre check: \" .. (a))\n"
1278 " if tonumber(a) == 2 then\n"
1279 " print \"match\"\n"
1285 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1286 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1287 "Host: www.emergingthreats.net\r\n\r\n";
1288 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1289 "Host: www.openinfosecfoundation.org\r\n\r\n";
1290 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1291 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1299 memset(&th_v, 0,
sizeof(th_v));
1300 memset(&f, 0,
sizeof(f));
1301 memset(&ssn, 0,
sizeof(ssn));
1308 f.
proto = IPPROTO_TCP;
1360 static int LuaMatchTest03a(
void)
1362 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1363 "function init (args)\n"
1364 " flowvarlib.register(\"cnt\")\n"
1365 " local needs = {}\n"
1366 " needs[\"packet\"] = tostring(true)\n"
1370 "function thread_init (args)\n"
1371 " cnt = flowvarlib.get(\"cnt\")\n"
1374 "function match(args)\n"
1375 " a = cnt:value()\n"
1377 " a = tostring(tonumber(a)+1)\n"
1381 " a = tostring(1)\n"
1386 " print (\"pre check: \" .. (a))\n"
1387 " if tonumber(a) == 2 then\n"
1388 " print \"match\"\n"
1394 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1395 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1396 "Host: www.emergingthreats.net\r\n\r\n";
1397 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1398 "Host: www.openinfosecfoundation.org\r\n\r\n";
1399 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1400 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1408 memset(&th_v, 0,
sizeof(th_v));
1409 memset(&f, 0,
sizeof(f));
1410 memset(&ssn, 0,
sizeof(ssn));
1417 f.
proto = IPPROTO_TCP;
1469 static int LuaMatchTest04(
void)
1471 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1472 "function init (args)\n"
1473 " flowintlib.register(\"cnt\")\n"
1477 "function thread_init (args)\n"
1478 " cnt = flowintlib.get(\"cnt\")\n"
1481 "function match(args)\n"
1482 " print \"inspecting\""
1483 " a = cnt:value()\n"
1490 " a = cnt:value()\n"
1492 " print \"match\"\n"
1498 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1500 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1501 "Host: www.emergingthreats.net\r\n\r\n";
1502 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1503 "Host: www.openinfosecfoundation.org\r\n\r\n";
1504 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1505 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1515 memset(&th_v, 0,
sizeof(th_v));
1516 memset(&f, 0,
sizeof(f));
1517 memset(&ssn, 0,
sizeof(ssn));
1524 f.
proto = IPPROTO_TCP;
1586 static int LuaMatchTest04a(
void)
1588 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1589 "function init (args)\n"
1590 " flowintlib.register(\"cnt\")\n"
1594 "function thread_init (args)\n"
1595 " cnt = flowintlib.get(\"cnt\")\n"
1598 "function match(args)\n"
1599 " print \"inspecting\""
1600 " a = cnt:value()\n"
1607 " a = cnt:value()\n"
1609 " print \"match\"\n"
1615 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1617 uint8_t httpbuf1[] =
1618 "POST / HTTP/1.1\r\n"
1619 "Host: www.emergingthreats.net\r\n\r\n";
1620 uint8_t httpbuf2[] =
1621 "POST / HTTP/1.1\r\n"
1622 "Host: www.openinfosecfoundation.org\r\n\r\n";
1623 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1624 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1634 memset(&th_v, 0,
sizeof(th_v));
1635 memset(&f, 0,
sizeof(f));
1636 memset(&ssn, 0,
sizeof(ssn));
1643 f.
proto = IPPROTO_TCP;
1705 static int LuaMatchTest05(
void)
1707 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1708 "function init (args)\n"
1709 " flowintlib.register(\"cnt\")\n"
1713 "function thread_init (args)\n"
1714 " cnt = flowintlib.get(\"cnt\")\n"
1717 "function match(args)\n"
1718 " print \"inspecting\""
1721 " print \"match\"\n"
1727 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1729 uint8_t httpbuf1[] =
1730 "POST / HTTP/1.1\r\n"
1731 "Host: www.emergingthreats.net\r\n\r\n";
1732 uint8_t httpbuf2[] =
1733 "POST / HTTP/1.1\r\n"
1734 "Host: www.openinfosecfoundation.org\r\n\r\n";
1735 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1736 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1746 memset(&th_v, 0,
sizeof(th_v));
1747 memset(&f, 0,
sizeof(f));
1748 memset(&ssn, 0,
sizeof(ssn));
1755 f.
proto = IPPROTO_TCP;
1817 static int LuaMatchTest05a(
void)
1819 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1820 "function init (args)\n"
1821 " flowintlib.register(\"cnt\")\n"
1825 "function thread_init (args)\n"
1826 " cnt = flowintlib.get(\"cnt\")\n"
1829 "function match(args)\n"
1830 " print \"inspecting\""
1833 " print \"match\"\n"
1839 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1841 uint8_t httpbuf1[] =
1842 "POST / HTTP/1.1\r\n"
1843 "Host: www.emergingthreats.net\r\n\r\n";
1844 uint8_t httpbuf2[] =
1845 "POST / HTTP/1.1\r\n"
1846 "Host: www.openinfosecfoundation.org\r\n\r\n";
1847 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1848 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1858 memset(&th_v, 0,
sizeof(th_v));
1859 memset(&f, 0,
sizeof(f));
1860 memset(&ssn, 0,
sizeof(ssn));
1867 f.
proto = IPPROTO_TCP;
1931 static int LuaMatchTest06(
void)
1933 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1934 "function init (args)\n"
1935 " flowintlib.register(\"cnt\")\n"
1939 "function thread_init (args)\n"
1940 " cnt = flowintlib.get(\"cnt\")\n"
1943 "function match(args)\n"
1944 " print \"inspecting\""
1945 " a = cnt:value()\n"
1946 " if a == nil then\n"
1947 " print \"new var set to 2\""
1952 " print \"match\"\n"
1958 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1960 uint8_t httpbuf1[] =
1961 "POST / HTTP/1.1\r\n"
1962 "Host: www.emergingthreats.net\r\n\r\n";
1963 uint8_t httpbuf2[] =
1964 "POST / HTTP/1.1\r\n"
1965 "Host: www.openinfosecfoundation.org\r\n\r\n";
1966 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1967 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1977 memset(&th_v, 0,
sizeof(th_v));
1978 memset(&f, 0,
sizeof(f));
1979 memset(&ssn, 0,
sizeof(ssn));
1986 f.
proto = IPPROTO_TCP;
2048 static int LuaMatchTest06a(
void)
2050 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2051 "function init (args)\n"
2052 " flowintlib.register(\"cnt\")\n"
2056 "function thread_init (args)\n"
2057 " cnt = flowintlib.get(\"cnt\")\n"
2060 "function match(args)\n"
2061 " print \"inspecting\""
2062 " a = cnt:value()\n"
2063 " if a == nil then\n"
2064 " print \"new var set to 2\""
2069 " print \"match\"\n"
2075 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2077 uint8_t httpbuf1[] =
2078 "POST / HTTP/1.1\r\n"
2079 "Host: www.emergingthreats.net\r\n\r\n";
2080 uint8_t httpbuf2[] =
2081 "POST / HTTP/1.1\r\n"
2082 "Host: www.openinfosecfoundation.org\r\n\r\n";
2083 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2084 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2094 memset(&th_v, 0,
sizeof(th_v));
2095 memset(&f, 0,
sizeof(f));
2096 memset(&ssn, 0,
sizeof(ssn));
2103 f.
proto = IPPROTO_TCP;
2164 void DetectLuaRegisterTests(
void)
#define FLAG_MEMORY_LIMIT_LOGGED
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define FLAG_BLOCKED_FUNCTION_LOGGED
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.
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.
int allow_restricted_functions
#define FLAG_INSTRUCTION_LIMIT_LOGGED
main detection engine ctx
uint16_t lua_blocked_function_errors
#define DEFAULT_LUA_INSTRUCTION_LIMIT
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
@ TLS_STATE_SERVER_HELLO_DONE
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]
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
uint16_t lua_instruction_limit_errors
#define SIG_FLAG_TOCLIENT
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FLAG_DATATYPE_PACKET
#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.
uint64_t instruction_limit
@ TLS_STATE_CLIENT_HELLO_DONE
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)
#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
uint16_t lua_memory_limit_errors
DetectLuaDataBytevarEntry bytevar[DETECT_LUA_MAX_BYTEVARS]
#define FLAG_DATATYPE_STREAM
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.
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)
#define DEFAULT_LUA_ALLOC_LIMIT
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)
Do the content inspection & validation for a signature.
union FlowVar_::@116 data
const char luaext_key_ld[]
#define SCLogError(...)
Macro used to log ERROR messages.
#define FLAG_DATATYPE_BUFFER
#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.
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
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(ThreadVars *tv)
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.