Debian Codegraph @

plug-ins/scan_poisoner/scan_poisoner.c

raw symbols SCIP
1 /*
2 scan_poisoner -- ettercap plugin -- Actively search other poisoners
3
4 It checks the hosts list, searching for eqaul mac addresses.
5 It also sends icmp packets to see if any ip-mac association has
6 changed.
7
8 Copyright (C) ALoR & NaGA
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26
27 #include <ec.h> /* required for global variables */
28 #include <ec_plugins.h> /* required for plugin ops */
29 #include <ec_packet.h>
30 #include <ec_hook.h>
31 #include <ec_send.h>
32 #include <ec_sleep.h>
33
34 /* globals */
35 char flag_strange;
36
37 /* mutexes */
38 static pthread_mutex_t scan_poisoner_mutex = PTHREAD_MUTEX_INITIALIZER;
39
40 /* protos */
41 int plugin_load(void *);
42 static int scan_poisoner_init(void *);
43 static int scan_poisoner_fini(void *);
44 static int scan_poisoner_unload(void *);
45 static EC_THREAD_FUNC(scan_poisoner_thread);
46 static void parse_icmp(struct packet_object *po);
47
48 /* plugin operations */
49
50 struct plugin_ops scan_poisoner_ops = {
51 /* ettercap version MUST be the global EC_VERSION */
52 .ettercap_version = EC_VERSION,
53 /* the name of the plugin */
54 .name = "scan_poisoner",
55 /* a short description of the plugin (max 50 chars) */
56 .info = "Actively search other poisoners",
57 /* the plugin version. */
58 .version = "1.0",
59 /* activation function */
60 .init = &scan_poisoner_init,
61 /* deactivation function */
62 .fini = &scan_poisoner_fini,
63 /* clean-up function */
64 .unload = &scan_poisoner_unload,
65 };
66
67 /**********************************************************/
68
69 /* this function is called on plugin load */
70 int plugin_load(void *handle)
71 {
72 return plugin_register(handle, &scan_poisoner_ops);
73 }
74
75 /******************* STANDARD FUNCTIONS *******************/
76
77 static int scan_poisoner_init(void *dummy)
78 {
79 /* variable not used */
80 (void) dummy;
81
82 ec_thread_new("scan_poisoner", "plugin scan_poisoner",
83 &scan_poisoner_thread, NULL);
84
85 return PLUGIN_RUNNING;
86 }
87
88 static int scan_poisoner_fini(void *dummy)
89 {
90 /* variable not used */
91 (void) dummy;
92
93 pthread_t pid;
94
95 pid = ec_thread_getpid("scan_poisoner");
96
97 if (!pthread_equal(pid, ec_thread_getpid(NULL)))
98 ec_thread_destroy(pid);
99
100 INSTANT_USER_MSG("scan_poisoner: plugin terminated...\n");
101
102 return PLUGIN_FINISHED;
103 }
104
105 static int scan_poisoner_unload(void *dummy)
106 {
107 /* variable not used */
108 (void) dummy;
109
110 return PLUGIN_UNLOADED;
111 }
112
113 static EC_THREAD_FUNC(scan_poisoner_thread)
114 {
115 /* variable not used */
116 (void) EC_THREAD_PARAM;
117
118
119 char tmp1[MAX_ASCII_ADDR_LEN];
120 char tmp2[MAX_ASCII_ADDR_LEN];
121 struct hosts_list *h1, *h2;
122
123 ec_thread_init();
124 PLUGIN_LOCK(scan_poisoner_mutex);
125
126 /* don't show packets while operating */
127 EC_GBL_OPTIONS->quiet = 1;
128
129 if (LIST_EMPTY(&EC_GBL_HOSTLIST)) {
130 INSTANT_USER_MSG("scan_poisoner: You have to build host-list to run this plugin.\n\n");
131 PLUGIN_UNLOCK(scan_poisoner_mutex);
132 plugin_kill_thread("scan_poisoner", "scan_poisoner");
133 return PLUGIN_FINISHED;
134 }
135
136 INSTANT_USER_MSG("scan_poisoner: Checking hosts list...\n");
137 flag_strange = 0;
138
139 /* Compares mac address of each host with any other */
140 LIST_FOREACH(h1, &EC_GBL_HOSTLIST, next)
141 for(h2=LIST_NEXT(h1,next); h2!=LIST_END(&EC_GBL_HOSTLIST); h2=LIST_NEXT(h2,next))
142 if (!memcmp(h1->mac, h2->mac, MEDIA_ADDR_LEN)) {
143 flag_strange = 1;
144 INSTANT_USER_MSG("scan_poisoner: - %s and %s have same MAC address\n", ip_addr_ntoa(&h1->ip, tmp1), ip_addr_ntoa(&h2->ip, tmp2));
145 }
146
147 if (!flag_strange)
148 INSTANT_USER_MSG("scan_poisoner: - Nothing strange\n");
149 flag_strange=0;
150
151 /* Can't continue in unoffensive */
152 if (EC_GBL_OPTIONS->unoffensive || EC_GBL_OPTIONS->read) {
153 INSTANT_USER_MSG("\nscan_poisoner: Can't make active test in UNOFFENSIVE mode.\n\n");
154 PLUGIN_UNLOCK(scan_poisoner_mutex);
155 plugin_kill_thread("scan_poisoner", "scan_poisoner");
156 return PLUGIN_FINISHED;
157 }
158
159 INSTANT_USER_MSG("\nscan_poisoner: Actively searching poisoners...\n");
160
161 /* Add the hook to collect ICMP replies from the victim */
162 hook_add(HOOK_PACKET_ICMP, &parse_icmp);
163
164 /* Send ICMP echo request to each target */
165 LIST_FOREACH(h1, &EC_GBL_HOSTLIST, next) {
166 send_L3_icmp_echo(&EC_GBL_IFACE->ip, &h1->ip);
167 ec_usleep(MILLI2MICRO(EC_GBL_CONF->arp_storm_delay));
168 }
169
170 /* wait for the response */
171 ec_usleep(SEC2MICRO(1));
172
173 /* remove the hook */
174 hook_del(HOOK_PACKET_ICMP, &parse_icmp);
175
176 /* We don't need mutex on it :) */
177 if (!flag_strange)
178 INSTANT_USER_MSG("scan_poisoner: - Nothing strange\n");
179
180 PLUGIN_UNLOCK(scan_poisoner_mutex);
181 plugin_kill_thread("scan_poisoner", "scan_poisoner");
182 return PLUGIN_FINISHED;
183 }
184
185
186 /*********************************************************/
187
188 /* Check icmp replies */
189 static void parse_icmp(struct packet_object *po)
190 {
191 struct hosts_list *h1, *h2;
192 char poisoner[MAX_ASCII_ADDR_LEN];
193 char tmp[MAX_ASCII_ADDR_LEN];
194
195 /* If the poisoner is not in the hosts list */
196 sprintf(poisoner, "UNKNOWN");
197
198 /* Check if the reply contains the correct ip/mac association */
199 LIST_FOREACH(h1, &EC_GBL_HOSTLIST, next) {
200 if (!ip_addr_cmp(&(po->L3.src), &h1->ip) && memcmp(po->L2.src, h1->mac, MEDIA_ADDR_LEN)) {
201 flag_strange = 1;
202 /* Check if the mac address of the poisoner is in the hosts list */
203 LIST_FOREACH(h2, &EC_GBL_HOSTLIST, next)
204 if (!memcmp(po->L2.src, h2->mac, MEDIA_ADDR_LEN))
205 ip_addr_ntoa(&h2->ip, poisoner);
206
207 INSTANT_USER_MSG("scan_poisoner: - %s is replying for %s\n", poisoner, ip_addr_ntoa(&h1->ip, tmp));
208 }
209 }
210 }
211
212
213 /* EOF */
214
215 // vim:ts=3:expandtab
216