-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplaso_log2timeline_v0.1.pl
189 lines (140 loc) · 5.21 KB
/
plaso_log2timeline_v0.1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/perl
#use warnings;
use File::Find;
use File::Copy;
use File::Basename;
use Digest::MD5 qw(md5_hex);
use Cwd 'abs_path';
use Cwd;
use Switch;
use Getopt::Long;
use Config::Tiny;
use File::Path;
use Pod::Usage;
#use strict;
use warnings;
my $version = 0.1;
#=============================================================================================
# Addslash
#=============================================================================================
sub addslash {
my ($path) = @_;
my $lastchar = substr($path,length($path)-1,1);
if ($lastchar ne "/") {
$path .= "/";
}
return($path);
}
#=============================================================================================
#=============================================================================================
# Start of MAIN
#=============================================================================================
#=============================================================================================
GetOptions ("mntdrive=s" => \$mntdrive # output directory
) || pod2usage(-verbose => 0);
pod2usage(-verbose => 1) if ($opt_help);
pod2usage(-verbose => 2) if ($opt_man);
pod2usage( { -message => q{Mandatory arguement '--mntdrive' is missing}
-exitval => 1,
-verbose => 1 }
) unless ($mntdrive);
#=============================================================================================
# Read in config file
#=============================================================================================
$Config = Config::Tiny->read( $config );
if ($config eq ""){
($filename, $directories, $suffix) = fileparse(abs_path($0));
$config = $directories."plugins.ini";
}
my $Config = Config::Tiny->read( $config );
if (defined $config) {
$savedirconfig=$Config->{plaso_log2timeline}->{savedir};
$driveconfig=$Config->{default}->{drive};
$log2timelinebin=$Config->{plaso_log2timeline}->{log2timeline};
$log2timelineopts=$Config->{plaso_log2timeline}->{plaso_opts};
$plaso_savefile=$Config->{plaso_log2timeline}->{plaso_savefile};
$workercnt=$Config->{plaso_log2timeline}->{workercnt};
$psortcmd=$Config->{plaso_log2timeline}->{psortcmd};
$psort_opts=$Config->{plaso_log2timeline}->{psort_opts};
$psort_log=$Config->{plaso_log2timeline}->{psort_log};
} else {
print "Need a working config.ini file.\n";
exit 1;
}
#=============================================================================================
#=============================================================================================
# Setup environment to begin work
#=============================================================================================
my $dircwd = getcwd();
chomp($dircwd);
$savedir = $dircwd . "/" . $savedirconfig;
$savedir = addslash($savedir);
$dir = addslash(abs_path($mntdrive));
$md5logfilename = $savedir . "/md5log";
print "Gathering data from $dir.\n";
print "Saving Plaso Log2timeline files to: $savedir\n";
print "Config File Used: $config\n";
chdir($dir) or die "Cannot change directory to $dir -- Error: $!";
#Creating the save directory
unless(-e $savedir or mkdir $savedir) {
die "Unable to create $savedir\n";
}
#=============================================================================================
#=============================================================================================
# Start of plugin code
#=============================================================================================
print "Running Plaso Log2TimeLine timescanner....\n";
# log2timeline.py --preprocess --partition all --zone UTC --disable_zerom -al
# --logfile {logfile} --status_view linear
# --workers {define core -2} {plaso} {image or directory}
$worker = $workercnt;
#if ($workercnt < 1) {
# $cores = `nproc`;
# chomp($cores);
# print "Number of cores detected: $cores\n";
# print "Number of workers per config: $workercnt\n";
# #Turn out negative to a positive. :)
# $workercnt = $workercnt * -1;
# $worker = $cores - $workercnt;
# print "Number of workers used: $worker\n";
#}
#my $l2tltext = $log2timelinebin ." ". $log2timelineopts . " --workers " . $worker ." ";
my $l2tltext = $log2timelinebin ." ". $log2timelineopts . " ";
$l2tltext .= $savedir.$plaso_savefile." ";
$l2tltext .= $dir;
print "CMD: $l2tltext\n";
#open(TIMESCANNER, "$l2tltext |") || die "Failed: $!\n";
#while (<TIMESCANNER>) {
# print "\t$_";
#}
#close(TIMESCANNER);
print "Running psort...\n";
chdir($savedir);
my $psortcmd = $psortcmd." ".$psort_opts." --write ".$savedir."/l2tl_bodyfile.csv ".$savedir."l2tl_bodyfile.plaso";
print "psortcmd: $psortcmd\n";
open(TIMESCANNER, "$psortcmd |") || die "Failed: $!\n";
while (<TIMESCANNER>) {
print "\t$_";
}
close(TIMESCANNER);
chdir($dircwd);
print "Completed command.\n"
__END__
=head1 sample.pl
Image device
=head1 SYNOPSIS
sample.pl [options] [file ...]
Options:
--mntdrive Where output date should go and where image is mounted (MANDATORY)
--help Brief help message
--man Full documentation
=head1 OPTIONS
=over 8
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
B<sample.pl> will
=cut