diff --git a/main.cpp b/main.cpp index 70139c8..629701f 100755 --- a/main.cpp +++ b/main.cpp @@ -951,6 +951,8 @@ int keep_connection_client(conn_info_t &conn_info) //for client send_info.seq = get_true_random_number(); send_info.ack_seq = get_true_random_number(); + send_info.first_seq=send_info.seq; + //send_info.first_ack_seq=send_info.ack_seq send_info.ts_ack = 0; send_info.ack = 0; send_info.syn = 1; @@ -1518,6 +1520,8 @@ int server_on_raw_ready(conn_info_t &conn_info) } conn_info.conv_manager->insert_conv(tmp_conv_id, new_udp_fd); + assert(conn_manager.udp_fd_mp.find(new_udp_fd)==conn_manager.udp_fd_mp.end()); + conn_manager.udp_fd_mp[new_udp_fd] = &conn_info; //pack_u64(conn_info.raw_info.recv_info.src_ip,conn_info.raw_info.recv_info.src_port); @@ -1551,8 +1555,8 @@ int server_on_raw_ready(conn_info_t &conn_info) int server_on_raw_pre_ready(conn_info_t &conn_info,char * data,int data_len) { uint32_t ip;uint16_t port; - ip=conn_info.raw_info.send_info.src_ip; - port=conn_info.raw_info.send_info.src_ip; + ip=conn_info.raw_info.recv_info.src_ip; + port=conn_info.raw_info.recv_info.src_port; char ip_port[40]; sprintf(ip_port,"%s:%d",my_ntoa(ip),port); @@ -1622,6 +1626,7 @@ int server_on_raw_pre_ready(conn_info_t &conn_info,char * data,int data_len) int new_timer_fd; set_timer_server(epollfd, new_timer_fd); conn_info.timer_fd=new_timer_fd; + assert(conn_manager.timer_fd_mp.find(new_timer_fd)==conn_manager.timer_fd_mp.end()); conn_manager.timer_fd_mp[new_timer_fd] = &conn_info;//pack_u64(ip,port); @@ -1718,6 +1723,7 @@ int server_on_raw_recv_multi() if(!conn_manager.exist(ip,port)) { raw_info_t tmp_raw_info; + tmp_raw_info.send_info.src_port=tmp_raw_info.send_info.dst_port=port; if(recv_bare(tmp_raw_info,data,data_len)<0) { @@ -2996,7 +3002,10 @@ int main(int argc, char *argv[]) signal(SIGINT, INThandler); process_arg(argc,argv); - iptables_warn(); + local_address_uint32=inet_addr(local_address); + remote_address_uint32=inet_addr(remote_address); + source_address_uint32=inet_addr(source_address); + current_time_rough=get_current_time(); @@ -3006,10 +3015,6 @@ int main(int argc, char *argv[]) mylog(log_info,"const_id:%x\n",const_id); - local_address_uint32=inet_addr(local_address); - remote_address_uint32=inet_addr(remote_address); - source_address_uint32=inet_addr(source_address); - char tmp[1000]=""; strcat(tmp,key_string); @@ -3026,6 +3031,7 @@ int main(int argc, char *argv[]) md5((uint8_t*)tmp,strlen(tmp),(uint8_t*)key2); + iptables_warn(); if(program_mode==client_mode) { client_event_loop(); diff --git a/network.cpp b/network.cpp index 19600a9..12f444f 100644 --- a/network.cpp +++ b/network.cpp @@ -126,20 +126,22 @@ tcpdump -i eth1 ip and icmp -dd packet_info_t::packet_info_t() { - if(raw_mode==mode_faketcp) - { - protocol=IPPROTO_TCP; - ack_seq=get_true_random_number(); - seq=get_true_random_number(); - } - else if(raw_mode==mode_udp) - { - protocol=IPPROTO_UDP; - } - else if(raw_mode==mode_icmp) - { - protocol=IPPROTO_ICMP; - } + src_port=0; + dst_port=0; + if (raw_mode == mode_faketcp) + { + protocol = IPPROTO_TCP; + ack_seq = get_true_random_number(); + seq = get_true_random_number(); + } + else if (raw_mode == mode_udp) + { + protocol = IPPROTO_UDP; + } + else if (raw_mode == mode_icmp) + { + protocol = IPPROTO_ICMP; + } } @@ -195,8 +197,10 @@ int init_raw_socket() void init_filter(int port) { sock_fprog bpf; - - filter_port=port; + if(raw_mode==mode_faketcp||raw_mode==mode_udp) + { + filter_port=port; + } if(disable_bpf_filter) return; //if(raw_mode==mode_icmp) return ; //code_tcp[8].k=code_tcp[10].k=port; @@ -451,7 +455,8 @@ int send_raw_icmp(raw_info_t &raw_info, const char * payload, int payloadlen) icmph->code=0; icmph->id=htons(send_info.src_port); - icmph->seq=htons(send_info.icmp_seq++); /////////////modify + + icmph->seq=htons(send_info.icmp_seq); /////////////modify memcpy(send_raw_icmp_buf+sizeof(icmphdr),payload,payloadlen); @@ -462,6 +467,11 @@ int send_raw_icmp(raw_info_t &raw_info, const char * payload, int payloadlen) return -1; } + if(program_mode==client_mode) + { + send_info.icmp_seq++; + } + return 0; } @@ -805,7 +815,7 @@ int send_raw_tcp_deprecated(const packet_info_t &info,const char * payload,int p int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen) { - const packet_info_t &send_info=raw_info.send_info; + packet_info_t &send_info=raw_info.send_info; packet_info_t &recv_info=raw_info.recv_info; static char recv_raw_icmp_buf[buf_len]; @@ -825,9 +835,15 @@ int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen) icmphdr *icmph=(struct icmphdr *) (ip_payload); + if(ntohs(icmph->id)!=send_info.src_port) + { + return -1; + } + recv_info.src_port=recv_info.dst_port=ntohs(icmph->id); + if(program_mode==client_mode) { if(icmph->type!=0) @@ -837,6 +853,7 @@ int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen) { if(icmph->type!=8) return -1; + } if(icmph->code!=0) @@ -849,6 +866,13 @@ int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen) mylog(log_debug,"icmp checksum fail %x\n",check); return -1; } + //mylog(log_info,"program_mode=%d\n",program_mode); + + if(program_mode==server_mode) + { + send_info.icmp_seq=ntohs(icmph->seq); + //mylog(log_info,"send_info.seq=%d\n",send_info.seq); + } payload=ip_payload+sizeof(icmphdr); payloadlen=ip_payloadlen-sizeof(icmphdr); diff --git a/network.h b/network.h index 02ab3e0..47b4600 100644 --- a/network.h +++ b/network.h @@ -32,7 +32,7 @@ struct pseudo_header { u_int16_t tcp_length; }; -struct packet_info_t +struct packet_info_t //todo change this to union { uint8_t protocol; //ip_part: