Changeset 709

Show
Ignore:
Timestamp:
07/20/07 15:58:14 (1 year ago)
Author:
kindlund
Message:

First shot at making the code be more flexible in accepting different Driver types.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-firefox/bin/StartManager.pl

    r701 r709  
    2424# They can however supply multiple urls which will be processed in order 
    2525 
    26 my $driver = "FF"; 
     26# Change to 'Browser::IE' or 'Browser::FF' 
     27my $driver = "Browser::IE"; 
    2728my $config = "/vm/master-vms/Agent.Master-23/winXPPro.cfg"; 
    2829my $maxrel = 10; 
     
    6061 
    6162my $agentState = HoneyClient::Manager->run( 
    62                     driver           => $driver, # Change to 'IE' or 'FF' 
     63                    driver           => $driver, 
    6364                    master_vm_config => $config, 
    6465                    agent_state      => encode_base64(nfreeze({ 
    65                         $driver => { # Change to 'IE' or 'FF' 
     66                        $driver => { 
    6667                            next_link_to_visit => $firsturl, 
    6768                            # Enable this line, if you want to only go to the 
  • honeyclient/branches/exp/kindlund-firefox/lib/HoneyClient/Agent.pm

    r701 r709  
    113113    # TODO: Eventually, make this more dynamic, based upon the presence of HoneyClient::Agent::Driver::* elements 
    114114    # within the global configuration file.  Or, feed the initialization logic through init() as part of the arguments. 
    115     @DRIVERS = ( 'FF' ); 
     115    @DRIVERS = ( 'Browser::IE' ); 
    116116    foreach (@DRIVERS) { 
    117         eval "use HoneyClient::Agent::Driver::Browser::$_"; 
     117        eval "use HoneyClient::Agent::Driver::$_"; 
    118118        if ($@) { 
    119119            Carp::croak "$@"; 
     
    150150use HoneyClient::Util::Config qw(getVar); 
    151151 
    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; 
     152# Make sure HoneyClient::Agent::Driver::Browser::IE loads. 
     153BEGIN { use_ok('HoneyClient::Agent::Driver::Browser::IE') or diag("Can't load HoneyClient::Agent::Driver::Browser::IE package.  Check to make sure the package library is correctly listed within the path."); } 
     154require_ok('HoneyClient::Agent::Driver::Browser::IE'); 
     155# TODO: Update this list of function names. 
     156can_ok('HoneyClient::Agent::Driver::Browser::IE', 'new'); 
     157can_ok('HoneyClient::Agent::Driver::Browser::IE', 'drive'); 
     158can_ok('HoneyClient::Agent::Driver::Browser::IE', 'getNextLink'); 
     159can_ok('HoneyClient::Agent::Driver::Browser::IE', 'next'); 
     160can_ok('HoneyClient::Agent::Driver::Browser::IE', 'isFinished'); 
     161can_ok('HoneyClient::Agent::Driver::Browser::IE', 'status'); 
     162use HoneyClient::Agent::Driver::Browser::IE; 
    163163 
    164164# Make sure Storable loads. 
     
    630630=pod 
    631631 
    632 =head1 EXPORT
    633  
    634 =head2 run(
     632=head1 EXTERNAL SOAP FUNCTION
     633 
     634=head2 run(driver_name => $driverName
    635635 
    636636=over 4 
    637637 
     638Runs the Agent for one cycle.  In this cycle, the following happens: 
     639 
     640=over 4 
     641 
     642=item 1) 
     643 
     644The specified Driver is driven for multiple work units, where each 
     645consecutive drive operation contacts the same network resources 
     646(aka. "targets").  The Driver ceases its operation, as soon as 
     647it has exhausted all targets or until it is ready to contact a 
     648different set of targets. 
     649 
     650=item 2) 
     651 
     652Once the specified driver has stopped, the Agent performs a corresponding 
     653Integrity check. 
     654 
     655=back  
     656 
    638657# XXX: Fill this in. 
    639658 
    640659I<Inputs>:  
    641  B<$arg> is an optional argument. 
    642 SOAP server to listen on
     660 B<$driverName> is the name of the Driver to use, when running this  
     661cycle
    643662  
    644 I<Output>: XXX: Fill this in. 
     663I<Output>: Returns true if the Agent successfully started a new cycle; 
     664returns false, if the Agent is still running an existing cycle and 
     665has not finished yet. 
     666 
     667I<Notes>: 
     668During a single run() cycle, it is expected that the driven application 
     669will only contact the same targets.  This allows the Manager to update 
     670firewall rules between cycles. 
    645671 
    646672=back 
    647673 
    648 =begin testing 
    649  
     674#=begin testing 
     675
    650676# XXX: Fill this in. 
    651 1; 
    652  
    653 =end testing 
     677
     678#=end testing 
    654679 
    655680=cut 
     
    657682sub run { 
    658683    # Extract arguments. 
     684    my ($class, %args) = @_; 
     685 
     686    # XXX: Change this to debug, eventually. 
     687    # Log resolved arguments. 
     688    $LOG->info(sub { 
     689        # Make Dumper format more terse. 
     690        $Data::Dumper::Terse = 1; 
     691        $Data::Dumper::Indent = 0; 
     692        Dumper(\%args); 
     693    }); 
     694 
     695    # Sanity check.  Make sure we get a valid argument. 
     696    my $argsExist = scalar(%args); 
     697    if (!$argsExist || 
     698        !exists($args{'driver_name'}) || 
     699        !defined($args{'driver_name'})) { 
     700 
     701        # Die if no valid argument is supplied. 
     702        $LOG->warn("No Driver name specified."); 
     703        die SOAP::Fault->faultcode(__PACKAGE__ . "->run()") 
     704                       ->faultstring("No Driver name specified."); 
     705    } 
    659706 
    660707    # Temporary variable, used to hold thawed driver data. 
     
    678725 
    679726# XXX: Delete this, eventually. 
    680 print "Checking TID = " . Dumper($tid) . "\n"; 
     727print $driverName . ": Checking TID = " . Dumper($tid) . "\n"; 
    681728if (defined(threads->object($tid))) { 
    682     print "Thread defined.\n"; 
     729    print $driverName . ": Thread defined.\n"; 
    683730    if (threads->object($tid)->is_running()) { 
    684         print "Thread is running.\n"; 
     731        print $driverName . ": Thread is running.\n"; 
    685732    } else { 
    686         print "Thread is NOT running.\n"; 
     733        print $driverName . ": Thread is NOT running.\n"; 
    687734    } 
    688735} else { 
    689     print "Thread NOT defined.\n"; 
     736    print $driverName . ": Thread NOT defined.\n"; 
    690737} 
    691738         
     
    702749        } else { 
    703750            # XXX: Remove this, eventually. 
    704             print "Creating a new run() child thread...\n"; 
     751            print $driverName . ": Creating a new run() child thread...\n"; 
    705752        } 
    706753 
     
    736783        if ($thread->is_running()) { 
    737784            # XXX: Debugging, remove eventually.  
    738             print "Thread ID = " . $thread->tid() . "\n"; 
     785            print $driverName . ": Thread ID = " . $thread->tid() . "\n"; 
    739786        } else { 
    740787            # XXX: Debugging, remove eventually.  
    741             print "Thread ID = " . $thread->tid() . " (NOT RUNNING)\n"; 
     788            print $driverName . ": Thread ID = " . $thread->tid() . " (NOT RUNNING)\n"; 
    742789        } 
    743790 
     
    747794 
    748795    # XXX: Debugging, remove eventually.  
    749     print "Run thread initialized.\n"; 
     796    print $driverName . ": Run thread initialized.\n"; 
    750797 
    751798    # At this point, the driver thread is initialized and running, 
     
    801848        # Now, initialize each driver object.  
    802849        # Figure out which $driver object to use... 
    803         my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
     850        my $driverClass = 'HoneyClient::Agent::Driver::' . $driverName; 
    804851 
    805852        if (!defined($data->{$driverName}->{'state'})) { 
     
    848895            # We assume $driver->next() returns defined data. 
    849896            foreach my $resource (keys %{$driver->next()->{resources}}) { 
    850                 $LOG->info("Driving To Resource: " . $resource); 
     897                $LOG->info($driverName . " - Driving To Resource: " . $resource); 
    851898                $lastResource = $resource; 
    852899            } 
     
    866913            # XXX: Delete this, eventually. 
    867914            if ($driverTargetsChanged) { 
    868                 $LOG->info("Driver targets have changed."); 
     915                $LOG->info($driverName . " - Driver targets have changed."); 
    869916                #$Data::Dumper::Terse = 0; 
    870917                #$Data::Dumper::Indent = 1; 
     
    884931        } 
    885932                 
    886         # TODO: Perform Integrity Check 
     933        # Perform Integrity Check 
     934        # XXX: We may want this logic moved out of the child thread, 
     935        # in case we ever have more than one worker thread simultaneously going. 
     936        # (We wouldn't want to have 2 worker threads simultaneously performing 
     937        # this check, as VM performance would slow to a crawl.) 
    887938        my $isCompromised = 0; 
    888939        my $changes = undef; 
     
    890941            # For now, we update a scalar called 'is_compromised' within 
    891942            # the $data->{$driverName}->{'status'} sub-hashtable. 
    892             $LOG->info("Performing Integrity Checks."); 
     943            $LOG->info($driverName . " - Performing Integrity Checks."); 
    893944            $changes = $integrity->check(); 
    894945            if (scalar(@{$changes->{registry}}) ||  
    895946                scalar(@{$changes->{filesystem}})) { 
    896                 $LOG->warn("Integrity Check: FAILED"); 
     947                $LOG->warn($driverName . " - Integrity Check: FAILED"); 
    897948                $isCompromised = 1; 
    898949                $changes->{'last_resource'} = $lastResource; 
    899950            } else { 
    900                 $LOG->info("Integrity Check: PASSED"); 
     951                $LOG->info($driverName . " - Integrity Check: PASSED"); 
    901952            } 
    902953        } 
     
    936987 
    937988        # TODO: Do proper fault queuing. 
    938         $LOG->error("FAULT: " . $@); 
     989        $LOG->error($driverName . " - FAULT: " . $@); 
    939990    } 
    940991 
    941992    # XXX: Debugging, remove eventually.  
    942     print "About to return out of child thread.\n"; 
     993    print $driverName . ": About to return out of child thread.\n"; 
    943994    if (!threads->is_detached()) { 
    944995        threads->detach(); 
     
    10341085            # Initialize the driver object.  
    10351086            # Figure out which $driver object to use... 
    1036             my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
     1087            my $driverClass = 'HoneyClient::Agent::Driver::' . $driverName; 
    10371088 
    10381089            if (!defined($data->{$driverName}->{'state'})) { 
  • honeyclient/branches/exp/kindlund-firefox/lib/HoneyClient/Manager.pm

    r696 r709  
    749749 
    750750                        print "Calling run()...\n"; 
    751                         $som = $stubAgent->run(); 
     751                        $som = $stubAgent->run(driver_name => $args{'driver'})); 
    752752                    } 
    753753                }