| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include <ec.h> |
| 28 |
#include <ec_plugins.h> |
| 29 |
#include <ec_packet.h> |
| 30 |
#include <ec_hook.h> |
| 31 |
#include <ec_send.h> |
| 32 |
#include <ec_sleep.h> |
| 33 |
|
| 34 |
|
| 35 |
char flag_strange; |
| 36 |
|
| 37 |
|
| 38 |
static pthread_mutex_t scan_poisoner_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 39 |
|
| 40 |
|
| 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 |
|
| 49 |
|
| 50 |
struct plugin_ops scan_poisoner_ops = { |
| 51 |
|
| 52 |
.ettercap_version = EC_VERSION, |
| 53 |
|
| 54 |
.name = "scan_poisoner", |
| 55 |
|
| 56 |
.info = "Actively search other poisoners", |
| 57 |
|
| 58 |
.version = "1.0", |
| 59 |
|
| 60 |
.init = &scan_poisoner_init, |
| 61 |
|
| 62 |
.fini = &scan_poisoner_fini, |
| 63 |
|
| 64 |
.unload = &scan_poisoner_unload, |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
int plugin_load(void *handle) |
| 71 |
{ |
| 72 |
return plugin_register(handle, &scan_poisoner_ops); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
static int scan_poisoner_init(void *dummy) |
| 78 |
{ |
| 79 |
|
| 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 |
|
| 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 |
|
| 108 |
(void) dummy; |
| 109 |
|
| 110 |
return PLUGIN_UNLOADED; |
| 111 |
} |
| 112 |
|
| 113 |
static EC_THREAD_FUNC(scan_poisoner_thread) |
| 114 |
{ |
| 115 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 162 |
hook_add(HOOK_PACKET_ICMP, &parse_icmp); |
| 163 |
|
| 164 |
|
| 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 |
|
| 171 |
ec_usleep(SEC2MICRO(1)); |
| 172 |
|
| 173 |
|
| 174 |
hook_del(HOOK_PACKET_ICMP, &parse_icmp); |
| 175 |
|
| 176 |
|
| 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 |
|
| 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 |
|
| 196 |
sprintf(poisoner, "UNKNOWN"); |
| 197 |
|
| 198 |
|
| 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 |
|
| 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 |
|
| 214 |
|
| 215 |
|
| 216 |
|