Changeset 1472
- Timestamp:
- 04/08/08 10:43:11 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Manager/VM/Clone.pm
r1463 r1472 68 68 my $ip_address = $clone->{'ip_address'}; 69 69 70 # Specify the type of work you want the clone to handle. 71 my $work = { 72 "http://www.google.com/" => 1, 73 "http://www.cnn.com/" => 1, 74 "http://www.mitre.org/" => 10, 75 }; 76 77 # Drive the clone, using the work specified. 78 $clone = $clone->drive(work => $work); 79 70 80 # Get the name of the cloned VM (as it appears in the VMware Console). 71 81 my $name = $clone->{'name'}; … … 528 538 529 539 if (($OBJECT_COUNT >= 0) && defined($self->{'config'})) { 540 # Signal firewall to deny traffic from this clone. 541 # XXX: Fill this in. 530 542 531 543 # Initialize a new handler, but suppress any initial connection errors. … … 711 723 $LOG->info("Initialized clone VM (" . $self->{'name'} . ") using IP (" . 712 724 $self->{'ip_address'} . ") and MAC (" . $self->{'mac_address'} . ")."); 725 726 # Signal firewall to allow traffic from this clone through. 727 # XXX: Test this. 728 $self->_allowNetwork(); 729 713 730 $LOG->info("Waiting for Agent daemon to initialize inside clone VM."); 714 731 $logMsgPrinted = 1; … … 736 753 # Register the cloned VM with the Drone database. 737 754 my $dt = DateTime::HiRes->now(time_zone => "local"); 738 755 756 # XXX: We need to separate this call into 2 smaller ones. 757 # 1) Register basic client information. 758 # 2) Register OS/application details. 759 # That way, if this function fails for some reason, 760 # we have *some* sort of record in the database about it, 761 # for cleanup purposes. 762 739 763 # Construct the 'Client' object. 740 764 my $client = { … … 866 890 # If specified, dumps the supplied fingerprint information to 867 891 # a corresponding file. 892 # 893 # Inputs: self, fingerprint hashref 868 894 sub _dumpFingerprint { 869 895 … … 871 897 my ($self, $fingerprint) = @_; 872 898 899 # XXX: Should this be a new .dump file, per compromise? 873 900 # Dump the fingerprint to a file, if needed. 874 901 my $COMPROMISE_FILE = getVar(name => "fingerprint_dump"); … … 884 911 $dump_file->close(); 885 912 } 913 } 914 915 # Allows the specified VM to use the network. 916 # 917 # Inputs: self 918 sub _allowNetwork { 919 # Extract arguments. 920 my ($self, %args) = @_; 921 922 # Determine if the firewall needs to be bypassed. 923 if ($self->{'_bypass_firewall'}) { 924 return; 925 } 926 927 # Build our VM's network connection table. 928 # Note: We assume our VM has a single MAC address 929 # and a single IP address. 930 my $netTable = {}; 931 932 # XXX: This code is a hack and needs to be fixed. 933 $netTable->{$self->{'name'}}->{'sources'}->{$self->{'mac_address'}}->{$self->{'ip_address'}} = { 934 # Allow all TCP traffic from this VM through on ports 80, 443, and 3690. 935 tcp => [ 80, ], #443, 3690 ], 936 }; 937 938 # XXX: This is a defect. The current FW code requires we set a target, but 939 # doesn't care what hostname we provide -- as long as it's resolvable. 940 # However, it *does* care about the target ports, which are hardcoded. 941 $netTable->{$self->{'name'}}->{'targets'} = { 942 'www.cnn.com' => { 943 tcp => [ 80, 443, 3690 ], 944 }, 945 }; 946 947 $LOG->info("Allowing VM (" . $self->{'name'} . ") network access."); 948 $self->{'_fw_handle'}->addChain($netTable); 949 $self->{'_fw_handle'}->addRules($netTable); 950 } 951 952 # Denies the specified VM use of the network. 953 # 954 # Inputs: self 955 sub _denyNetwork { 956 # Extract arguments. 957 my ($self, %args) = @_; 958 959 # Determine if the firewall needs to be bypassed. 960 if ($self->{'_bypass_firewall'}) { 961 return; 962 } 963 964 # Build our VM's network connection table. 965 # Note: We assume our VM has a single MAC address 966 # and a single IP address. 967 my $netTable = {}; 968 969 # XXX: This code is a hack and needs to be fixed. 970 $netTable->{$self->{'name'}}->{'sources'}->{$self->{'mac_address'}}->{$self->{'ip_address'}} = { 971 # Deny all TCP traffic from this VM. 972 tcp => [ 80, ], #443, 3690 ], 973 }; 974 975 $LOG->info("Denying VM (" . $self->{'name'} . ") network access."); 976 $self->{'_fw_handle'}->deleteChain($netTable); 886 977 } 887 978 … … 968 1059 969 1060 # Create a generic empty clone, with test state data. 970 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM, _dont_init => 1 );971 is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1 )") or diag("The new() call failed.");972 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1 )") or diag("The new() call failed.");1061 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM, _dont_init => 1, _bypass_firewall => 1); 1062 is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1, _bypass_firewall => 1)") or diag("The new() call failed."); 1063 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1, _bypass_firewall => 1)") or diag("The new() call failed."); 973 1064 $clone = undef; 974 1065 … … 981 1072 "# with a fully functional master VM that has the HoneyClient code\n" . 982 1073 "# loaded upon boot-up.\n" . 1074 "#\n" . 1075 "# This test also requires that the firewall VM is registered,\n" . 1076 "# powered on, and operational.\n" . 983 1077 "#\n" . 984 1078 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . … … 1073 1167 _agent_handle => undef, 1074 1168 1169 # A SOAP handle to the FW daemon. (This internal variable 1170 # should never be modified externally.) 1171 _fw_handle => undef, 1172 1075 1173 # A variable indicated how long the object should wait for 1076 1174 # between subsequent retries to any SOAP server … … 1078 1176 # be modified externally.) 1079 1177 _retry_period => 2, 1178 1179 # A variable indicating if the firewall should be bypassed. 1180 # (For testing use only.) 1181 _bypass_firewall => 0, 1080 1182 ); 1081 1183 … … 1097 1199 # Set a valid handle for the VM daemon. 1098 1200 $self->{'_vm_handle'} = getClientHandle(namespace => "HoneyClient::Manager::VM"); 1201 1202 # Set a valid handle for the FW daemon. 1203 $self->{'_fw_handle'} = getClientHandle(namespace => "HoneyClient::Manager::FW"); 1204 1205 # XXX: Delete this, eventually. 1206 $LOG->info("Installing default firewall rules."); 1207 $self->{'_fw_handle'}->installDefaultRules(); 1208 1209 # Determine if the firewall needs to be bypassed. 1210 if ($self->{'_bypass_firewall'}) { 1211 $self->{'_fw_handle'}->allowAllTraffic(); 1212 } 1099 1213 1100 1214 # If the clone's configuration wasn't supplied initially, then … … 1184 1298 "# loaded upon boot-up.\n" . 1185 1299 "#\n" . 1300 "# This test also requires that the firewall VM is registered,\n" . 1301 "# powered on, and operational.\n" . 1302 "#\n" . 1186 1303 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . 1187 1304 "#\n" . … … 1190 1307 1191 1308 # Create a generic empty clone, with test state data. 1192 my $clone = HoneyClient::Manager::VM::Clone->new( );1309 my $clone = HoneyClient::Manager::VM::Clone->new(_bypass_firewall => 1); 1193 1310 my $cloneConfig = $clone->{config}; 1194 1311 … … 1254 1371 } 1255 1372 1373 # Signal firewall to deny traffic from this clone. 1374 # XXX: Fill this in. 1375 1256 1376 # Extract the VM configuration file. 1257 1377 my $vmConfig = $self->{'config'}; … … 1343 1463 "# loaded upon boot-up.\n" . 1344 1464 "#\n" . 1465 "# This test also requires that the firewall VM is registered,\n" . 1466 "# powered on, and operational.\n" . 1467 "#\n" . 1345 1468 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . 1346 1469 "#\n" . … … 1349 1472 1350 1473 # Create a generic empty clone, with test state data. 1351 my $clone = HoneyClient::Manager::VM::Clone->new( );1474 my $clone = HoneyClient::Manager::VM::Clone->new(_bypass_firewall => 1); 1352 1475 my $cloneConfig = $clone->{config}; 1353 1476 … … 1431 1554 $result = thaw(decode_base64($som->result())); 1432 1555 1433 # XXX: Delete this, eventually.1434 print Dumper($result) . "\n";1435 1436 1556 # Figure out if there was a compromise found. 1437 1557 if (scalar(@{$result->{'fingerprint'}->{os_processes}})) { … … 1478 1598 } 1479 1599 } 1600 1601 # XXX: Add error handling. 1480 1602 1481 1603 return $self; honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_manager_vm_clone.t
r1461 r1472 198 198 199 199 # Create a generic empty clone, with test state data. 200 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM, _dont_init => 1 );201 is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1 )") or diag("The new() call failed.");202 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1 )") or diag("The new() call failed.");200 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM, _dont_init => 1, _bypass_firewall => 1); 201 is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1, _bypass_firewall => 1)") or diag("The new() call failed."); 202 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM', _dont_init => 1, _bypass_firewall => 1)") or diag("The new() call failed."); 203 203 $clone = undef; 204 204 … … 211 211 "# with a fully functional master VM that has the HoneyClient code\n" . 212 212 "# loaded upon boot-up.\n" . 213 "#\n" . 214 "# This test also requires that the firewall VM is registered,\n" . 215 "# powered on, and operational.\n" . 213 216 "#\n" . 214 217 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . … … 264 267 "# loaded upon boot-up.\n" . 265 268 "#\n" . 269 "# This test also requires that the firewall VM is registered,\n" . 270 "# powered on, and operational.\n" . 271 "#\n" . 266 272 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . 267 273 "#\n" . … … 270 276 271 277 # Create a generic empty clone, with test state data. 272 my $clone = HoneyClient::Manager::VM::Clone->new( );278 my $clone = HoneyClient::Manager::VM::Clone->new(_bypass_firewall => 1); 273 279 my $cloneConfig = $clone->{config}; 274 280 … … 325 331 "# loaded upon boot-up.\n" . 326 332 "#\n" . 333 "# This test also requires that the firewall VM is registered,\n" . 334 "# powered on, and operational.\n" . 335 "#\n" . 327 336 "# Your master VM is: " . getVar(name => "master_vm_config", namespace => "HoneyClient::Manager::VM") . "\n" . 328 337 "#\n" . … … 331 340 332 341 # Create a generic empty clone, with test state data. 333 my $clone = HoneyClient::Manager::VM::Clone->new( );342 my $clone = HoneyClient::Manager::VM::Clone->new(_bypass_firewall => 1); 334 343 my $cloneConfig = $clone->{config}; 335 344 336 # TODO: Fix this.337 345 $clone = $clone->drive(work => { 'http://www.google.com/' => 1 }); 338 346 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "drive(work => { 'http://www.google.com/' => 1})") or diag("The drive() call failed.");
