Changeset 1450

Show
Ignore:
Timestamp:
04/03/08 17:07:10 (3 months ago)
Author:
kindlund
Message:

Starting integration of new Agent code inside Manager code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-simpler_agent/etc/honeyclient.xml

    r1448 r1450  
    302302        <VM> 
    303303            <master_vm_config description="The full absolute path to the VM configuration file on the host system that will be used by all subsequent cloned VMs."> 
    304                 /vm/masters/Agent.Master-36/winXPPro.cfg 
     304                /vm/masters/Agent.Master-37/winXPPro.cfg 
    305305            </master_vm_config> 
    306306            <port description="The TCP port number that the SOAP server of the VM daemon will listen on for requests.  Note: This port should be unique and not already be used by other modules, services, or daemons running on the host system." default="8089"> 
  • honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Agent.pm

    r1443 r1450  
    3838=head1 VERSION 
    3939 
    40 1.02 
     40This documentation refers to HoneyClient::Agent version 1.02. 
    4141 
    4242=head1 SYNOPSIS 
  • honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Manager/Database.pm

    r1353 r1450  
    344344=head1 COPYRIGHT & LICENSE 
    345345 
    346 Copyright (C) 2008 The MITRE Corporation.  All rights reserved. 
     346Copyright (C) 2007-2008 The MITRE Corporation.  All rights reserved. 
    347347 
    348348This program is free software; you can redistribute it and/or 
  • honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Manager/VM/Clone.pm

    r1419 r1450  
    238238use HoneyClient::Manager::VM; 
    239239 
     240# Make sure HoneyClient::Manager::Database loads. 
     241BEGIN { use_ok('HoneyClient::Manager::Database') or diag("Can't load HoneyClient::Manager::Database package.  Check to make sure the package library is correctly listed within the path."); } 
     242require_ok('HoneyClient::Manager::Database'); 
     243use HoneyClient::Manager::Database; 
     244 
    240245# Make sure VMware::VmPerl loads. 
    241246BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package.  Check to make sure the package library is correctly listed within the path."); } 
     
    287292use File::Basename qw(dirname basename); 
    288293 
     294# Make sure Sys::Hostname loads. 
     295BEGIN { use_ok('Sys::Hostname') or diag("Can't load Sys::Hostname package.  Check to make sure the package library is correctly listed within the path."); } 
     296require_ok('Sys::Hostname'); 
     297use Sys::Hostname; 
     298 
     299# Make sure Sys::HostIP loads. 
     300BEGIN { use_ok('Sys::HostIP') or diag("Can't load Sys::HostIP package.  Check to make sure the package library is correctly listed within the path."); } 
     301require_ok('Sys::HostIP'); 
     302use Sys::HostIP; 
     303 
     304# Make sure DateTime::HiRes loads. 
     305BEGIN { use_ok('DateTime::HiRes') or diag("Can't load Sys::HostIP package.  Check to make sure the package library is correctly listed within the path."); } 
     306require_ok('DateTime::HiRes'); 
     307use DateTime::HiRes; 
     308 
    289309=end testing 
    290310 
     
    325345our $LOG = get_logger(); 
    326346 
     347# Use Hostname Libraries 
     348use Sys::Hostname::Long; 
     349 
     350# Use HostIP Libraries 
     351use Sys::HostIP; 
     352 
     353# Use DateTime::HiRes Libraries 
     354use DateTime::HiRes; 
     355 
    327356# The global variable, used to count the number of 
    328357# Clone objects that have been created. 
    329358our $OBJECT_COUNT : shared = -1; 
     359 
     360# Include Database Libraries 
     361use HoneyClient::Manager::Database; 
    330362 
    331363=pod 
     
    390422 
    391423The ID of the VM instance, if it is stored within the Drone database. 
     424 
     425=back 
     426 
     427=head2 status 
     428 
     429=over 4 
     430 
     431The status of the cloned VM. 
     432 
     433=back 
     434 
     435=head2 driver_name 
     436 
     437=over 4 
     438 
     439The Driver assigned to this cloned VM. 
    392440 
    393441=back 
     
    496544            $LOG->error("Unable to suspend VM (" . $self->{'config'} . ")."); 
    497545        } 
    498  
    499546    } 
    500547 
     
    593640        } 
    594641    } 
     642    $self->_changeStatus(status => "initialized"); 
    595643 
    596644    # Wait until the VM gets registered, before proceeding. 
     
    606654        } 
    607655    } 
     656    $self->_changeStatus(status => "registered"); 
    608657 
    609658    # Once registered, check if the VM is ON yet. 
     
    619668        } 
    620669    } 
     670    $self->_changeStatus(status => "running"); 
    621671 
    622672    # Now, get the VM's MAC address. 
     
    655705 
    656706        eval { 
    657             $som = $stubAgent->getStatus(); 
     707            $som = $stubAgent->getProperties(driver_name => $self->{'driver_name'}); 
    658708            $ret = $som->result(); 
    659709        }; 
     
    666716        if (!defined($ret)) { 
    667717            sleep ($self->{'_retry_period'}); 
     718        } elsif (getVar(name      => "enable", 
     719                        namespace => "HoneyClient::Manager::Database")) { 
     720            # Register the cloned VM with the Drone database. 
     721            my $dt = DateTime::HiRes->now(time_zone => "local"); 
     722     
     723            # Construct the 'Client' object. 
     724            my $client = { 
     725                cid => $self->{'name'}, 
     726                status => $self->{'status'}, 
     727                host => { 
     728                    org => getVar(name => "organization"), 
     729                    hostname => Sys::Hostname::Long::hostname_long, 
     730                    ip => Sys::HostIP->ip, 
     731                }, 
     732                os => $ret, 
     733                start => $dt->ymd('-').'T'.$dt->hms(':'), 
     734            }; 
     735            $self->{'database_id'} = HoneyClient::Manager::Database::insert_client($client); 
    668736        } 
     737    } 
     738 
     739    return $self; 
     740} 
     741 
     742# TODO: Comment this. 
     743# XXX: Should this be made public? 
     744sub _changeStatus { 
     745 
     746    # Extract arguments. 
     747    my ($self, %args) = @_; 
     748 
     749    # Sanity check: Make sure we've been fed an object. 
     750    unless (ref($self)) { 
     751        $LOG->error("Error: Function must be called in reference to a " . 
     752                    __PACKAGE__ . "->new() object!"); 
     753        Carp::croak "Error: Function must be called in reference to a " . 
     754                    __PACKAGE__ . "->new() object!"; 
     755    } 
     756 
     757    # Sanity check.  Make sure we get a valid argument. 
     758    my $argsExist = scalar(%args); 
     759    if (!$argsExist ||  
     760        !exists($args{'status'}) || 
     761        !defined($args{'status'})) { 
     762 
     763        # Croak if no valid argument is supplied. 
     764        $LOG->error("Error: No status argument supplied."); 
     765        Carp::croak "Error: No status argument supplied."; 
     766    } 
     767 
     768    # Don't change the status field for any VM that has been marked 
     769    # as suspicious or compromised. 
     770    if (($self->{'status'} ne "suspicious") && 
     771        ($self->{'status'} ne "compromised")) { 
     772        $self->{'status'} = $args{'status'}; 
    669773    } 
    670774 
     
    847951        # A variable containing the database identifier, if any is specified. 
    848952        database_id => undef, 
    849      
     953    
     954        # A variable reflecting the current status of the cloned VM. 
     955        status => "uninitialized", 
     956 
     957        # A variable reflected the driver assigned to this cloned VM. 
     958        driver_name => getVar(name      => "default_driver", 
     959                              namespace => "HoneyClient::Agent"); 
     960 
    850961        # A SOAP handle to the VM manager daemon.  (This internal variable 
    851962        # should never be modified externally.)