root/honeyclient/tags/exp/DOWN1-stephenson-link_scoring/lib/HoneyClient/Manager.pm

Revision 153, 24.4 kB (checked in by kindlund, 2 years ago)

Merged trunk changes back into exp branch, in order to prepare for final merge back into trunk.

  • Property svn:keywords set to Id "$file"
Line 
1 #######################################################################
2 # Created on:  May 11, 2006
3 # Package:     HoneyClient::Manager
4 # File:        Manager.pm
5 # Description: Central library used for manager-based operations.
6 #
7 # CVS: $Id$
8 #
9 # @author knwang, ttruong, jdurick, kindlund
10 #
11 # Copyright (C) 2006 The MITRE Corporation.  All rights reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation, using version 2
16 # of the License.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301, USA.
27 #
28 #######################################################################
29
30 =pod
31
32 =head1 NAME
33
34 # XXX: Fill this in.
35
36 =head1 VERSION
37
38 This documentation refers to HoneyClient::Manager version 0.92.
39
40 =head1 SYNOPSIS
41
42 =head2 CREATING THE SOAP SERVER
43
44 # XXX: Fill this in.
45
46 =head2 INTERACTING WITH THE SOAP SERVER
47
48 # XXX: Fill this in.
49
50 =head1 DESCRIPTION
51
52 # XXX: Fill this in.
53
54 =cut
55
56 package HoneyClient::Manager;
57
58 # XXX: Disabled version check, Honeywall does not have Perl v5.8 installed.
59 #use 5.008006;
60 use strict;
61 use warnings FATAL => 'all';
62 use Config;
63 use Carp ();
64
65 #######################################################################
66 # Module Initialization                                               #
67 #######################################################################
68
69 BEGIN {
70     # Defines which functions can be called externally.
71     require Exporter;
72     our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION, @DRIVERS);
73
74     # Set our package version.
75     $VERSION = 0.92;
76
77     @ISA = qw(Exporter);
78
79     # Symbols to export on request
80     @EXPORT = qw(init destroy);
81
82     # Items to export into callers namespace by default. Note: do not export
83     # names by default without a very good reason. Use EXPORT_OK instead.
84     # Do not simply export all your public functions/methods/constants.
85
86     # This allows declaration use HoneyClient::Manager ':all';
87     # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
88     # will save memory.
89
90     %EXPORT_TAGS = (
91         'all' => [ qw(init destroy) ],
92     );
93
94     # Symbols to autoexport (:DEFAULT tag)
95     @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
96
97     # Check to see if ithreads are compiled into this version of Perl.
98     $Config{useithreads} or Carp::croak "Error: Recompile Perl with ithread support, in order to use this module.\n";
99
100     $SIG{PIPE} = 'IGNORE'; # Do not exit on broken pipes.
101 }
102 our (@EXPORT_OK, $VERSION);
103
104 =pod
105
106 =begin testing
107
108 # Make sure the module loads properly, with the exportable
109 # functions shared.
110 BEGIN { use_ok('HoneyClient::Manager', qw(init destroy)) or diag("Can't load HoneyClient::Manager package.  Check to make sure the package library is correctly listed within the path."); }
111 require_ok('HoneyClient::Manager');
112 can_ok('HoneyClient::Manager', 'init');
113 can_ok('HoneyClient::Manager', 'destroy');
114 use HoneyClient::Manager qw(init destroy);
115
116 # Make sure HoneyClient::Util::SOAP loads.
117 BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getServerHandle getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package.  Check to make sure the package library is correctly listed within the path."); }
118 require_ok('HoneyClient::Util::SOAP');
119 can_ok('HoneyClient::Util::SOAP', 'getServerHandle');
120 can_ok('HoneyClient::Util::SOAP', 'getClientHandle');
121 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle);
122
123 # Make sure HoneyClient::Util::Config loads.
124 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path."); }
125 require_ok('HoneyClient::Util::Config');
126 can_ok('HoneyClient::Util::Config', 'getVar');
127 use HoneyClient::Util::Config qw(getVar);
128
129 # Make sure Storable loads.
130 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."); }
131 require_ok('Storable');
132 can_ok('Storable', 'nfreeze');
133 can_ok('Storable', 'thaw');
134 use Storable qw(nfreeze thaw);
135
136 # Make sure MIME::Base64 loads.
137 BEGIN { use_ok('MIME::Base64', qw(encode_base64 decode_base64)) or diag("Can't load MIME::Base64 package.  Check to make sure the package library is correctly listed within the path."); }
138 require_ok('MIME::Base64');
139 can_ok('MIME::Base64', 'encode_base64');
140 can_ok('MIME::Base64', 'decode_base64');
141 use MIME::Base64 qw(encode_base64 decode_base64);
142
143 =end testing
144
145 =cut
146
147 #######################################################################
148
149 # Include the SOAP Utility Library
150 use HoneyClient::Util::SOAP qw(getClientHandle getServerHandle);
151
152 # Include Thread Libraries
153 use threads;
154 use threads::shared;
155 use Thread::Semaphore;
156 use Thread::Queue;
157
158 # Include utility access to global configuration.
159 use HoneyClient::Util::Config qw(getVar);
160
161 # Include the VM Utility Library
162 # TODO: Include unit tests.
163 use HoneyClient::Manager::VM qw();
164
165 # XXX: Remove this, eventually.
166 use Data::Dumper;
167
168 # Make Dumper format more verbose.
169 $Data::Dumper::Terse = 0;
170 $Data::Dumper::Indent = 2;
171
172 # Include Hash Serialization Utility Libraries
173 use Storable qw(nfreeze thaw);
174
175 # Include Base64 Libraries
176 use MIME::Base64 qw(encode_base64 decode_base64);
177
178 # Include FW Utility Library
179 # TODO: Include unit tests.
180 use HoneyClient::Manager::FW;
181
182 # Include Hash Serialization Utility Libraries
183 # TODO: Include unit tests.
184 use Storable qw(nfreeze thaw);
185
186 # Include VmPerl Constants.
187 # TODO: Include unit tests.
188 use VMware::VmPerl qw(VM_EXECUTION_STATE_ON
189                       VM_EXECUTION_STATE_OFF
190                       VM_EXECUTION_STATE_STUCK
191                       VM_EXECUTION_STATE_SUSPENDED);
192
193 # TODO: Include unit tests.
194 use IO::File;
195
196 # Complete URL of SOAP server, when initialized.
197 our $URL_BASE       : shared = undef;
198 our $URL            : shared = undef;
199
200 # The process ID of the SOAP server daemon, once created.
201 our $DAEMON_PID     : shared = undef;
202
203 # XXX: These will be migrated somewhere else, eventually.
204 our $vmStateTable = { };
205 our $vmCloneConfig      = undef;
206 our $stubVM             = undef;
207 our $stubAgent          = undef;
208 our $stubFW             = undef;
209
210 # This is a temporary, shared variable, used to print out the
211 # state of the agent, when _cleanup() occurs.
212 # XXX: This variable and all reference to it will be deleted,
213 # eventually.
214 our $globalAgentState   = undef;
215
216 # This static variable may contain a filename that the Manager
217 # would use to dump its entire state information, upon termination.
218 # XXX: May want to change this format/usage, eventually.
219 our $STATE_FILE = getVar(name => "manager_state");
220
221 #######################################################################
222 # Daemon Initialization / Destruction                                 #
223 #######################################################################
224
225 =pod
226
227 =head1 EXPORTED FUNCTIONS
228
229 The following init() and destroy() functions are the only direct
230 calls required to startup and shutdown the SOAP server.
231
232 All other interactions with this daemon should be performed as
233 C<SOAP::Lite> function calls, in order to ensure consistency across
234 client sessions.  See the L<"EXTERNAL SOAP FUNCTIONS"> section, for
235 more details.
236
237 =head2 HoneyClient::Manager->init()
238
239 =over 4
240
241 Starts a new SOAP server, within a child process.
242
243 I<Inputs>:
244
245 # XXX: Finish this.
246
247 I<Output>:
248
249 # XXX: Finish this.
250
251 =back
252
253 =begin testing
254
255 # XXX: Test init() method.
256
257 =end testing
258
259 =cut
260
261 sub init {
262     # Extract arguments.
263     # Hash-based arguments are used, since HoneyClient::Util::SOAP is unable to handle
264     # hash references directly.  Thus, flat hashtables are used throughout the code
265     # for consistency.
266     my ($class, %args) = @_;
267    
268     # XXX: Finish this.
269 }
270
271 =pod
272
273 =head2 HoneyClient::Manager->destroy()
274
275 =over 4
276
277 Terminates the SOAP server within the child process.
278
279 I<Output>: True if successful, false otherwise.
280
281 =back
282
283 =begin testing
284
285 # XXX: Test destroy() method.
286
287 # TODO: delete this.
288 #exit;
289
290 =end testing
291
292 =cut
293
294 sub destroy {
295     my $ret = undef;
296    
297     # XXX: Finish this.
298     
299     return $ret;
300 }
301
302 #######################################################################
303 # Private Methods Implemented                                         #
304 #######################################################################
305
306 sub _handleFault {
307
308     # Extract arguments.
309     my ($class, $res) = @_;
310
311     # Construct error message.
312     # Figure out if the error occurred in transport or over
313     # on the other side.
314     my $errMsg = $class->transport->status; # Assume transport error.
315
316     if (ref $res) {
317         $errMsg = $res->faultcode . ": ".  $res->faultstring . "\n";
318     }
319
320     Carp::carp __PACKAGE__ . "->_handleFault(): Error occurred during processing.\n" . $errMsg;
321 }
322
323 sub _handleFaultAndCleanup {
324
325     # Extract arguments.
326     my ($class, $res) = @_;
327
328     # Print fault.
329     _handleFault($class, $res);
330    
331     # Cleanup before dying.
332     _cleanup();
333 }
334
335 sub _cleanup {
336
337     print "Cleaning up...\n";
338
339     # Mask all possible signals, so that we don't call this function multiple times.
340     $SIG{HUP}     = sub { };
341     $SIG{INT}     = sub { };
342     $SIG{QUIT}    = sub { };
343     $SIG{ABRT}    = sub { };
344     $SIG{PIPE}    = sub { };
345     $SIG{TERM}    = sub { };
346
347     HoneyClient::Manager::VM->destroy();
348
349     # XXX: Need to clean this up.
350     my $stubFW = getClientHandle(namespace     => "HoneyClient::Manager::FW");
351
352     # XXX: Change this to fwInit(), eventually.
353     # Reset the firewall, to allow everything open.
354     $stubFW->testConnect();
355
356     # Check to see if a clone was created...
357     if (defined($vmCloneConfig)) {
358         # We sleep for a bit, to make sure that the previous VM daemon was
359         # properly destroyed and released the previous port that was in use.
360         sleep (10);
361
362         # We reinstantiate a new VM daemon, because if the user had hit CTRL-C
363         # or called any other signal, then that signal would propagate to all
364         # processes, causing the VM daemon's signal handler to self terminate.
365         #
366         # Hence, rather than fight the VM daemon's natural self termination,
367         # we let the daemon die, but the create a new one, for the sole purpose
368         # of cleanup up the clones.
369         HoneyClient::Manager::VM->init();
370         print "Calling suspendVM(config => $vmCloneConfig)...\n";
371         my $stubVM = getClientHandle(namespace     => "HoneyClient::Manager::VM");
372         $stubVM->suspendVM(config => $vmCloneConfig);
373         print "Done!\n";
374         HoneyClient::Manager::VM->destroy();
375     }
376
377     # XXX: May want to change this format/usage, eventually.
378     if (length($STATE_FILE) > 0 &&
379         defined($globalAgentState)) {
380         print "Saving state to '" . $STATE_FILE . "'...\n";
381         my $dump_file = new IO::File($STATE_FILE, "w");
382
383         # XXX: Delete this block, eventually.
384         $Data::Dumper::Terse = 0;
385         $Data::Dumper::Indent = 2;
386         print $dump_file Dumper(thaw(decode_base64($globalAgentState)));
387     }
388
389     exit;
390 }
391
392 # XXX: Install the cleanup handler, in case the parent process dies
393 # unexpectedly.
394 $SIG{HUP} = sub { _cleanup(); };
395 $SIG{INT}   = sub { _cleanup(); };
396 $SIG{QUIT}  = sub { _cleanup(); };
397 $SIG{ABRT}  = sub { _cleanup(); };
398 $SIG{PIPE}  = sub { _cleanup(); };
399 $SIG{TERM}  = sub { _cleanup(); };
400
401 #######################################################################
402 # Public Methods Implemented                                          #
403 #######################################################################
404
405 =pod
406
407 =head1 EXPORTS
408
409 =head2 run()
410
411 =over 4
412
413 # XXX: Fill this in.
414
415 I<Inputs>:
416  B<$arg> is an optional argument.
417
418 driver
419 master_vm_config
420 start_state
421  
422 I<Output>: XXX: Fill this in.
423
424 =back
425
426 =begin testing
427
428 # XXX: Fill this in.
429
430 =end testing
431
432 =cut
433
434 sub run {
435     # Extract arguments.
436     # Hash-based arguments are used, since HoneyClient::Util::SOAP is unable to handle
437     # hash references directly.  Thus, flat hashtables are used throughout the code
438     # for consistency.
439     my ($class, %args) = @_;
440     my $agentState = undef;
441
442     for (;;) {
443         print "Starting new session...\n";
444         $agentState = $class->runSession(%args);
445         $args{'agent_state'} = $agentState;
446
447         # XXX: Delete this, eventually.
448         $globalAgentState = $agentState;
449
450         #$Data::Dumper::Terse = 0;
451         #$Data::Dumper::Indent = 2;
452         #print Dumper(thaw(decode_base64($agentState)));
453     }
454 }
455
456 sub runSession {
457
458     # Extract arguments.
459     # Hash-based arguments are used, since HoneyClient::Util::SOAP is unable to handle
460     # hash references directly.  Thus, flat hashtables are used throughout the code
461     # for consistency.
462     my ($class, %args) = @_;
463
464     my $som       = undef;
465     my $ret       = undef;
466     my $vmIP      = undef;
467     my $vmMAC     = undef;
468     my $vmName    = undef;
469     my $URL       = undef;
470     my $vmState   = undef;
471     my $vmCompromised = 0;
472
473     # Get a stub connection to the firewall.
474     $stubFW = getClientHandle(namespace     => "HoneyClient::Manager::FW",
475                               fault_handler => \&_handleFaultAndCleanup);
476
477     # Open up the firewall initially, to allow the Agent to do an SVN update.
478     $stubFW->testConnect();
479
480     $URL = HoneyClient::Manager::VM->init();
481     print "VM Daemon Listening On: " . $URL . "\n";
482    
483     $stubVM = getClientHandle(namespace     => "HoneyClient::Manager::VM",
484                               fault_handler => \&_handleFaultAndCleanup);
485    
486     print "Calling setMasterVM()...\n";
487     $som = $stubVM->setMasterVM(config => $args{'master_vm_config'});
488     print "Result: " . $som->result() . "\n";
489
490     print "Calling quickCloneVM()...\n";
491     $som = $stubVM->quickCloneVM();
492     print "Result: " . $som->result() . "\n";
493     $vmCloneConfig = $som->result();
494
495     # Make sure the VM is fully cloned, before trying to make any subsequent calls.
496     print "Calling isRegisteredVM()...\n";
497     $som = $stubVM->isRegisteredVM(config => $vmCloneConfig);
498     $ret = $som->result();
499
500     if (defined($ret)) {
501         print "Result: " . $ret . "\n";
502     }
503
504     while (!defined($ret)) {
505         sleep (3);
506         print "Calling isRegisteredVM()...\n";
507         $som = $stubVM->isRegisteredVM(config => $vmCloneConfig);
508         print "Result: " . $som->result() . "\n";
509         $ret = $som->result();
510     }
511
512     print "Calling getStateVM()...\n";
513     $som = $stubVM->getStateVM(config => $vmCloneConfig);
514     $vmState = $som->result();
515
516     if ($som->result() == VM_EXECUTION_STATE_ON) {
517         print "ON\n";
518     } elsif ($som->result() == VM_EXECUTION_STATE_OFF) {
519         print "OFF\n";
520     } elsif ($som->result() == VM_EXECUTION_STATE_SUSPENDED) {
521         print "SUSPENDED\n";
522     } elsif ($som->result() == VM_EXECUTION_STATE_STUCK) {
523         print "STUCK\n";
524     } else {
525         print "UNKNOWN\n";
526     }
527
528     while ($vmState != VM_EXECUTION_STATE_ON) {
529         sleep (3);
530
531         print "Calling getStateVM()...\n";
532         $som = $stubVM->getStateVM(config => $vmCloneConfig);
533         $vmState = $som->result();
534
535         if ($som->result() == VM_EXECUTION_STATE_ON) {
536             print "ON\n";
537         } elsif ($som->result() == VM_EXECUTION_STATE_OFF) {
538             print "OFF\n";
539         } elsif ($som->result() == VM_EXECUTION_STATE_SUSPENDED) {
540             print "SUSPENDED\n";
541         } elsif ($som->result() == VM_EXECUTION_STATE_STUCK) {
542             print "STUCK\n";
543         } else {
544             print "UNKNOWN\n";
545         }
546     }
547
548     print "Calling getMACaddrVM()...\n";
549     $som = $stubVM->getMACaddrVM(config => $vmCloneConfig);
550     print "Result: " . $som->result() . "\n";
551     $vmMAC = $som->result();
552
553     # Figure out when the Agent on the VM is alive and well.
554     $ret = undef;
555     while (!$ret) {
556         sleep (3);
557         print "Calling getIPaddrVM()...\n";
558         $som = $stubVM->getIPaddrVM(config => $vmCloneConfig);
559         if (defined($som->result())) {
560             print "Result: " . $som->result() . "\n";
561         }
562         $vmIP = $som->result();
563
564         if (defined($vmIP)) {
565
566             # Try contacting the Agent; ignore any faults.
567             $stubAgent = getClientHandle(namespace     => "HoneyClient::Agent",
568                                          address       => $vmIP,
569                                          fault_handler => \&_handleFault);
570
571             eval {
572                 print "Calling getStatus()...\n";
573                 $som = $stubAgent->getStatus();
574                 $ret = thaw(decode_base64($som->result()));
575                 print "Result:\n";
576                 # Make Dumper format more verbose.
577                 $Data::Dumper::Terse = 0;
578                 $Data::Dumper::Indent = 2;
579                 print Dumper($ret);
580
581                 print "Calling getNameVM()...\n";
582                 $som = $stubVM->getNameVM(config => $vmCloneConfig);
583                 print "Result: " . $som->result() . "\n";
584                 $vmName = $som->result();
585             };
586             # Clear returned state, if any fault occurs.
587             if ($@) {
588                 $ret = undef;
589             }
590         }
591     }
592
593     # Build our VM's connection table.
594     # Note: We assume our VM has a single MAC address
595     # and a single IP address.
596     $vmStateTable->{$vmName}->{sources}->{$vmMAC}->{$vmIP} = {
597         # XXX: We assume we can't pinpoint what source TCP ports the
598         # corresponding driver will need.  (We may want to get this
599         # information eventually from the Agent, as part of Driver::next().)
600         'tcp' => undef,
601     };
602
603     print "VM State Table:\n";
604     # Make Dumper format more verbose.
605     $Data::Dumper::Terse = 0;
606     $Data::Dumper::Indent = 2;
607     print Dumper($vmStateTable) . "\n";
608  
609     # Initialize the firewall.
610     $stubFW->fwInit();
611
612     # Add new chain, per cloned VM.
613     $stubFW->addChain($vmStateTable);
614    
615     sleep (2);
616
617     # Recreate the client stub; ignore faults.
618     $stubAgent = getClientHandle(namespace     => "HoneyClient::Agent",
619                                  address       => $vmIP,
620                                  fault_handler => \&_handleFault);
621
622     # Recreate the firewall stub; ignore faults.
623     $stubFW = getClientHandle(namespace     => "HoneyClient::Manager::FW",
624                               fault_handler => \&_handleFault);
625
626     for (my $counter = 1;; $counter++) {
627
628         # From this point on, catch all errors generated and
629         # assume that the Agent's watchdog process will recover.
630         eval {
631             print "Calling getStatus()...\n";
632             $som = $stubAgent->getStatus();
633             print "Result:\n";
634             my $ret = thaw(decode_base64($som->result()));
635             # Make Dumper format more verbose.
636             $Data::Dumper::Terse = 0;
637             $Data::Dumper::Indent = 2;
638             print Dumper($ret->{$args{'driver'}}->{status});
639             #print Dumper($ret);
640
641             # Check to see if Agent::run() thread has stopped
642             # and that a compromise was detected.
643             if (!defined($ret->{$args{'driver'}}->{thread_id})) {
644                 if ($ret->{$args{'driver'}}->{status}->{is_compromised}) {
645                     print "Calling getState()...\n";
646                     $som = $stubAgent->getState();
647                     $args{'agent_state'} = $som->result();
648
649                     # XXX: Delete this, eventually.
650                     $globalAgentState = $args{'agent_state'};
651
652                     # Check to see if the VM has been compromised.
653                     print "WARNING: VM HAS BEEN COMPROMISED!\n";
654                     print "Suspending: (" . $vmCloneConfig . ")...\n";
655                     print "Calling suspendVM()...\n";
656                     $som = $stubVM->suspendVM(config => $vmCloneConfig);
657                     HoneyClient::Manager::VM->destroy();
658                     $vmCompromised = 1;
659                     return; # Return out of eval block.
660                 } else {
661                     print "VM Integrity Check: OK!\n";
662                 }
663             }
664            
665             # Only call updateState() on the first iteration.
666             # TODO: Need to support asynchronous updates (url adding)
667             # from user input.
668             if ($counter == 1) {
669                 print "Calling updateState()...\n";
670                 $som = $stubAgent->updateState($args{'agent_state'});
671             }
672            
673             print "Calling getState()...\n";
674             $som = $stubAgent->getState();
675             $args{'agent_state'} = $som->result();
676
677             # XXX: Delete this, eventually.
678             $globalAgentState = $args{'agent_state'};
679
680             print "Calling getStatus()...\n";
681             $som = $stubAgent->getStatus();
682             print "Result:\n";
683             $ret = thaw(decode_base64($som->result()));
684             # Make Dumper format more verbose.
685             $Data::Dumper::Terse = 0;
686             $Data::Dumper::Indent = 2;
687             #print Dumper($ret->{$args{'driver'}}->{status});
688             print Dumper($ret);
689
690             # The Agent::run() thread has stopped; we assume
691             # it's because the Agent is waiting for the firewall
692             # to allow access to the new targets.
693             # TODO: Need to distinguish between run() stopping because
694             # of firewall mods, or if the Agent is completely finished
695             # and needs more input to continue.
696             if (!defined($ret->{$args{'driver'}}->{thread_id})) {
697
698
699                 # Delete the old firewall rules, based upon existing
700                 # targets.
701                 $stubFW->deleteRules($vmStateTable);
702
703                 # Get the new targets from the Agent.
704                 $vmStateTable->{$vmName}->{targets} = $ret->{$args{'driver'}}->{next}->{targets};
705
706                 print "VM State Table:\n";
707                 # Make Dumper format more verbose.
708                 $Data::Dumper::Terse = 0;
709                 $Data::Dumper::Indent = 2;
710                 print Dumper($vmStateTable) . "\n";
711
712                 # Add the new targets from the Agent.
713                 $stubFW->addRules($vmStateTable);
714
715                 print "Calling run()...\n";
716                 $som = $stubAgent->run();
717             }
718         };
719         if ($@) {
720             my $resetSuccessful = 0;
721             while (!$resetSuccessful) {
722                 print "Resetting firewall...\n";
723                 eval {
724                     # We assume the error was caused by some sort of communications
725                     # problem with the Agent.  Assume the Agent's watchdog will restart
726                     # the daemon, in which case, we indefinately try to reset the
727                     # firewall accordingly.
728                     $stubFW->fwInit();
729                     $stubFW->addChain($vmStateTable);
730                     $stubFW->addRules($vmStateTable);
731                 };
732                 if (!$@) {
733                     $resetSuccessful = 1;
734                 } else {
735                     sleep (3);
736                 }
737             }   
738         }
739         if ($vmCompromised) {
740             return $args{'agent_state'};
741         }
742         sleep (10);
743     }
744 }
745
746 #######################################################################
747
748 1;
749
750 #######################################################################
751 # Additional Module Documentation                                     #
752 #######################################################################
753
754 __END__
755
756 =head1 BUGS & ASSUMPTIONS
757
758 # XXX: Fill this in.
759
760 =head1 SEE ALSO
761
762 L<http://www.honeyclient.org/trac>
763
764 =head1 REPORTING BUGS
765
766 L<http://www.honeyclient.org/trac/newticket>
767
768 =head1 ACKNOWLEDGEMENTS
769
770 Paul Kulchenko for developing the SOAP::Lite module.
771
772 =head1 AUTHORS
773
774 Kathy Wang, E<lt>knwang@mitre.orgE<gt>
775
776 Thanh Truong, E<lt>ttruong@mitre.orgE<gt>
777
778 Darien Kindlund, E<lt>kindlund@mitre.orgE<gt>
779
780 =head1 COPYRIGHT & LICENSE
781
782 Copyright (C) 2006 The MITRE Corporation.  All rights reserved.
783
784 This program is free software; you can redistribute it and/or
785 modify it under the terms of the GNU General Public License
786 as published by the Free Software Foundation, using version 2
787 of the License.
788  
789 This program is distributed in the hope that it will be useful,
790 but WITHOUT ANY WARRANTY; without even the implied warranty of
791 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
792 GNU General Public License for more details.
793  
794 You should have received a copy of the GNU General Public License
795 along with this program; if not, write to the Free Software
796 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
797 02110-1301, USA.
798
799
800 =cut
Note: See TracBrowser for help on using the browser.