Changeset 409

Show
Ignore:
Timestamp:
05/29/07 23:12:01 (1 year ago)
Author:
kindlund
Message:

Merged kindlund-filesystem branch back into trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/bin/StartAgent.pl

    r333 r409  
    77use Carp (); 
    88 
     9use HoneyClient::Util::Config qw(getVar); 
    910use HoneyClient::Agent; 
    1011use HoneyClient::Util::SOAP qw(getClientHandle); 
     
    1213use MIME::Base64 qw(decode_base64 encode_base64); 
    1314use Storable qw(thaw nfreeze); 
     15use Log::Log4perl qw(:easy); 
     16 
     17# The global logging object. 
     18our $LOG = get_logger(); 
    1419 
    1520our ($stub, $som); 
     
    1823our $agentState = undef; 
    1924my $tempState = undef; 
     25our $faultDetected = 0; 
    2026 
    2127print "URL: " . $URL. "\n"; 
     
    3541    } 
    3642 
    37     print "Watchdog fault detected, recovering Agent daemon.\n"; 
     43    if (!$faultDetected) { 
     44        $LOG->error("Watchdog fault detected, recovering Agent daemon."); 
     45        $faultDetected = 1; 
     46    } 
    3847    # XXX: Reenable this, eventually. 
    39     #Carp::carp __PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg; 
     48    $LOG->error(__PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg); 
     49    Carp::carp __PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg; 
    4050 
    4151 
  • honeyclient/trunk/bin/StartManager.pl

    r351 r409  
    2525 
    2626my $driver = "IE"; 
    27 my $config = "/vm/master-vms/Agent.Master-16/winXPPro.cfg"; 
     27my $config = "/vm/master-vms/Agent.Master-19/winXPPro.cfg"; 
    2828my $maxrel = 5; 
    2929my $nexturl = ""; 
  • honeyclient/trunk/etc/honeyclient.xml

    r359 r409  
    5454        etc/honeyclient_log.conf 
    5555    </log_config> 
     56    <syslog_address description="The IP address of the syslog server that all logging messages will be sent to by both Agent and Manager processes over UDP port 514." default="10.0.0.1"> 
     57        10.0.0.1 
     58    </syslog_address> 
    5659    <!-- HoneyClient::Agent Options --> 
    5760    <Agent> 
     
    121124        </Driver> 
    122125        <perform_integrity_checks description="An integer, representing whether the Agent should perform any integrity checks. 1 enables, 0 disables." default="1"> 
    123             1 
     126            1  
    124127        </perform_integrity_checks> 
    125128        <!-- HoneyClient::Agent::Integrity Options --> 
     
    137140                    <regex>C:/Documents and Settings/Administrator/Application Data/Mozilla/Firefox/Profiles.*</regex> 
    138141                    <regex>C:/Documents and Settings/Administrator/Cookies.*</regex> 
     142                    <regex>C:/Documents and Settings/Administrator/Local Settings/Application Data/Macromedia/Flash Player.*</regex> 
    139143                    <regex>C:/Documents and Settings/Administrator/Local Settings/Application Data/Mozilla/Firefox/Profiles.*</regex> 
    140144                    <regex>C:/Documents and Settings/Administrator/Local Settings/History/History.IE5.*</regex> 
     
    181185                    <name>HKEY_CURRENT_USER</name> 
    182186                    <name>HKEY_USERS</name> 
    183                     <name>HKEY_CURRENT_CONFIG</name>  
     187                    <name>HKEY_CURRENT_CONFIG</name> 
    184188                </hives_to_check> 
    185189                <exclude_list description="List of perl regular expressions, each matching one or more registry key directory names to exclude from analysis.  These entries match registry key directories that change normally during the course of driving the target application.  As such, they are excluded from analysis in order to reduce false positives.  As in normal regular expressions, each backslash (\) must be escaped (\\) and each regex must not end with any backslash character."> 
  • honeyclient/trunk/etc/honeyclient_log.conf

    r158 r409  
    5959####################################################################### 
    6060 
    61 log4perl.rootLogger=INFO, Screen 
     61log4perl.rootLogger=INFO, Screen, Syslog 
     62 
     63# Screen Logging Settings 
    6264#log4perl.logger.HoneyClient.Agent.Integrity.Registry=DEBUG, Screen 
    6365# Suppress Parser Debugging Messages 
     
    7072log4perl.appender.Screen.layout=Log::Log4perl::Layout::PatternLayout 
    7173log4perl.appender.Screen.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n 
     74 
     75# Syslog Logging Settings 
     76log4perl.appender.Syslog=Log::Dispatch::Syslog 
     77log4perl.appender.Syslog.socket=inet 
     78log4perl.appender.Syslog.Threshold=DEBUG 
     79log4perl.appender.Syslog.layout=Log::Log4perl::Layout::PatternLayout 
     80log4perl.appender.Syslog.layout.ConversionPattern=%5p [%M] (%F:%L) - %m%n 
  • honeyclient/trunk/lib/HoneyClient/Agent.pm

    r333 r409  
    163163 
    164164# Make sure Storable loads. 
    165 BEGIN { use_ok('Storable', qw(freeze nfreeze thaw)) or diag("Can't load Storable package.  Check to make sure the package library is correctly listed within the path."); } 
     165BEGIN { use_ok('Storable', qw(freeze nfreeze thaw dclone)) or diag("Can't load Storable package.  Check to make sure the package library is correctly listed within the path."); } 
    166166require_ok('Storable'); 
    167167can_ok('Storable', 'freeze'); 
    168168can_ok('Storable', 'nfreeze'); 
    169169can_ok('Storable', 'thaw'); 
    170 use Storable qw(freeze nfreeze thaw); 
     170can_ok('Storable', 'dclone'); 
     171use Storable qw(freeze nfreeze thaw dclone); 
    171172 
    172173# Make sure MIME::Base64 loads. 
     
    209210 
    210211# Include Hash Serialization Utility Libraries 
    211 # TODO: Update unit tests to include 'dclone' 
    212212use Storable qw(freeze nfreeze thaw dclone); 
    213213$Storable::Deparse = 1; 
     
    228228use Data::Compare; 
    229229 
     230# Include Logging Library 
     231use Log::Log4perl qw(:easy); 
     232 
     233# The global logging object. 
     234our $LOG = get_logger(); 
     235 
    230236# Complete URL of SOAP server, when initialized. 
    231237our $URL_BASE       : shared = undef; 
     
    240246    getVar(name => "perform_integrity_checks"); 
    241247 
    242 # A globally shared, serialized hashtable, containing the 
    243 # initialized integrity state of the VM -- ready to be checked 
    244 # against, at any time. 
    245 #our $integrity = undef; 
    246 our $integrityState : shared = undef; 
     248# A globally shared object, containing the initialized integrity 
     249# state of the VM -- ready to be checked against, at any time after 
     250# initialization. 
     251our $integrityData; 
    247252 
    248253# A globally shared, serialized hashtable, containing data per 
     
    344349    # Sanity check.  Make sure the daemon isn't already running. 
    345350    if (defined($DAEMON_PID)) { 
     351        $LOG->fatal("Error: " . __PACKAGE__ . " daemon is already running (PID = " . $DAEMON_PID .")!"); 
    346352        Carp::croak "Error: " . __PACKAGE__ . " daemon is already running (PID = $DAEMON_PID)!\n"; 
    347353    } 
     
    370376 
    371377    # Perform initial integrity baseline check. 
    372     #my $integrity = undef; 
    373     #if ($PERFORM_INTEGRITY_CHECKS) { 
    374     #    $integrity = HoneyClient::Agent::Integrity->new(); 
    375     #    $integrity->closeFiles(); 
    376     #    $integrityState = freeze($integrity); 
    377     #} 
    378     # XXX: Check to make sure this doesn't destroy the integrity 
    379     # object prematurely. 
    380     #$integrity = undef; 
     378    if ($PERFORM_INTEGRITY_CHECKS) { 
     379        $integrityData = HoneyClient::Agent::Integrity->new(); 
     380        $integrityData->closeFiles(); 
     381    } 
    381382 
    382383    # Release data lock. 
     
    412413        # Make sure the fork was successful. 
    413414        if (!defined($pid)) { 
     415            $LOG->fatal("Error: Unable to fork child process.\n$!"); 
    414416            Carp::croak "Error: Unable to fork child process.\n$!"; 
    415417        } 
     
    438440     
    439441        for (;;) { 
    440             $daemon->handle
     442            $daemon->handle()
    441443        } 
    442444    } 
     
    472474    # the parent process... 
    473475    if (defined($DAEMON_PID) && ($DAEMON_PID != 0)) { 
     476        $LOG->error("Killing PID = " . $DAEMON_PID); 
    474477        print STDERR "Killing PID = " . $DAEMON_PID . "\n"; 
    475478        # The Win32 version of kill() seems to only respond to SIGKILL(9). 
     
    494497        %driverUpdateQueues   = ( ); 
    495498 
     499        # Destroy all integrity data, if defined. 
     500        if (defined($integrityData)) { 
     501            $integrityData->destroy(); 
     502        } 
     503        $integrityData        = undef; 
     504         
    496505        # Release data lock. 
    497506        _unlock(); 
     
    562571# When called from run(), this function takes in the corresponding 
    563572# Driver object; checks to see if there's a new entry within the 
    564 # driver's corresponding update queue; and dequeues the *first
    565 # entry in the queue, overwriting the Driver's state data 
     573# driver's corresponding update queue; and dequeues the *all
     574# entries in the queue, overwriting the Driver's state data 
    566575# accordingly. 
    567576# 
    568577# The external updateState() call adds new driver state into the queue, 
    569578# one entry per call.  The internal _update() function merges this 
    570 # driver state with the currently running driver, one merge 
    571 # operation per call.  In order words, a single call to _update() 
    572 # may *NOT* empty the corresponding Driver update queue completely 
    573 # -- only one entry within the queue will be dequeued per _update() 
     579# driver state with the currently running driver, merging everything 
     580# queued per call.  In order words, a single call to _update() 
     581# *WILL* empty the corresponding Driver update queue completely 
     582# -- all entries within the queue will be dequeued per _update() 
    574583# call made. 
    575584# 
     
    587596    my $queue = $driverUpdateQueues{$driverName}; 
    588597 
     598    # XXX: One possible DoS condition here; what if 
     599    # the manager keeps feeding updates to the Agent 
     600    # before the Agent has a chance to do any work? 
     601     
    589602    # If we have data in our driver specific queue... 
    590     if ($queue->pending) { 
     603    while ($queue->pending) { 
    591604 
    592605        # Update our driver state with the first entry 
     
    663676        # Read the TID. 
    664677        $tid = $data->{$driverName}->{'thread_id'}; 
     678 
     679# XXX: Delete this, eventually. 
     680print "Checking TID = " . Dumper($tid) . "\n"; 
     681if (defined(threads->object($tid))) { 
     682    print "Thread defined.\n"; 
     683    if (threads->object($tid)->is_running()) { 
     684        print "Thread is running.\n"; 
     685    } else { 
     686        print "Thread is NOT running.\n"; 
     687    } 
     688} else { 
     689    print "Thread NOT defined.\n"; 
     690} 
    665691         
    666692        # Sanity check: Return false, if we already have a 
     
    674700 
    675701            return 0; 
     702        } else { 
     703            # XXX: Remove this, eventually. 
     704            print "Creating a new run() child thread...\n"; 
    676705        } 
    677706 
     
    693722        _unlock($data); 
    694723 
    695         # TODO: Clean up this comment block. 
    696         # This function should do the following: 
    697         # - Initialize all drivers with starting state. 
    698         # - "Drive" each driver, one-by-one. 
    699         # - Collect any integrity violations found, with offending 
    700         #   state information. 
    701         # 
    702         # Notes: 
    703         # This function will eventually sit in a sub-thread, allowing the parent 
    704         # thread to return without any delay.  It is expected that the Manager 
    705         # would then subsequently call a getStatus() operation, in order to 
    706         # then poll for any new violations found. 
    707         # 
    708         # TODO: We need to create a fault reporting mechanism, in order 
    709         # to properly deal with exceptions/faults that occur within this 
    710         # thread. 
    711         $thread = async { 
    712             threads->yield(); 
    713      
    714             # Trap all faults that may occur from these asynchronous operations. 
    715             eval { 
    716  
    717                 ################################### 
    718                 ### Driver Initialization Phase ### 
    719                 ################################### 
    720  
    721                 # Initially set local integrity object to undef. 
    722                 my $integrity = undef; 
    723                  
    724                 # Initially set all driver objects to undef.  
    725                 my $driver = undef; 
    726      
    727                 # Acquire lock on stored driver state. 
    728                 $data = _lock(); 
    729  
    730                 if ($PERFORM_INTEGRITY_CHECKS) { 
    731                     # XXX: WARNING - The $integrityState object data is NOT thread-safe 
    732                     # (since it relies on external data stored on the file system). 
    733                     # As such, do NOT try to call integrity checks on multiple, simultaneous 
    734                     # asynchronous threaded drivers. 
    735                     #$integrity = thaw($integrityState); 
    736                     # Perform initial integrity baseline check. 
    737                     #print "Initializing Integrity Check...\n"; 
    738                     # TODO: Initialize Integrity Checks 
    739                     $integrity = HoneyClient::Agent::Integrity->new(); 
    740                 } 
    741  
    742                 # Now, initialize each driver object.  
    743                 # Figure out which $driver object to use... 
    744                 my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
    745                  
    746                 if (!defined($data->{$driverName}->{'state'})) { 
    747      
    748                     # If the driver state is undefined, then 
    749                     # create a new state object. 
    750                     $driver = $driverClass->new(); 
    751  
    752                 } else { 
    753                     # Then the driver state object is already defined, 
    754                     # so go ahead and reuse it. 
    755                     $driver = $driverClass->new( 
    756                         %{$data->{$driverName}->{'state'}},  
    757                     ); 
    758                 } 
    759  
    760                 # Next, we make sure we have no updates, before we update 
    761                 # the corresponding shared memory version. 
    762                 $driver = _update($driver); 
    763  
    764                 # Once we've initialized the object, be sure to update 
    765                 # the corresponding shared memory version.  We do this 
    766                 # one time before the loop starts, in case we end up 
    767                 # finishing before we drove anywhere. 
    768                  
    769                 # Copy object data to shared memory. 
    770                 $data->{$driverName}->{'next'} = $driver->next(); 
    771                 $data->{$driverName}->{'status'} = $driver->status(); 
    772                 $data->{$driverName}->{'status'}->{'is_compromised'} = 0; 
    773                 $data->{$driverName}->{'state'} = $driver; 
    774  
    775                 if ($driver->isFinished()) { 
    776                     # Thread is about to finish, set the ID back to undef. 
    777                     # This looks ugly, but setting it this early avoids the 
    778                     # potential race condition of when the run() thread is finished 
    779                     # and when updateState() checks for $driverData->{$driverName}->{'thread_id'} 
    780                     # to be set to undef. 
    781                     $data->{$driverName}->{'thread_id'} = undef; 
    782                 } 
    783  
    784                 # Release lock on stored driver state. 
    785                 _unlock($data); 
    786                  
    787                 ################################### 
    788                 ### Driver Running Phase        ### 
    789                 ################################### 
    790  
    791                 # Boolean to indicate that the driver is about to transition 
    792                 # to a new set of targets upon the next drive() operation. 
    793                 my $driverTargetsChanged = 0; 
    794  
    795                 while (!$driver->isFinished() && !$driverTargetsChanged) { 
    796                     # XXX: Debug.  Remove this. 
    797                     # We assume $driver->next() returns defined data. 
    798                     foreach my $resource (keys %{$driver->next()->{resources}}) { 
    799                         print "Using Resource: " . $resource . "\n"; 
    800                     } 
    801  
    802                     # Drive the driver for one step. 
    803                     # If the operation fails, then an exception will be generated. 
    804                     $driver->drive(); 
    805     
    806                     # Acquire lock on stored driver state. 
    807                     $data = _lock(); 
    808                      
    809                     # Check for any additional external driver updates. 
    810                     $driver = _update($driver); 
    811  
    812                     # Check to see if our driver's targets have changed. 
    813                     $driverTargetsChanged = not(Compare($data->{$driverName}->{'next'}->{'targets'}, $driver->next()->{'targets'})); 
    814                     # XXX: Delete this, eventually. 
    815                     if ($driverTargetsChanged) { 
    816                         print "Driver targets have changed.\n"; 
    817                         #$Data::Dumper::Terse = 0; 
    818                         #$Data::Dumper::Indent = 1; 
    819                         #print "Current: " . Dumper($data->{$driverName}->{'next'}->{'targets'}) . "\n"; 
    820                         #print "Next: " . Dumper($driver->next()->{'targets'}) . "\n"; 
    821                     } 
    822  
    823                     # Copy object data to shared memory. 
    824                     $data->{$driverName}->{'next'} = $driver->next(); 
    825                     $data->{$driverName}->{'status'} = $driver->status(); 
    826                     $data->{$driverName}->{'status'}->{'is_compromised'} = 0; 
    827                     $data->{$driverName}->{'state'} = $driver; 
    828  
    829                     if ($driver->isFinished() or $driverTargetsChanged) { 
    830                         # Thread is about to finish, set the ID back to undef. 
    831                         # This looks ugly, but setting it this early avoids the 
    832                         # potential race condition of when the run() thread is finished 
    833                         # and when updateState() checks for $driverData->{$driverName}->{'thread_id'} 
    834                         # to be set to undef. 
    835                         $data->{$driverName}->{'thread_id'} = undef; 
    836                     } 
    837  
    838                     # Release lock on stored driver state. 
    839                     _unlock($data); 
    840                 } 
    841                  
    842                 # Acquire lock on stored driver state. 
    843                 $data = _lock(); 
    844                  
    845                 # TODO: Perform Integrity Check 
    846                 if (defined($integrity)) { 
    847                     # For now, we update a scalar called 'is_compromised' within 
    848                     # the $data->{$driverName}->{'status'} sub-hashtable. 
    849                     print "Performing Integrity Checks...\n"; 
    850                     my $changes = $integrity->check(); 
    851                     if (scalar(@{$changes->{registry}}) ||  
    852                         scalar(@{$changes->{filesystem}})) { 
    853                         print "Integrity Check: FAILED\n"; 
    854                         $data->{$driverName}->{'status'}->{'is_compromised'} = 1; 
    855                     } else { 
    856                         print "Integrity Check: PASSED\n"; 
    857                     } 
    858                 } 
    859  
    860                 # Release lock on stored driver state. 
    861                 _unlock($data); 
    862  
    863                 # XXX: Debugging, remove eventually.  
    864                 print "Exiting run() thread.\n"; 
    865                 #print Dumper($driver); 
    866                 # Verbose debugging: 
    867                 #print Dumper($driver->status()); 
    868                 # Short-hand debugging: 
    869                 #my $status = $driver->status(); 
    870                 #print "R(" . $status->{relative_links_remaining} . ") | [ " . 
    871                 #      "V(" . $status->{links_remaining} . ") + ". 
    872                 #      "P(" . $status->{links_processed} . ") = " . 
    873                 #      "T(" . $status->{links_total} . ") ] " . 
    874                 #      "| (" . $status->{percent_complete} . ")\n"; 
    875             }; 
    876      
    877             ################################### 
    878             ### Driver Cleanup Phase        ### 
    879             ################################### 
    880             
    881             # Check to see if any errors occurred within the thread. 
    882             # Queue any faults found, to transmit back to the next SOAP 
    883             # caller.  
    884             if ($@) { 
    885                 # Release any pending locks, to avoid deadlocks. 
    886                 _unlock(); 
    887  
    888                 # Acquire lock on stored driver state. 
    889                 $data = _lock(); 
    890                   
    891                 # Make sure we update our state to reflect ourself dying. 
    892                 $data->{$driverName}->{'thread_id'} = undef; 
    893  
    894                 # Release lock on stored driver state. 
    895                 _unlock($data); 
    896      
    897                 # TODO: Do proper fault queuing. 
    898                 print "FAULT: " . $@ . "\n"; 
    899             } 
    900  
    901             threads->detach(); # XXX: Test this. 
    902             return; 
    903         }; 
     724        $thread = threads->create(\&worker, 
     725                                  { 
     726                                    'driver_name' => $driverName, 
     727                                    'integrity'   => $integrityData, 
     728                                  } 
     729                                 ); 
    904730             
    905731        # Acquire data lock. 
     
    907733             
    908734        # Set the valid thread ID. 
     735        $data->{$driverName}->{'thread_id'} = $thread->tid(); 
    909736        if ($thread->is_running()) { 
    910             $data->{$driverName}->{'thread_id'} = $thread->tid(); 
     737            # XXX: Debugging, remove eventually.  
     738            print "Thread ID = " . $thread->tid() . "\n"; 
    911739        } else { 
    912             $data->{$driverName}->{'thread_id'} = undef; 
     740            # XXX: Debugging, remove eventually.  
     741            print "Thread ID = " . $thread->tid() . " (NOT RUNNING)\n"; 
    913742        } 
    914743 
     
    916745        _unlock($data); 
    917746    } 
     747 
     748    # XXX: Debugging, remove eventually.  
     749    print "Run thread initialized.\n"; 
    918750 
    919751    # At this point, the driver thread is initialized and running, 
    920752    # return true. 
    921753    return 1; 
     754} 
     755 
     756# TODO: Clean up this comment block. 
     757# This function should do the following: 
     758# - Initialize all drivers with starting state. 
     759# - "Drive" each driver, one-by-one. 
     760# - Collect any integrity violations found, with offending 
     761#   state information. 
     762# 
     763# Notes: 
     764# This function will eventually sit in a sub-thread, allowing the parent 
     765# thread to return without any delay.  It is expected that the Manager 
     766# would then subsequently call a getStatus() operation, in order to 
     767# then poll for any new violations found. 
     768# 
     769# TODO: We need to create a fault reporting mechanism, in order 
     770# to properly deal with exceptions/faults that occur within this 
     771# thread. 
     772sub worker { 
     773 
     774    # Extract arguments. 
     775    my $args = shift; 
     776    my $driverName = $args->{'driver_name'}; 
     777    my $integrity  = $args->{'integrity'}; 
     778 
     779    # Temporary variable, used to hold thawed driver data. 
     780    my $data = undef; 
     781 
     782    # Yield processing to parent thread. 
     783    threads->yield(); 
     784 
     785    # Trap all faults that may occur from these asynchronous operations. 
     786    eval { 
     787 
     788        ################################### 
     789        ### Driver Initialization Phase ### 
     790        ################################### 
     791 
     792        # Initially set all driver objects to undef.  
     793        my $driver = undef; 
     794     
     795        # Acquire lock on stored driver state. 
     796        $data = _lock(); 
     797 
     798        # Now, initialize each driver object.  
     799        # Figure out which $driver object to use... 
     800        my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
     801 
     802        if (!defined($data->{$driverName}->{'state'})) { 
     803     
     804            # If the driver state is undefined, then 
     805            # create a new state object. 
     806            $driver = $driverClass->new(); 
     807 
     808        } else { 
     809            # Then the driver state object is already defined, 
     810            # so go ahead and reuse it. 
     811            $driver = $driverClass->new( 
     812                        %{$data->{$driverName}->{'state'}},  
     813            ); 
     814        } 
     815 
     816        # Next, we make sure we have no updates, before we update 
     817        # the corresponding shared memory version. 
     818        $driver = _update($driver); 
     819 
     820        # Once we've initialized the object, be sure to update 
     821        # the corresponding shared memory version.  We do this 
     822        # one time before the loop starts, in case we end up 
     823        # finishing before we drove anywhere. 
     824                 
     825        # Copy object data to shared memory. 
     826        $data->{$driverName}->{'next'} = $driver->next(); 
     827        $data->{$driverName}->{'status'} = $driver->status(); 
     828        $data->{$driverName}->{'status'}->{'is_compromised'} = 0; 
     829        $data->{$driverName}->{'status'}->{'is_running'} = 1; 
     830        $data->{$driverName}->{'state'} = $driver; 
     831 
     832        # Release lock on stored driver state. 
     833        _unlock($data); 
     834                 
     835        ################################### 
     836        ### Driver Running Phase        ### 
     837        ################################### 
     838 
     839        # Boolean to indicate that the driver is about to transition 
     840        # to a new set of targets upon the next drive() operation. 
     841        my $driverTargetsChanged = 0; 
     842 
     843        while (!$driver->isFinished() && !$driverTargetsChanged) { 
     844            # XXX: Debug.  Remove this. 
     845            # We assume $driver->next() returns defined data. 
     846            foreach my $resource (keys %{$driver->next()->{resources}}) { 
     847                $LOG->info("Driving To Resource: " . $resource); 
     848            } 
     849 
     850            # Drive the driver for one step. 
     851            # If the operation fails, then an exception will be generated. 
     852            $driver->drive(); 
     853    
     854            # Acquire lock on stored driver state. 
     855            $data = _lock(); 
     856                     
     857            # Check for any additional external driver updates. 
     858            $driver = _update($driver); 
     859 
     860            # Check to see if our driver's targets have changed. 
     861            $driverTargetsChanged = not(Compare($data->{$driverName}->{'next'}->{'targets'}, $driver->next()->{'targets'})); 
     862            # XXX: Delete this, eventually. 
     863            if ($driverTargetsChanged) { 
     864                $LOG->info("Driver targets have changed."); 
     865                #$Data::Dumper::Terse = 0; 
     866                #$Data::Dumper::Indent = 1; 
     867                #print "Current: " . Dumper($data->{$driverName}->{'next'}->{'targets'}) . "\n"; 
     868                #print "Next: " . Dumper($driver->next()->{'targets'}) . "\n"; 
     869            } 
     870 
     871            # Copy object data to shared memory. 
     872            $data->{$driverName}->{'next'} = $driver->next(); 
     873            $data->{$driverName}->{'status'} = $driver->status(); 
     874            $data->{$driverName}->{'status'}->{'is_compromised'} = 0; 
     875            $data->{$driverName}->{'status'}->{'is_running'} = 1; 
     876            $data->{$driverName}->{'state'} = $driver; 
     877 
     878            # Release lock on stored driver state. 
     879            _unlock($data); 
     880        } 
     881                 
     882        # TODO: Perform Integrity Check 
     883        my $isCompromised = 0; 
     884        if (defined($integrity)) { 
     885            # For now, we update a scalar called 'is_compromised' within 
     886            # the $data->{$driverName}->{'status'} sub-hashtable. 
     887            $LOG->info("Performing Integrity Checks."); 
     888            my $changes = $integrity->check(); 
     889            if (scalar(@{$changes->{registry}}) ||  
     890                scalar(@{$changes->{filesystem}})) { 
     891                $LOG->warn("Integrity Check: FAILED"); 
     892                $isCompromised = 1; 
     893            } else { 
     894                $LOG->info("Integrity Check: PASSED"); 
     895            } 
     896        } 
     897        # Release our copy of the integrity object, but do not destroy  
     898        # any internal references. 
     899        $integrity = undef; 
     900 
     901        # Update driver state one last time, before exiting. 
     902                 
     903        # Acquire lock on stored driver state. 
     904        $data = _lock(); 
     905                     
     906        # Check for any additional external driver updates. 
     907        $driver = _update($driver); 
     908 
     909        # Copy object data to shared memory. 
     910        $data->{$driverName}->{'next'} = $driver->next(); 
     911        $data->{$driverName}->{'status'} = $driver->status(); 
     912        $data->{$driverName}->{'status'}->{'is_compromised'} = $isCompromised; 
     913        $data->{$driverName}->{'status'}->{'is_running'} = 0; 
     914        $data->{$driverName}->{'state'} = $driver; 
     915  
     916        # Release lock on stored driver state. 
     917        _unlock($data); 
     918    }; 
     919     
     920    ################################### 
     921    ### Driver Cleanup Phase        ### 
     922    ################################### 
     923            
     924    # Check to see if any errors occurred within the thread. 
     925    # Queue any faults found, to transmit back to the next SOAP 
     926    # caller.  
     927    if ($@) { 
     928        # Release any pending locks, to avoid deadlocks. 
     929        _unlock(); 
     930 
     931        # TODO: Do proper fault queuing. 
     932        $LOG->error("FAULT: " . $@); 
     933    } 
     934 
     935    # XXX: Debugging, remove eventually.  
     936    print "About to return out of child thread.\n"; 
     937    if (!threads->is_detached()) { 
     938        threads->detach(); 
     939    } 
     940    threads->exit(); 
    922941} 
    923942 
     
    10101029            # Figure out which $driver object to use... 
    10111030            my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
    1012                  
     1031 
    10131032            if (!defined($data->{$driverName}->{'state'})) { 
    10141033     
     
    10361055            # would get overwritten, during the next updateState() call. 
    10371056            $data->{$driverName}->{'status'}->{'is_compromised'} = 0; 
     1057            $data->{$driverName}->{'status'}->{'is_running'} = 0; 
    10381058            $data->{$driverName}->{'state'} = $driver; 
    10391059 
     
    11191139        if ($proc->{Name} eq $processName) { 
    11201140            # TODO: Should this statement be in here? 
     1141            $LOG->warn("Killing Process ID: " . $proc->{ProcessId}); 
    11211142            Carp::carp "Killing Process ID: " . $proc->{ProcessId} . "\n"; 
    11221143            Win32::Process::KillProcess($proc->{ProcessId}, 0); 
  • honeyclient/trunk/lib/HoneyClient/Agent/Driver/Browser.pm

    r357 r409  
    234234# TODO: Need unit testing. 
    235235use URI::URL; 
     236 
     237# Include Logging Library 
     238use Log::Log4perl qw(:easy); 
     239 
     240# The global logging object. 
     241our $LOG = get_logger(); 
    236242 
    237243=pod 
     
    10251031    if ($self->_remaining_number_of_relative_links_to_visit == 1) { 
    10261032 
    1027         # XXX: Delete this, eventually. 
    1028         print "Resetting relative links to visit counter.\n"
     1033        # XXX: Do we need this message in here? 
     1034        $LOG->info("Resetting relative links to visit counter.")
    10291035 
    10301036        # The counter has reached one, so drop all other relative links 
  • honeyclient/trunk/lib/HoneyClient/Agent/Integrity.pm

    r328 r409  
    535535 
    536536    # Log resolved arguments. 
    537     # Make Dumper format more terse. 
    538     $Data::Dumper::Terse = 1; 
    539     $Data::Dumper::Indent = 0; 
    540     $LOG->debug(Dumper(\%args)); 
     537    $LOG->debug(sub { 
     538        # Make Dumper format more terse. 
     539        $Data::Dumper::Terse = 1; 
     540        $Data::Dumper::Indent = 0; 
     541        Dumper(\%args); 
     542    }); 
    541543 
    542544    my $changes = { 
     
    568570    if (defined($self->{'_registry'})) { 
    569571        $self->{'_registry'}->closeFiles(); 
     572    } 
     573} 
     574 
     575# TODO: Comment this. 
     576sub destroy { 
     577    my $self = shift; 
     578 
     579    if (defined($self->{'_registry'})) { 
     580        $self->{'_registry'}->destroy(); 
    570581    } 
    571582} 
  • honeyclient/trunk/lib/HoneyClient/Agent/Integrity/Filesystem.pm

    • Property svn:executable deleted
    r328 r409  
    10081008 
    10091009    # Log resolved arguments. 
    1010     # Make Dumper format more terse. 
    1011     $Data::Dumper::Terse = 1; 
    1012     $Data::Dumper::Indent = 0; 
    1013     $LOG->debug(Dumper(\%args)); 
     1010    $LOG->debug(sub { 
     1011        # Make Dumper format more terse. 
     1012        $Data::Dumper::Terse = 1; 
     1013        $Data::Dumper::Indent = 0; 
     1014        Dumper(\%args); 
     1015    }); 
    10141016 
    10151017    # Analyze the filesystem. 
  • honeyclient/trunk/lib/HoneyClient/Agent/Integrity/Registry.pm

    r328 r409  
    403403 
    404404# Base destructor function. 
    405 # Since none of our state data ever contains circular references, 
    406 # we can simply leave the garbage collection up to Perl's internal 
    407 # mechanism. 
    408 sub DESTROY { 
     405sub destroy { 
     406    # Extract arguments. 
    409407    my $self = shift; 
     408 
     409    # Delete any temporary files created by the baseline 
     410    # and checkpoint parsers. 
     411    $self->_cleanupParsers($self->{_baseline_parsers}); 
     412    $self->_cleanupParsers($self->{_checkpoint_parsers}); 
     413} 
     414 
     415# Helper function, designed to cleanup temporary files created 
     416# by specified parsers. 
     417# 
     418# Inputs: HoneyClient::Agent::Integrity::Registry object, 
     419#         the hashtable collection of specified parsers 
     420# 
     421# Outputs: None. 
     422sub _cleanupParsers { 
     423    # Extract arguments. 
     424    my ($self, $parser_collection) = @_; 
    410425 
    411426    # Delete any temporary files created. 
     
    413428    my $fname = undef; 
    414429    foreach my $hive (@{$self->{hives_to_check}}) { 
    415         $parser = $self->{_baseline_parsers}->{$hive}; 
     430        $parser = $parser_collection->{$hive}; 
    416431        if (defined($parser)) { 
    417432            $fname = $parser->getFilename(); 
    418433            if (defined($fname) && (-f $fname)) { 
    419                 $LOG->debug("Deleting baseline of hive '" . $hive . "' in '" . 
     434                $LOG->debug("Deleting temporary '" . $hive . "' hive data in '" . 
    420435                            $fname . "'."); 
    421436                if (!unlink($fname)) { 
     
    424439                } 
    425440            } 
    426             delete($self->{_baseline_parsers}->{$hive}); 
    427         } 
    428         $parser = $self->{_checkpoint_parsers}->{$hive}; 
    429         if (defined($parser)) { 
    430             $fname = $parser->getFilename(); 
    431             if (defined($fname) && (-f $fname)) { 
    432                 $LOG->debug("Deleting checkpoint of hive '" . $hive . "' in '" . 
    433                             $fname . "'."); 
    434                 if (!unlink($fname)) { 
    435                     $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    436                     Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    437                 } 
    438             } 
    439             delete($self->{_checkpoint_parsers}->{$hive}); 
     441            delete($parser_collection->{$hive}); 
    440442        } 
    441443    } 
     
    457459    my $fname_tmp = undef; 
    458460    foreach my $hive (@{$self->{hives_to_check}}) { 
    459         $fname = tmpnam();  
     461        # Check to see if we can reuse temporary files from 
     462        # past checkpoint operations. 
     463        if (exists($parser_collection->{$hive}) && 
     464            defined($parser_collection->{$hive})) { 
     465            $parser = $parser_collection->{$hive}; 
     466            $fname = $parser->getFilename(); 
     467        } else { 
     468            $fname = tmpnam(); 
     469        } 
     470 
    460471        $fname_tmp = tmpnam();  
    461472        $LOG->debug("Storing snapshot of hive '" . $hive . "' into '" . $fname . "'."); 
     
    11721183 
    11731184    # Log resolved arguments. 
    1174     # Make Dumper format more terse. 
    1175     $Data::Dumper::Terse = 1; 
    1176     $Data::Dumper::Indent = 0; 
    1177     $LOG->debug(Dumper(\%args)); 
     1185    $LOG->debug(sub { 
     1186        # Make Dumper format more terse. 
     1187        $Data::Dumper::Terse = 1; 
     1188        $Data::Dumper::Indent = 0; 
     1189        Dumper(\%args); 
     1190    }); 
    11781191 
    11791192    # Check to see if the class name is inherited or defined. 
     
    13901403 
    13911404    # Log resolved arguments. 
    1392     # Make Dumper format more terse. 
    1393     $Data::Dumper::Terse = 1; 
    1394     $Data::Dumper::Indent = 0; 
    1395     $