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)
265 lua_getglobal(tlua->
luastate,
"match");
268 lua_pushliteral(tlua->
luastate,
"offset");
279 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
312 flags = STREAM_TOSERVER;
314 flags = STREAM_TOCLIENT;
329 lua_getglobal(tlua->
luastate,
"match");
335 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
361 lua_getglobal(tlua->
luastate,
"match");
367 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
386 void *state,
void *txv,
const Signature *s,
389 return DetectLuaAppMatchCommon(det_ctx, f,
flags, state, s,
ctx);
395 static const char *ut_script = NULL;
398 static void *DetectLuaThreadInit(
void *data)
425 LuaStateSetDetectLuaData(t->
luastate, lua);
429 if (ut_script != NULL) {
430 status = luaL_loadbuffer(t->
luastate, ut_script, strlen(ut_script),
"unittest");
447 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
453 lua_getglobal(t->
luastate,
"thread_init");
454 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 DetectLuaThreadFree(
void *
ctx)
501 if (strlen(
str) &&
str[0] ==
'!') {
515 DetectLuaFree(
de_ctx, lua);
524 if (luastate == NULL)
527 luaL_openlibs(luastate);
532 LuaStateSetDetectLuaData(luastate, ld);
536 if (ut_script != NULL) {
537 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
539 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
544 status = luaL_loadfile(luastate, ld->
filename);
546 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
554 if (lua_pcall(luastate, 0, 0, 0) != 0) {
555 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
559 lua_getglobal(luastate,
"init");
560 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
567 lua_pushlightuserdata(luastate, (
void *)s);
569 if (lua_pcall(luastate, 1, 1, 0) != 0) {
570 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
575 if (lua_gettop(luastate) == 0) {
576 SCLogError(
"init function in script should return table, nothing returned");
579 if (lua_type(luastate, 1) != LUA_TTABLE) {
580 SCLogError(
"init function in script should return table, returned is not table");
584 lua_pushnil(luastate);
586 while (lua_next(luastate, -2)) {
587 k = lua_tostring(luastate, -2);
592 if (strcmp(k,
"flowvar") == 0) {
593 if (lua_istable(luastate, -1)) {
594 lua_pushnil(luastate);
595 while (lua_next(luastate, -2) != 0) {
597 const char *value = lua_tostring(luastate, -1);
600 lua_pop(luastate, 1);
614 lua_pop(luastate, 1);
616 }
else if (strcmp(k,
"flowint") == 0) {
617 if (lua_istable(luastate, -1)) {
618 lua_pushnil(luastate);
619 while (lua_next(luastate, -2) != 0) {
621 const char *value = lua_tostring(luastate, -1);
624 lua_pop(luastate, 1);
638 lua_pop(luastate, 1);
642 bool required = lua_toboolean(luastate, -1);
643 lua_pop(luastate, 1);
648 if (strcmp(k,
"ja3") == 0) {
650 }
else if (strcmp(k,
"ja3s") == 0) {
652 }
else if (strcmp(k,
"packet") == 0) {
654 }
else if (strcmp(k,
"payload") == 0) {
656 }
else if (strcmp(k,
"buffer") == 0) {
664 }
else if (strcmp(k,
"stream") == 0) {
673 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
674 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
675 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
676 SCLogError(
"data type %s no longer supported, use rule hooks", k);
686 lua_pop(luastate, 1);
710 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
711 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
722 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
723 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
727 int allow_restricted_functions = 0;
728 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
731 if (DetectLuaSetupPrime(
de_ctx, lua, s) == -1) {
736 DetectLuaThreadInit, (
void *)lua,
737 DetectLuaThreadFree, 0);
743 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
761 list = g_lua_ja3_list_id;
763 list = g_lua_ja3s_list_id;
775 DetectLuaFree(
de_ctx, lua);
794 for (uint16_t i = 0; i < lua->
flowints; i++) {
797 for (uint16_t i = 0; i < lua->
flowvars; i++) {
800 for (uint16_t i = 0; i < lua->
bytevars; i++) {
814 static int LuaMatchTest01(
void)
818 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
819 "function init (args)\n"
820 " flowvarlib.register(\"cnt\")\n"
823 "function thread_init (args)\n"
824 " cnt = flowvarlib.get(\"cnt\")\n"
827 "function match(args)\n"
830 " a = tostring(tonumber(a)+1)\n"
839 " print (\"pre check: \" .. (a))\n"
840 " if tonumber(a) == 2 then\n"
847 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
850 "POST / HTTP/1.1\r\n"
851 "Host: www.emergingthreats.net\r\n\r\n";
853 "POST / HTTP/1.1\r\n"
854 "Host: www.openinfosecfoundation.org\r\n\r\n";
855 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
856 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
866 memset(&th_v, 0,
sizeof(th_v));
868 memset(&f, 0,
sizeof(f));
869 memset(&ssn, 0,
sizeof(ssn));
876 f.
proto = IPPROTO_TCP;
940 static int LuaMatchTest01a(
void)
942 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
943 "function init (args)\n"
944 " flowvarlib.register(\"cnt\")\n"
947 "function thread_init (args)\n"
948 " cnt = flowvarlib.get(\"cnt\")\n"
951 "function match(args)\n"
952 " a = cnt:value(0)\n"
954 " a = tostring(tonumber(a)+1)\n"
963 " print (\"pre check: \" .. (a))\n"
964 " if tonumber(a) == 2 then\n"
971 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
973 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
974 "Host: www.emergingthreats.net\r\n\r\n";
975 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
976 "Host: www.openinfosecfoundation.org\r\n\r\n";
977 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
978 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
988 memset(&th_v, 0,
sizeof(th_v));
990 memset(&f, 0,
sizeof(f));
991 memset(&ssn, 0,
sizeof(ssn));
998 f.
proto = IPPROTO_TCP;
1063 static int LuaMatchTest02(
void)
1065 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1066 "function init (args)\n"
1067 " flowvarlib.register(\"cnt\")\n"
1068 " local needs = {}\n"
1069 " needs[\"payload\"] = tostring(true)\n"
1072 "function thread_init (args)\n"
1073 " cnt = flowvarlib.get(\"cnt\")\n"
1076 "function match(args)\n"
1077 " a = cnt:value()\n"
1079 " a = tostring(tonumber(a)+1)\n"
1083 " a = tostring(1)\n"
1088 " print (\"pre check: \" .. (a))\n"
1089 " if tonumber(a) == 2 then\n"
1090 " print \"match\"\n"
1096 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1097 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1098 "Host: www.emergingthreats.net\r\n\r\n";
1099 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1100 "Host: www.openinfosecfoundation.org\r\n\r\n";
1101 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1102 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1110 memset(&th_v, 0,
sizeof(th_v));
1112 memset(&f, 0,
sizeof(f));
1113 memset(&ssn, 0,
sizeof(ssn));
1120 f.
proto = IPPROTO_TCP;
1175 static int LuaMatchTest02a(
void)
1177 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1178 "function init (args)\n"
1179 " flowvarlib.register(\"cnt\")"
1180 " local needs = {}\n"
1181 " needs[\"payload\"] = tostring(true)\n"
1184 "function thread_init (args)\n"
1185 " cnt = flowvarlib.get(\"cnt\")"
1188 "function match(args)\n"
1189 " a = cnt:value()\n"
1191 " a = tostring(tonumber(a)+1)\n"
1195 " a = tostring(1)\n"
1200 " print (\"pre check: \" .. (a))\n"
1201 " if tonumber(a) == 2 then\n"
1202 " print \"match\"\n"
1208 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1209 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1210 "Host: www.emergingthreats.net\r\n\r\n";
1211 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1212 "Host: www.openinfosecfoundation.org\r\n\r\n";
1213 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1214 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1222 memset(&th_v, 0,
sizeof(th_v));
1224 memset(&f, 0,
sizeof(f));
1225 memset(&ssn, 0,
sizeof(ssn));
1232 f.
proto = IPPROTO_TCP;
1285 static int LuaMatchTest03(
void)
1287 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1288 "function init (args)\n"
1289 " flowvarlib.register(\"cnt\")\n"
1290 " local needs = {}\n"
1291 " needs[\"packet\"] = tostring(true)\n"
1295 "function thread_init (args)\n"
1296 " cnt = flowvarlib.get(\"cnt\")\n"
1299 "function match(args)\n"
1300 " a = cnt:value()\n"
1302 " a = tostring(tonumber(a)+1)\n"
1306 " a = tostring(1)\n"
1311 " print (\"pre check: \" .. (a))\n"
1312 " if tonumber(a) == 2 then\n"
1313 " print \"match\"\n"
1319 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1320 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1321 "Host: www.emergingthreats.net\r\n\r\n";
1322 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1323 "Host: www.openinfosecfoundation.org\r\n\r\n";
1324 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1325 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1333 memset(&th_v, 0,
sizeof(th_v));
1335 memset(&f, 0,
sizeof(f));
1336 memset(&ssn, 0,
sizeof(ssn));
1343 f.
proto = IPPROTO_TCP;
1395 static int LuaMatchTest03a(
void)
1397 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1398 "function init (args)\n"
1399 " flowvarlib.register(\"cnt\")\n"
1400 " local needs = {}\n"
1401 " needs[\"packet\"] = tostring(true)\n"
1405 "function thread_init (args)\n"
1406 " cnt = flowvarlib.get(\"cnt\")\n"
1409 "function match(args)\n"
1410 " a = cnt:value()\n"
1412 " a = tostring(tonumber(a)+1)\n"
1416 " a = tostring(1)\n"
1421 " print (\"pre check: \" .. (a))\n"
1422 " if tonumber(a) == 2 then\n"
1423 " print \"match\"\n"
1429 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1430 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1431 "Host: www.emergingthreats.net\r\n\r\n";
1432 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1433 "Host: www.openinfosecfoundation.org\r\n\r\n";
1434 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1435 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1443 memset(&th_v, 0,
sizeof(th_v));
1445 memset(&f, 0,
sizeof(f));
1446 memset(&ssn, 0,
sizeof(ssn));
1453 f.
proto = IPPROTO_TCP;
1505 static int LuaMatchTest04(
void)
1507 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1508 "function init (args)\n"
1509 " flowintlib.register(\"cnt\")\n"
1513 "function thread_init (args)\n"
1514 " cnt = flowintlib.get(\"cnt\")\n"
1517 "function match(args)\n"
1518 " print \"inspecting\""
1519 " a = cnt:value()\n"
1526 " a = cnt:value()\n"
1528 " print \"match\"\n"
1534 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1536 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1537 "Host: www.emergingthreats.net\r\n\r\n";
1538 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1539 "Host: www.openinfosecfoundation.org\r\n\r\n";
1540 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1541 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1551 memset(&th_v, 0,
sizeof(th_v));
1553 memset(&f, 0,
sizeof(f));
1554 memset(&ssn, 0,
sizeof(ssn));
1561 f.
proto = IPPROTO_TCP;
1623 static int LuaMatchTest04a(
void)
1625 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1626 "function init (args)\n"
1627 " flowintlib.register(\"cnt\")\n"
1631 "function thread_init (args)\n"
1632 " cnt = flowintlib.get(\"cnt\")\n"
1635 "function match(args)\n"
1636 " print \"inspecting\""
1637 " a = cnt:value()\n"
1644 " a = cnt:value()\n"
1646 " print \"match\"\n"
1652 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1654 uint8_t httpbuf1[] =
1655 "POST / HTTP/1.1\r\n"
1656 "Host: www.emergingthreats.net\r\n\r\n";
1657 uint8_t httpbuf2[] =
1658 "POST / HTTP/1.1\r\n"
1659 "Host: www.openinfosecfoundation.org\r\n\r\n";
1660 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1661 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1671 memset(&th_v, 0,
sizeof(th_v));
1673 memset(&f, 0,
sizeof(f));
1674 memset(&ssn, 0,
sizeof(ssn));
1681 f.
proto = IPPROTO_TCP;
1743 static int LuaMatchTest05(
void)
1745 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1746 "function init (args)\n"
1747 " flowintlib.register(\"cnt\")\n"
1751 "function thread_init (args)\n"
1752 " cnt = flowintlib.get(\"cnt\")\n"
1755 "function match(args)\n"
1756 " print \"inspecting\""
1759 " print \"match\"\n"
1765 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1767 uint8_t httpbuf1[] =
1768 "POST / HTTP/1.1\r\n"
1769 "Host: www.emergingthreats.net\r\n\r\n";
1770 uint8_t httpbuf2[] =
1771 "POST / HTTP/1.1\r\n"
1772 "Host: www.openinfosecfoundation.org\r\n\r\n";
1773 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1774 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1784 memset(&th_v, 0,
sizeof(th_v));
1786 memset(&f, 0,
sizeof(f));
1787 memset(&ssn, 0,
sizeof(ssn));
1794 f.
proto = IPPROTO_TCP;
1856 static int LuaMatchTest05a(
void)
1858 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1859 "function init (args)\n"
1860 " flowintlib.register(\"cnt\")\n"
1864 "function thread_init (args)\n"
1865 " cnt = flowintlib.get(\"cnt\")\n"
1868 "function match(args)\n"
1869 " print \"inspecting\""
1872 " print \"match\"\n"
1878 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1880 uint8_t httpbuf1[] =
1881 "POST / HTTP/1.1\r\n"
1882 "Host: www.emergingthreats.net\r\n\r\n";
1883 uint8_t httpbuf2[] =
1884 "POST / HTTP/1.1\r\n"
1885 "Host: www.openinfosecfoundation.org\r\n\r\n";
1886 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1887 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1897 memset(&th_v, 0,
sizeof(th_v));
1899 memset(&f, 0,
sizeof(f));
1900 memset(&ssn, 0,
sizeof(ssn));
1907 f.
proto = IPPROTO_TCP;
1971 static int LuaMatchTest06(
void)
1973 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1974 "function init (args)\n"
1975 " flowintlib.register(\"cnt\")\n"
1979 "function thread_init (args)\n"
1980 " cnt = flowintlib.get(\"cnt\")\n"
1983 "function match(args)\n"
1984 " print \"inspecting\""
1985 " a = cnt:value()\n"
1986 " if a == nil then\n"
1987 " print \"new var set to 2\""
1992 " print \"match\"\n"
1998 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2000 uint8_t httpbuf1[] =
2001 "POST / HTTP/1.1\r\n"
2002 "Host: www.emergingthreats.net\r\n\r\n";
2003 uint8_t httpbuf2[] =
2004 "POST / HTTP/1.1\r\n"
2005 "Host: www.openinfosecfoundation.org\r\n\r\n";
2006 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2007 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2017 memset(&th_v, 0,
sizeof(th_v));
2019 memset(&f, 0,
sizeof(f));
2020 memset(&ssn, 0,
sizeof(ssn));
2027 f.
proto = IPPROTO_TCP;
2089 static int LuaMatchTest06a(
void)
2091 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2092 "function init (args)\n"
2093 " flowintlib.register(\"cnt\")\n"
2097 "function thread_init (args)\n"
2098 " cnt = flowintlib.get(\"cnt\")\n"
2101 "function match(args)\n"
2102 " print \"inspecting\""
2103 " a = cnt:value()\n"
2104 " if a == nil then\n"
2105 " print \"new var set to 2\""
2110 " print \"match\"\n"
2116 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2118 uint8_t httpbuf1[] =
2119 "POST / HTTP/1.1\r\n"
2120 "Host: www.emergingthreats.net\r\n\r\n";
2121 uint8_t httpbuf2[] =
2122 "POST / HTTP/1.1\r\n"
2123 "Host: www.openinfosecfoundation.org\r\n\r\n";
2124 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2125 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2135 memset(&th_v, 0,
sizeof(th_v));
2137 memset(&f, 0,
sizeof(f));
2138 memset(&ssn, 0,
sizeof(ssn));
2145 f.
proto = IPPROTO_TCP;
2206 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 SCLuaSbUpdateBytesLimit(lua_State *L)
void(* Free)(DetectEngineCtx *, void *)
#define FLAG_BLOCKED_FUNCTION_LOGGED
union FlowVar_::@117 data
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.
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.
void SCLuaSbRestoreBytesLimit(lua_State *L, const uint64_t cfg_limit)
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.