--
-- alert tcp any any -> any 80 ( \
-- msg:"luajit example"; sid:1; \
--- content:"GET /"; \
--- find:pat "GET .+ HTTP/1.1"; )
+-- content:"GET"; \
+-- find:"pat='HTTP/1%.%d'"; )
--
-- the arg string is (in general) optional
-- if present, it will be put in a table named args, eg:
-- args { pat='GET .+ HTTP/1.1' }
--
-- this table is defined before init is called
+-- the args string, if present, must be valid lua code like
+-- name1 = value1, name2 = 'value2'.
-- ----------------------------------------------------------
-- this pulls in snort bindings with ffi
-- see snort.lua for available buffers
-- buf is a luajit cdata
- local buf = ffi.C.get_cursor()
+ local buf = ffi.C.get_buffer()
-- str is a lua string
local str = ffi.string(buf.data, buf.len)
ParseError("%s luajit failed to init chunk %s",
name, lua_tostring(L, -1));
- // create an args table with any rule options
- string table("args = {");
- table += args;
- table += "}";
-
// load the args table
- if ( luaL_loadstring(L, table.c_str()) )
+ if ( luaL_loadstring(L, args.c_str()) )
ParseError("%s luajit failed to load args %s",
name, lua_tostring(L, -1));
static const Parameter luajit_params[] =
{
- { "*", Parameter::PT_STRING, nullptr, nullptr,
+ { "~", Parameter::PT_STRING, nullptr, nullptr,
"luajit arguments" },
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
-LuaJitModule::LuaJitModule() : Module("luajit", luajit_params)
+LuaJitModule::LuaJitModule(const char* name) : Module(name, luajit_params)
{ }
ProfileStats* LuaJitModule::get_profile() const
const char* name, string& chunk, LuaJitModule* mod)
: IpsOption(name)
{
- config = mod->args;
+ string args = mod->args;
+
+ // if args not empty, it has to be a quoted string
+ // so remove enclosing quotes
+ if ( args.size() > 1 )
+ {
+ args.erase(0, 1);
+ args.erase(args.size()-1);
+ }
+
+ // create an args table with any rule options
+ config = "args = { ";
+ config += args;
+ config += "}";
+
unsigned max = get_instance_max();
lua = new lua_State*[max];
class LuaJitModule : public Module
{
public:
- LuaJitModule();
+ LuaJitModule(const char* name);
bool begin(const char*, int, SnortConfig*);
bool set(const char*, Value&, SnortConfig*);
#endif
Module* mod = current_module;
- current_keyword = nullptr;
current_module = nullptr;
current_params = nullptr;
{
ErrorMessage("ERROR can't finalize %s\n", key);
s_errors++;
+ current_keyword = nullptr;
return false;
}
// FIXIT need to error out in the end if any errors
IpsOption* ips = opt->api->ctor(mod, otn);
type = opt->api->type;
+ current_keyword = nullptr;
if ( !ips )
return ( type == OPT_TYPE_META );
return symbols[pt].name;
}
+static const char* current_plugin = nullptr;
+
+const char* PluginManager::get_current_plugin()
+{ return current_plugin; }
+
struct Plugin
{
string key;
{
if ( p.api->mod_ctor )
{
+ current_plugin = p.api->name;
Module* m = p.api->mod_ctor();
ModuleManager::add_module(m, p.api);
}
static const BaseApi* get_api(PlugType, const char* name);
static void instantiate(const BaseApi*, Module*, SnortConfig*);
static const char* get_type_name(PlugType);
+ static const char* get_current_plugin();
};
#endif
#include "ips_manager.h"
#include "framework/ips_option.h"
+#include "managers/plugin_manager.h"
#include "ips_options/ips_luajit.h"
#include "parser/parser.h"
#include "helpers/directory.h"
static Module* mod_ctor()
{
- return new LuaJitModule;
+ const char* key = PluginManager::get_current_plugin();
+ return new LuaJitModule(key);
}
static void mod_dtor(Module* m)
return nullptr;
LuaJitModule* mod = (LuaJitModule*)m;
- return new LuaJitOption(api->name.c_str(), api->chunk, mod);
+ return new LuaJitOption(key, api->chunk, mod);
}
static void dtor(IpsOption* p)