-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEngine.pm
208 lines (171 loc) · 5.18 KB
/
Engine.pm
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package Engine;
#---------------------------------------------------------------------
# Engine - Forensic System Scanner Engine
#
#
#
# created for ASI
# Author: H. Carvey, [email protected]
#
# This software is released under the Perl Artistic License:
# http://dev.perl.org/licenses/artistic.html
#---------------------------------------------------------------------
use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.1;
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = qw(new);
use WinSetup;
# Global variables
# self reference
my $self = {};
my $win;
my %sys = ();
my %plugins0; # hash-of-lists for system class plugins
my %plugins1; # hash-of-lists for user class plugins
#---------------------------------------------------------------------
# new()
#
#---------------------------------------------------------------------
sub new {
my $class = shift;
$win = WinSetup->new();
return bless($self, $class);
}
#---------------------------------------------------------------------
# systemDir()
#
#---------------------------------------------------------------------
sub systemDir {
my $class = $_[0];
if ($_[1] eq "") {
return $self->{systemdir};
}
else {
# should end in system32
$self->{systemdir} = $_[1];
$self->{systemdir} .= "\\" unless ($self->{systemdir} =~ m/\\$/);
my @segs = split(/\\/,$self->{systemdir});
my $num = scalar(@segs);
$self->{drive} = join('\\',@segs[0..($num - 3)])."\\";
}
}
#---------------------------------------------------------------------
#
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# getSystemInfo ()
#
#---------------------------------------------------------------------
sub getSystemInfo {
my %hives = $win->setup($self->{systemdir});
%sys = $win->getOSData();
$sys{drive} = $self->{drive};
# Need to get SystemRoot path for the image, so it can be passed to the
# plugins
my ($d,$w) = split(/\\/,$sys{"SystemRoot"},2);
$sys{systemroot} = $sys{drive}.$w;
$sys{systemroot} .= "\\" unless ($sys{systemroot} =~ m/\\$/);
$self->{osflag} = $sys{osflag};
return %sys;
}
sub getUserInfo {
my %users = $win->getUserData();
return %users;
}
#---------------------------------------------------------------------
# pluginsDir()
# Returns the plugins dir path
#---------------------------------------------------------------------
sub pluginsDir {
my $class = $_[0];
($_[1] eq "") ? (return $self->{plugindir}) : ($self->{plugindir} = $_[1]);
}
#---------------------------------------------------------------------
# sortPlugins()
#
# Accesses the plugins dir to get a list of plugins
# 1. Check OSMask value (osflag & osmask)
# 2. Generates (2) hashes-of-arrays, one for system class plugins, the
# other for user class plugins
# 3. The keys of each hash are the categories.
# 4. UI must then call the appropriate function to retrieve the
# appropropriate hash
#
#---------------------------------------------------------------------
sub sortPlugins {
my $class = shift;
my $output = shift || "report";
my %plugins;
%plugins0 = ();
%plugins1 = ();
my $cwd = Win32::GetCwd();
$cwd .= "\\" unless ($cwd =~ m/\\$/);
my $pluginsdir = $cwd."plugins\\";
my @plugs;
opendir(DIR,$pluginsdir);
@plugs = grep {!/^\./ && m/\.pl$/} readdir(DIR);
closedir(DIR);
foreach my $p (@plugs) {
eval {
require $pluginsdir.$p;
my $pkg = (split(/\./,$p,2))[0];
# Get the config information, create the list of plugins to run
my $pluginconfig = $pkg->getConfig();
if (($pluginconfig->{osmask} & $self->{osflag}) && ($pluginconfig->{"output"} =~ m/^$output/i)) {
if ($pluginconfig->{class} == 0) {
my @categories = split(/,/,$pluginconfig->{category});
foreach my $c (@categories) {
push(@{$plugins0{$c}},$pluginsdir.$p);
}
}
else {
my @categories = split(/,/,$pluginconfig->{category});
foreach my $c (@categories) {
push(@{$plugins1{$c}},$pluginsdir.$p);
}
}
}
};
::logMsg("Engine Error: ".$@) if ($@);
}
}
#----------------------------------------------------------------
# getSystemPlugins()
# returns the hash-of-lists of system plugins
#----------------------------------------------------------------
sub getSystemPlugins {
return %plugins0;
}
#----------------------------------------------------------------
# getUserPlugins()
# returns the hash-of-lists of user plugins
#----------------------------------------------------------------
sub getUserPlugins {
return %plugins1;
}
#----------------------------------------------------------------
# getError()
# returns the error message for the module
#----------------------------------------------------------------
sub getError {return $self->{error};}
1;
__END__
=head1 NAME
Name
=head1 SYNOPSIS
see example files
=head1 DESCRIPTION
Blah is a Perl module ...
=head1 SEE ALSO
=head1 AUTHOR
Harlan Carvey, E<lt>[email protected]<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2012
This library is free software; you can redistribute it and/or modify
it as you like. However, please be sure to provide proper credit where
it is due.
=cut