Show
Ignore:
Timestamp:
04/09/08 15:47:11 (8 months ago)
Author:
kindlund
Message:

Merging simpler_agent branch into trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/bin/StartManager.pl

    r1008 r1499  
    1 #!perl -w -Ilib 
    2  
    3 # $Id$ 
     1#!perl -Ilib 
     2####################################################################### 
     3# Created on:  Apr 08, 2008 
     4# File:        StartManager.pl 
     5# Description: Start up script for manager-based operations. 
     6
     7# CVS: $Id$ 
     8
     9# @author knwang, kindlund 
     10
     11# Copyright (C) 2007-2008 The MITRE Corporation.  All rights reserved. 
     12
     13# This program is free software; you can redistribute it and/or 
     14# modify it under the terms of the GNU General Public License 
     15# as published by the Free Software Foundation, using version 2 
     16# of the License. 
     17#  
     18# This program is distributed in the hope that it will be useful, 
     19# but WITHOUT ANY WARRANTY; without even the implied warranty of 
     20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     21# GNU General Public License for more details. 
     22#  
     23# You should have received a copy of the GNU General Public License 
     24# along with this program; if not, write to the Free Software 
     25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
     26# 02110-1301, USA. 
     27
     28####################################################################### 
     29 
     30BEGIN { 
     31    our $VERSION = 1.02; 
     32
     33our ($VERSION); 
     34 
     35=pod 
     36 
     37=head1 NAME 
     38 
     39StartManager.pl - Perl script to start the Manager on the 
     40host system. 
     41 
     42=head1 SYNOPSIS 
     43 
     44 StartManager.pl [options] [http://www.google.com http://www.cnn.com ...] 
     45 
     46 Options: 
     47 --help               This help message. 
     48 --man                Print full man page. 
     49 --driver_name=       Name of driver to use. 
     50 --master_vm_config=  Absolute path to the master VM configuration to use. 
     51 --url_list=          File containing newline separated URLs to use. 
     52 
     53=head1 OPTIONS 
     54 
     55=over 4 
     56 
     57=item B<--help> 
     58 
     59Print a brief help message and exits. 
     60 
     61=item B<--driver_name=> 
     62 
     63Specifies the driver name to use.  If none is specified, the 
     64default will be used. 
     65 
     66=item B<--master_vm_config=> 
     67 
     68Specifies the master VM configuration file to use.  If none 
     69is specified, the default will be used. 
     70 
     71=item B<--url_list=> 
     72 
     73If specified, the newline separated URLs inside this file will 
     74be parsed and fed into the Manager upon startup. 
     75 
     76=back 
     77 
     78=head1 DESCRIPTION 
     79 
     80This program starts the Manager on the host system.  If URLs 
     81are specified on the command-line, the program will  
     82assign a base priority to each URL and feed them into the Manager 
     83for additional processing. 
     84 
     85This program will run until manually terminated by the user, by 
     86pressing CTRL-C. 
     87 
     88=head1 SEE ALSO 
     89 
     90L<http://www.honeyclient.org/trac> 
     91 
     92=head1 REPORTING BUGS 
     93 
     94L<http://www.honeyclient.org/trac/newticket> 
     95 
     96=head1 AUTHORS 
     97 
     98Darien Kindlund, E<lt>kindlund@mitre.orgE<gt> 
     99 
     100Kathy Wang, E<lt>knwang@mitre.orgE<gt> 
     101 
     102=head1 COPYRIGHT & LICENSE 
     103 
     104Copyright (C) 2007-2008 The MITRE Corporation.  All rights reserved. 
     105 
     106This program is free software; you can redistribute it and/or 
     107modify it under the terms of the GNU General Public License 
     108as published by the Free Software Foundation, using version 2 
     109of the License. 
     110  
     111This program is distributed in the hope that it will be useful, 
     112but WITHOUT ANY WARRANTY; without even the implied warranty of 
     113MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     114GNU General Public License for more details. 
     115  
     116You should have received a copy of the GNU General Public License 
     117along with this program; if not, write to the Free Software 
     118Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
     11902110-1301, USA. 
     120 
     121=cut 
    4122 
    5123use strict; 
     
    7125use Carp (); 
    8126 
     127# Include Pod Library 
     128use Pod::Usage; 
     129 
    9130# Include Dumper Library 
    10131use Data::Dumper; 
     
    17138 
    18139# Include Getopt Parser 
    19 use Getopt::Long
     140use Getopt::Long qw(:config auto_help ignore_case_always)
    20141 
    21142# Include utility access to global configuration. 
    22143use HoneyClient::Util::Config qw(getVar); 
    23144 
    24 # Include Manager Library 
    25 use HoneyClient::Manager; 
    26145 
    27146# Include Logging Library 
     
    34153# Namely, the initial set of URLs that they want the Agent to use. 
    35154 
    36 # Change to 'HoneyClient::Agent::Driver::Browser::IE' or 
    37 #           'HoneyClient::Agent::Driver::Browser::FF' 
    38 my $driver = undef; 
    39 my $config = undef; 
    40 my $maxrel = undef; 
    41 my $nexturl = ""; 
    42 my $urllist= ""; 
    43  
    44 # TODO: Need --help option, along with sanity checking. 
    45 # TODO: Also need a decent POD for this code. 
    46 GetOptions('driver=s'             => \$driver, 
    47            'master_vm_config=s'   => \$config, 
    48            'url_list=s'           => \$urllist, 
    49            'max_relative_links:i' => \$maxrel); 
    50  
    51 # Sanity Check.  Make sure $driver is set. 
    52 unless (defined($driver)) { 
    53     $driver = getVar(name      => "default_driver", 
    54                      namespace => "HoneyClient::Agent"); 
    55 
    56  
    57 # Sanity Check.  Make sure $max_relative_links is set. 
    58 unless (defined($maxrel)) { 
    59     $maxrel = getVar(name      => "max_relative_links_to_visit", 
    60                      namespace => "HoneyClient::Agent::Driver::Browser"); 
    61 
     155# Inputs. 
     156my $driver_name = undef; 
     157my $master_vm_config = undef; 
     158my $url_list= ""; 
     159 
     160GetOptions('driver_name=s'        => \$driver_name, 
     161           'master_vm_config=s'   => \$master_vm_config, 
     162           'url_list=s'           => \$url_list, 
     163           'man'                  => sub { pod2usage(-exitstatus => 0, -verbose => 2) }, 
     164           'version'              => sub { 
     165                                        print "MITRE HoneyClient Project (http://www.honeyclient.org)\n" . 
     166                                              "------------------------------------------------------\n" . 
     167                                              $0  . " (v" . $VERSION . ")\n"; 
     168                                        exit(0); 
     169                                     }) or pod2usage(2); 
    62170 
    63171# Go through the list of urls to create the array 
     
    66174my @urls; 
    67175push( @urls, @ARGV );  
    68 if( -e $urllist ){ 
    69     open URL, $urllist; 
     176if( -e $url_list ){ 
     177    open URL, $url_list; 
    70178    push(@urls, <URL>); 
    71179} 
    72180 
    73 # Get the first url from the list 
    74 # Create a hashtable in the form: url => 1 for links_to_visit  
    75 chomp @urls; 
    76 my $firsturl = shift @urls; 
    77 my %remaining_urls; 
     181# Get the base priority. 
     182my $priority = getVar(name      => "command_line_base_priority", 
     183                      namespace => "HoneyClient::Manager"); 
     184 
     185# Create a hashtable in the form: url => priority. 
     186my $work = {}; 
    78187foreach(@urls){ 
    79188    # We assign our initial list of URLs a priority of 1000, so that 
    80189    # they'll be (likely to be) selected first, before going to any other 
    81190    # external URLs found from subsequent drive operations. 
    82     $remaining_urls{$_} = 1000; 
     191    chomp; 
     192    if ($_ ne "") { 
     193        $work->{$_} = $priority; 
     194    } 
    83195} 
    84196 
    85 my $agentState = HoneyClient::Manager->run( 
    86                     driver           => $driver, 
    87                     master_vm_config => $config, 
    88                     agent_state      => encode_base64(nfreeze({ 
    89                         $driver => { 
    90                             next_link_to_visit => $firsturl, 
    91                             max_relative_links_to_visit => $maxrel, 
    92                             links_to_visit => \%remaining_urls, 
    93                          }, 
    94                     })),  
    95                  ); 
    96  
     197# Start the Manager. 
     198require HoneyClient::Manager; 
     199HoneyClient::Manager->run( 
     200    driver_name      => $driver_name, 
     201    master_vm_config => $master_vm_config, 
     202    work             => $work, 
     203);