forked from mozilla/MozDef
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jeffbryner/MozDef
pull master
- Loading branch information
Showing
21 changed files
with
1,374 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- Copyright (c) 2014 Mozilla Corporation | ||
-- | ||
-- Contributors: | ||
-- Anthony Verez averez@mozilla.com | ||
-- Jeff Bryner jbryner@mozilla.com | ||
-- Michal Purzynski mpurzynski@mozilla.com | ||
|
||
require "lpeg" | ||
require "string" | ||
-- Some magic for parsing tab-separated logs | ||
local sep = lpeg.P"\t" | ||
local elem = lpeg.C((1-sep)^0) | ||
local grammar = -lpeg.P"#" * lpeg.Ct(elem * (sep * elem)^0) -- ignore comment, split on tabs, return as table | ||
|
||
local msg = { | ||
Type = "bro_known_certs", | ||
Logger = "nsm", | ||
Fields = { | ||
-- Initializing our fields | ||
['ts'] = nil, | ||
['host'] = nil, | ||
['port_num_int'] = nil, | ||
['subject'] = nil, | ||
['issuer_subject'] = nil, | ||
['serial'] = nil, | ||
summary = nil, | ||
severity = "INFO", | ||
category = "bro_known_certs", | ||
tags = "nsm,bro,known_certs" | ||
} | ||
} | ||
|
||
function toString(value) | ||
if value == "-" then | ||
return nil | ||
end | ||
return value | ||
end | ||
|
||
function nilToString(value) | ||
if value == nil then | ||
return "" | ||
end | ||
return value | ||
end | ||
|
||
function toNumber(value) | ||
if value == "-" then | ||
return nil | ||
end | ||
return tonumber(value) | ||
end | ||
|
||
function process_message() | ||
local log = read_message("Payload") | ||
|
||
local matches = grammar:match(log) | ||
if not matches then return -1 end | ||
|
||
msg.Fields['ts'] = toString(matches[1]) | ||
msg.Fields['host'] = toString(matches[2]) | ||
msg.Fields['port_num_int'] = toNumber(matches[3]) | ||
msg.Fields['subject'] = toString(matches[4]) | ||
msg.Fields['issuer_subject'] = toString(matches[5]) | ||
msg.Fields['serial'] = toString(string.sub(matches[6], 1, -2)) -- remove last "\n" | ||
msg.Fields['summary'] = nilToString(msg.Fields['host']) .. ":".. nilToString(msg.Fields['port_num_int']) .. " " .. nilToString(msg.Fields['subject']) | ||
inject_message(msg) | ||
return 0 | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- Copyright (c) 2014 Mozilla Corporation | ||
-- | ||
-- Contributors: | ||
-- Anthony Verez averez@mozilla.com | ||
-- Jeff Bryner jbryner@mozilla.com | ||
-- Michal Purzynski mpurzynski@mozilla.com | ||
|
||
local l=require "lpeg" | ||
local string=require "string" | ||
l.locale(l) --add locale entries in the lpeg table | ||
local space = l.space^0 --define a space constant | ||
local sep = l.P"\t" | ||
local elem = l.C((1-sep)^0) | ||
grammar = l.Ct(elem * (sep * elem)^0) -- split on tabs, return as table | ||
|
||
function toString(value) | ||
if value == "-" then | ||
return nil | ||
end | ||
return value | ||
end | ||
|
||
function nilToString(value) | ||
if value == nil then | ||
return "" | ||
end | ||
return value | ||
end | ||
|
||
function process_message() | ||
local log = read_message("Payload") | ||
|
||
--set a default msg that heka's | ||
--message matcher can ignore via a message matcher: | ||
-- message_matcher = "( Type!='heka.all-report' && Type != 'IGNORE' )" | ||
local msg = { | ||
Type = "IGNORE", | ||
Fields={} | ||
} | ||
local matches = grammar:match(log) | ||
if not matches then | ||
--return 0 to not propogate errors to heka's log. | ||
--return a message with IGNORE type to not match heka's message matcher | ||
inject_message(msg) | ||
return 0 | ||
end | ||
if string.sub(log,1,1)=='#' then | ||
--it's a comment line | ||
inject_message(msg) | ||
return 0 | ||
end | ||
|
||
msg['Type']='broknownhosts' | ||
msg['Logger']='nsm' | ||
msg['ts'] = toString(matches[1]) | ||
msg.Fields['host'] = toString(matches[2]) | ||
msg['Payload'] = "New host: " .. nilToString(msg.Fields['host']) | ||
inject_message(msg) | ||
return 0 | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- Copyright (c) 2014 Mozilla Corporation | ||
-- | ||
-- Contributors: | ||
-- Anthony Verez averez@mozilla.com | ||
-- Jeff Bryner jbryner@mozilla.com | ||
-- Michal Purzynski mpurzynski@mozilla.com | ||
|
||
local l=require "lpeg" | ||
local string=require "string" | ||
l.locale(l) --add locale entries in the lpeg table | ||
local space = l.space^0 --define a space constant | ||
local sep = l.P"\t" | ||
local elem = l.C((1-sep)^0) | ||
grammar = l.Ct(elem * (sep * elem)^0) -- split on tabs, return as table | ||
|
||
function toString(value) | ||
if value == "-" then | ||
return nil | ||
end | ||
return value | ||
end | ||
|
||
function nilToString(value) | ||
if value == nil then | ||
return "" | ||
end | ||
return value | ||
end | ||
|
||
function process_message() | ||
local log = read_message("Payload") | ||
|
||
--set a default msg that heka's | ||
--message matcher can ignore via a message matcher: | ||
-- message_matcher = "( Type!='heka.all-report' && Type != 'IGNORE' )" | ||
local msg = { | ||
Type = "IGNORE", | ||
Fields={} | ||
} | ||
local matches = grammar:match(log) | ||
if not matches then | ||
--return 0 to not propogate errors to heka's log. | ||
--return a message with IGNORE type to not match heka's message matcher | ||
inject_message(msg) | ||
return 0 | ||
end | ||
if string.sub(log,1,1)=='#' then | ||
--it's a comment line | ||
inject_message(msg) | ||
return 0 | ||
end | ||
|
||
msg['Type']='broknownhosts' | ||
msg['Logger']='nsm' | ||
msg['ts'] = toString(matches[1]) | ||
msg.Fields['host'] = toString(matches[2]) | ||
msg['Payload'] = "New host: " .. nilToString(msg.Fields['host']) | ||
inject_message(msg) | ||
return 0 | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.