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;
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,
bool allow_restricted_functions)
418 if (allow_restricted_functions) {
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 *DetectLuaThreadRestrictedInit(
void *data)
475 return DetectLuaThreadInit(data,
false);
478 static void *DetectLuaThreadAllowInit(
void *data)
480 return DetectLuaThreadInit(data,
true);
483 static void DetectLuaThreadFree(
void *
ctx)
511 if (strlen(
str) &&
str[0] ==
'!') {
525 DetectLuaFree(
de_ctx, lua);
530 int allow_restricted_functions)
535 if (luastate == NULL)
537 if (allow_restricted_functions) {
538 luaL_openlibs(luastate);
543 LuaStateSetDetectLuaData(luastate, ld);
547 if (ut_script != NULL) {
548 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
550 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
555 status = luaL_loadfile(luastate, ld->
filename);
557 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
565 if (lua_pcall(luastate, 0, 0, 0) != 0) {
566 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
570 lua_getglobal(luastate,
"init");
571 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
578 lua_pushlightuserdata(luastate, (
void *)s);
580 if (lua_pcall(luastate, 1, 1, 0) != 0) {
581 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
586 if (lua_gettop(luastate) == 0) {
587 SCLogError(
"init function in script should return table, nothing returned");
590 if (lua_type(luastate, 1) != LUA_TTABLE) {
591 SCLogError(
"init function in script should return table, returned is not table");
595 lua_pushnil(luastate);
597 while (lua_next(luastate, -2)) {
598 k = lua_tostring(luastate, -2);
603 if (strcmp(k,
"flowvar") == 0) {
604 if (lua_istable(luastate, -1)) {
605 lua_pushnil(luastate);
606 while (lua_next(luastate, -2) != 0) {
608 const char *value = lua_tostring(luastate, -1);
611 lua_pop(luastate, 1);
625 lua_pop(luastate, 1);
627 }
else if (strcmp(k,
"flowint") == 0) {
628 if (lua_istable(luastate, -1)) {
629 lua_pushnil(luastate);
630 while (lua_next(luastate, -2) != 0) {
632 const char *value = lua_tostring(luastate, -1);
635 lua_pop(luastate, 1);
649 lua_pop(luastate, 1);
653 bool required = lua_toboolean(luastate, -1);
654 lua_pop(luastate, 1);
659 if (strcmp(k,
"ja3") == 0) {
661 }
else if (strcmp(k,
"ja3s") == 0) {
663 }
else if (strcmp(k,
"packet") == 0) {
665 }
else if (strcmp(k,
"payload") == 0) {
667 }
else if (strcmp(k,
"buffer") == 0) {
673 }
else if (strcmp(k,
"stream") == 0) {
680 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
681 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
682 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
683 SCLogError(
"data type %s no longer supported, use rule hooks", k);
693 lua_pop(luastate, 1);
717 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
718 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
729 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
730 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
734 int allow_restricted_functions = 0;
735 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
737 if (DetectLuaSetupPrime(
de_ctx, lua, s, allow_restricted_functions) == -1) {
741 void *cb = DetectLuaThreadRestrictedInit;
742 if (allow_restricted_functions) {
743 cb = DetectLuaThreadAllowInit;
753 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
771 list = g_lua_ja3_list_id;
773 list = g_lua_ja3s_list_id;
785 DetectLuaFree(
de_ctx, lua);
804 for (uint16_t i = 0; i < lua->
flowints; i++) {
807 for (uint16_t i = 0; i < lua->
flowvars; i++) {
810 for (uint16_t i = 0; i < lua->
bytevars; i++) {
824 static int LuaMatchTest01(
void)
828 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
829 "function init (args)\n"
830 " flowvarlib.register(\"cnt\")\n"
833 "function thread_init (args)\n"
834 " cnt = flowvarlib.get(\"cnt\")\n"
837 "function match(args)\n"
840 " a = tostring(tonumber(a)+1)\n"
849 " print (\"pre check: \" .. (a))\n"
850 " if tonumber(a) == 2 then\n"
857 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
860 "POST / HTTP/1.1\r\n"
861 "Host: www.emergingthreats.net\r\n\r\n";
863 "POST / HTTP/1.1\r\n"
864 "Host: www.openinfosecfoundation.org\r\n\r\n";
865 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
866 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
878 memset(&f, 0,
sizeof(f));
879 memset(&ssn, 0,
sizeof(ssn));
886 f.
proto = IPPROTO_TCP;
950 static int LuaMatchTest01a(
void)
952 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
953 "function init (args)\n"
954 " flowvarlib.register(\"cnt\")\n"
957 "function thread_init (args)\n"
958 " cnt = flowvarlib.get(\"cnt\")\n"
961 "function match(args)\n"
962 " a = cnt:value(0)\n"
964 " a = tostring(tonumber(a)+1)\n"
973 " print (\"pre check: \" .. (a))\n"
974 " if tonumber(a) == 2 then\n"
981 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
983 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
984 "Host: www.emergingthreats.net\r\n\r\n";
985 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
986 "Host: www.openinfosecfoundation.org\r\n\r\n";
987 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
988 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1000 memset(&f, 0,
sizeof(f));
1001 memset(&ssn, 0,
sizeof(ssn));
1008 f.
proto = IPPROTO_TCP;
1073 static int LuaMatchTest02(
void)
1075 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1076 "function init (args)\n"
1077 " flowvarlib.register(\"cnt\")\n"
1078 " local needs = {}\n"
1079 " needs[\"payload\"] = tostring(true)\n"
1082 "function thread_init (args)\n"
1083 " cnt = flowvarlib.get(\"cnt\")\n"
1086 "function match(args)\n"
1087 " a = cnt:value()\n"
1089 " a = tostring(tonumber(a)+1)\n"
1093 " a = tostring(1)\n"
1098 " print (\"pre check: \" .. (a))\n"
1099 " if tonumber(a) == 2 then\n"
1100 " print \"match\"\n"
1106 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1107 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1108 "Host: www.emergingthreats.net\r\n\r\n";
1109 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1110 "Host: www.openinfosecfoundation.org\r\n\r\n";
1111 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1112 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1122 memset(&f, 0,
sizeof(f));
1123 memset(&ssn, 0,
sizeof(ssn));
1130 f.
proto = IPPROTO_TCP;
1185 static int LuaMatchTest02a(
void)
1187 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1188 "function init (args)\n"
1189 " flowvarlib.register(\"cnt\")"
1190 " local needs = {}\n"
1191 " needs[\"payload\"] = tostring(true)\n"
1194 "function thread_init (args)\n"
1195 " cnt = flowvarlib.get(\"cnt\")"
1198 "function match(args)\n"
1199 " a = cnt:value()\n"
1201 " a = tostring(tonumber(a)+1)\n"
1205 " a = tostring(1)\n"
1210 " print (\"pre check: \" .. (a))\n"
1211 " if tonumber(a) == 2 then\n"
1212 " print \"match\"\n"
1218 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1219 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1220 "Host: www.emergingthreats.net\r\n\r\n";
1221 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1222 "Host: www.openinfosecfoundation.org\r\n\r\n";
1223 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1224 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1234 memset(&f, 0,
sizeof(f));
1235 memset(&ssn, 0,
sizeof(ssn));
1242 f.
proto = IPPROTO_TCP;
1295 static int LuaMatchTest03(
void)
1297 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1298 "function init (args)\n"
1299 " flowvarlib.register(\"cnt\")\n"
1300 " local needs = {}\n"
1301 " needs[\"packet\"] = tostring(true)\n"
1305 "function thread_init (args)\n"
1306 " cnt = flowvarlib.get(\"cnt\")\n"
1309 "function match(args)\n"
1310 " a = cnt:value()\n"
1312 " a = tostring(tonumber(a)+1)\n"
1316 " a = tostring(1)\n"
1321 " print (\"pre check: \" .. (a))\n"
1322 " if tonumber(a) == 2 then\n"
1323 " print \"match\"\n"
1329 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1330 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1331 "Host: www.emergingthreats.net\r\n\r\n";
1332 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1333 "Host: www.openinfosecfoundation.org\r\n\r\n";
1334 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1335 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1345 memset(&f, 0,
sizeof(f));
1346 memset(&ssn, 0,
sizeof(ssn));
1353 f.
proto = IPPROTO_TCP;
1405 static int LuaMatchTest03a(
void)
1407 const char script[] =
"local flowvarlib = require(\"suricata.flowvar\")\n"
1408 "function init (args)\n"
1409 " flowvarlib.register(\"cnt\")\n"
1410 " local needs = {}\n"
1411 " needs[\"packet\"] = tostring(true)\n"
1415 "function thread_init (args)\n"
1416 " cnt = flowvarlib.get(\"cnt\")\n"
1419 "function match(args)\n"
1420 " a = cnt:value()\n"
1422 " a = tostring(tonumber(a)+1)\n"
1426 " a = tostring(1)\n"
1431 " print (\"pre check: \" .. (a))\n"
1432 " if tonumber(a) == 2 then\n"
1433 " print \"match\"\n"
1439 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1440 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1441 "Host: www.emergingthreats.net\r\n\r\n";
1442 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1443 "Host: www.openinfosecfoundation.org\r\n\r\n";
1444 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1445 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1455 memset(&f, 0,
sizeof(f));
1456 memset(&ssn, 0,
sizeof(ssn));
1463 f.
proto = IPPROTO_TCP;
1515 static int LuaMatchTest04(
void)
1517 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1518 "function init (args)\n"
1519 " flowintlib.register(\"cnt\")\n"
1523 "function thread_init (args)\n"
1524 " cnt = flowintlib.get(\"cnt\")\n"
1527 "function match(args)\n"
1528 " print \"inspecting\""
1529 " a = cnt:value()\n"
1536 " a = cnt:value()\n"
1538 " print \"match\"\n"
1544 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1546 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1547 "Host: www.emergingthreats.net\r\n\r\n";
1548 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1549 "Host: www.openinfosecfoundation.org\r\n\r\n";
1550 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1551 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1563 memset(&f, 0,
sizeof(f));
1564 memset(&ssn, 0,
sizeof(ssn));
1571 f.
proto = IPPROTO_TCP;
1633 static int LuaMatchTest04a(
void)
1635 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1636 "function init (args)\n"
1637 " flowintlib.register(\"cnt\")\n"
1641 "function thread_init (args)\n"
1642 " cnt = flowintlib.get(\"cnt\")\n"
1645 "function match(args)\n"
1646 " print \"inspecting\""
1647 " a = cnt:value()\n"
1654 " a = cnt:value()\n"
1656 " print \"match\"\n"
1662 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1664 uint8_t httpbuf1[] =
1665 "POST / HTTP/1.1\r\n"
1666 "Host: www.emergingthreats.net\r\n\r\n";
1667 uint8_t httpbuf2[] =
1668 "POST / HTTP/1.1\r\n"
1669 "Host: www.openinfosecfoundation.org\r\n\r\n";
1670 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1671 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1683 memset(&f, 0,
sizeof(f));
1684 memset(&ssn, 0,
sizeof(ssn));
1691 f.
proto = IPPROTO_TCP;
1753 static int LuaMatchTest05(
void)
1755 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1756 "function init (args)\n"
1757 " flowintlib.register(\"cnt\")\n"
1761 "function thread_init (args)\n"
1762 " cnt = flowintlib.get(\"cnt\")\n"
1765 "function match(args)\n"
1766 " print \"inspecting\""
1769 " print \"match\"\n"
1775 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1777 uint8_t httpbuf1[] =
1778 "POST / HTTP/1.1\r\n"
1779 "Host: www.emergingthreats.net\r\n\r\n";
1780 uint8_t httpbuf2[] =
1781 "POST / HTTP/1.1\r\n"
1782 "Host: www.openinfosecfoundation.org\r\n\r\n";
1783 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1784 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1796 memset(&f, 0,
sizeof(f));
1797 memset(&ssn, 0,
sizeof(ssn));
1804 f.
proto = IPPROTO_TCP;
1866 static int LuaMatchTest05a(
void)
1868 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1869 "function init (args)\n"
1870 " flowintlib.register(\"cnt\")\n"
1874 "function thread_init (args)\n"
1875 " cnt = flowintlib.get(\"cnt\")\n"
1878 "function match(args)\n"
1879 " print \"inspecting\""
1882 " print \"match\"\n"
1888 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1890 uint8_t httpbuf1[] =
1891 "POST / HTTP/1.1\r\n"
1892 "Host: www.emergingthreats.net\r\n\r\n";
1893 uint8_t httpbuf2[] =
1894 "POST / HTTP/1.1\r\n"
1895 "Host: www.openinfosecfoundation.org\r\n\r\n";
1896 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1897 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1909 memset(&f, 0,
sizeof(f));
1910 memset(&ssn, 0,
sizeof(ssn));
1917 f.
proto = IPPROTO_TCP;
1981 static int LuaMatchTest06(
void)
1983 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
1984 "function init (args)\n"
1985 " flowintlib.register(\"cnt\")\n"
1989 "function thread_init (args)\n"
1990 " cnt = flowintlib.get(\"cnt\")\n"
1993 "function match(args)\n"
1994 " print \"inspecting\""
1995 " a = cnt:value()\n"
1996 " if a == nil then\n"
1997 " print \"new var set to 2\""
2002 " print \"match\"\n"
2008 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2010 uint8_t httpbuf1[] =
2011 "POST / HTTP/1.1\r\n"
2012 "Host: www.emergingthreats.net\r\n\r\n";
2013 uint8_t httpbuf2[] =
2014 "POST / HTTP/1.1\r\n"
2015 "Host: www.openinfosecfoundation.org\r\n\r\n";
2016 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2017 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2029 memset(&f, 0,
sizeof(f));
2030 memset(&ssn, 0,
sizeof(ssn));
2037 f.
proto = IPPROTO_TCP;
2099 static int LuaMatchTest06a(
void)
2101 const char script[] =
"local flowintlib = require(\"suricata.flowint\")\n"
2102 "function init (args)\n"
2103 " flowintlib.register(\"cnt\")\n"
2107 "function thread_init (args)\n"
2108 " cnt = flowintlib.get(\"cnt\")\n"
2111 "function match(args)\n"
2112 " print \"inspecting\""
2113 " a = cnt:value()\n"
2114 " if a == nil then\n"
2115 " print \"new var set to 2\""
2120 " print \"match\"\n"
2126 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2128 uint8_t httpbuf1[] =
2129 "POST / HTTP/1.1\r\n"
2130 "Host: www.emergingthreats.net\r\n\r\n";
2131 uint8_t httpbuf2[] =
2132 "POST / HTTP/1.1\r\n"
2133 "Host: www.openinfosecfoundation.org\r\n\r\n";
2134 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2135 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2147 memset(&f, 0,
sizeof(f));
2148 memset(&ssn, 0,
sizeof(ssn));
2155 f.
proto = IPPROTO_TCP;
2216 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
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
struct lua_State lua_State
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
#define FLOW_INITIALIZE(f)
#define SIG_FLAG_TOSERVER
uint32_t VarNameStoreLookupByName(const char *name, const enum VarTypes type)
find name for id+type at packet time. As the active store won't be modified, we don't need locks.
#define PASS
Pass the test.
void SCLuaSbRestoreBytesLimit(lua_State *L, const uint64_t cfg_limit)
StatsCounterId lua_memory_limit_errors
uint64_t instruction_limit
@ 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)
union FlowVar_::@121 data
#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 FLOW_PKT_ESTABLISHED
DetectEngineCtx * DetectEngineCtxInit(void)
bool instruction_count_error
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
lua_State * SCLuaSbStateNew(uint64_t alloclimit, uint64_t instructionlimit)
Allocate a new Lua sandbox.
FlowVar * FlowVarGet(Flow *f, uint32_t idx)
get the flowvar with index 'idx' from the flow
int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *de_ctx, void *data, const char *name)
Remove Thread keyword context registration.
AppProto alproto
application level protocol
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
void StatsThreadCleanup(StatsThreadContext *stats)
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.