Changeset 1486

Show
Ignore:
Timestamp:
04/08/08 14:48:13 (4 months ago)
Author:
kindlund
Message:

Got most of the FW handling code working properly, also added error checking during drive operations.

Files:

Legend:

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

    r1472 r1486  
    539539    if (($OBJECT_COUNT >= 0) && defined($self->{'config'})) { 
    540540        # Signal firewall to deny traffic from this clone. 
    541         # XXX: Fill this in.  
     541        $self->_denyNetwork(); 
    542542        
    543543        # Initialize a new handler, but suppress any initial connection errors. 
     
    725725 
    726726            # Signal firewall to allow traffic from this clone through. 
    727             # XXX: Test this. 
    728727            $self->_allowNetwork(); 
    729728 
     
    858857                    !defined($args{'fingerprint'})) { 
    859858 
    860                     # Croak if no valid argument is supplied. 
    861                     $LOG->error("Error: No fingerprint argument supplied."); 
    862                     Carp::croak "Error: No fingerprint argument supplied."; 
    863                 } 
    864  
    865                 $LOG->info("(" . $self->{'name'} . ") - Inserting Fingerprint Into Database."); 
    866                 # Make sure the fingerprint contains a client_id. 
    867                 $args{'fingerprint'}->{'client_id'} = $self->{'database_id'}; 
    868                 my $fingerprint_id = undef; 
    869                 eval { 
    870                     $fingerprint_id = HoneyClient::Manager::Database::insert_fingerprint($args{'fingerprint'}); 
    871                 }; 
    872                 if ($@ || ($fingerprint_id == 0) || !defined($fingerprint_id)) { 
    873                     $LOG->warn("(" . $self->{'name'} . ") - Failure Inserting Fingerprint: " . $@); 
     859                    # Warn if no valid fingerprint is supplied. 
     860                    $LOG->warn("(" . $self->{'name'} . ") - No valid fingerprint found."); 
     861                    Carp::carp "(" . $self->{'name'} . ") - No valid fingerprint found."; 
     862 
     863                    # Mark the VM as suspicious, manually. 
     864                    my $dt = DateTime::HiRes->now(time_zone => "local"); 
     865                    HoneyClient::Manager::Database::set_client_suspicious({ 
     866                        client_id => $self->{'database_id'}, 
     867                        compromise => $dt->ymd('-').'T'.$dt->hms(':'), 
     868                    }); 
     869 
    874870                } else { 
    875                     $LOG->info("(" . $self->{'name'} . ") - Database Insert Successful."); 
     871 
     872                    # Mark the VM as suspicious indirectly, by inserting the fingerprint. 
     873 
     874                    $LOG->info("(" . $self->{'name'} . ") - Inserting Fingerprint Into Database."); 
     875                    # Make sure the fingerprint contains a client_id. 
     876                    $args{'fingerprint'}->{'client_id'} = $self->{'database_id'}; 
     877                    my $fingerprint_id = undef; 
     878                    eval { 
     879                        $fingerprint_id = HoneyClient::Manager::Database::insert_fingerprint($args{'fingerprint'}); 
     880                    }; 
     881                    if ($@ || ($fingerprint_id == 0) || !defined($fingerprint_id)) { 
     882                        $LOG->warn("(" . $self->{'name'} . ") - Failure Inserting Fingerprint: " . $@); 
     883                    } else { 
     884                        $LOG->info("(" . $self->{'name'} . ") - Database Insert Successful."); 
     885                    } 
    876886                } 
    877887            } elsif (/compromised/) { 
     
    925935    } 
    926936 
     937    # Mark that the VM has been granted network access. 
     938    $self->{'_has_network_access'} = 1; 
     939 
    927940    # Build our VM's network connection table. 
    928941    # Note: We assume our VM has a single MAC address 
     
    946959 
    947960    $LOG->info("Allowing VM (" . $self->{'name'} . ") network access."); 
     961    # XXX: Currently, faults get propagated -- is this okay? 
    948962    $self->{'_fw_handle'}->addChain($netTable); 
    949963    $self->{'_fw_handle'}->addRules($netTable); 
     
    961975        return; 
    962976    } 
     977 
     978    # Check if the VM even has network access. 
     979    if (!$self->{'_has_network_access'}) { 
     980        return; 
     981    } 
     982     
     983    # Mark that the VM has been denied network access. 
     984    $self->{'_has_network_access'} = 0; 
    963985 
    964986    # Build our VM's network connection table. 
     
    973995    }; 
    974996 
     997    # XXX: This is a defect.  The current FW code requires we set a target, but 
     998    # doesn't care what hostname we provide -- as long as it's resolvable. 
     999    # However, it *does* care about the target ports, which are hardcoded. 
     1000    $netTable->{$self->{'name'}}->{'targets'} = { 
     1001        'www.cnn.com' => { 
     1002            tcp => [ 80, 443, 3690 ], 
     1003        }, 
     1004    }; 
     1005 
    9751006    $LOG->info("Denying VM (" . $self->{'name'} . ") network access."); 
     1007    # XXX: Currently, faults get propagated -- is this okay? 
     1008    $self->{'_fw_handle'}->deleteRules($netTable); 
    9761009    $self->{'_fw_handle'}->deleteChain($netTable); 
    9771010} 
     
    11801213        # (For testing use only.) 
    11811214        _bypass_firewall => 0, 
     1215 
     1216        # A variable indicating if the cloned VM has been granted 
     1217        # network access. 
     1218        _has_network_access => 0, 
    11821219    ); 
    11831220 
     
    12031240    $self->{'_fw_handle'} = getClientHandle(namespace => "HoneyClient::Manager::FW"); 
    12041241 
    1205     # XXX: Delete this, eventually. 
     1242    # TODO: Fix this, eventually. 
    12061243    $LOG->info("Installing default firewall rules."); 
     1244    # XXX: Currently, faults get propagated -- is this okay? 
    12071245    $self->{'_fw_handle'}->installDefaultRules(); 
    12081246 
    12091247    # Determine if the firewall needs to be bypassed. 
    12101248    if ($self->{'_bypass_firewall'}) { 
     1249        # XXX: Currently, faults get propagated -- is this okay? 
    12111250        $self->{'_fw_handle'}->allowAllTraffic(); 
    12121251    } 
     
    13721411 
    13731412    # Signal firewall to deny traffic from this clone. 
    1374     # XXX: Fill this in.  
     1413    $self->_denyNetwork(); 
    13751414 
    13761415    # Extract the VM configuration file. 
     
    13811420    $self->{'config'} = undef; 
    13821421     
    1383     $LOG->debug("Suspending clone VM (" . $vmConfig . ")."); 
     1422    $LOG->info("Suspending clone VM (" . $vmConfig . ")."); 
    13841423    my $som = $self->{'_vm_handle'}->suspendVM(config => $vmConfig); 
    13851424 
     
    15491588        $currentWork = _pop($args{'work'}); 
    15501589 
    1551         $LOG->info("(" . $self->{'name'} . ") - " . $self->{'driver_name'} . " - Driving To Resource: " . $currentWork); 
    1552         $som = $self->{'_agent_handle'}->drive(driver_name => $self->{'driver_name'}, 
    1553                                            parameters  => encode_base64($currentWork)); 
    1554         $result = thaw(decode_base64($som->result())); 
     1590        # Drive the Agent. 
     1591        eval { 
     1592            $LOG->info("(" . $self->{'name'} . ") - " . $self->{'driver_name'} . " - Driving To Resource: " . $currentWork); 
     1593            $som = $self->{'_agent_handle'}->drive(driver_name => $self->{'driver_name'}, 
     1594                                                   parameters  => encode_base64($currentWork)); 
     1595            $result = thaw(decode_base64($som->result())); 
     1596        }; 
     1597        if ($@) { 
     1598            # We lost communications with the Agent; assume the worst 
     1599            # and mark the VM as suspicious. 
     1600            $LOG->warn("(" . $self->{'name'} . ") - Lost Communication with Agent! Assuming Integrity Failure."); 
     1601 
     1602            # Suspend and archive the cloned VM. 
     1603            $self->suspend(); 
     1604 
     1605            # If possibile, insert work history. 
     1606            # XXX: This may need to be changed; we need to mark these URLs differently. 
     1607            #      Technically, the link didn't time out; we lost some sort of communication 
     1608            #      with the Agent, when we tried visiting the link. 
     1609            $finishedWork->{'links_timed_out'}->{$currentWork} = $result->{'time_at'}; 
     1610            if (defined($self->{'database_id'})) { 
     1611                $numWorkInserted = HoneyClient::Manager::Database::insert_history_urls($finishedWork); 
     1612                $LOG->info($numWorkInserted . " URL(s) Inserted."); 
     1613            } 
     1614 
     1615            # Mark the VM as suspicious. 
     1616            $self->_changeStatus(status => "suspicious"); 
    15551617 
    15561618        # Figure out if there was a compromise found. 
    1557         if (scalar(@{$result->{'fingerprint'}->{os_processes}})) { 
     1619        } elsif (scalar(@{$result->{'fingerprint'}->{os_processes}})) { 
    15581620            $LOG->warn("(" . $self->{'name'} . ") - " . $self->{'driver_name'} . " - Integrity Check: FAILED"); 
    15591621 
     
    15881650 
    15891651        # Create a new clone, if a compromise was found and we still have work to do. 
    1590         if (scalar(@{$result->{'fingerprint'}->{os_processes}}) && 
     1652        if (($self->{'status'} eq "suspicious") && 
    15911653            scalar(%{$args{'work'}})) { 
    15921654            # Be sure to carry over any customizations into the newly created 
     
    15991661    } 
    16001662 
    1601     # XXX: Add error handling. 
     1663    # TODO: Add more error handling? 
    16021664 
    16031665    return $self;