-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ece629b
commit f5f9878
Showing
3 changed files
with
94 additions
and
0 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
56 changes: 56 additions & 0 deletions
56
OpenSOC-MessageParsers/src/main/java/com/opensoc/parsing/parsers/GrokSourcefireParser.java
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,56 @@ | ||
package com.opensoc.parsing.parsers; | ||
|
||
import java.net.URL; | ||
|
||
import oi.thekraken.grok.api.Match; | ||
import oi.thekraken.grok.api.Grok; | ||
import oi.thekraken.grok.api.exception.GrokException; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
|
||
public class GrokSourcefireParser extends AbstractParser{ | ||
|
||
Grok grok; | ||
|
||
public GrokSourcefireParser() throws GrokException | ||
{ | ||
URL pattern_url = getClass().getClassLoader().getResource( | ||
"pattarns/sourcefire"); | ||
grok = Grok.create(pattern_url.getFile()); | ||
grok.compile("%{SOURCEFIRE}"); | ||
} | ||
|
||
@Override | ||
public JSONObject parse(byte[] raw_message) { | ||
JSONObject payload = new JSONObject(); | ||
String toParse = ""; | ||
JSONObject toReturn; | ||
|
||
|
||
try { | ||
|
||
toParse = new String(raw_message, "UTF-8"); | ||
Match gm = grok.match(toParse); | ||
gm.captures(); | ||
|
||
toReturn = new JSONObject(); | ||
|
||
toReturn.putAll(gm.toMap()); | ||
toReturn.remove("SOURCEFIRE"); | ||
String proto = toReturn.get("protocol").toString(); | ||
proto = proto.replace("{", ""); | ||
proto = proto.replace("}", ""); | ||
toReturn.put("protocol", proto); | ||
return toReturn; | ||
|
||
} | ||
catch(Exception e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
OpenSOC-MessageParsers/src/main/resources/patters/sourcefire
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,30 @@ | ||
POSINT \b(?:[1-9][0-9]*)\b | ||
NONNEGINT \b(?:[0-9]+)\b | ||
WORD \b\w+\b | ||
NOTSPACE \S+ | ||
SPACE \s* | ||
DATA .*? | ||
GREEDYDATA .* | ||
QUOTEDSTRING (?>(?<!\\)(?>"(?>\\.|[^\\"]+)+"|""|(?>'(?>\\.|[^\\']+)+')|''|(?>`(?>\\.|[^\\`]+)+`)|``)) | ||
UUID [A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12} | ||
|
||
# Networking | ||
MAC (?:%{CISCOMAC}|%{WINDOWSMAC}|%{COMMONMAC}) | ||
CISCOMAC (?:(?:[A-Fa-f0-9]{4}\.){2}[A-Fa-f0-9]{4}) | ||
WINDOWSMAC (?:(?:[A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}) | ||
COMMONMAC (?:(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}) | ||
IPV6 ((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-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STNAME}|%{IP}) | ||
HOSTPORT %{IPORHOST}:%{POSINT} | ||
|
||
#Sourcefire Logs | ||
protocol \{[a-zA-Z0-9]+\} | ||
ip_src_addr (?<![0-9])(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))(?![0-9]) | ||
ip_dst_addr (?<![0-9])(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))(?![0-9]) | ||
ip_src_port [0-9]+ | ||
ip_dst_port [0-9]+ | ||
SOURCEFIRE %{GREEDYDATA}%{protocol}\s%{ip_src_addr}\:%{ip_src_port}\s->\s%{ip_dst_addr}\:%{ip_dst_port} |