lib/eris/log/context/snort.pm

filter: Statementstmt 30.0% 9 / 30 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 50.0% 1 / 2 totaltotal 23.5% 12 / 51 CC 8 SCAR 38.8
CC
8
Cov
20%
contextualize_message
72.0
_build_matcher
2.0
sample_messages
2.0
CRAP 48.5
« lib/eris/log/context/iptables.pm ↑ Summary lib/eris/log/decoders.pm »
1 package eris::log::context::snort;
2 # ABSTRACT: Parses the Snort and Suricata alert logs
3  
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 with qw(
7 eris::role::context
8 );
9  
10 1 our $VERSION = '0.008'; # VERSION
11  
12  
13 sub _build_matcher {
14 0 ▶ [qw(suricata snort)]
Subroutine _build_matcher: not called CC=1 SCAR=6.9
15 }
16  
17  
18 sub sample_messages {
19 0 ▶ my @msgs = split /\r?\n/, <<EOF;
Subroutine sample_messages: not called CC=1 SCAR=6.9
Pod undocumented
20 Jul 26 15:50:21 ether suricata: [1:2210045:2] SURICATA STREAM Packet with invalid ack [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 5.22.134.191:15682 -> 99.46.177.250:50673
21 Jul 26 15:50:21 ether suricata: [1:2210046:2] SURICATA STREAM SHUTDOWN RST invalid ack [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 5.22.134.191:15682 -> 99.46.177.250:50673
22 Jul 26 15:50:21 ether suricata: [1:2210046:2] SURICATA STREAM SHUTDOWN RST invalid ack [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 141.226.218.88:48038 -> 99.46.177.250:50673
23 Jul 26 15:50:21 ether suricata: [1:2210045:2] SURICATA STREAM Packet with invalid ack [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 141.226.218.88:48038 -> 99.46.177.250:50673
24 Jul 26 15:50:21 ether suricata: [1:2010935:2] ET POLICY Suspicious inbound to MSSQL port 1433 [Classification: Potentially Bad Traffic] [Priority: 2] {TCP} 183.60.48.25:12216 -> 99.46.177.250:1433
25 Jul 26 15:50:21 ether suricata: [1:2010935:2] ET POLICY Suspicious inbound to MSSQL port 1433 [Classification: Potentially Bad Traffic] [Priority: 2] {TCP} 208.100.26.228:50861 -> 99.46.177.250:1433
26 Jul 26 15:50:21 ether suricata: [1:2008581:3] ET P2P BitTorrent DHT ping request [Classification: Potential Corporate Privacy Violation] [Priority: 1] {UDP} 99.46.177.250:29902 -> 112.157.21.174:4652
27 EOF
28 0 return @msgs;
29 }
30  
31  
32 sub contextualize_message {
33 0 ▶ my ($self,$log) = @_;
Subroutine contextualize_message: not called CC=8 SCAR=42.8
Pod documented
34 0 my $str = $log->context->{message};
35  
36 0 $log->add_tags(qw(security ids));
37  
38 0 my %ctxt = ();
39 0 ▶ if ( $str =~ /^\[(\S+)\]\s+/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^\[(\S+)\]\s+/g) 0 0 0
40 0 $ctxt{id} = (split /:/, $1, 3)[1];
41 0 ▶ if ( $str =~ /\G([^\[]+)/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G([^\[]+)/cg) 0 0 0
42 0 $ctxt{name} = $1;
43 0 $ctxt{name} =~ s/\s+$//;
44 0 ▶ if ( $str =~ /(?>\[Classification: ([^\]]+)\])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?>\[Classification: ([^\]]+)\])/) 0 0 0
45 0 $ctxt{class} = $1;
46 }
47 0 ▶ if ( $str =~ /(?>\[Priority: (\d+)\])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?>\[Priority: (\d+)\])/) 0 0 0
48 0 $ctxt{pri} = $1;
49 }
50 0 ▶ if ( $str =~ /(?>\{(\S+)\})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?>\{(\S+)\})/) 0 0 0
51 0 $ctxt{proto_app} = $1;
52 }
53 0 ▶ if( $str =~ /(?>(\S+):(\d+) -> (\S+):(\d+))/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?>(\S+):(\d+) -> (\S+):(\d+))/) 0 0 0
54 0 @ctxt{qw(src_ip src_port dst_ip dst_port)} = ($1,$2,$3,$4);
55 }
56 }
57 }
58  
59 0 ▶ $log->add_context($self->name,\%ctxt) if keys %ctxt;
Branch: 1 branch
BranchTrueFalseTotal
if keys %ctxt 0 0 0
60 }
61  
62  
63 1 1;
64  
65 __END__
66  
67 =pod
68  
69 =encoding UTF-8
70  
71 =head1 NAME
72  
73 eris::log::context::snort - Parses the Snort and Suricata alert logs
74  
75 =head1 VERSION
76  
77 version 0.008
78  
79 =head1 SYNOPSIS
80  
81 This parses data in the Snort and Suricata alert logs into structured data.
82  
83 =head1 ATTRIBUTES
84  
85 =head2 matcher
86  
87 Matches the literal string 'snort' and 'suricata'
88  
89 =head1 METHODS
90  
91 =head2 contextualize_message
92  
93 Extracts information from the Snort and Suricata alert logs
94  
95 name => rule name
96 class => rule classification
97 pri => rule priority
98 proto_app => protocol
99  
100 And
101  
102 src_ip src_port dst_ip dst_port
103  
104 Tags messages with 'security' and 'ids'.
105  
106 =for Pod::Coverage sample_messages
107  
108 =head1 SEE ALSO
109  
110 L<eris::log::contextualizer>, L<eris::role::context>
111  
112 =head1 AUTHOR
113  
114 Brad Lhotsky <brad@divisionbyzero.net>
115  
116 =head1 COPYRIGHT AND LICENSE
117  
118 This software is Copyright (c) 2015 by Brad Lhotsky.
119  
120 This is free software, licensed under:
121  
122 The (three-clause) BSD License
123  
124 =cut
« lib/eris/log/context/iptables.pm ↑ Summary lib/eris/log/decoders.pm »