Changeset 1434
- Timestamp:
- 04/02/08 22:47:32 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Agent.pm
r1431 r1434 44 44 =head2 CREATING THE SOAP SERVER 45 45 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(); 47 88 48 89 =head2 INTERACTING WITH THE SOAP SERVER 49 90 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"; 51 110 52 111 =head1 DESCRIPTION … … 185 244 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 186 245 246 # Make sure HoneyClient::Agent::Integrity loads. 247 BEGIN { 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."); } 248 require_ok('HoneyClient::Agent::Integrity'); 249 use HoneyClient::Agent::Integrity; 250 187 251 # 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."); }252 BEGIN { 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."); } 189 253 require_ok('Storable'); 190 can_ok('Storable', 'freeze');191 254 can_ok('Storable', 'nfreeze'); 192 255 can_ok('Storable', 'thaw'); 193 can_ok('Storable', 'dclone'); 194 use Storable qw(freeze nfreeze thaw dclone); 256 use Storable qw(nfreeze thaw); 195 257 196 258 # Make sure MIME::Base64 loads. … … 244 306 245 307 # Include Integrity Library 246 # TODO: Include corresponding unit tests.247 308 use HoneyClient::Agent::Integrity; 248 309 … … 254 315 255 316 # Include Hash Serialization Utility Libraries 256 use Storable qw( freeze nfreeze thaw dclone);317 use Storable qw(nfreeze thaw); 257 318 $Storable::Deparse = 1; 258 319 $Storable::Eval = 1; … … 524 585 cycle. 525 586 B<$params> are the optional parameters to supply to the driven 526 application, as arguments. 587 application, as arguments. If supplied, then this data MUST be base64 588 encoded. 527 589 B<$timeout> is an optional argument, specifying how long the Agent 528 590 should wait after executing the driven application before it performs … … 530 592 531 593 I<Output>: 532 A hashtable containing the following information: 594 A nfreezed, base64 encoded hashtable containing the following 595 information: 533 596 534 597 { … … 593 656 594 657 # Verify changes. 595 my $changes = $som->result();658 my $changes = thaw(decode_base64($som->result())); 596 659 597 660 # Check to see if the drive operation completed properly. … … 1223 1286 1224 1287 # Verify changes. 1225 $changes = $som->result();1288 $changes = thaw(decode_base64($som->result())); 1226 1289 1227 1290 # Check to see if the drive operation completed properly. … … 1293 1356 !defined($args{'parameters'})) { 1294 1357 $args{'parameters'} = ""; 1295 } 1358 } else { 1359 $args{'parameters'} = decode_base64($args{'parameters'}); 1360 } 1361 1296 1362 if (!$argsExist || 1297 1363 !exists($args{'timeout'}) || … … 1384 1450 } 1385 1451 1386 return $ret;1452 return encode_base64(nfreeze($ret)); 1387 1453 } 1388 1454 honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_agent.t
r1431 r1434 83 83 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); 84 84 85 # Make sure HoneyClient::Agent::Integrity loads. 86 BEGIN { 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."); } 87 require_ok('HoneyClient::Agent::Integrity'); 88 use HoneyClient::Agent::Integrity; 89 85 90 # 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."); }91 BEGIN { 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."); } 87 92 require_ok('Storable'); 88 can_ok('Storable', 'freeze');89 93 can_ok('Storable', 'nfreeze'); 90 94 can_ok('Storable', 'thaw'); 91 can_ok('Storable', 'dclone'); 92 use Storable qw(freeze nfreeze thaw dclone); 95 use Storable qw(nfreeze thaw); 93 96 94 97 # Make sure MIME::Base64 loads. … … 199 202 200 203 # Verify changes. 201 my $changes = $som->result();204 my $changes = thaw(decode_base64($som->result())); 202 205 203 206 # Check to see if the drive operation completed properly. … … 829 832 830 833 # Verify changes. 831 $changes = $som->result();834 $changes = thaw(decode_base64($som->result())); 832 835 833 836 # Check to see if the drive operation completed properly.
