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));
838 memset(&f, 0,
sizeof(f));
839 memset(&ssn, 0,
sizeof(ssn));
846 f.
proto = IPPROTO_TCP;
910 static int LuaMatchTest01a(
void)
912 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
913 "function init (args)\n"
914 " flowvarlib.register(\"cnt\")\n"
917 "function thread_init (args)\n"
918 " cnt = flowvarlib.get(\"cnt\")\n"
921 "function match(args)\n"
922 " a = cnt:value(0)\n"
924 " a = tostring(tonumber(a)+1)\n"
933 " print (\"pre check: \" .. (a))\n"
934 " if tonumber(a) == 2 then\n"
941 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
943 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
944 "Host: www.emergingthreats.net\r\n\r\n";
945 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
946 "Host: www.openinfosecfoundation.org\r\n\r\n";
947 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
948 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
958 memset(&th_v, 0,
sizeof(th_v));
960 memset(&f, 0,
sizeof(f));
961 memset(&ssn, 0,
sizeof(ssn));
968 f.
proto = IPPROTO_TCP;
1033 static int LuaMatchTest02(
void)
1035 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1036 "function init (args)\n"
1037 " flowvarlib.register(\"cnt\")\n"
1038 " local needs = {}\n"
1039 " needs[\"payload\"] = tostring(true)\n"
1042 "function thread_init (args)\n"
1043 " cnt = flowvarlib.get(\"cnt\")\n"
1046 "function match(args)\n"
1047 " a = cnt:value()\n"
1049 " a = tostring(tonumber(a)+1)\n"
1053 " a = tostring(1)\n"
1058 " print (\"pre check: \" .. (a))\n"
1059 " if tonumber(a) == 2 then\n"
1060 " print \"match\"\n"
1066 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1067 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1068 "Host: www.emergingthreats.net\r\n\r\n";
1069 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1070 "Host: www.openinfosecfoundation.org\r\n\r\n";
1071 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1072 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1080 memset(&th_v, 0,
sizeof(th_v));
1082 memset(&f, 0,
sizeof(f));
1083 memset(&ssn, 0,
sizeof(ssn));
1090 f.
proto = IPPROTO_TCP;
1145 static int LuaMatchTest02a(
void)
1147 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1148 "function init (args)\n"
1149 " flowvarlib.register(\"cnt\")"
1150 " local needs = {}\n"
1151 " needs[\"payload\"] = tostring(true)\n"
1154 "function thread_init (args)\n"
1155 " cnt = flowvarlib.get(\"cnt\")"
1158 "function match(args)\n"
1159 " a = cnt:value()\n"
1161 " a = tostring(tonumber(a)+1)\n"
1165 " a = tostring(1)\n"
1170 " print (\"pre check: \" .. (a))\n"
1171 " if tonumber(a) == 2 then\n"
1172 " print \"match\"\n"
1178 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1179 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1180 "Host: www.emergingthreats.net\r\n\r\n";
1181 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1182 "Host: www.openinfosecfoundation.org\r\n\r\n";
1183 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1184 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1192 memset(&th_v, 0,
sizeof(th_v));
1194 memset(&f, 0,
sizeof(f));
1195 memset(&ssn, 0,
sizeof(ssn));
1202 f.
proto = IPPROTO_TCP;
1255 static int LuaMatchTest03(
void)
1257 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1258 "function init (args)\n"
1259 " flowvarlib.register(\"cnt\")\n"
1260 " local needs = {}\n"
1261 " needs[\"packet\"] = tostring(true)\n"
1265 "function thread_init (args)\n"
1266 " cnt = flowvarlib.get(\"cnt\")\n"
1269 "function match(args)\n"
1270 " a = cnt:value()\n"
1272 " a = tostring(tonumber(a)+1)\n"
1276 " a = tostring(1)\n"
1281 " print (\"pre check: \" .. (a))\n"
1282 " if tonumber(a) == 2 then\n"
1283 " print \"match\"\n"
1289 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1290 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1291 "Host: www.emergingthreats.net\r\n\r\n";
1292 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1293 "Host: www.openinfosecfoundation.org\r\n\r\n";
1294 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1295 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1303 memset(&th_v, 0,
sizeof(th_v));
1305 memset(&f, 0,
sizeof(f));
1306 memset(&ssn, 0,
sizeof(ssn));
1313 f.
proto = IPPROTO_TCP;
1365 static int LuaMatchTest03a(
void)
1367 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1368 "function init (args)\n"
1369 " flowvarlib.register(\"cnt\")\n"
1370 " local needs = {}\n"
1371 " needs[\"packet\"] = tostring(true)\n"
1375 "function thread_init (args)\n"
1376 " cnt = flowvarlib.get(\"cnt\")\n"
1379 "function match(args)\n"
1380 " a = cnt:value()\n"
1382 " a = tostring(tonumber(a)+1)\n"
1386 " a = tostring(1)\n"
1391 " print (\"pre check: \" .. (a))\n"
1392 " if tonumber(a) == 2 then\n"
1393 " print \"match\"\n"
1399 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1400 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1401 "Host: www.emergingthreats.net\r\n\r\n";
1402 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1403 "Host: www.openinfosecfoundation.org\r\n\r\n";
1404 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1405 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1413 memset(&th_v, 0,
sizeof(th_v));
1415 memset(&f, 0,
sizeof(f));
1416 memset(&ssn, 0,
sizeof(ssn));
1423 f.
proto = IPPROTO_TCP;
1475 static int LuaMatchTest04(
void)
1477 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1478 "function init (args)\n"
1479 " flowintlib.register(\"cnt\")\n"
1483 "function thread_init (args)\n"
1484 " cnt = flowintlib.get(\"cnt\")\n"
1487 "function match(args)\n"
1488 " print \"inspecting\""
1489 " a = cnt:value()\n"
1496 " a = cnt:value()\n"
1498 " print \"match\"\n"
1504 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1506 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1507 "Host: www.emergingthreats.net\r\n\r\n";
1508 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1509 "Host: www.openinfosecfoundation.org\r\n\r\n";
1510 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1511 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1521 memset(&th_v, 0,
sizeof(th_v));
1523 memset(&f, 0,
sizeof(f));
1524 memset(&ssn, 0,
sizeof(ssn));
1531 f.
proto = IPPROTO_TCP;
1593 static int LuaMatchTest04a(
void)
1595 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1596 "function init (args)\n"
1597 " flowintlib.register(\"cnt\")\n"
1601 "function thread_init (args)\n"
1602 " cnt = flowintlib.get(\"cnt\")\n"
1605 "function match(args)\n"
1606 " print \"inspecting\""
1607 " a = cnt:value()\n"
1614 " a = cnt:value()\n"
1616 " print \"match\"\n"
1622 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1624 uint8_t httpbuf1[] =
1625 "POST / HTTP/1.1\r\n"
1626 "Host: www.emergingthreats.net\r\n\r\n";
1627 uint8_t httpbuf2[] =
1628 "POST / HTTP/1.1\r\n"
1629 "Host: www.openinfosecfoundation.org\r\n\r\n";
1630 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1631 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1641 memset(&th_v, 0,
sizeof(th_v));
1643 memset(&f, 0,
sizeof(f));
1644 memset(&ssn, 0,
sizeof(ssn));
1651 f.
proto = IPPROTO_TCP;
1713 static int LuaMatchTest05(
void)
1715 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1716 "function init (args)\n"
1717 " flowintlib.register(\"cnt\")\n"
1721 "function thread_init (args)\n"
1722 " cnt = flowintlib.get(\"cnt\")\n"
1725 "function match(args)\n"
1726 " print \"inspecting\""
1729 " print \"match\"\n"
1735 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1737 uint8_t httpbuf1[] =
1738 "POST / HTTP/1.1\r\n"
1739 "Host: www.emergingthreats.net\r\n\r\n";
1740 uint8_t httpbuf2[] =
1741 "POST / HTTP/1.1\r\n"
1742 "Host: www.openinfosecfoundation.org\r\n\r\n";
1743 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1744 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1754 memset(&th_v, 0,
sizeof(th_v));
1756 memset(&f, 0,
sizeof(f));
1757 memset(&ssn, 0,
sizeof(ssn));
1764 f.
proto = IPPROTO_TCP;
1826 static int LuaMatchTest05a(
void)
1828 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1829 "function init (args)\n"
1830 " flowintlib.register(\"cnt\")\n"
1834 "function thread_init (args)\n"
1835 " cnt = flowintlib.get(\"cnt\")\n"
1838 "function match(args)\n"
1839 " print \"inspecting\""
1842 " print \"match\"\n"
1848 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1850 uint8_t httpbuf1[] =
1851 "POST / HTTP/1.1\r\n"
1852 "Host: www.emergingthreats.net\r\n\r\n";
1853 uint8_t httpbuf2[] =
1854 "POST / HTTP/1.1\r\n"
1855 "Host: www.openinfosecfoundation.org\r\n\r\n";
1856 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1857 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1867 memset(&th_v, 0,
sizeof(th_v));
1869 memset(&f, 0,
sizeof(f));
1870 memset(&ssn, 0,
sizeof(ssn));
1877 f.
proto = IPPROTO_TCP;
1941 static int LuaMatchTest06(
void)
1943 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1944 "function init (args)\n"
1945 " flowintlib.register(\"cnt\")\n"
1949 "function thread_init (args)\n"
1950 " cnt = flowintlib.get(\"cnt\")\n"
1953 "function match(args)\n"
1954 " print \"inspecting\""
1955 " a = cnt:value()\n"
1956 " if a == nil then\n"
1957 " print \"new var set to 2\""
1962 " print \"match\"\n"
1968 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1970 uint8_t httpbuf1[] =
1971 "POST / HTTP/1.1\r\n"
1972 "Host: www.emergingthreats.net\r\n\r\n";
1973 uint8_t httpbuf2[] =
1974 "POST / HTTP/1.1\r\n"
1975 "Host: www.openinfosecfoundation.org\r\n\r\n";
1976 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1977 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1987 memset(&th_v, 0,
sizeof(th_v));
1989 memset(&f, 0,
sizeof(f));
1990 memset(&ssn, 0,
sizeof(ssn));
1997 f.
proto = IPPROTO_TCP;
2059 static int LuaMatchTest06a(
void)
2061 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2062 "function init (args)\n"
2063 " flowintlib.register(\"cnt\")\n"
2067 "function thread_init (args)\n"
2068 " cnt = flowintlib.get(\"cnt\")\n"
2071 "function match(args)\n"
2072 " print \"inspecting\""
2073 " a = cnt:value()\n"
2074 " if a == nil then\n"
2075 " print \"new var set to 2\""
2080 " print \"match\"\n"
2086 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2088 uint8_t httpbuf1[] =
2089 "POST / HTTP/1.1\r\n"
2090 "Host: www.emergingthreats.net\r\n\r\n";
2091 uint8_t httpbuf2[] =
2092 "POST / HTTP/1.1\r\n"
2093 "Host: www.openinfosecfoundation.org\r\n\r\n";
2094 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2095 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2105 memset(&th_v, 0,
sizeof(th_v));
2107 memset(&f, 0,
sizeof(f));
2108 memset(&ssn, 0,
sizeof(ssn));
2115 f.
proto = IPPROTO_TCP;
2176 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.
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define FLAG_BLOCKED_FUNCTION_LOGGED
union FlowVar_::@117 data
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
#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)
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
#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.
StatsCounterId lua_memory_limit_errors
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)
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]
#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.
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)
#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.
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(StatsThreadContext *stats)
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.