line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# string::yara Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::String::Yara; |
7
|
1
|
|
|
1
|
|
653
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
381
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable encode decode) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
encode => [ qw($data_hash) ], |
20
|
|
|
|
|
|
|
decode => [ qw($data_string) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
require_modules => { |
23
|
|
|
|
|
|
|
'Parse::YARA' => [ ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Takes a hash and return a YARA string |
29
|
|
|
|
|
|
|
sub encode { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my ($data) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('encode', $data) or return; |
34
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('encode', $data, 'HASH') or return; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $encoded = ''; |
37
|
0
|
|
|
|
|
|
eval { |
38
|
0
|
|
|
|
|
|
$encoded = Parse::YARA->new(rulehash => $data, disable_includes => 0, verbose => 0); |
39
|
|
|
|
|
|
|
}; |
40
|
0
|
0
|
|
|
|
|
if ($@) { |
41
|
0
|
|
|
|
|
|
chomp($@); |
42
|
0
|
|
|
|
|
|
return $self->log->error("encode: unable to encode YARA: $@"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $encoded->as_string; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Takes a YARA string and return a hash |
49
|
|
|
|
|
|
|
sub decode { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my ($data) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('decode', $data) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $decoded = ''; |
56
|
0
|
|
|
|
|
|
eval { |
57
|
0
|
|
|
|
|
|
$decoded = Parse::YARA->new(rule => $data, disable_includes => 0, verbose => 0); |
58
|
|
|
|
|
|
|
}; |
59
|
0
|
0
|
|
|
|
|
if ($@) { |
60
|
0
|
|
|
|
|
|
chomp($@); |
61
|
0
|
|
|
|
|
|
return $self->log->error("decode: unable to decode YARA: $@"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return $decoded->{rules}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |