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

« back to all changes in this revision

Viewing changes to src/ec_dissector_mountd.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 mountd (NFS) -- RPC
 
3
 
 
4
    Copyright (C) 2001  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
 
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
    $Id: ec_dissector_mountd.c,v 1.3 2002/04/12 15:59:15 alor Exp $
 
21
*/
 
22
 
 
23
#include "include/ec_main.h"
 
24
 
 
25
#include "include/ec_dissector.h"
 
26
#include "include/ec_inet_structures.h"
 
27
 
 
28
#define XID_LEN 1024
 
29
 
 
30
int SID_MAP_TCP[XID_LEN];
 
31
int versions_tcp[XID_LEN];
 
32
char *REM_DIRS_TCP[XID_LEN];
 
33
 
 
34
int SID_MAP_UDP[XID_LEN];
 
35
int versions_udp[XID_LEN];
 
36
char *REM_DIRS_UDP[XID_LEN];
 
37
 
 
38
// protos....
 
39
 
 
40
FUNC_DISSECTOR(Dissector_mountdUDP);
 
41
FUNC_DISSECTOR(Dissector_mountdTCP);
 
42
 
 
43
// ==========================================================
 
44
 
 
45
 
 
46
FUNC_DISSECTOR(Dissector_mountdTCP)
 
47
{
 
48
   TCP_header *tcp;
 
49
   u_char *buf;
 
50
   int XID,type;
 
51
 
 
52
   tcp = (TCP_header *) data;
 
53
   buf = (char *)((int)tcp + tcp->doff * 4);
 
54
 
 
55
   if (data_to_ettercap->datalen==0) return (0);
 
56
 
 
57
   type    = *(int *)(buf+8);
 
58
   XID     = *(int *)(buf+4);
 
59
 
 
60
   sprintf(data_to_ettercap->type, "mountd");
 
61
 
 
62
   if (ntohs(tcp->source) != SERV_PORT)
 
63
   {
 
64
      int program,proc,version;
 
65
 
 
66
      program = *(int *)(buf + 16);
 
67
      proc    = *(int *)(buf + 24);
 
68
      version = *(int *)(buf + 20);
 
69
 
 
70
      // CALL
 
71
      if (type == 0 && ntohl(program) == 100005 && ntohl(proc) == 1 )
 
72
      {
 
73
         int len, i, cred;
 
74
 
 
75
         DEBUG_MSG("\tDissector_mountd TCP - CALL");
 
76
 
 
77
         for (i=0; i<XID_LEN; i++)
 
78
            if (!SID_MAP_TCP[i]) break;
 
79
 
 
80
         if (i==XID_LEN) return (0);
 
81
 
 
82
         SID_MAP_TCP[i] = XID;
 
83
         cred = *(int *)(buf + 32);
 
84
         cred = ntohl(cred);
 
85
         len = *(int *)(buf+44+cred);
 
86
         if (ntohl(len)>100)
 
87
         {
 
88
            SID_MAP_TCP[i] = 0;
 
89
            return 0;
 
90
         }
 
91
         REM_DIRS_TCP[i] = calloc(1, ntohl(len)+1);
 
92
         memcpy(REM_DIRS_TCP[i], buf+48+cred, ntohl(len));
 
93
         versions_tcp[i]=version;
 
94
      }
 
95
      return (0);
 
96
   }
 
97
 
 
98
   // REPLY
 
99
   if ( ntohl(type) == 1 )
 
100
   {
 
101
      int i, len,result,offs;
 
102
      char *outstr;
 
103
 
 
104
      DEBUG_MSG("\tDissector_mountd TCP - REPLY");
 
105
 
 
106
      for (i=0; i<XID_LEN; i++)
 
107
         if (SID_MAP_TCP[i]==XID) break;
 
108
 
 
109
      if (i==XID_LEN) return (0);
 
110
 
 
111
      SID_MAP_TCP[i]=0;
 
112
 
 
113
      result = *(int *)(buf+28);
 
114
      if (result)
 
115
      {
 
116
         free(REM_DIRS_TCP[i]);
 
117
         return (0); //Unautorized
 
118
      }
 
119
 
 
120
      outstr = data_to_ettercap->info;
 
121
      snprintf(outstr, sizeof(data_to_ettercap->info), "NFS SERVER: %s  FHANDLE: %s [", data_to_ettercap->source_ip, REM_DIRS_TCP[i]);
 
122
 
 
123
      free(REM_DIRS_TCP[i]);
 
124
 
 
125
      if (ntohl(versions_tcp[i])==3)
 
126
      {
 
127
         len = *(int *)(buf+32);
 
128
         len = ntohl(len);
 
129
         if (len>64) len=64;
 
130
         offs=36;
 
131
      }
 
132
      else
 
133
      {
 
134
         len = 32;
 
135
         offs= 32;
 
136
      }
 
137
 
 
138
      for (i=0; i<len-1; i++)
 
139
         snprintf(outstr, sizeof(data_to_ettercap->info), "%s%.2x ", outstr, buf[i+offs]);
 
140
 
 
141
      snprintf(outstr, sizeof(data_to_ettercap->info), "%s%.2x]\n", outstr, buf[i+offs]);
 
142
 
 
143
      sprintf(data_to_ettercap->user, "\n");
 
144
      sprintf(data_to_ettercap->pass, "\n");
 
145
   }
 
146
   return 0;
 
147
}
 
148
 
 
149
 
 
150
 
 
151
FUNC_DISSECTOR(Dissector_mountdUDP)
 
152
{
 
153
   UDP_header *udp;
 
154
   u_char *buf;
 
155
   int XID,type;
 
156
 
 
157
   udp = (UDP_header *) data;
 
158
   buf = data + UDP_HEADER;
 
159
 
 
160
   type    = *(int *)(buf+4);
 
161
   XID     = *(int *)(buf);
 
162
 
 
163
   sprintf(data_to_ettercap->type,"mountd");
 
164
 
 
165
   if (ntohs(udp->source) != SERV_PORT)
 
166
   {
 
167
      int program,proc,version;
 
168
 
 
169
      program = *(int *)(buf+12);
 
170
      proc    = *(int *)(buf+20);
 
171
      version = *(int *)(buf+16);
 
172
 
 
173
      // CALL
 
174
      if (type == 0 && ntohl(program) == 100005 && ntohl(proc) == 1 )
 
175
      {
 
176
         int len, i, cred;
 
177
 
 
178
         DEBUG_MSG("\tDissector_mountd UDP - CALL");
 
179
 
 
180
         for (i=0; i<XID_LEN; i++)
 
181
            if (!SID_MAP_UDP[i]) break;
 
182
 
 
183
         if (i==XID_LEN) return (0);
 
184
 
 
185
         SID_MAP_UDP[i] = XID;
 
186
         cred = *(int *)(buf+28);
 
187
         cred = ntohl(cred);
 
188
         len = *(int *)(buf+40+cred);
 
189
         if (ntohl(len)>100)
 
190
         {
 
191
            SID_MAP_UDP[i] = 0;
 
192
            return 0;
 
193
         }
 
194
         REM_DIRS_UDP[i] = calloc(1, ntohl(len)+1);
 
195
         memcpy(REM_DIRS_UDP[i], buf+44+cred, ntohl(len));
 
196
         versions_udp[i] = version;
 
197
      }
 
198
      return (0);
 
199
   }
 
200
 
 
201
   // REPLY
 
202
   if ( ntohl(type) == 1 )
 
203
   {
 
204
      int i, len, offs,result;
 
205
      char *outstr;
 
206
 
 
207
      DEBUG_MSG("\tDissector_mountd UCP - REPLY");
 
208
 
 
209
      for (i=0; i<XID_LEN; i++)
 
210
         if (SID_MAP_UDP[i]==XID) break;
 
211
 
 
212
      if (i==XID_LEN) return (0);
 
213
 
 
214
      SID_MAP_UDP[i]=0;
 
215
 
 
216
      result = *(int *)(buf+24);
 
217
      if (result)
 
218
      {
 
219
         free(REM_DIRS_UDP[i]);
 
220
         return (0); //Unautorized
 
221
      }
 
222
 
 
223
      outstr = data_to_ettercap->info;
 
224
      snprintf(outstr, sizeof(data_to_ettercap->info), "NFS SERVER: %s  FHANDLE: %s [", data_to_ettercap->source_ip, REM_DIRS_UDP[i]);
 
225
 
 
226
      free(REM_DIRS_UDP[i]);
 
227
 
 
228
      if (ntohl(versions_udp[i]) == 3)
 
229
      {
 
230
         len = *(int *)(buf+28);
 
231
         len = ntohl(len);
 
232
         if (len>64) len = 64;
 
233
         offs = 32;
 
234
      }
 
235
      else
 
236
      {
 
237
         len = 32;
 
238
         offs = 28;
 
239
      }
 
240
 
 
241
      for (i=0; i<len-1; i++)
 
242
         snprintf(outstr, sizeof(data_to_ettercap->info), "%s%.2x ", outstr, buf[i+offs]);
 
243
 
 
244
      snprintf(outstr, sizeof(data_to_ettercap->info), "%s%.2x]\n", outstr, buf[i+offs]);
 
245
 
 
246
      sprintf(data_to_ettercap->user, "\n");
 
247
      sprintf(data_to_ettercap->pass, "\n");
 
248
   }
 
249
   return 0;
 
250
}
 
251
 
 
252
// vim:ts=3:expandtab
 
253