| 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 |
=pod |
|---|
| 31 |
|
|---|
| 32 |
=head1 NAME |
|---|
| 33 |
|
|---|
| 34 |
HoneyClient::Agent - Perl extension to instantiate a SOAP server |
|---|
| 35 |
that provides a central interface for all agent-based HoneyClient |
|---|
| 36 |
operations. |
|---|
| 37 |
|
|---|
| 38 |
=head1 VERSION |
|---|
| 39 |
|
|---|
| 40 |
$Rev: 1626 $ |
|---|
| 41 |
|
|---|
| 42 |
=head1 SYNOPSIS |
|---|
| 43 |
|
|---|
| 44 |
=head2 CREATING THE SOAP SERVER |
|---|
| 45 |
|
|---|
| 46 |
# XXX: Fill this in. |
|---|
| 47 |
|
|---|
| 48 |
=head2 INTERACTING WITH THE SOAP SERVER |
|---|
| 49 |
|
|---|
| 50 |
# XXX: Fill this in. |
|---|
| 51 |
|
|---|
| 52 |
=head1 DESCRIPTION |
|---|
| 53 |
|
|---|
| 54 |
This library creates a SOAP server within the HoneyClient VM, allowing |
|---|
| 55 |
the HoneyClient::Manager to perform agent-based operations within the |
|---|
| 56 |
VM. |
|---|
| 57 |
|
|---|
| 58 |
=cut |
|---|
| 59 |
|
|---|
| 60 |
package HoneyClient::Agent; |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
use strict; |
|---|
| 65 |
use warnings FATAL => 'all'; |
|---|
| 66 |
use Config; |
|---|
| 67 |
use Carp (); |
|---|
| 68 |
|
|---|
| 69 |
use POSIX qw(SIGALRM); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
BEGIN { |
|---|
| 76 |
|
|---|
| 77 |
require Exporter; |
|---|
| 78 |
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION, @DRIVERS); |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
$VERSION = 0.9; |
|---|
| 82 |
|
|---|
| 83 |
@ISA = qw(Exporter); |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
@EXPORT = qw(); |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
%EXPORT_TAGS = ( |
|---|
| 97 |
'all' => [ qw() ], |
|---|
| 98 |
); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
$Config{useithreads} or Carp::croak "Error: Recompile Perl with ithread support, in order to use this module.\n"; |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
@DRIVERS = ( 'IE' ); |
|---|
| 116 |
foreach (@DRIVERS) { |
|---|
| 117 |
eval "use HoneyClient::Agent::Driver::Browser::$_"; |
|---|
| 118 |
if ($@) { |
|---|
| 119 |
Carp::croak "$@"; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
$SIG{PIPE} = 'IGNORE'; |
|---|
| 124 |
} |
|---|
| 125 |
our (@EXPORT_OK, $VERSION, @DRIVERS); |
|---|
| 126 |
|
|---|
| 127 |
=pod |
|---|
| 128 |
|
|---|
| 129 |
=begin testing |
|---|
| 130 |
|
|---|
| 131 |
# Make sure the module loads properly, with the exportable |
|---|
| 132 |
# functions shared. |
|---|
| 133 |
BEGIN { use_ok('HoneyClient::Agent') or diag("Can't load HoneyClient::Agent package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 134 |
require_ok('HoneyClient::Agent'); |
|---|
| 135 |
can_ok('HoneyClient::Agent', 'init'); |
|---|
| 136 |
can_ok('HoneyClient::Agent', 'destroy'); |
|---|
| 137 |
use HoneyClient::Agent; |
|---|
| 138 |
|
|---|
| 139 |
# Make sure HoneyClient::Util::SOAP loads. |
|---|
| 140 |
BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getServerHandle getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 141 |
require_ok('HoneyClient::Util::SOAP'); |
|---|
| 142 |
can_ok('HoneyClient::Util::SOAP', 'getServerHandle'); |
|---|
| 143 |
can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); |
|---|
| 144 |
use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); |
|---|
| 145 |
|
|---|
| 146 |
# Make sure HoneyClient::Util::Config loads. |
|---|
| 147 |
BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) or diag("Can't load HoneyClient::Util::Config package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 148 |
require_ok('HoneyClient::Util::Config'); |
|---|
| 149 |
can_ok('HoneyClient::Util::Config', 'getVar'); |
|---|
| 150 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 151 |
|
|---|
| 152 |
# TODO: Change Driver::IE to Driver::Browser::IE |
|---|
| 153 |
# Make sure HoneyClient::Agent::Driver::IE loads. |
|---|
| 154 |
BEGIN { use_ok('HoneyClient::Agent::Driver::IE') or diag("Can't load HoneyClient::Agent::Driver::IE package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 155 |
require_ok('HoneyClient::Agent::Driver::IE'); |
|---|
| 156 |
can_ok('HoneyClient::Agent::Driver::IE', 'new'); |
|---|
| 157 |
can_ok('HoneyClient::Agent::Driver::IE', 'drive'); |
|---|
| 158 |
can_ok('HoneyClient::Agent::Driver::IE', 'getNextLink'); |
|---|
| 159 |
can_ok('HoneyClient::Agent::Driver::IE', 'next'); |
|---|
| 160 |
can_ok('HoneyClient::Agent::Driver::IE', 'isFinished'); |
|---|
| 161 |
can_ok('HoneyClient::Agent::Driver::IE', 'status'); |
|---|
| 162 |
use HoneyClient::Agent::Driver::IE; |
|---|
| 163 |
|
|---|
| 164 |
# Make sure Storable loads. |
|---|
| 165 |
BEGIN { use_ok('Storable', qw(nfreeze thaw)) or diag("Can't load Storable package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 166 |
require_ok('Storable'); |
|---|
| 167 |
can_ok('Storable', 'nfreeze'); |
|---|
| 168 |
can_ok('Storable', 'thaw'); |
|---|
| 169 |
use Storable qw(nfreeze thaw); |
|---|
| 170 |
|
|---|
| 171 |
# Make sure MIME::Base64 loads. |
|---|
| 172 |
BEGIN { use_ok('MIME::Base64', qw(encode_base64 decode_base64)) or diag("Can't load MIME::Base64 package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 173 |
require_ok('MIME::Base64'); |
|---|
| 174 |
can_ok('MIME::Base64', 'encode_base64'); |
|---|
| 175 |
can_ok('MIME::Base64', 'decode_base64'); |
|---|
| 176 |
use MIME::Base64 qw(encode_base64 decode_base64); |
|---|
| 177 |
|
|---|
| 178 |
#XXX: Check to see if the port number should be externalized. |
|---|
| 179 |
# Global test variables. |
|---|
| 180 |
our $PORT = getVar(name => "port", |
|---|
| 181 |
namespace => "HoneyClient::Agent"); |
|---|
| 182 |
our ($stub, $som); |
|---|
| 183 |
|
|---|
| 184 |
=end testing |
|---|
| 185 |
|
|---|
| 186 |
=cut |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
use HoneyClient::Util::SOAP qw(getClientHandle getServerHandle); |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
use HoneyClient::Agent::Integrity; |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
use threads; |
|---|
| 199 |
use threads::shared; |
|---|
| 200 |
use Thread::Semaphore; |
|---|
| 201 |
use Thread::Queue; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
use Data::Dumper; |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
use Storable qw(nfreeze thaw dclone); |
|---|
| 212 |
$Storable::Deparse = 1; |
|---|
| 213 |
$Storable::Eval = 1; |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
use MIME::Base64 qw(encode_base64 decode_base64); |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
use Data::Diff; |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
use Data::Structure::Util qw(unbless); |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
use Data::Compare; |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
our $URL_BASE : shared = undef; |
|---|
| 231 |
our $URL : shared = undef; |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
our $DAEMON_PID : shared = undef; |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
our $PERFORM_INTEGRITY_CHECKS : shared = |
|---|
| 239 |
getVar(name => "perform_integrity_checks"); |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
our $integrityState : shared = undef; |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
our $driverData : shared = undef; |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
our $driverDataSemaphore = Thread::Semaphore->new(1); |
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
our %driverUpdateQueues : shared = ( ); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
=pod |
|---|
| 276 |
|
|---|
| 277 |
=head1 LOCAL FUNCTIONS |
|---|
| 278 |
|
|---|
| 279 |
The following init() and destroy() functions are the only direct |
|---|
| 280 |
calls required to startup and shutdown the SOAP server. |
|---|
| 281 |
|
|---|
| 282 |
All other interactions with this daemon should be performed as |
|---|
| 283 |
C<SOAP::Lite> function calls, in order to ensure consistency across |
|---|
| 284 |
client sessions. See the L<"EXTERNAL SOAP FUNCTIONS"> section, for |
|---|
| 285 |
more details. |
|---|
| 286 |
|
|---|
| 287 |
=head2 HoneyClient::Agent->init(address => $localAddr, port => $localPort, ...) |
|---|
| 288 |
|
|---|
| 289 |
=over 4 |
|---|
| 290 |
|
|---|
| 291 |
Starts a new SOAP server, within a child process. |
|---|
| 292 |
|
|---|
| 293 |
I<Inputs>: |
|---|
| 294 |
B<$localAddr> is an optional argument, specifying the IP address for the SOAP server to listen on. |
|---|
| 295 |
B<$localPort> is an optional argument, specifying the TCP port for the SOAP server to listen on. |
|---|
| 296 |
|
|---|
| 297 |
Additionally optional, driver-specific arguments can be specified |
|---|
| 298 |
as sub-hashtables, where the top-level key corresponds to the name of |
|---|
| 299 |
the implemented driver and the value contains all the expected hash data |
|---|
| 300 |
that can be fed to HoneyClient::Agent::Driver->new() instances. |
|---|
| 301 |
|
|---|
| 302 |
Here is an example set of arguments: |
|---|
| 303 |
|
|---|
| 304 |
HoneyClient::Agent->init( |
|---|
| 305 |
address => '127.0.0.1', |
|---|
| 306 |
port => 9000, |
|---|
| 307 |
IE => { |
|---|
| 308 |
timeout => 30, |
|---|
| 309 |
links_to_visit => { |
|---|
| 310 |
'http://www.mitre.org/' => 1, |
|---|
| 311 |
}, |
|---|
| 312 |
}, |
|---|
| 313 |
); |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
I<Output>: The full URL of the web service provided by the SOAP server. |
|---|
| 317 |
|
|---|
| 318 |
=back |
|---|
| 319 |
|
|---|
| 320 |
=begin testing |
|---|
| 321 |
|
|---|
| 322 |
# XXX: Test init() method. |
|---|
| 323 |
our $URL = HoneyClient::Agent->init(); |
|---|
| 324 |
our $PORT = getVar(name => "port", |
|---|
| 325 |
namespace => "HoneyClient::Agent"); |
|---|
| 326 |
our $HOST = getVar(name => "address", |
|---|
| 327 |
namespace => "HoneyClient::Agent"); |
|---|
| 328 |
is($URL, "http://$HOST:$PORT/HoneyClient/Agent", "init()") or diag("Failed to start up the VM SOAP server. Check to see if any other daemon is listening on TCP port $PORT."); |
|---|
| 329 |
|
|---|
| 330 |
=end testing |
|---|
| 331 |
|
|---|
| 332 |
=cut |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
sub init { |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
my ($class, %args) = @_; |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
if (defined($DAEMON_PID)) { |
|---|
| 344 |
Carp::croak "Error: " . __PACKAGE__ . " daemon is already running (PID = $DAEMON_PID)!\n"; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
_lock(); |
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
my $data = { }; |
|---|
| 352 |
for my $driverName (@DRIVERS) { |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
$data->{$driverName} = { |
|---|
| 359 |
'state' => undef, |
|---|
| 360 |
'thread_id' => undef, |
|---|
| 361 |
'status' => undef, |
|---|
| 362 |
'next' => undef, |
|---|
| 363 |
}; |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
$driverUpdateQueues{$driverName} = new Thread::Queue; |
|---|
| 367 |
} |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
_unlock($data); |
|---|
| 381 |
|
|---|
| 382 |
my $argsExist = scalar(%args); |
|---|
| 383 |
|
|---|
| 384 |
if (!($argsExist && |
|---|
| 385 |
exists($args{'address'}) && |
|---|
| 386 |
defined($args{'address'}))) { |
|---|
| 387 |
$args{'address'} = getVar(name => "address"); |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
if (!($argsExist && |
|---|
| 391 |
exists($args{'port'}) && |
|---|
| 392 |
defined($args{'port'}))) { |
|---|
| 393 |
$args{'port'} = getVar(name => "port"); |
|---|
| 394 |
} |
|---|
| 395 |
|
|---|
| 396 |
$URL_BASE = "http://" . $args{'address'} . ":" . $args{'port'}; |
|---|
| 397 |
$URL = $URL_BASE . "/" . join('/', split(/::/, __PACKAGE__)); |
|---|
| 398 |
|
|---|
| 399 |
my $pid = undef; |
|---|
| 400 |
if ($pid = fork) { |
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
$DAEMON_PID = $pid; |
|---|
| 406 |
return $URL; |
|---|
| 407 |
|
|---|
| 408 |
} else { |
|---|
| 409 |
|
|---|
| 410 |
if (!defined($pid)) { |
|---|
| 411 |
Carp::croak "Error: Unable to fork child process.\n$!"; |
|---|
| 412 |
} |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
local $SIG{HUP} = sub { exit; }; |
|---|
| 417 |
local $SIG{INT} = sub { exit; }; |
|---|
| 418 |
local $SIG{QUIT} = sub { exit; }; |
|---|
| 419 |
local $SIG{ABRT} = sub { exit; }; |
|---|
| 420 |
local $SIG{PIPE} = sub { exit; }; |
|---|
| 421 |
local $SIG{TERM} = sub { exit; }; |
|---|
| 422 |
|
|---|
| 423 |
my $daemon = getServerHandle(address => $args{'address'}, |
|---|
| 424 |
port => $args{'port'}); |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
delete($args{'address'}); |
|---|
| 429 |
delete($args{'port'}); |
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
updateState($class, encode_base64(nfreeze(\%args))); |
|---|
| 435 |
|
|---|
| 436 |
for (;;) { |
|---|
| 437 |
$daemon->handle; |
|---|
| 438 |
} |
|---|
| 439 |
} |
|---|
| 440 |
} |
|---|
| 441 |
|
|---|
| 442 |
=pod |
|---|
| 443 |
|
|---|
| 444 |
=head2 HoneyClient::Agent->destroy() |
|---|
| 445 |
|
|---|
| 446 |
=over 4 |
|---|
| 447 |
|
|---|
| 448 |
Terminates the SOAP server within the child process. |
|---|
| 449 |
|
|---|
| 450 |
I<Output>: True if successful, false otherwise. |
|---|
| 451 |
|
|---|
| 452 |
=back |
|---|
| 453 |
|
|---|
| 454 |
=begin testing |
|---|
| 455 |
|
|---|
| 456 |
# XXX: Test destroy() method. |
|---|
| 457 |
is(HoneyClient::Agent->destroy(), 1, "destroy()") or diag("Unable to terminate Agent SOAP server. Be sure to check for any stale or lingering processes."); |
|---|
| 458 |
|
|---|
| 459 |
# TODO: delete this. |
|---|
| 460 |
#exit; |
|---|
| 461 |
|
|---|
| 462 |
=end testing |
|---|
| 463 |
|
|---|
| 464 |
=cut |
|---|
| 465 |
|
|---|
| 466 |
sub destroy { |
|---|
| 467 |
my $ret = undef; |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
if (defined($DAEMON_PID) && ($DAEMON_PID != 0)) { |
|---|
| 471 |
|
|---|
| 472 |
$ret = kill(9, $DAEMON_PID); |
|---|
| 473 |
} |
|---|
| 474 |
if ($ret) { |
|---|
| 475 |
|
|---|
| 476 |
_lock(); |
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
$URL = undef; |
|---|
| 480 |
$URL_BASE = undef; |
|---|
| 481 |
$DAEMON_PID = undef; |
|---|
| 482 |
$driverData = undef; |
|---|
| 483 |
$driverDataSemaphore = Thread::Semaphore->new(1); |
|---|
| 484 |
%driverUpdateQueues = ( ); |
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
_unlock(); |
|---|
| 488 |
} |
|---|
| 489 |
return $ret; |
|---|
| 490 |
} |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
sub _lock { |
|---|
| 514 |
|
|---|
| 515 |
$driverDataSemaphore->down(); |
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
return thaw($driverData); |
|---|
| 519 |
} |
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
sub _unlock { |
|---|
| 538 |
my $data = shift; |
|---|
| 539 |
|
|---|
| 540 |
if (defined($data)) { |
|---|
| 541 |
|
|---|
| 542 |
$driverData = nfreeze($data); |
|---|
| 543 |
} |
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
$driverDataSemaphore->up(); |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
sub _update { |
|---|
| 569 |
|
|---|
| 570 |
my $driver = shift; |
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
my @package = split(/::/, ref($driver)); |
|---|
| 574 |
my $driverName = pop(@package); |
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
my $queue = $driverUpdateQueues{$driverName}; |
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
if ($queue->pending) { |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
my $queuedData = thaw($queue->dequeue_nb); |
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
if (defined($queuedData)) { |
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
@{$driver}{keys %{$queuedData}} = values %{$queuedData}; |
|---|
| 596 |
} |
|---|
| 597 |
} |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
return $driver; |
|---|
| 601 |
} |
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
=pod |
|---|
| 608 |
|
|---|
| 609 |
=head1 EXPORTS |
|---|
| 610 |
|
|---|
| 611 |
=head2 run() |
|---|
| 612 |
|
|---|
| 613 |
=over 4 |
|---|
| 614 |
|
|---|
| 615 |
# XXX: Fill this in. |
|---|
| 616 |
|
|---|
| 617 |
I<Inputs>: |
|---|
| 618 |
B<$arg> is an optional argument. |
|---|
| 619 |
SOAP server to listen on. |
|---|
| 620 |
|
|---|
| 621 |
I<Output>: XXX: Fill this in. |
|---|
| 622 |
|
|---|
| 623 |
=back |
|---|
| 624 |
|
|---|
| 625 |
=begin testing |
|---|
| 626 |
|
|---|
| 627 |
# XXX: Fill this in. |
|---|
| 628 |
1; |
|---|
| 629 |
|
|---|
| 630 |
=end testing |
|---|
| 631 |
|
|---|
| 632 |
=cut |
|---|
| 633 |
|
|---|
| 634 |
sub run { |
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
my $data = undef; |
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
my $tid = undef; |
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
my $thread = undef; |
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
for my $driverName (@DRIVERS) { |
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
$data = _lock(); |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
$tid = $data->{$driverName}->{'thread_id'}; |
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
if (defined($tid) && |
|---|
| 659 |
defined($thread = threads->object($tid)) && |
|---|
| 660 |
$thread->is_running()) { |
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
_unlock(); |
|---|
| 664 |
|
|---|
| 665 |
return 0; |
|---|
| 666 |
} |
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
$data->{$driverName}->{'thread_id'} = 0; |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
_unlock($data); |
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
$thread = async { |
|---|
| 702 |
threads->yield(); |
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
eval { |
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
my $integrity = undef; |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
my $driver = undef; |
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
$data = _lock(); |
|---|
| 719 |
|
|---|
| 720 |
if ($PERFORM_INTEGRITY_CHECKS) { |
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
print "Initializing Integrity Check...\n"; |
|---|
| 728 |
|
|---|
| 729 |
$integrity = HoneyClient::Agent::Integrity->new(); |
|---|
| 730 |
$integrity->initAll(); |
|---|
| 731 |
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
} |
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; |
|---|
| 741 |
|
|---|
| 742 |
if (!defined($data->{$driverName}->{'state'})) { |
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
$driver = $driverClass->new(); |
|---|
| 747 |
|
|---|
| 748 |
} else { |
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
$driver = $driverClass->new( |
|---|
| 752 |
%{$data->{$driverName}->{'state'}}, |
|---|
| 753 |
); |
|---|
| 754 |
} |
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
$driver = _update($driver); |
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
$data->{$driverName}->{'next'} = $driver->next(); |
|---|
| 767 |
$data->{$driverName}->{'status'} = $driver->status(); |
|---|
| 768 |
$data->{$driverName}->{'status'}->{'is_compromised'} = 0; |
|---|
| 769 |
$data->{$driverName}->{'state'} = $driver; |
|---|
| 770 |
|
|---|
| 771 |
if ($driver->isFinished()) { |
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
$data->{$driverName}->{'thread_id'} = undef; |
|---|
| 778 |
} |
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
_unlock($data); |
|---|
| 782 |
|
|---|
| 783 |
|
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
my $driverTargetsChanged = 0; |
|---|
| 790 |
|
|---|
| 791 |
while (!$driver->isFinished() && !$driverTargetsChanged) { |
|---|
| 792 |
|
|---|
| 793 |
|
|---|
| 794 |
foreach my $resource (keys %{$driver->next()->{resources}}) { |
|---|
| 795 |
print "Using Resource: " . $resource . "\n"; |
|---|
| 796 |
} |
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 |
$driver->drive(); |
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
$data = _lock(); |
|---|
| 804 |
|
|---|
| 805 |
|
|---|
| 806 |
$driver = _update($driver); |
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
$driverTargetsChanged = not(Compare($data->{$driverName}->{'next'}->{'targets'}, $driver->next()->{'targets'})); |
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
$data->{$driverName}->{'next'} = $driver->next(); |
|---|
| 813 |
$data->{$driverName}->{'status'} = $driver->status(); |
|---|
| 814 |
$data->{$driverName}->{'status'}->{'is_compromised'} = 0; |
|---|
| 815 |
$data->{$driverName}->{'state'} = $driver; |
|---|
| 816 |
|
|---|
| 817 |
if ($driver->isFinished() or $driverTargetsChanged) { |
|---|
| 818 |
|
|---|