~ubuntu-branches/ubuntu/precise/ettercap/precise

« back to all changes in this revision

Viewing changes to src/ec_dissector_snmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Murat Demirten
  • Date: 2003-06-21 19:57:18 UTC
  • Revision ID: james.westby@ubuntu.com-20030621195718-qqbbfk18e1djchd9
Tags: upstream-0.6.b
ImportĀ upstreamĀ versionĀ 0.6.b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ettercap -- dissector for SNMP (community names) -- UDP 161
 
3
 
 
4
    Copyright (C) 2001  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
 
5
 
 
6
    Additional Copyright for this file: LnZ Lorenzo Porro <lporro@libero.it>
 
7
 
 
8
    This program is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 2 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License
 
19
    along with this program; if not, write to the Free Software
 
20
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
21
    USA.
 
22
 
 
23
    $Id: ec_dissector_snmp.c,v 1.8 2002/04/27 17:48:27 alor Exp $
 
24
*/
 
25
 
 
26
 
 
27
#include "include/ec_main.h"
 
28
 
 
29
#include "include/ec_dissector.h"
 
30
#include "include/ec_inet_structures.h"
 
31
 
 
32
/* Protocol version numbers */
 
33
/* for further implementation
 
34
#define SNMP_VERSION_1 0
 
35
#define SNMP_VERSION_2c 1
 
36
#define SNMP_VERSION_2u 2
 
37
#define SNMP_VERSION_3 3
 
38
 
 
39
static const value_string versions[] = {
 
40
 { SNMP_VERSION_1, "1" },
 
41
 { SNMP_VERSION_2c, "2C" },
 
42
 { SNMP_VERSION_2u, "2U" },
 
43
 { SNMP_VERSION_3, "3" },
 
44
 { 0, NULL },
 
45
};*/
 
46
//------------------------------------
 
47
 
 
48
// protos
 
49
 
 
50
FUNC_DISSECTOR(Dissector_snmp);
 
51
char *com_name(unsigned char *buf);
 
52
// --------------------
 
53
 
 
54
char *com_name(unsigned char *buf)
 
55
{
 
56
   unsigned int i=0, ssize=0;
 
57
   u_char *name;
 
58
 
 
59
   while(buf[i++] != '\x04' && i < 500);
 
60
 
 
61
   if(buf[i-1] == '\x04' && buf[i] != '\x00')
 
62
   {
 
63
      if(buf[i] == 129)
 
64
      {
 
65
         i++;
 
66
         ssize = buf[i];
 
67
      }
 
68
      else if(buf[i] == 130)
 
69
      {
 
70
         if(buf[i+1]=='\x01'&&buf[i+2]=='\x00')
 
71
         {
 
72
            i+=2;
 
73
            ssize = 256;
 
74
         }
 
75
         else
 
76
            return NULL;
 
77
      }
 
78
      else
 
79
         ssize = buf[i];
 
80
 
 
81
      if (ssize>100) return NULL; // Another little check
 
82
 
 
83
      name = (char *)calloc(ssize+5,1);
 
84
      memcpy(name, (char *)&buf[i+1], ssize);
 
85
      return name;
 
86
   }
 
87
 
 
88
   return NULL;
 
89
}
 
90
 
 
91
 
 
92
FUNC_DISSECTOR(Dissector_snmp)
 
93
{
 
94
   UDP_header *udp;
 
95
   u_char *payload;
 
96
   u_char *dname;
 
97
 
 
98
   udp = (UDP_header *) data;
 
99
   payload = (char *) ((int)udp + UDP_HEADER);
 
100
 
 
101
   DEBUG_MSG("\tDissector_SNMP");
 
102
 
 
103
   if (data_to_ettercap->datalen == 0) return 0; // No data...
 
104
 
 
105
   dname = com_name(payload);
 
106
 
 
107
   if (dname != NULL)
 
108
   {
 
109
      sprintf(data_to_ettercap->user, "\n");
 
110
      snprintf(data_to_ettercap->pass, sizeof(data_to_ettercap->pass), "%s\n", dname);
 
111
      free(dname);
 
112
   }
 
113
 
 
114
   return 0;
 
115
}
 
116
 
 
117
/* EOF */
 
118
 
 
119
// vim:ts=3:expandtab
 
120