Changeset 1426
- Timestamp:
- 04/02/08 20:35:55 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Agent.pm
r1425 r1426 111 111 =begin testing 112 112 113 # Make sure Log::Log4perl loads 114 BEGIN { use_ok('Log::Log4perl', qw(:nowarn)) 115 or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); 116 117 # Suppress all logging messages, since we need clean output for unit testing. 118 Log::Log4perl->init({ 119 "log4perl.rootLogger" => "DEBUG, Buffer", 120 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 121 "log4perl.appender.Buffer.min_level" => "fatal", 122 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 123 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 124 }); 125 } 126 require_ok('Log::Log4perl'); 127 use Log::Log4perl qw(:easy); 128 129 # Make sure HoneyClient::Util::Config loads. 130 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) 131 or diag("Can't load HoneyClient::Util::Config package. Check to make sure the package library is correctly listed within the path."); 132 133 # Suppress all logging messages, since we need clean output for unit testing. 134 Log::Log4perl->init({ 135 "log4perl.rootLogger" => "DEBUG, Buffer", 136 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 137 "log4perl.appender.Buffer.min_level" => "fatal", 138 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 139 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 140 }); 141 } 142 require_ok('HoneyClient::Util::Config'); 143 can_ok('HoneyClient::Util::Config', 'getVar'); 144 use HoneyClient::Util::Config qw(getVar); 145 146 # Suppress all logging messages, since we need clean output for unit testing. 147 Log::Log4perl->init({ 148 "log4perl.rootLogger" => "DEBUG, Buffer", 149 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 150 "log4perl.appender.Buffer.min_level" => "fatal", 151 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 152 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 153 }); 154 113 155 # Make sure the module loads properly, with the exportable 114 156 # functions shared. … … 125 167 can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 126 168 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 127 128 # Make sure HoneyClient::Util::Config loads.129 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."); }130 require_ok('HoneyClient::Util::Config');131 can_ok('HoneyClient::Util::Config', 'getVar');132 use HoneyClient::Util::Config qw(getVar);133 169 134 170 # Make sure Storable loads. … … 153 189 use Win32::Job; 154 190 191 # Make sure DateTime::HiRes loads. 192 BEGIN { use_ok('DateTime::HiRes') or diag("Can't load DateTime::HiRes package. Check to make sure the package library is correctly listed within the path."); } 193 require_ok('DateTime::HiRes'); 194 use DateTime::HiRes; 195 155 196 # Global test variables. 156 197 our $PORT = getVar(name => "port", … … 188 229 use Win32::Job; 189 230 231 # Use ISO 8601 DateTime Libraries 232 use DateTime::HiRes; 233 190 234 # Include Logging Library 191 235 use Log::Log4perl qw(:easy); … … 200 244 # The process ID of the SOAP server daemon, once created. 201 245 our $DAEMON_PID = undef; 202 203 # Global array, to indicate which implemented Drivers the204 # Agent is allowed to run.205 our $ALLOWED_DRIVERS = getVar(name => 'allowed_drivers')->{name};206 207 # Global value, to indicate if the Agent should perform208 # any integrity checks.209 our $PERFORM_INTEGRITY_CHECKS =210 getVar(name => "perform_integrity_checks");211 246 212 247 ####################################################################### … … 281 316 Carp::croak "Error: " . __PACKAGE__ . " daemon is already running (PID = $DAEMON_PID)!\n"; 282 317 } 283 284 # Reinitialize global constants (for dynamic updates).285 $PERFORM_INTEGRITY_CHECKS = getVar(name => "perform_integrity_checks");286 287 # Figure out what our list of allowed Drivers are.288 $ALLOWED_DRIVERS = getVar(name => 'allowed_drivers')->{name};289 318 290 319 my $argsExist = scalar(%args); … … 386 415 } 387 416 if ($ret) { 388 $DAEMON_PID = undef;417 $DAEMON_PID = undef; 389 418 } 390 419 return $ret; … … 394 423 # Private Methods Implemented # 395 424 ####################################################################### 425 426 # Helper function designed to get a current timestamp from 427 # the system OS. 428 # 429 # Note: This timestamp is in ISO 8601 format. 430 # 431 # Inputs: none 432 # Outputs: timestamp 433 sub _getTimestamp { 434 my $dt = DateTime::HiRes->now(time_zone => "local"); 435 return $dt->ymd('-') . " " . 436 $dt->hms(':') . "." . 437 $dt->nanosecond(); 438 } 396 439 397 440 ####################################################################### … … 462 505 address => "localhost"); 463 506 507 diag("Driving HoneyClient::Agent::Driver::Browser::IE with no parameters..."); 508 464 509 # Drive the Agent using IE. 465 $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE", 466 parameters => "http://www.google.com"); 467 468 # Make sure the test VM is stopped. 469 #$som = $stub->stopVM(config => $testVM); 470 471 # Test isRegisteredVM() method. 472 #$som = $stub->isRegisteredVM(config => $testVM); 473 474 # The test VM should be registered. 475 #ok($som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed. If ($testVM) is still registered, be sure to unregister it manually."); 476 477 # Make sure the test VM is unregistered. 478 #$som = $stub->unregisterVM(config => $testVM); 479 480 # Test isRegisteredVM() method. 481 #$som = $stub->isRegisteredVM(config => $testVM); 482 483 # The test VM should not be registered. 484 #ok(!$som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed. If ($testVM) is still registered, be sure to unregister it manually."); 510 $som = $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE"); 511 512 # Verify changes. 513 my $changes = $som->result(); 514 515 use Data::Dumper; 516 diag(Dumper($changes)); 517 518 # Check to see if the drive operation completed properly. 519 ok($changes, "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 520 ok(exists($changes->{'status'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 521 ok(exists($changes->{'driven_at'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 522 ok(exists($changes->{'fingerprint'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 523 524 # Check that os_processes is empty. 525 ok(!scalar(@{$changes->{'fingerprint'}->{os_processes}}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 526 485 527 }; 486 528 … … 516 558 517 559 # Die if no valid argument is supplied. 518 $LOG-> warn("No Driver name specified.");560 $LOG->error("No Driver name specified."); 519 561 die SOAP::Fault->faultcode(__PACKAGE__ . "->drive()") 520 562 ->faultstring("No Driver name specified."); … … 523 565 # Sanity check. Make sure the driver name specified is 524 566 # on our allowed list. 525 my @drivers_found = grep(/^$args{'driver_name'}$/, @{ $ALLOWED_DRIVERS});567 my @drivers_found = grep(/^$args{'driver_name'}$/, @{getVar(name => 'allowed_drivers')->{name}}); 526 568 my $driverName = pop(@drivers_found); 527 569 unless (defined($driverName)) { 528 $LOG-> warn("Not allowed to run Driver (" . $args{'driver_name'} . ").");570 $LOG->error("Not allowed to run Driver (" . $args{'driver_name'} . ")."); 529 571 die SOAP::Fault->faultcode(__PACKAGE__ . "->drive()") 530 572 ->faultstring("Not allowed to run Driver (" . $args{'driver_name'} . ")."); … … 544 586 } 545 587 588 # Construct the output hashtable. 589 my $ret = { 590 # Time when application was driven. 591 'driven_at' => _getTimestamp(), 592 593 # Fingerprint information found (if any). 594 'fingerprint' => undef, 595 596 # Status information about the Win32::Job call. 597 'status' => undef, 598 }; 599 546 600 # Create a new Job. 547 601 my $job = Win32::Job->new(); … … 567 621 ->faultstring("Error: Unable to execute '" . $processExec . "'"); 568 622 } 623 $ret->{'status'} = $status; 624 625 $LOG->info($args{'driver_name'} . " - Driving To Resource: " . $args{'parameters'}); 569 626 570 627 # Run the job. … … 601 658 } 602 659 603 return 1; 660 # Perform an integrity check, if desired. 661 if (getVar(name => "perform_integrity_checks")) { 662 my $integrity = HoneyClient::Agent::Integrity->new(); 663 $ret->{'fingerprint'} = $integrity->check(); 664 if (scalar(@{$ret->{'fingerprint'}->{os_processes}})) { 665 $LOG->warn($args{'driver_name'} . " - Integrity Check: FAILED"); 666 } else { 667 $LOG->info($args{'driver_name'} . " - Integrity Check: PASSED"); 668 } 669 } 670 671 return $ret; 604 672 } 605 673 … … 616 684 =head1 BUGS & ASSUMPTIONS 617 685 618 # XXX: Fill this in. 619 # XXX: If, at any time, the Manager's SOAP connection to the Agent 686 If, at any time, the Manager's SOAP connection to the Agent 620 687 is disrupted during a drive() operation, then the Manager should assume 621 688 that the VM has been compromised and proceed to handle the VM as such. honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_agent.t
r1425 r1426 9 9 # =begin testing 10 10 { 11 # Make sure Log::Log4perl loads 12 BEGIN { use_ok('Log::Log4perl', qw(:nowarn)) 13 or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); 14 15 # Suppress all logging messages, since we need clean output for unit testing. 16 Log::Log4perl->init({ 17 "log4perl.rootLogger" => "DEBUG, Buffer", 18 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 19 "log4perl.appender.Buffer.min_level" => "fatal", 20 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 21 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 22 }); 23 } 24 require_ok('Log::Log4perl'); 25 use Log::Log4perl qw(:easy); 26 27 # Make sure HoneyClient::Util::Config loads. 28 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) 29 or diag("Can't load HoneyClient::Util::Config package. Check to make sure the package library is correctly listed within the path."); 30 31 # Suppress all logging messages, since we need clean output for unit testing. 32 Log::Log4perl->init({ 33 "log4perl.rootLogger" => "DEBUG, Buffer", 34 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 35 "log4perl.appender.Buffer.min_level" => "fatal", 36 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 37 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 38 }); 39 } 40 require_ok('HoneyClient::Util::Config'); 41 can_ok('HoneyClient::Util::Config', 'getVar'); 42 use HoneyClient::Util::Config qw(getVar); 43 44 # Suppress all logging messages, since we need clean output for unit testing. 45 Log::Log4perl->init({ 46 "log4perl.rootLogger" => "DEBUG, Buffer", 47 "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", 48 "log4perl.appender.Buffer.min_level" => "fatal", 49 "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", 50 "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 51 }); 52 11 53 # Make sure the module loads properly, with the exportable 12 54 # functions shared. … … 23 65 can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 24 66 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 25 26 # Make sure HoneyClient::Util::Config loads.27 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."); }28 require_ok('HoneyClient::Util::Config');29 can_ok('HoneyClient::Util::Config', 'getVar');30 use HoneyClient::Util::Config qw(getVar);31 67 32 68 # Make sure Storable loads. … … 50 86 require_ok('Win32::Job'); 51 87 use Win32::Job; 88 89 # Make sure DateTime::HiRes loads. 90 BEGIN { use_ok('DateTime::HiRes') or diag("Can't load DateTime::HiRes package. Check to make sure the package library is correctly listed within the path."); } 91 require_ok('DateTime::HiRes'); 92 use DateTime::HiRes; 52 93 53 94 # Global test variables. … … 93 134 address => "localhost"); 94 135 136 diag("Driving HoneyClient::Agent::Driver::Browser::IE with no parameters..."); 137 95 138 # Drive the Agent using IE. 96 $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE", 97 parameters => "http://www.google.com"); 139 $som = $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE"); 98 140 99 # Make sure the test VM is stopped.100 #$som = $stub->stopVM(config => $testVM);141 # Verify changes. 142 my $changes = $som->result(); 101 143 102 # Test isRegisteredVM() method. 103 #$som = $stub->isRegisteredVM(config => $testVM); 144 use Data::Dumper; 145 diag(Dumper($changes)); 146 147 # Check to see if the drive operation completed properly. 148 ok($changes, "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 149 ok(exists($changes->{'status'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 150 ok(exists($changes->{'driven_at'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 151 ok(exists($changes->{'fingerprint'}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 104 152 105 # The test VM should be registered.106 #ok($som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed. If ($testVM) is still registered, be sure to unregister it manually.");153 # Check that os_processes is empty. 154 ok(!scalar(@{$changes->{'fingerprint'}->{os_processes}}), "drive(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 107 155 108 # Make sure the test VM is unregistered.109 #$som = $stub->unregisterVM(config => $testVM);110 111 # Test isRegisteredVM() method.112 #$som = $stub->isRegisteredVM(config => $testVM);113 114 # The test VM should not be registered.115 #ok(!$som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed. If ($testVM) is still registered, be sure to unregister it manually.");116 156 }; 117 157 honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_manager_vm.t
r1008 r1426 250 250 # Kill the child daemon, if it still exists. 251 251 HoneyClient::Manager::VM->destroy(); 252 # XXX: See if this is still needed.253 #sleep (1);254 252 255 253 # Report any failure found. … … 295 293 # Kill the child daemon, if it still exists. 296 294 HoneyClient::Manager::VM->destroy(); 297 # XXX: See if this is still needed.298 #sleep (1);299 295 300 296 # Report any failure found. … … 339 335 # Kill the child daemon, if it still exists. 340 336 HoneyClient::Manager::VM->destroy(); 341 # XXX: See if this is still needed.342 #sleep (1);343 337 344 338 # Report any failure found. … … 395 389 # Kill the child daemon, if it still exists. 396 390 HoneyClient::Manager::VM->destroy(); 397 # XXX: See if this is still needed.398 #sleep (1);399 391 400 392 # Report any failure found. … … 442 434 # Kill the child daemon, if it still exists. 443 435 HoneyClient::Manager::VM->destroy(); 444 # XXX: See if this is still needed.445 #sleep (1);446 436 447 437 # Report any failure found. … … 499 489 # Kill the child daemon, if it still exists. 500 490 HoneyClient::Manager::VM->destroy(); 501 # XXX: See if this is still needed.502 #sleep (1);503 491 504 492 # Report any failure found. … … 548 536 # Kill the child daemon, if it still exists. 549 537 HoneyClient::Manager::VM->destroy(); 550 # XXX: See if this is still needed.551 #sleep (1);552 538 553 539 # Report any failure found. … … 618 604 # Kill the child daemon, if it still exists. 619 605 HoneyClient::Manager::VM->destroy(); 620 # XXX: See if this is still needed.621 #sleep (1);622 606 623 607 # Report any failure found. … … 662 646 # Kill the child daemon, if it still exists. 663 647 HoneyClient::Manager::VM->destroy(); 664 # XXX: See if this is still needed.665 #sleep (1);666 648 667 649 # Report any failure found. … … 715 697 # Kill the child daemon, if it still exists. 716 698 HoneyClient::Manager::VM->destroy(); 717 # XXX: See if this is still needed.718 #sleep (1);719 699 720 700 # Report any failure found. … … 761 741 # Kill the child daemon, if it still exists. 762 742 HoneyClient::Manager::VM->destroy(); 763 # XXX: See if this is still needed.764 #sleep (1);765 743 766 744 # Report any failure found. … … 813 791 # Kill the child daemon, if it still exists. 814 792 HoneyClient::Manager::VM->destroy(); 815 # XXX: See if this is still needed.816 #sleep (1);817 793 818 794 # Report any failure found. … … 860 836 # Kill the child daemon, if it still exists. 861 837 HoneyClient::Manager::VM->destroy(); 862 # XXX: See if this is still needed.863 #sleep (1);864 838 865 839 # Report any failure found. … … 904 878 # Kill the child daemon, if it still exists. 905 879 HoneyClient::Manager::VM->destroy(); 906 # XXX: See if this is still needed.907 #sleep (1);908 880 909 881 # Report any failure found. … … 975 947 # Kill the child daemon, if it still exists. 976 948 HoneyClient::Manager::VM->destroy(); 977 # XXX: See if this is still needed.978 #sleep (1);979 949 980 950 # Report any failure found. … … 1047 1017 # Kill the child daemon, if it still exists. 1048 1018 HoneyClient::Manager::VM->destroy(); 1049 # XXX: See if this is still needed.1050 #sleep (1);1051 1019 1052 1020 # Report any failure found. … … 1132 1100 # Kill the child daemon, if it still exists. 1133 1101 HoneyClient::Manager::VM->destroy(); 1134 # XXX: See if this is still needed.1135 #sleep (1);1136 1102 1137 1103 # Report any failure found. … … 1228 1194 # Kill the child daemon, if it still exists. 1229 1195 HoneyClient::Manager::VM->destroy(); 1230 # XXX: See if this is still needed.1231 #sleep (1);1232 1196 1233 1197 # Report any failure found. … … 1341 1305 # Kill the child daemon, if it still exists. 1342 1306 HoneyClient::Manager::VM->destroy(); 1343 # XXX: See if this is still needed.1344 #sleep (1);1345 1307 1346 1308 # Report any failure found. … … 1453 1415 # Kill the child daemon, if it still exists. 1454 1416 HoneyClient::Manager::VM->destroy(); 1455 # XXX: See if this is still needed.1456 #sleep (1);1457 1417 1458 1418 # Report any failure found.
