Skip to content

Commit

Permalink
Added grok compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
james-sirota committed Sep 22, 2014
1 parent ece629b commit f5f9878
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OpenSOC-MessageParsers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>json-schema-validator</artifactId>
<version>${global_json_schema_validator_version}</version>
</dependency>
<dependency>
<groupId>io.thekraken</groupId>
<artifactId>grok</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<reporting>
<plugins>
Expand Down Expand Up @@ -74,6 +79,9 @@
</reporting>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/test/resources</directory>
</resource>
Expand Down
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 OpenSOC-MessageParsers/src/main/resources/patters/sourcefire
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
POSINT \b(?:[1-9][0-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:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((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}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,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}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((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}))|:)))(%.+)?
IPV4 (?<![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 (?:%{IPV6}|%{IPV4})
HOSTNAME \b(?:[0-9A-Za-z][0-9A-Za-z-]{0,62})(?:\.(?:[0-9A-Za-z][0-9A-Za-z-]{0,62}))*(\.?|\b)
HOST %{HOSTNAME}
IPORHOST (?:%{HOSTNAME}|%{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}

0 comments on commit f5f9878

Please sign in to comment.