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

« back to all changes in this revision

Viewing changes to plugins/hunter/hunter.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
    hunter -- ettercap plugin -- Promisc Finder
 
3
 
 
4
    Copyright (C) 2003  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
*/
 
21
 
 
22
#ifdef CYGWIN
 
23
   #include <windows.h>
 
24
   #include <winsock2.h> 
 
25
#else
 
26
   #include <sys/time.h>
 
27
   #include <unistd.h>
 
28
#endif
 
29
 
 
30
#include <stdlib.h>
 
31
 
 
32
#include "../../src/include/ec_main.h"
 
33
#include "../../src/include/ec_version.h"
 
34
#include "../../src/include/ec_plugins.h"
 
35
#include "../../src/include/ec_inet_structures.h"
 
36
#include "../../src/include/ec_inet.h"
 
37
#include "../../src/include/ec_inet_forge.h"
 
38
 
 
39
 
 
40
// protos...
 
41
 
 
42
int Plugin_Init(void *);
 
43
int Plugin_Fini(void *);
 
44
int hunter(void *dummy);
 
45
 
 
46
// plugin operation
 
47
 
 
48
struct plugin_ops hunter_ops = {
 
49
   ettercap_version: VERSION,
 
50
   plug_info:        "Search promisc NICs",
 
51
   plug_version:     10,
 
52
   plug_type:        PT_EXT,
 
53
   hook_point:       HOOK_NONE,
 
54
   hook_function:    &hunter,
 
55
};
 
56
 
 
57
struct recv_packet recvpck;
 
58
u_long sock, MyIP;
 
59
char   MyMAC[6]; 
 
60
 
 
61
//==================================
 
62
 
 
63
int Plugin_Init(void *params)
 
64
{
 
65
   return Plugin_Register(params, &hunter_ops);
 
66
}
 
67
 
 
68
int Plugin_Fini(void *params)
 
69
{
 
70
   return 0;
 
71
}
 
72
 
 
73
void SendProbes(char *DestMAC)
 
74
{
 
75
   char *to_send;
 
76
   int i;
 
77
 
 
78
   to_send = recvpck.aligned;
 
79
   to_send += Inet_Forge_ethernet(to_send, MyMAC, DestMAC, ETH_P_ARP);
 
80
      
 
81
   if (!strcmp(Host_Dest.ip, "") )
 
82
   {    
 
83
      for (i=1; i< number_of_hosts_in_lan; i++)
 
84
      {
 
85
          usleep(1500);
 
86
          Inet_Forge_arp(to_send, ARPOP_REQUEST, MyMAC, MyIP, DestMAC, inet_addr(Host_In_LAN[i].ip));
 
87
          Inet_SendRawPacket(sock, recvpck.aligned, ETH_HEADER + ARP_HEADER);
 
88
      }
 
89
   }
 
90
   else
 
91
   {
 
92
      Inet_Forge_arp(to_send, ARPOP_REQUEST, MyMAC, MyIP, DestMAC, inet_addr(Host_Dest.ip));
 
93
      Inet_SendRawPacket(sock, recvpck.aligned, ETH_HEADER + ARP_HEADER);
 
94
   }    
 
95
}
 
96
 
 
97
// =================================
 
98
 
 
99
int hunter(void *dummy)
 
100
{
 
101
   int len=0, MTU, i, notrecv=1;
 
102
   u_long *Hosts;
 
103
   ETH_header *eth;
 
104
   ARP_header *arp;
 
105
 
 
106
   char OddMAC[6]={0xfd, 0xfd, 0x00, 0x00, 0x00, 0x00};
 
107
   char PassMAC[6]={0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
 
108
 
 
109
   TIME_DECLARE;
 
110
 
 
111
   Plugin_Output("Scanning: ");
 
112
   if (!strcmp(Host_Dest.ip, "") )
 
113
         Plugin_Output("ANY\n");
 
114
   else
 
115
         Plugin_Output("%s\n", Host_Dest.ip);
 
116
 
 
117
   sock = Inet_OpenRawSock(Options.netiface);
 
118
   Inet_GetIfaceInfo(Options.netiface, &MTU, MyMAC, &MyIP, NULL);
 
119
   Inet_SetNonBlock(sock);
 
120
 
 
121
   recvpck.buf = Inet_Forge_packet( MTU + ALIGN_ETH_TO_WORD);
 
122
   recvpck.aligned = recvpck.buf + ALIGN_ETH_TO_WORD;
 
123
 
 
124
   SendProbes(OddMAC); 
 
125
   
 
126
   Hosts=calloc(number_of_hosts_in_lan*2,sizeof(u_long));
 
127
   
 
128
   TIME_START;
 
129
   do
 
130
   {
 
131
       short pkttype;
 
132
       len = Inet_GetRawPacket(sock, recvpck.aligned, MTU, &pkttype);
 
133
       TIME_FINISH;
 
134
 
 
135
       if ( len > 0 && pkttype == PACKET_HOST )
 
136
       {
 
137
          eth = (ETH_header *) recvpck.aligned;
 
138
          if (eth->type == htons(ETH_P_ARP))
 
139
          {
 
140
             arp = (ARP_header *)(eth+1);
 
141
             
 
142
             if ( ntohs(arp->opcode) == ARPOP_REPLY )
 
143
                 for (i=0; i<number_of_hosts_in_lan*2-1; i++)
 
144
                 {
 
145
                     if (Hosts[i]==*(u_int32 *)arp->source_ip) break;
 
146
                     
 
147
                     if (!Hosts[i])
 
148
                     {
 
149
                         Hosts[i]=*(u_int32 *)arp->source_ip;
 
150
                         break;
 
151
                     }
 
152
                 }
 
153
          }
 
154
       }
 
155
       else
 
156
         if (len <=0 )
 
157
            usleep(1500);
 
158
 
 
159
   } while(TIME_ELAPSED < 3);
 
160
 
 
161
   SendProbes(PassMAC);
 
162
 
 
163
   Plugin_Output("\nMost probably sniffing NICs:");
 
164
   
 
165
   TIME_START;
 
166
   do
 
167
   {
 
168
       short pkttype;
 
169
       len = Inet_GetRawPacket(sock, recvpck.aligned, MTU, &pkttype);
 
170
       TIME_FINISH;
 
171
 
 
172
       if ( len > 0 && pkttype == PACKET_HOST )
 
173
       {
 
174
          eth = (ETH_header *) recvpck.aligned;
 
175
          if (eth->type == htons(ETH_P_ARP))
 
176
          {
 
177
             arp = (ARP_header *)(eth+1);
 
178
             
 
179
             if ( ntohs(arp->opcode) == ARPOP_REPLY )
 
180
                 for (i=0; i<number_of_hosts_in_lan*2-1; i++)
 
181
                 {
 
182
                     if (Hosts[i]==*(u_int32 *)arp->source_ip) break;
 
183
                     
 
184
                     if (!Hosts[i])
 
185
                     {
 
186
                         struct in_addr conv;
 
187
                         
 
188
                         conv.s_addr = *(u_int32 *)arp->source_ip;
 
189
                         Plugin_Output("\n- %s",   inet_ntoa(conv));
 
190
                         notrecv = 0;
 
191
                         break;
 
192
                     }
 
193
                 }
 
194
          }
 
195
       }
 
196
       else
 
197
         if (len <=0 )
 
198
            usleep(1500);
 
199
 
 
200
   } while(TIME_ELAPSED < 3);
 
201
   
 
202
   if (notrecv)
 
203
       Plugin_Output("\n- NONE \n");
 
204
   else    
 
205
       Plugin_Output("\n");
 
206
       
 
207
   Plugin_Output("\nLess probably sniffing NICs:");
 
208
   
 
209
   if (!Hosts[0])
 
210
       Plugin_Output("\n- NONE");
 
211
   else
 
212
   {
 
213
       struct in_addr conv;
 
214
       for (i=0; Hosts[i]; i++)
 
215
       {
 
216
           conv.s_addr = Hosts[i];
 
217
           Plugin_Output("\n- %s",   inet_ntoa(conv));
 
218
       }
 
219
   }
 
220
   Plugin_Output("\n");
 
221
   
 
222
   Inet_Forge_packet_destroy( recvpck.buf );
 
223
   free(Hosts);
 
224
   return 0;
 
225
}
 
226
 
 
227
/* EOF */