Changeset 1434

Show
Ignore:
Timestamp:
04/02/08 22:47:32 (5 months ago)
Author:
kindlund
Message:

Added proper documentation and argument/parameter encoding.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Agent.pm

    r1431 r1434  
    4444=head2 CREATING THE SOAP SERVER 
    4545 
    46 # XXX: Fill this in. 
     46  use HoneyClient::Agent; 
     47 
     48  # Handle SOAP requests on the default address:port. 
     49  my $URL = HoneyClient::Agent->init(); 
     50 
     51  # Handle SOAP requests on TCP port localhost:9090 
     52  my $URL = HoneyClient::Agent->init(address => "localhost", 
     53                                     port    => 9090); 
     54 
     55  print "Server URL: " . $URL . "\n"; 
     56 
     57  # Create a cleanup function, to execute whenever 
     58  # the SOAP server needs to be destroyed. 
     59  sub cleanup { 
     60      HoneyClient::Agent->destroy(); 
     61      exit; 
     62  } 
     63 
     64  # Install the cleanup handler, in case parent process 
     65  # dies unexpectedly. 
     66  $SIG{HUP}       = \&cleanup; 
     67  $SIG{INT}       = \&cleanup; 
     68  $SIG{QUIT}      = \&cleanup; 
     69  $SIG{ABRT}      = \&cleanup; 
     70  $SIG{PIPE}      = \&cleanup; 
     71  $SIG{TERM}      = \&cleanup; 
     72 
     73  # Catch all parent code errors, in order to perform cleanup 
     74  # on all child processes before exiting. 
     75  eval { 
     76      # Do rest of the parent processing here... 
     77  }; 
     78 
     79  # We assume you still want to still want to "die" on 
     80  # any errors found within the eval block. 
     81  if ($@) { 
     82      HoneyClient::Agent->destroy(); 
     83      die $@; 
     84  } 
     85 
     86  # Even if no errors occurred, initiate cleanup. 
     87  cleanup(); 
    4788 
    4889=head2 INTERACTING WITH THE SOAP SERVER 
    4990 
    50 # XXX: Fill this in. 
     91  use HoneyClient::Util::SOAP qw(getClientHandle); 
     92  use Data::Dumper; 
     93  use MIME::Base64 qw(encode_base64 decode_base64); 
     94  use Storable qw(thaw); 
     95  $Storable::Deparse = 1; 
     96  $Storable::Eval = 1; 
     97 
     98  # Create a new SOAP client, to talk to the HoneyClient::Agent 
     99  # module. 
     100  my $stub = getClientHandle(namespace => "HoneyClient::Agent"); 
     101  my $som; 
     102 
     103  # Drive HoneyClient::Agent::Driver::Browser::IE to a website. 
     104  $som = $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE", 
     105                      parameters  => encode_base64("http://www.mitre.org")); 
     106 
     107  # Check the result to see if any compromise was found. 
     108  # Look for the 'fingerprint' key in the resulting hastable. 
     109  print Dumper(thaw(decode_base64($som->result()))) . "\n";  
    51110 
    52111=head1 DESCRIPTION 
     
    185244use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 
    186245 
     246# Make sure HoneyClient::Agent::Integrity loads. 
     247BEGIN { use_ok('HoneyClient::Agent::Integrity') or diag("Can't load HoneyClient::Agent::Integrity package.  Check to make sure the package library is correctly listed within the path."); } 
     248require_ok('HoneyClient::Agent::Integrity'); 
     249use HoneyClient::Agent::Integrity; 
     250 
    187251# Make sure Storable loads. 
    188 BEGIN { 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."); } 
     252BEGIN { 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."); } 
    189253require_ok('Storable'); 
    190 can_ok('Storable', 'freeze'); 
    191254can_ok('Storable', 'nfreeze'); 
    192255can_ok('Storable', 'thaw'); 
    193 can_ok('Storable', 'dclone'); 
    194 use Storable qw(freeze nfreeze thaw dclone); 
     256use Storable qw(nfreeze thaw); 
    195257 
    196258# Make sure MIME::Base64 loads. 
     
    244306 
    245307# Include Integrity Library 
    246 # TODO: Include corresponding unit tests. 
    247308use HoneyClient::Agent::Integrity; 
    248309 
     
    254315 
    255316# Include Hash Serialization Utility Libraries 
    256 use Storable qw(freeze nfreeze thaw dclone); 
     317use Storable qw(nfreeze thaw); 
    257318$Storable::Deparse = 1; 
    258319$Storable::Eval = 1; 
     
    524585cycle. 
    525586 B<$params> are the optional parameters to supply to the driven 
    526 application, as arguments. 
     587application, as arguments.  If supplied, then this data MUST be base64 
     588encoded. 
    527589 B<$timeout> is an optional argument, specifying how long the Agent 
    528590should wait after executing the driven application before it performs 
     
    530592 
    531593I<Output>: 
    532  A hashtable containing the following information: 
     594 A nfreezed, base64 encoded hashtable containing the following 
     595 information: 
    533596 
    534597 { 
     
    593656 
    594657        # Verify changes. 
    595         my $changes = $som->result(); 
     658        my $changes = thaw(decode_base64($som->result())); 
    596659 
    597660        # Check to see if the drive operation completed properly.  
     
    12231286 
    12241287        # Verify changes. 
    1225         $changes = $som->result(); 
     1288        $changes = thaw(decode_base64($som->result())); 
    12261289    
    12271290        # Check to see if the drive operation completed properly.  
     
    12931356        !defined($args{'parameters'})) { 
    12941357        $args{'parameters'} = ""; 
    1295     } 
     1358    } else { 
     1359        $args{'parameters'} = decode_base64($args{'parameters'}); 
     1360    } 
     1361 
    12961362    if (!$argsExist || 
    12971363        !exists($args{'timeout'}) || 
     
    13841450    } 
    13851451  
    1386     return $ret
     1452    return encode_base64(nfreeze($ret))
    13871453} 
    13881454 
  • honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_agent.t

    r1431 r1434  
    8383use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 
    8484 
     85# Make sure HoneyClient::Agent::Integrity loads. 
     86BEGIN { use_ok('HoneyClient::Agent::Integrity') or diag("Can't load HoneyClient::Agent::Integrity package.  Check to make sure the package library is correctly listed within the path."); } 
     87require_ok('HoneyClient::Agent::Integrity'); 
     88use HoneyClient::Agent::Integrity; 
     89 
    8590# Make sure Storable loads. 
    86 BEGIN { 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."); } 
     91BEGIN { 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."); } 
    8792require_ok('Storable'); 
    88 can_ok('Storable', 'freeze'); 
    8993can_ok('Storable', 'nfreeze'); 
    9094can_ok('Storable', 'thaw'); 
    91 can_ok('Storable', 'dclone'); 
    92 use Storable qw(freeze nfreeze thaw dclone); 
     95use Storable qw(nfreeze thaw); 
    9396 
    9497# Make sure MIME::Base64 loads. 
     
    199202 
    200203        # Verify changes. 
    201         my $changes = $som->result(); 
     204        my $changes = thaw(decode_base64($som->result())); 
    202205 
    203206        # Check to see if the drive operation completed properly.  
     
    829832 
    830833        # Verify changes. 
    831         $changes = $som->result(); 
     834        $changes = thaw(decode_base64($som->result())); 
    832835    
    833836        # Check to see if the drive operation completed properly.