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_LIST_JA3 BIT_U32(3)
115 #define FLAG_LIST_JA3S BIT_U32(4)
116 #define FLAG_ERROR_LOGGED BIT_U32(23)
117 #define FLAG_BLOCKED_FUNCTION_LOGGED BIT_U32(24)
118 #define FLAG_INSTRUCTION_LIMIT_LOGGED BIT_U32(25)
119 #define FLAG_MEMORY_LIMIT_LOGGED BIT_U32(26)
121 #define DEFAULT_LUA_ALLOC_LIMIT 500000
122 #define DEFAULT_LUA_INSTRUCTION_LIMIT 500000
127 int size = lua_gettop(state);
128 printf(
"%s: size %d\n", prefix, size);
130 for (
int i = 1; i <= size; i++) {
131 int type = lua_type(state, i);
132 printf(
"- %s: Stack size=%d, level=%d, type=%d, ", prefix, size, i,
type);
136 printf(
"function %s", lua_tostring(state, i));
139 printf(
"bool %s", lua_toboolean(state, i) ?
"true" :
"false");
142 printf(
"number %g", lua_tonumber(state, i));
145 printf(
"string `%s'", lua_tostring(state, i));
148 printf(
"table `%s'", lua_tostring(state, i));
151 printf(
"other %s", lua_typename(state,
type));
162 lua_pushlightuserdata(state, (
void *)data);
163 lua_settable(state, LUA_REGISTRYINDEX);
170 static int DetectLuaRunMatch(
176 if (lua_pcall(tlua->
luastate, 1, 1, 0) != 0) {
177 const char *reason = lua_tostring(tlua->
luastate, -1);
188 reason =
"memory limit exceeded";
196 if (!(tlua->
flags & flag)) {
197 SCLogWarning(
"Lua script failed to run successfully: %s", reason);
202 while (lua_gettop(tlua->
luastate) > 0) {
211 if (lua_gettop(tlua->
luastate) > 0) {
213 if (lua_type(tlua->
luastate, 1) == LUA_TNUMBER) {
214 lua_Integer script_ret = lua_tointeger(tlua->
luastate, 1);
220 SCLogDebug(
"Unsupported datatype returned from Lua script");
231 while (lua_gettop(tlua->
luastate) > 0) {
244 if (buffer == NULL || buffer_len == 0)
263 lua_getglobal(tlua->
luastate,
"match");
266 lua_pushliteral(tlua->
luastate,
"offset");
277 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
310 flags = STREAM_TOSERVER;
312 flags = STREAM_TOCLIENT;
327 lua_getglobal(tlua->
luastate,
"match");
333 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
359 lua_getglobal(tlua->
luastate,
"match");
365 int r = DetectLuaRunMatch(det_ctx, lua, tlua);
384 void *state,
void *txv,
const Signature *s,
387 return DetectLuaAppMatchCommon(det_ctx, f,
flags, state, s,
ctx);
393 static const char *ut_script = NULL;
396 static void *DetectLuaThreadInit(
void *data,
bool allow_restricted_functions)
416 if (allow_restricted_functions) {
423 LuaStateSetDetectLuaData(t->
luastate, lua);
427 if (ut_script != NULL) {
428 status = luaL_loadbuffer(t->
luastate, ut_script, strlen(ut_script),
"unittest");
445 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
451 lua_getglobal(t->
luastate,
"thread_init");
452 if (lua_isfunction(t->
luastate, -1)) {
453 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
454 SCLogError(
"couldn't run script 'thread_init' function: %s",
471 static void *DetectLuaThreadRestrictedInit(
void *data)
473 return DetectLuaThreadInit(data,
false);
476 static void *DetectLuaThreadAllowInit(
void *data)
478 return DetectLuaThreadInit(data,
true);
481 static void DetectLuaThreadFree(
void *
ctx)
509 if (strlen(
str) &&
str[0] ==
'!') {
523 DetectLuaFree(
de_ctx, lua);
528 int allow_restricted_functions)
533 if (luastate == NULL)
535 if (allow_restricted_functions) {
536 luaL_openlibs(luastate);
541 LuaStateSetDetectLuaData(luastate, ld);
545 if (ut_script != NULL) {
546 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
548 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
553 status = luaL_loadfile(luastate, ld->
filename);
555 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
563 if (lua_pcall(luastate, 0, 0, 0) != 0) {
564 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
568 lua_getglobal(luastate,
"init");
569 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
576 lua_pushlightuserdata(luastate, (
void *)s);
578 if (lua_pcall(luastate, 1, 1, 0) != 0) {
579 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
584 if (lua_gettop(luastate) == 0) {
585 SCLogError(
"init function in script should return table, nothing returned");
588 if (lua_type(luastate, 1) != LUA_TTABLE) {
589 SCLogError(
"init function in script should return table, returned is not table");
593 lua_pushnil(luastate);
595 while (lua_next(luastate, -2)) {
596 k = lua_tostring(luastate, -2);
601 if (strcmp(k,
"flowvar") == 0) {
602 if (lua_istable(luastate, -1)) {
603 lua_pushnil(luastate);
604 while (lua_next(luastate, -2) != 0) {
606 const char *value = lua_tostring(luastate, -1);
609 lua_pop(luastate, 1);
623 lua_pop(luastate, 1);
625 }
else if (strcmp(k,
"flowint") == 0) {
626 if (lua_istable(luastate, -1)) {
627 lua_pushnil(luastate);
628 while (lua_next(luastate, -2) != 0) {
630 const char *value = lua_tostring(luastate, -1);
633 lua_pop(luastate, 1);
647 lua_pop(luastate, 1);
651 bool required = lua_toboolean(luastate, -1);
652 lua_pop(luastate, 1);
657 if (strcmp(k,
"ja3") == 0) {
659 }
else if (strcmp(k,
"ja3s") == 0) {
661 }
else if (strcmp(k,
"packet") == 0) {
663 }
else if (strcmp(k,
"payload") == 0) {
665 }
else if (strcmp(k,
"buffer") == 0) {
671 }
else if (strcmp(k,
"stream") == 0) {
678 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
679 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
680 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
681 SCLogError(
"data type %s no longer supported, use rule hooks", k);
691 lua_pop(luastate, 1);
715 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
716 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
727 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
728 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
732 int allow_restricted_functions = 0;
733 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
735 if (DetectLuaSetupPrime(
de_ctx, lua, s, allow_restricted_functions) == -1) {
739 void *cb = DetectLuaThreadRestrictedInit;
740 if (allow_restricted_functions) {
741 cb = DetectLuaThreadAllowInit;
751 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
769 list = g_lua_ja3_list_id;
771 list = g_lua_ja3s_list_id;
783 DetectLuaFree(
de_ctx, lua);
802 for (uint16_t i = 0; i < lua->
flowints; i++) {
805 for (uint16_t i = 0; i < lua->
flowvars; i++) {
808 for (uint16_t i = 0; i < lua->
bytevars; i++) {
822 static int LuaMatchTest01(
void)
826 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
827 "function init (args)\n"
828 " flowvarlib.register(\"cnt\")\n"
831 "function thread_init (args)\n"
832 " cnt = flowvarlib.get(\"cnt\")\n"
835 "function match(args)\n"
838 " a = tostring(tonumber(a)+1)\n"
847 " print (\"pre check: \" .. (a))\n"
848 " if tonumber(a) == 2 then\n"
855 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
858 "POST / HTTP/1.1\r\n"
859 "Host: www.emergingthreats.net\r\n\r\n";
861 "POST / HTTP/1.1\r\n"
862 "Host: www.openinfosecfoundation.org\r\n\r\n";
863 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
864 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
874 memset(&th_v, 0,
sizeof(th_v));
876 memset(&f, 0,
sizeof(f));
877 memset(&ssn, 0,
sizeof(ssn));
884 f.
proto = IPPROTO_TCP;
948 static int LuaMatchTest01a(
void)
950 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
951 "function init (args)\n"
952 " flowvarlib.register(\"cnt\")\n"
955 "function thread_init (args)\n"
956 " cnt = flowvarlib.get(\"cnt\")\n"
959 "function match(args)\n"
960 " a = cnt:value(0)\n"
962 " a = tostring(tonumber(a)+1)\n"
971 " print (\"pre check: \" .. (a))\n"
972 " if tonumber(a) == 2 then\n"
979 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
981 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
982 "Host: www.emergingthreats.net\r\n\r\n";
983 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
984 "Host: www.openinfosecfoundation.org\r\n\r\n";
985 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
986 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
996 memset(&th_v, 0,
sizeof(th_v));
998 memset(&f, 0,
sizeof(f));
999 memset(&ssn, 0,
sizeof(ssn));
1006 f.
proto = IPPROTO_TCP;
1071 static int LuaMatchTest02(
void)
1073 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1074 "function init (args)\n"
1075 " flowvarlib.register(\"cnt\")\n"
1076 " local needs = {}\n"
1077 " needs[\"payload\"] = tostring(true)\n"
1080 "function thread_init (args)\n"
1081 " cnt = flowvarlib.get(\"cnt\")\n"
1084 "function match(args)\n"
1085 " a = cnt:value()\n"
1087 " a = tostring(tonumber(a)+1)\n"
1091 " a = tostring(1)\n"
1096 " print (\"pre check: \" .. (a))\n"
1097 " if tonumber(a) == 2 then\n"
1098 " print \"match\"\n"
1104 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1105 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1106 "Host: www.emergingthreats.net\r\n\r\n";
1107 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1108 "Host: www.openinfosecfoundation.org\r\n\r\n";
1109 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1110 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1118 memset(&th_v, 0,
sizeof(th_v));
1120 memset(&f, 0,
sizeof(f));
1121 memset(&ssn, 0,
sizeof(ssn));
1128 f.
proto = IPPROTO_TCP;
1183 static int LuaMatchTest02a(
void)
1185 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1186 "function init (args)\n"
1187 " flowvarlib.register(\"cnt\")"
1188 " local needs = {}\n"
1189 " needs[\"payload\"] = tostring(true)\n"
1192 "function thread_init (args)\n"
1193 " cnt = flowvarlib.get(\"cnt\")"
1196 "function match(args)\n"
1197 " a = cnt:value()\n"
1199 " a = tostring(tonumber(a)+1)\n"
1203 " a = tostring(1)\n"
1208 " print (\"pre check: \" .. (a))\n"
1209 " if tonumber(a) == 2 then\n"
1210 " print \"match\"\n"
1216 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1217 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1218 "Host: www.emergingthreats.net\r\n\r\n";
1219 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1220 "Host: www.openinfosecfoundation.org\r\n\r\n";
1221 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1222 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1230 memset(&th_v, 0,
sizeof(th_v));
1232 memset(&f, 0,
sizeof(f));
1233 memset(&ssn, 0,
sizeof(ssn));
1240 f.
proto = IPPROTO_TCP;
1293 static int LuaMatchTest03(
void)
1295 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1296 "function init (args)\n"
1297 " flowvarlib.register(\"cnt\")\n"
1298 " local needs = {}\n"
1299 " needs[\"packet\"] = tostring(true)\n"
1303 "function thread_init (args)\n"
1304 " cnt = flowvarlib.get(\"cnt\")\n"
1307 "function match(args)\n"
1308 " a = cnt:value()\n"
1310 " a = tostring(tonumber(a)+1)\n"
1314 " a = tostring(1)\n"
1319 " print (\"pre check: \" .. (a))\n"
1320 " if tonumber(a) == 2 then\n"
1321 " print \"match\"\n"
1327 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1328 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1329 "Host: www.emergingthreats.net\r\n\r\n";
1330 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1331 "Host: www.openinfosecfoundation.org\r\n\r\n";
1332 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1333 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1341 memset(&th_v, 0,
sizeof(th_v));
1343 memset(&f, 0,
sizeof(f));
1344 memset(&ssn, 0,
sizeof(ssn));
1351 f.
proto = IPPROTO_TCP;
1403 static int LuaMatchTest03a(
void)
1405 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1406 "function init (args)\n"
1407 " flowvarlib.register(\"cnt\")\n"
1408 " local needs = {}\n"
1409 " needs[\"packet\"] = tostring(true)\n"
1413 "function thread_init (args)\n"
1414 " cnt = flowvarlib.get(\"cnt\")\n"
1417 "function match(args)\n"
1418 " a = cnt:value()\n"
1420 " a = tostring(tonumber(a)+1)\n"
1424 " a = tostring(1)\n"
1429 " print (\"pre check: \" .. (a))\n"
1430 " if tonumber(a) == 2 then\n"
1431 " print \"match\"\n"
1437 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1438 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1439 "Host: www.emergingthreats.net\r\n\r\n";
1440 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1441 "Host: www.openinfosecfoundation.org\r\n\r\n";
1442 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1443 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1451 memset(&th_v, 0,
sizeof(th_v));
1453 memset(&f, 0,
sizeof(f));
1454 memset(&ssn, 0,
sizeof(ssn));
1461 f.
proto = IPPROTO_TCP;
1513 static int LuaMatchTest04(
void)
1515 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1516 "function init (args)\n"
1517 " flowintlib.register(\"cnt\")\n"
1521 "function thread_init (args)\n"
1522 " cnt = flowintlib.get(\"cnt\")\n"
1525 "function match(args)\n"
1526 " print \"inspecting\""
1527 " a = cnt:value()\n"
1534 " a = cnt:value()\n"
1536 " print \"match\"\n"
1542 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1544 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1545 "Host: www.emergingthreats.net\r\n\r\n";
1546 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1547 "Host: www.openinfosecfoundation.org\r\n\r\n";
1548 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1549 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1559 memset(&th_v, 0,
sizeof(th_v));
1561 memset(&f, 0,
sizeof(f));
1562 memset(&ssn, 0,
sizeof(ssn));
1569 f.
proto = IPPROTO_TCP;
1631 static int LuaMatchTest04a(
void)
1633 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1634 "function init (args)\n"
1635 " flowintlib.register(\"cnt\")\n"
1639 "function thread_init (args)\n"
1640 " cnt = flowintlib.get(\"cnt\")\n"
1643 "function match(args)\n"
1644 " print \"inspecting\""
1645 " a = cnt:value()\n"
1652 " a = cnt:value()\n"
1654 " print \"match\"\n"
1660 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1662 uint8_t httpbuf1[] =
1663 "POST / HTTP/1.1\r\n"
1664 "Host: www.emergingthreats.net\r\n\r\n";
1665 uint8_t httpbuf2[] =
1666 "POST / HTTP/1.1\r\n"
1667 "Host: www.openinfosecfoundation.org\r\n\r\n";
1668 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1669 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1679 memset(&th_v, 0,
sizeof(th_v));
1681 memset(&f, 0,
sizeof(f));
1682 memset(&ssn, 0,
sizeof(ssn));
1689 f.
proto = IPPROTO_TCP;
1751 static int LuaMatchTest05(
void)
1753 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1754 "function init (args)\n"
1755 " flowintlib.register(\"cnt\")\n"
1759 "function thread_init (args)\n"
1760 " cnt = flowintlib.get(\"cnt\")\n"
1763 "function match(args)\n"
1764 " print \"inspecting\""
1767 " print \"match\"\n"
1773 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1775 uint8_t httpbuf1[] =
1776 "POST / HTTP/1.1\r\n"
1777 "Host: www.emergingthreats.net\r\n\r\n";
1778 uint8_t httpbuf2[] =
1779 "POST / HTTP/1.1\r\n"
1780 "Host: www.openinfosecfoundation.org\r\n\r\n";
1781 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1782 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1792 memset(&th_v, 0,
sizeof(th_v));
1794 memset(&f, 0,
sizeof(f));
1795 memset(&ssn, 0,
sizeof(ssn));
1802 f.
proto = IPPROTO_TCP;
1864 static int LuaMatchTest05a(
void)
1866 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1867 "function init (args)\n"
1868 " flowintlib.register(\"cnt\")\n"
1872 "function thread_init (args)\n"
1873 " cnt = flowintlib.get(\"cnt\")\n"
1876 "function match(args)\n"
1877 " print \"inspecting\""
1880 " print \"match\"\n"
1886 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1888 uint8_t httpbuf1[] =
1889 "POST / HTTP/1.1\r\n"
1890 "Host: www.emergingthreats.net\r\n\r\n";
1891 uint8_t httpbuf2[] =
1892 "POST / HTTP/1.1\r\n"
1893 "Host: www.openinfosecfoundation.org\r\n\r\n";
1894 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1895 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1905 memset(&th_v, 0,
sizeof(th_v));
1907 memset(&f, 0,
sizeof(f));
1908 memset(&ssn, 0,
sizeof(ssn));
1915 f.
proto = IPPROTO_TCP;
1979 static int LuaMatchTest06(
void)
1981 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1982 "function init (args)\n"
1983 " flowintlib.register(\"cnt\")\n"
1987 "function thread_init (args)\n"
1988 " cnt = flowintlib.get(\"cnt\")\n"
1991 "function match(args)\n"
1992 " print \"inspecting\""
1993 " a = cnt:value()\n"
1994 " if a == nil then\n"
1995 " print \"new var set to 2\""
2000 " print \"match\"\n"
2006 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2008 uint8_t httpbuf1[] =
2009 "POST / HTTP/1.1\r\n"
2010 "Host: www.emergingthreats.net\r\n\r\n";
2011 uint8_t httpbuf2[] =
2012 "POST / HTTP/1.1\r\n"
2013 "Host: www.openinfosecfoundation.org\r\n\r\n";
2014 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2015 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2025 memset(&th_v, 0,
sizeof(th_v));
2027 memset(&f, 0,
sizeof(f));
2028 memset(&ssn, 0,
sizeof(ssn));
2035 f.
proto = IPPROTO_TCP;
2097 static int LuaMatchTest06a(
void)
2099 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2100 "function init (args)\n"
2101 " flowintlib.register(\"cnt\")\n"
2105 "function thread_init (args)\n"
2106 " cnt = flowintlib.get(\"cnt\")\n"
2109 "function match(args)\n"
2110 " print \"inspecting\""
2111 " a = cnt:value()\n"
2112 " if a == nil then\n"
2113 " print \"new var set to 2\""
2118 " print \"match\"\n"
2124 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2126 uint8_t httpbuf1[] =
2127 "POST / HTTP/1.1\r\n"
2128 "Host: www.emergingthreats.net\r\n\r\n";
2129 uint8_t httpbuf2[] =
2130 "POST / HTTP/1.1\r\n"
2131 "Host: www.openinfosecfoundation.org\r\n\r\n";
2132 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2133 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2143 memset(&th_v, 0,
sizeof(th_v));
2145 memset(&f, 0,
sizeof(f));
2146 memset(&ssn, 0,
sizeof(ssn));
2153 f.
proto = IPPROTO_TCP;
2214 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
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.
#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]
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.
union FlowVar_::@116 data
const char luaext_key_ld[]
#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.
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.