ec_dissector.c
上传用户:nilegod
上传日期:2007-01-08
资源大小:220k
文件大小:4k
源码类别:

网络截获/分析

开发平台:

C/C++

  1. /*
  2.     ettercap -- the protocol dissector
  3.     Copyright (C) 2001  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.     GNU General Public License for more details.
  12.     You should have received a copy of the GNU General Public License
  13.     along with this program; if not, write to the Free Software
  14.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "include/ec_main.h"
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <errno.h>
  21. #include "include/ec_dissector.h"
  22. #include "include/ec_inet_structures.h"
  23. #include "include/ec_decodedata.h"
  24. #include "include/ec_error.h"
  25. #ifdef DEBUG
  26.    #include "include/ec_debug.h"
  27. #endif
  28. typedef struct {
  29.    char mode;
  30.    short proto;
  31.    short port;
  32.    int (*dissector)(u_char *, void *, int);
  33. } DISSECTOR;
  34. #define ALL_P -1
  35. static DISSECTOR Available_Dissectors[] = {
  36.    {MACBASED,  IPPROTO_TCP,    21, &Dissector_ftp},
  37. #ifdef HAVE_OPENSSL
  38.    {ARPBASED,  IPPROTO_TCP,    22, &Dissector_ssh},
  39. #endif
  40.    {MACBASED,  IPPROTO_TCP,    23, &Dissector_telnet},
  41.    {MACBASED,  IPPROTO_TCP,    80, &Dissector_http},
  42.    {MACBASED,  IPPROTO_TCP,   110, &Dissector_pop},
  43.    {MACBASED,  IPPROTO_TCP,   139, &Dissector_smb},
  44.    {MACBASED,  IPPROTO_TCP,   513, &Dissector_rlogin},
  45.    {MACBASED,  IPPROTO_TCP,  3306, &Dissector_mysql},
  46.    {MACBASED,  IPPROTO_UDP,  4000, &Dissector_icq},
  47.    //{MACBASED,  IPPROTO_TCP,  6666, &Dissector_irc}, // TODO
  48.    //{MACBASED,  IPPROTO_TCP,  6667, &Dissector_irc},
  49.    //{MACBASED,  IPPROTO_TCP,  6668, &Dissector_irc},
  50.    //{MACBASED,  IPPROTO_TCP,  6669, &Dissector_irc},
  51.    {MACBASED,  IPPROTO_UDP, ALL_P, &Dissector_icq},   // ICQv5 uses different server port
  52.                                           };
  53. // protos....
  54. void Dissector_Connections( char mode, short proto, u_char *data, void *data_to_ettercap, int Conn_Mode  );
  55. // -------------------------------------
  56. void Dissector_Connections( char mode, short proto, u_char *data, void *data_to_ettercap, int Conn_Mode )
  57. {
  58.    TCP_header *tcp;
  59.    UDP_header *udp;
  60.    DISSECTOR *ds;
  61.    switch(proto)
  62.    {
  63.       case IPPROTO_TCP:
  64.                         tcp = (TCP_header *) data;
  65.                         for( ds = Available_Dissectors; ds->port != 0; ds++)
  66.                         {
  67.                            if ( ds->proto == IPPROTO_TCP && mode <= ds->mode && (ds->port == ALL_P || ntohs(tcp->source) == ds->port || ntohs(tcp->dest) == ds->port) )
  68.                            {
  69.                               if (ds->mode == ARPBASED)
  70.                               {
  71.                                  if (active_dissector)      // activated by user in iterface_sniff
  72.                                     ds->dissector(data, data_to_ettercap, Conn_Mode);
  73.                               }
  74.                               else
  75.                                  ds->dissector(data, data_to_ettercap, Conn_Mode);
  76.                               break;
  77.                            }
  78.                         }
  79.                         break;
  80.       case IPPROTO_UDP:
  81.                         udp = (UDP_header *) data;
  82.                         for( ds = Available_Dissectors; ds->port != 0; ds++)
  83.                         {
  84.                            if ( ds->proto == IPPROTO_UDP && mode <= ds->mode && (ds->port == ALL_P || ntohs(udp->source) == ds->port || ntohs(udp->dest) == ds->port) )
  85.                            {
  86.                               if (ds->mode == ARPBASED)
  87.                               {
  88.                                  if (active_dissector)      // activated by user in iterface_sniff
  89.                                     ds->dissector(data, data_to_ettercap, Conn_Mode);
  90.                               }
  91.                               else
  92.                                  ds->dissector(data, data_to_ettercap, Conn_Mode);
  93.                               break;
  94.                            }
  95.                         }
  96.                         break;
  97.    }
  98. }
  99. /* EOF */