| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 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 |
|
|---|
| 59 |
|
|---|
| 60 |
use strict; |
|---|
| 61 |
use warnings FATAL => 'all'; |
|---|
| 62 |
use Config; |
|---|
| 63 |
use Carp (); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
BEGIN { |
|---|
| 70 |
|
|---|
| 71 |
require Exporter; |
|---|
| 72 |
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION, @DRIVERS); |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
$VERSION = 0.92; |
|---|
| 76 |
|
|---|
| 77 |
@ISA = qw(Exporter); |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
@EXPORT = qw(init destroy); |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
%EXPORT_TAGS = ( |
|---|
| 91 |
'all' => [ qw(init destroy) ], |
|---|
| 92 |
); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
$Config{useithreads} or Carp::croak "Error: Recompile Perl with ithread support, in order to use this module.\n"; |
|---|
| 99 |
|
|---|
| 100 |
$SIG{PIPE} = 'IGNORE'; |
|---|
| 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 |
|
|---|
| 150 |
use HoneyClient::Util::SOAP qw(getClientHandle getServerHandle); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
use threads; |
|---|
| 154 |
use threads::shared; |
|---|
| 155 |
use Thread::Semaphore; |
|---|
| 156 |
use Thread::Queue; |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
use HoneyClient::Manager::VM qw(); |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
use Data::Dumper; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
$Data::Dumper::Terse = 0; |
|---|
| 170 |
$Data::Dumper::Indent = 2; |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
use Storable qw(nfreeze thaw); |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
use MIME::Base64 qw(encode_base64 decode_base64); |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
use HoneyClient::Manager::FW; |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
use Storable qw(nfreeze thaw); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 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 |
|
|---|
| 194 |
use IO::File; |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
our $URL_BASE : shared = undef; |
|---|
| 198 |
our $URL : shared = undef; |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
our $DAEMON_PID : shared = undef; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
our $vmStateTable = { }; |
|---|
| 205 |
our $vmCloneConfig = undef; |
|---|
| 206 |
our $stubVM = undef; |
|---|
| 207 |
our $stubAgent = undef; |
|---|
| 208 |
our $stubFW = undef; |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
our $globalAgentState = undef; |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
our $STATE_FILE = getVar(name => "manager_state"); |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 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 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
my ($class, %args) = @_; |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 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 |
|
|---|
| 298 |
|
|---|
| 299 |
return $ret; |
|---|
| 300 |
} |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
sub _handleFault { |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
my ($class, $res) = @_; |
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
my $errMsg = $class->transport->status; |
|---|
| 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 |
|
|---|
| 326 |
my ($class, $res) = @_; |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
_handleFault($class, $res); |
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
_cleanup(); |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
sub _cleanup { |
|---|
| 336 |
|
|---|
| 337 |
print "Cleaning up...\n"; |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 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 |
|
|---|
| 350 |
my $stubFW = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
$stubFW->testConnect(); |
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
if (defined($vmCloneConfig)) { |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
sleep (10); |
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 393 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 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 |
|
|---|
| 448 |
$globalAgentState = $agentState; |
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
} |
|---|
| 454 |
} |
|---|
| 455 |
|
|---|
| 456 |
sub runSession { |
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 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 |
|
|---|
| 474 |
$stubFW = getClientHandle(namespace => "HoneyClient::Manager::FW", |
|---|
| 475 |
fault_handler => \&_handleFaultAndCleanup); |
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 587 |
if ($@) { |
|---|
| 588 |
$ret = undef; |
|---|
| 589 |
} |
|---|
| 590 |
} |
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
$vmStateTable->{$vmName}->{sources}->{$vmMAC}->{$vmIP} = { |
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
'tcp' => undef, |
|---|
| 601 |
}; |
|---|
| 602 |
|
|---|
| 603 |
print "VM State Table:\n"; |
|---|
| 604 |
|
|---|
| 605 |
$Data::Dumper::Terse = 0; |
|---|
| 606 |
$Data::Dumper::Indent = 2; |
|---|
| 607 |
print Dumper($vmStateTable) . "\n"; |
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
$stubFW->fwInit(); |
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
$stubFW->addChain($vmStateTable); |
|---|
| 614 |
|
|---|
| 615 |
sleep (2); |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
$stubAgent = getClientHandle(namespace => "HoneyClient::Agent", |
|---|
| 619 |
address => $vmIP, |
|---|
| 620 |
fault_handler => \&_handleFault); |
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
$stubFW = getClientHandle(namespace => "HoneyClient::Manager::FW", |
|---|
| 624 |
fault_handler => \&_handleFault); |
|---|
| 625 |
|
|---|
| 626 |
for (my $counter = 1;; $counter++) { |
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
eval { |
|---|
| 631 |
print "Calling getStatus()...\n"; |
|---|
| 632 |
$som = $stubAgent->getStatus(); |
|---|
| 633 |
print "Result:\n"; |
|---|
| 634 |
my $ret = thaw(decode_base64($som->result())); |
|---|
| 635 |
|
|---|
| 636 |
$Data::Dumper::Terse = 0; |
|---|
| 637 |
$Data::Dumper::Indent = 2; |
|---|
| 638 |
print Dumper($ret->{$args{'driver'}}->{status}); |
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 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 |
|
|---|
| 650 |
$globalAgentState = $args{'agent_state'}; |
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 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; |
|---|
| 660 |
} else { |
|---|
| 661 |
print "VM Integrity Check: OK!\n"; |
|---|
| 662 |
} |
|---|
| 663 |
} |
|---|
| 664 |
|
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 685 |
$Data::Dumper::Terse = 0; |
|---|
| 686 |
$Data::Dumper::Indent = 2; |
|---|
| 687 |
|
|---|
| 688 |
print Dumper($ret); |
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
if (!defined($ret->{$args{'driver'}}->{thread_id})) { |
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
$stubFW->deleteRules($vmStateTable); |
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
$vmStateTable->{$vmName}->{targets} = $ret->{$args{'driver'}}->{next}->{targets}; |
|---|
| 705 |
|
|---|
| 706 |
print "VM State Table:\n"; |
|---|
| 707 |
|
|---|
| 708 |
$Data::Dumper::Terse = 0; |
|---|
| 709 |
$Data::Dumper::Indent = 2; |
|---|
| 710 |
print Dumper($vmStateTable) . "\n"; |
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 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 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 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 |
|
|---|
| 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 |
|---|