00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "peercon.h"
00026 #include "util.h"
00027 #include "peerdef.h"
00028 #include <time.h>
00029 #include <stdlib.h>
00030 #include "spoof.h"
00031 #include "sniff.h"
00032 #include "debug.h"
00033
00034 errorcode wait_for_direct_conn(flag_t *check_flag) {
00035
00036
00037
00038
00039 CHECK_NOT_NULL(check_flag,ERROR_NULL_ARG_1);
00040
00041
00042 CHECK_FAILED(wait_for_flag(check_flag,FLAG_FAILED|FLAG_SUCCESS,
00043 DIRECT_CONNECTION_TIMEOUT),ERROR_1);
00044
00045 return SUCCESS;
00046 }
00047
00048 errorcode findDevice(char **dev) {
00049
00050
00051 char errbuf[PCAP_ERRBUF_SIZE];
00052
00053
00054 CHECK_NOT_NULL(dev,ERROR_NULL_ARG_1);
00055
00056
00057 *dev = pcap_lookupdev(errbuf);
00058
00059 if (*dev==NULL)
00060 return ERROR_NO_DEV_FOUND;
00061
00062 return SUCCESS;
00063 }
00064
00065 errorcode flood_syns(tcp_packet_info_t tcp_skeleton, char *device) {
00066
00067
00068 int i;
00069
00070
00071 CHECK_NOT_NULL(device,ERROR_NULL_ARG_1);
00072
00073
00074
00075
00076 tcp_skeleton.syn_flag = FLAG_SET;
00077 tcp_skeleton.ack_flag = FLAG_UNSET;
00078 tcp_skeleton.window = WINDOW_DEFAULT;
00079 tcp_skeleton.ack_num = 0;
00080
00081 DEBUG(DBG_BDAY,"DBAY:d_port = %u\n",DBG_PORT(tcp_skeleton.d_port));
00082
00083
00084 srand(time(NULL));
00085
00086 for (i=0;i<SYN_FLOOD_COUNT;i++) {
00087 tcp_skeleton.s_port = (port_t)rand();
00088 CHECK_FAILED(spoof(&tcp_skeleton,device,NULL,0,TTL_TOO_LOW),
00089 ERROR_CALLED_FUNCTION);
00090 }
00091
00092 return SUCCESS;
00093 }
00094
00095 errorcode start_find_synack(peer_conn_info_t *info) {
00096
00097
00098
00099
00100 CHECK_NOT_NULL(info,ERROR_NULL_ARG_1);
00101
00102
00103 info->bday.stop_synack_find = FLAG_UNSET;
00104 info->bday.find_synack_done = FLAG_UNSET;
00105 info->bday.port_set = FLAG_UNSET;
00106 if (pthread_create(&info->bday.find_synack_tid,NULL,
00107 run_find_synack,info)<0)
00108 return ERROR_PTHREAD_CREATE_FAILED;
00109
00110 return SUCCESS;
00111 }
00112
00113 void *run_find_synack(void* arg) {
00114
00115
00116 peer_conn_info_t *cast_arg;
00117 errorcode ret;
00118
00119
00120 CHECK_NOT_NULL(arg,(void*)ERROR_NULL_ARG_1);
00121
00122
00123 cast_arg = (peer_conn_info_t*) arg;
00124 ret = capture_flooded_synack(cast_arg);
00125
00126 cast_arg->bday.find_synack_done = FLAG_SET;
00127
00128 if (FAILED(ret))
00129 return (void*)ERROR_CALLED_FUNCTION;
00130 else
00131 return (void*)SUCCESS;
00132 }
00133
00134 errorcode wait_and_join_find_synack(peer_conn_info_t *info) {
00135
00136
00137 errorcode wait_ret;
00138 errorcode thread_ret;
00139
00140
00141 CHECK_NOT_NULL(info,ERROR_NULL_ARG_1);
00142
00143
00144 DBG_TIME("waiting for SYNACK flood listening thread to finished");
00145
00146 wait_ret = wait_for_flag(&info->bday.find_synack_done,FLAG_SET,
00147 FIND_SYN_ACK_TIMEOUT);
00148
00149
00150 info->bday.stop_synack_find = FLAG_SET;
00151
00152
00153 if (pthread_join(info->bday.find_synack_tid,(void**)&thread_ret)<0)
00154 return ERROR_PTHREAD_JOIN;
00155 DBG_TIME("finished waiting for SYNACK flood listening thread to finish");
00156
00157
00158 if (FAILED(wait_ret))
00159 return ERROR_1;
00160 if (FAILED(thread_ret))
00161 return ERROR_2;
00162
00163 return SUCCESS;
00164 }
00165
00166 errorcode synack_flood(peer_conn_info_t *info, seq_num_t seq_num) {
00167
00168
00169 int i;
00170 tcp_packet_info_t skeleton;
00171 port_t port;
00172
00173
00174 CHECK_NOT_NULL(info,ERROR_NULL_ARG_1);
00175
00176
00177
00178
00179 skeleton.d_addr = info->buddy.ext_ip;
00180 skeleton.s_addr = info->peer.ip;
00181 skeleton.s_port = info->peer.port;
00182 skeleton.seq_num = (seq_num_t)rand();
00183 skeleton.ack_num = SEQ_NUM_ADD(seq_num,1);
00184 skeleton.ack_flag = FLAG_SET;
00185 skeleton.syn_flag = FLAG_SET;
00186 skeleton.window = WINDOW_DEFAULT;
00187
00188
00189 srand(time(NULL));
00190
00191
00192 for (i=0;i<SYN_ACK_FLOOD_COUNT;i++) {
00193 skeleton.d_port = port = (port_t)rand();
00194 CHECK_FAILED(spoof(&skeleton, info->device,&port,sizeof(port),
00195 TTL_OK),ERROR_1);
00196 }
00197
00198 return SUCCESS;
00199 }
00200