Changeset 1104

Show
Ignore:
Timestamp:
01/11/08 15:46:34 (7 months ago)
Author:
kindlund
Message:

Converted all tabs to 4-spaces.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/lib/HoneyClient/Manager.pm

    r1084 r1104  
    301301    require HoneyClient::DB::Url::History; 
    302302    require HoneyClient::DB::Time; 
    303    %link_categories = ( 
    304        $HoneyClient::DB::Url::History::STATUS_VISITED => 'links_visited', 
    305        $HoneyClient::DB::Url::History::STATUS_TIMED_OUT => 'links_timed_out', 
     303    %link_categories = ( 
     304        $HoneyClient::DB::Url::History::STATUS_VISITED => 'links_visited', 
     305        $HoneyClient::DB::Url::History::STATUS_TIMED_OUT => 'links_timed_out', 
    306306# For the time being, ignored links will not be inserted. 
    307 #      $HoneyClient::DB::Url::History::STATUS_IGNORED => 'links_ignored', 
    308    ); 
     307#        $HoneyClient::DB::Url::History::STATUS_IGNORED => 'links_ignored', 
     308    ); 
    309309} 
    310310 
     
    581581        $dump_file->close(); 
    582582    } 
    583    #XXX: Insert Urls. To be moved eventually. 
    584    if ($DB_ENABLE && ($clientDbId > 0)) { 
    585        $LOG->info("Saving Url History to Database."); 
    586        insert_url_history(agent_state => $globalAgentState); 
    587        HoneyClient::DB::Client->update( 
    588            '-set' => { 
    589                status => $HoneyClient::DB::Client::STATUS_CLEAN, 
    590            }, 
    591            '-where' => { 
    592                id => $clientDbId, 
    593            
    594        ); 
    595    
     583    #XXX: Insert Urls. To be moved eventually. 
     584    #if ($DB_ENABLE && ($clientDbId > 0)) { 
     585        $LOG->info("Saving Url History to Database."); 
     586        insert_url_history(agent_state => $globalAgentState); 
     587        HoneyClient::DB::Client->update( 
     588            '-set' => { 
     589                status => $HoneyClient::DB::Client::STATUS_CLEAN, 
     590            }, 
     591            '-where' => { 
     592                id => $clientDbId, 
     593           
     594        ); 
     595   
    596596 
    597597    # XXX: There is an issue where if we try to quit but are in the 
     
    708708    # Open up the firewall initially, to allow the Agent to do an SVN update. 
    709709    #FIXME: This needs to be more limited for the multi-vm case, and should probably  
    710    # just be included by making the default rules require no action 
    711    $stubFW->allowAllTraffic(); 
     710    # just be included by making the default rules require no action 
     711    $stubFW->allowAllTraffic(); 
    712712 
    713713# XXX: Remove these, eventually. 
     
    957957                    # Insert Compromised Fingerprint into DB. 
    958958                    if ($DB_ENABLE && ($clientDbId > 0)) { 
    959                        #XXX: This should occurr as a resource is accessed and will be moved. Also should be in Browser code. 
    960                        # Put Honeyclient Link History in database. 
    961                        $LOG->info("Saving Url History to Database."); 
    962                        $args{'agent_state'} = insert_url_history(agent_state => $args{'agent_state'}); 
     959                        #XXX: This should occurr as a resource is accessed and will be moved. Also should be in Browser code. 
     960                        # Put Honeyclient Link History in database. 
     961                        $LOG->info("Saving Url History to Database."); 
     962                        $args{'agent_state'} = insert_url_history(agent_state => $args{'agent_state'}); 
    963963                        $globalAgentState = $args{'agent_state'}; 
    964964 
    965                        # Remove the compromise time from the fingerprint. This is to be added to the Client Object 
    966                        delete $fingerprint->{last_resource}; 
    967                        my $compromise_time = HoneyClient::DB::Time->new(delete($fingerprint->{'compromise_time'})); 
     965                        # Remove the compromise time from the fingerprint. This is to be added to the Client Object 
     966                        delete $fingerprint->{last_resource}; 
     967                        my $compromise_time = HoneyClient::DB::Time->new(delete($fingerprint->{'compromise_time'})); 
    968968                        $LOG->info("Inserting Fingerprint Into Database."); 
    969969                        my $fp = HoneyClient::DB::Fingerprint->new($fingerprint); 
     
    10701070    my %args = @_; 
    10711071 
    1072    my $agent_state = thaw(decode_base64($args{'agent_state'})); 
    1073  
    1074    my $state; 
    1075    my $agent_driver; 
    1076    foreach my $driver (keys %$agent_state) { 
    1077        if ($agent_state->{$driver}) { 
    1078            $state = $agent_state->{$driver}; 
     1072    my $agent_state = thaw(decode_base64($args{'agent_state'})); 
     1073 
     1074    my $state; 
     1075    my $agent_driver; 
     1076    foreach my $driver (keys %$agent_state) { 
     1077        if ($agent_state->{$driver}) { 
     1078            $state = $agent_state->{$driver}; 
    10791079            $agent_driver = $driver; 
    1080            last; 
    1081        
    1082    
    1083  
    1084    foreach my $i (keys %link_categories) { 
    1085        my @url_history; 
    1086        while (my ($url,$url_time) = each(%{$state->{$link_categories{$i}}})) { 
     1080            last; 
     1081       
     1082   
     1083 
     1084    foreach my $i (keys %link_categories) { 
     1085        my @url_history; 
     1086        while (my ($url,$url_time) = each(%{$state->{$link_categories{$i}}})) { 
    10871087            # Don't insert already inserted URLs into DB. 
    1088            if (!$url_time) { 
     1088            if (!$url_time) { 
    10891089                next; 
    10901090            } 
    1091            # Some ignored links are the result of invalid Urls. Preprocess to avoid errors. 
    1092            my $url_obj = HoneyClient::DB::Url->new($url); 
    1093            next if (!$url_obj); 
    1094            my $u = HoneyClient::DB::Url::History->new({ 
    1095                url => $url_obj, 
    1096                visited => $url_time, 
    1097                status => $i, 
    1098            }); 
    1099            push @url_history,$u; 
     1091            # Some ignored links are the result of invalid Urls. Preprocess to avoid errors. 
     1092            my $url_obj = HoneyClient::DB::Url->new($url); 
     1093            next if (!$url_obj); 
     1094            my $u = HoneyClient::DB::Url::History->new({ 
     1095                url => $url_obj, 
     1096                visited => $url_time, 
     1097                status => $i, 
     1098            }); 
     1099            push @url_history,$u; 
    11001100            # For all sucessfully inserted URLs, set their timestamps to 0. 
    1101            $agent_state->{$agent_driver}->{$link_categories{$i}}->{$url} = 0; 
    1102        
     1101            $agent_state->{$agent_driver}->{$link_categories{$i}}->{$url} = 0; 
     1102       
    11031103 
    11041104# Update the History item to reflect the Client it belongs to. 
    11051105# get_col_name is used to get the foreign key column associated w/ the url_history array 
    1106        HoneyClient::DB::Client->append_children( 
    1107            '-parent_id' => $clientDbId, 
    1108            'url_history' => \@url_history, 
    1109        ); 
    1110        $LOG->info("Inserted Urls of type ".$link_categories{$i}); 
    1111    
    1112  
    1113    return encode_base64(nfreeze($agent_state)); 
     1106        HoneyClient::DB::Client->append_children( 
     1107            '-parent_id' => $clientDbId, 
     1108            'url_history' => \@url_history, 
     1109        ); 
     1110        $LOG->info("Inserted Urls of type ".$link_categories{$i}); 
     1111   
     1112 
     1113    return encode_base64(nfreeze($agent_state)); 
    11141114} 
    11151115 
     
    11201120    $LOG->info("Attempting to Register Client $vmName."); 
    11211121 
    1122    # Register the VM with the DB 
    1123    my $clientObj = HoneyClient::DB::Client->new({ 
    1124        system_id => $vmName, 
    1125        status => $HoneyClient::DB::Client::STATUS_RUNNING, 
    1126        # TODO: Collect host,application, and config through automation/config files 
    1127        host => { 
    1128            organization => 'MITRE', 
    1129            host_name => Sys::Hostname::Long::hostname_long, 
    1130            ip_address => Sys::HostIP->ip, 
    1131        }, 
    1132        client_app => { 
    1133            manufacturer => 'Microsoft', 
    1134            name => 'Internet Explorer', 
    1135            major_version => '6', 
    1136        }, 
    1137        config => { 
    1138            name => 'Default Windows XP SP2', 
    1139            os_name => 'Microsoft Windows', 
    1140            os_version => 'XP Professional', 
    1141            os_patches => [{ 
    1142                name => 'Service Pack 2', 
    1143            }], 
    1144        }, 
    1145        start_time => $dt->ymd('-').'T'.$dt->hms(':'), 
    1146    }); 
    1147    return $clientObj->insert(); 
     1122    # Register the VM with the DB 
     1123    my $clientObj = HoneyClient::DB::Client->new({ 
     1124        system_id => $vmName, 
     1125        status => $HoneyClient::DB::Client::STATUS_RUNNING, 
     1126        # TODO: Collect host,application, and config through automation/config files 
     1127        host => { 
     1128            organization => 'MITRE', 
     1129            host_name => Sys::Hostname::Long::hostname_long, 
     1130            ip_address => Sys::HostIP->ip, 
     1131        }, 
     1132        client_app => { 
     1133            manufacturer => 'Microsoft', 
     1134            name => 'Internet Explorer', 
     1135            major_version => '6', 
     1136        }, 
     1137        config => { 
     1138            name => 'Default Windows XP SP2', 
     1139            os_name => 'Microsoft Windows', 
     1140            os_version => 'XP Professional', 
     1141            os_patches => [{ 
     1142                name => 'Service Pack 2', 
     1143            }], 
     1144        }, 
     1145        start_time => $dt->ymd('-').'T'.$dt->hms(':'), 
     1146    }); 
     1147    return $clientObj->insert(); 
    11481148} 
    11491149