Changeset 1200

Show
Ignore:
Timestamp:
02/15/08 15:59:44 (6 months ago)
Author:
kindlund
Message:

Added initial logic to have the Manager fetch initial URLs from a centralized database.

Files:

Legend:

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

    r1140 r1200  
    755755 
    756756    # TODO XXX: Get URL list from database. 
     757    if ($DB_ENABLE && ($vm->database_id > 0)) { 
     758        $args{'agent_state'} = get_urls($vm, $args{'agent_state'}, $args{'driver'}); 
     759    } 
    757760 
    758761    # Call updateState() first, to seed initial data. 
     
    777780        # assume that the Agent's watchdog process will recover. 
    778781        eval { 
    779             print "Calling getState()...\n"; 
    780             $som = $stubAgent->getState(); 
    781             $args{'agent_state'} = $som->result(); 
     782            #print "Calling getState()...\n"; 
     783            #$som = $stubAgent->getState(); 
     784            #$args{'agent_state'} = $som->result(); 
    782785 
    783786            # XXX: Delete this, eventually. 
    784             $globalAgentState = $args{'agent_state'}; 
     787            #$globalAgentState = $args{'agent_state'}; 
     788            #print "Result:\n"; 
     789            #print Dumper(thaw(decode_base64($globalAgentState))); 
    785790 
    786791            print "Calling getStatus()...\n"; 
     
    794799            #print Dumper($ret); 
    795800 
     801            # Extract current agent state. 
     802            my @driverNames = keys(%{$ret}); 
     803            my $state = {}; 
     804            foreach my $driverName (@driverNames) { 
     805                $state->{$driverName} = $ret->{$driverName}->{'state'}; 
     806            } 
     807            $args{'agent_state'} = encode_base64(nfreeze($state)); 
     808            $globalAgentState = $args{'agent_state'}; 
     809            print "GlobalAgentState:\n"; 
     810            print Dumper(thaw(decode_base64($globalAgentState))); 
     811 
    796812            # Check to see if Agent::run() thread has stopped 
    797813            # and that a compromise was detected. 
     
    850866                        $LOG->info("Database Insert Successful."); 
    851867                    } 
     868                    # The VM should be suspended, at this point.  Clear out the global DB ID, so 
     869                    # that our cleanup code doesn't re-mark the VM as suspended. 
     870                    $clientDbId = 0; 
     871 
    852872                    # Make sure VM is suspended. 
    853873                    $vm = undef; 
     
    9921012} 
    9931013 
     1014sub get_urls { 
     1015    my $vm = shift; 
     1016    my $agent_state = shift; 
     1017    my $driver = shift; 
     1018 
     1019    # Decode and thaw the initial agent state. 
     1020    my $state = thaw(decode_base64($agent_state)); 
     1021 
     1022    # XXX: We hardcode the value of 10 URLs to request; this will change, eventually. 
     1023    my $queue_url_list = {}; 
     1024    $LOG->info("Retrieving new URLs from database."); 
     1025    $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(10, $vm->database_id); 
     1026    my $remoteLinksExist = scalar(%{$queue_url_list}); 
     1027 
     1028    # While we have no local URLs and no URLs from the database, re-query the database. 
     1029    while (!defined($state->{$driver}->{next_link_to_visit}) && 
     1030           !$remoteLinksExist) { 
     1031 
     1032        # XXX: Hardcoded timeout. 
     1033        sleep (2); 
     1034        $LOG->info("Retrieving new URLs from database."); 
     1035        $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(10, $vm->database_id); 
     1036        $remoteLinksExist = scalar(%{$queue_url_list}); 
     1037    } 
     1038 
     1039    # If we do have URLs from the database, then merge them into the agent state. 
     1040    # Note: Priorities specified in the database take precedent over any URLs specified locally. 
     1041    if ($remoteLinksExist) { 
     1042        $state->{$driver}->{links_to_visit} = { %{$state->{$driver}->{links_to_visit}},  
     1043                                                %{$queue_url_list} }; 
     1044        $agent_state = encode_base64(nfreeze($state)); 
     1045    } 
     1046 
     1047    return $agent_state; 
     1048} 
     1049 
    9941050####################################################################### 
    9951051