Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua file handler #332

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion suricata/update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
INDEX_EXPIRATION_TIME = 60 * 60 * 24 * 14

# Rule keywords that come with files
file_kw = ["filemd5", "filesha1", "filesha256", "dataset"]
file_kw = ["filemd5", "filesha1", "filesha256", "dataset", "lua", "luajit"]

def strict_error(msg):
logger.error(msg)
Expand Down Expand Up @@ -499,6 +499,28 @@ def handle_filehash_files(rule, dep_files, fhash):
else:
logger.error("{} file {} was not found".format(fhash, filehash_fname))

def handle_lua_rule_files(rule, dep_files, kw):
if not rule.enabled:
return
lua_rule_fname = rule.get(kw)
filename = [fname for fname, content in dep_files.items() if fname == lua_rule_fname]
if filename:
logger.debug("Copying lua file %s to output directory" % (lua_rule_fname))
filepath = os.path.join(config.get_state_dir(), "rules", os.path.dirname(filename[0]))
logger.debug("filepath: %s" % filepath)
try:
os.makedirs(filepath)
except OSError as oserr:
if oserr.errno != errno.EEXIST:
logger.error(oserr)
sys.exit(1)
logger.debug("output fname: %s" % os.path.join(filepath, os.path.basename(lua_rule_fname)))
with open(os.path.join(filepath, os.path.basename(lua_rule_fname)), "w+") as fp:
fp.write(dep_files[lua_rule_fname].decode("utf-8"))
else:
logger.error("lua file {} was not found".format(lua_rule_fname))


def write_merged(filename, rulemap, dep_files):

if not args.quiet:
Expand Down Expand Up @@ -540,6 +562,8 @@ def write_merged(filename, rulemap, dep_files):
if kw in rule:
if "dataset" == kw:
reformatted = handle_dataset_files(rule, dep_files)
elif kw in ["lua", "luajit"]:
handle_lua_rule_files(rule, dep_files, kw)
else:
handle_filehash_files(rule, dep_files, kw)
if reformatted:
Expand Down Expand Up @@ -601,6 +625,8 @@ def write_to_directory(directory, files, rulemap, dep_files):
if kw in rule:
if "dataset" == kw:
reformatted = handle_dataset_files(rulemap[rule.id], dep_files)
elif kw in ["lua", "luajit"]:
handle_lua_rule_files(rulemap[rule.id], dep_files, kw)
else:
handle_filehash_files(rulemap[rule.id], dep_files, kw)
if reformatted:
Expand Down
Loading