"Fossies" - the Fresh Open Source Software Archive

Member "ettercap-0.8.3.1/src/ec_main.c" (1 Aug 2020, 5924 Bytes) of package /linux/privat/ettercap-0.8.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ec_main.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.8.3_vs_0.8.3.1.

    1 /*
    2     ettercap -- everything starts from this file... 
    3 
    4     Copyright (C) ALoR & NaGA
    5 
    6     This program is free software; you can redistribute it and/or modify
    7     it under the terms of the GNU General Public License as published by
    8     the Free Software Foundation; either version 2 of the License, or
    9     (at your option) any later version.
   10 
   11     This program is distributed in the hope that it will be useful,
   12     but WITHOUT ANY WARRANTY; without even the implied warranty of
   13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14     GNU General Public License for more details.
   15 
   16     You should have received a copy of the GNU General Public License
   17     along with this program; if not, write to the Free Software
   18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   19 
   20 */
   21 
   22 #include <ec.h>
   23 #include <ec_version.h>
   24 #include <ec_globals.h>
   25 #include <ec_conf.h>
   26 #include <ec_libettercap.h>
   27 #include <ec_network.h>
   28 #include <ec_signals.h>
   29 #include <ec_parser.h>
   30 #include <ec_threads.h>
   31 #include <ec_capture.h>
   32 #include <ec_dispatcher.h>
   33 #include <ec_send.h>
   34 #include <ec_plugins.h>
   35 #include <ec_format.h>
   36 #include <ec_fingerprint.h>
   37 #include <ec_geoip.h>
   38 #include <ec_manuf.h>
   39 #include <ec_services.h>
   40 #include <ec_http.h>
   41 #include <ec_scan.h>
   42 #include <ec_ui.h>
   43 #include <ec_mitm.h>
   44 #include <ec_sslwrap.h>
   45 #include <ec_utils.h>
   46 #ifdef HAVE_EC_LUA
   47 #include <ec_lua.h>
   48 #endif
   49 
   50 /* global vars */
   51 
   52 /* protos */
   53 
   54 /*******************************************/
   55 
   56 int main(int argc, char *argv[])
   57 {
   58    /*
   59     * Alloc the global structures
   60     * We can access these structs via the macro in ec_globals.h
   61     */
   62         
   63    libettercap_init(PROGRAM, EC_VERSION);
   64    libettercap_load_conf();
   65 
   66    DEBUG_MSG("main -- here we go !!");
   67 
   68    /* initialize the filter mutex */
   69    filter_init_mutex();
   70    
   71    /* register the main thread as "init" */
   72    ec_thread_register(ec_thread_getpid(NULL), "init", "initialization phase");
   73    
   74    /* activate the signal handler */
   75    signal_handler();
   76    
   77 #ifdef OS_GNU
   78   fprintf(stdout,"%s is still not fully supported in this OS because of missing live capture support.", EC_GBL_PROGRAM);
   79 #endif
   80    /* ettercap copyright */
   81    fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", 
   82          EC_GBL_PROGRAM, EC_GBL_VERSION, EC_COPYRIGHT, EC_AUTHORS);
   83    
   84    /* getopt related parsing...  */
   85    parse_options(argc, argv);
   86 
   87    /* 
   88     * get the list of available interfaces 
   89     * 
   90     * this function will not return if the -I option was
   91     * specified on command line. it will instead print the
   92     * list and exit
   93     */
   94    capture_getifs();
   95    
   96    /* initialize the user interface */
   97    libettercap_ui_init();
   98    
   99    /* initialize the network subsystem */
  100    network_init();
  101    
  102 #ifdef HAVE_GEOIP
  103    /* initialize the GeoIP API */
  104    if (EC_GBL_CONF->geoip_support_enable)
  105       geoip_init();
  106 #endif
  107 
  108    /* 
  109     * always disable the kernel ip forwarding (except when reading from file).
  110     * the forwarding will be done by ettercap.
  111     */
  112    if(!EC_GBL_OPTIONS->read && !EC_GBL_OPTIONS->unoffensive && !EC_GBL_OPTIONS->only_mitm) {
  113 #ifdef WITH_IPV6
  114       /*
  115        * disable_ipv6_forward() registers the restore function with atexit() 
  116        * which relies on the regain_privs_atexit() registered in 
  117        * disable_ip_forward() below. 
  118        * So the call of disable_ipv6_forward() must NOT be after the call of 
  119        * disable_ip_forward().
  120        */
  121       disable_ipv6_forward();
  122 #endif
  123       disable_ip_forward();
  124     
  125 #ifdef OS_LINUX
  126       if (!EC_GBL_OPTIONS->read)
  127         disable_interface_offload();
  128 #endif
  129       /* binds ports and set redirect for ssl wrapper */
  130       if(EC_GBL_SNIFF->type == SM_UNIFIED && EC_GBL_OPTIONS->ssl_mitm)
  131          ssl_wrap_init();
  132 
  133 #if defined OS_LINUX && defined WITH_IPV6
  134       /* check if privacy extensions are enabled */
  135       check_tempaddr(EC_GBL_OPTIONS->iface);
  136 #endif
  137    }
  138    
  139    /* 
  140     * drop root privileges 
  141     * we have already opened the sockets with high privileges
  142     * we don't need anymore root privs.
  143     */
  144    drop_privs();
  145 
  146 /***** !! NO PRIVS AFTER THIS POINT !! *****/
  147 
  148    /* load all the plugins */
  149    plugin_load_all();
  150 
  151    /* print how many dissectors were loaded */
  152    conf_dissectors();
  153    
  154    /* load the mac-fingerprints */
  155    manuf_init();
  156 
  157    /* load the tcp-fingerprints */
  158    fingerprint_init();
  159    
  160    /* load the services names */
  161    services_init();
  162    
  163    /* load http known fileds for user/pass */
  164    http_fields_init();
  165 
  166 #ifdef HAVE_EC_LUA
  167    /* Initialize lua */
  168    ec_lua_init();
  169 #endif
  170 
  171    /* set the encoding for the UTF-8 visualization */
  172    set_utf8_encoding((u_char*)EC_GBL_CONF->utf8_encoding);
  173   
  174    /* print all the buffered messages */
  175    if (EC_GBL_UI->type == UI_TEXT)
  176       USER_MSG("\n");
  177    
  178    ui_msg_flush(MSG_ALL);
  179 
  180 /**** INITIALIZATION PHASE TERMINATED ****/
  181    
  182    /* 
  183     * we are interested only in the mitm attack i
  184     * if entered, this function will not return...
  185     */
  186    if (EC_GBL_OPTIONS->only_mitm)
  187       only_mitm();
  188    
  189    /* create the dispatcher thread */
  190    ec_thread_new("top_half", "dispatching module", &top_half, NULL);
  191 
  192    /* this thread becomes the UI then displays it */
  193    ec_thread_register(ec_thread_getpid(NULL), EC_GBL_PROGRAM, "the user interface");
  194 
  195    /* start unified sniffing for curses and GTK at startup */
  196    if ((EC_GBL_UI->type == UI_CURSES || EC_GBL_UI->type == UI_GTK) &&
  197          EC_GBL_CONF->sniffing_at_startup)
  198       EXECUTE(EC_GBL_SNIFF->start);
  199 
  200    /* start the actual user interface */
  201    libettercap_ui_start();
  202 
  203 /******************************************** 
  204  * reached only when the UI is shutted down 
  205  ********************************************/
  206 
  207    /* Call all the proper stop methods to ensure
  208     * that no matter what UI was selected, everything is 
  209     * turned off gracefully */
  210    clean_exit(0);
  211 
  212    return 0; //Never reaches here
  213 }
  214 
  215 /* EOF */
  216 
  217 // vim:ts=3:expandtab
  218