我正在使用WinPcap編程一個TCP syn flooder(爲了教育目的),但是當我發送我製作的數據包時服務器沒有收到任何東西。我目前正在本地主機上測試我的程序,但我也在Wireshark網絡上用Wireshark監控我的網絡流量,根據Wireshark數據包是正確的,但服務器仍然沒有收到任何東西。服務器沒有收到TCP SYN數據包
這裏是我的以太網/ IP/TCP報頭結構:
#ifdef _MSC_VER
#pragma pack(push, 1)
#else
#pragma pack(1)
#endif
struct ethernet_header {
u8 dst_mac[6];
u8 src_mac[6];
u16 type;
};
struct ipv4_header {
u8 ver_ihl;
u8 tos;
u16 length;
u16 id;
u16 flags_fo;
u8 ttl;
u8 protocol;
u16 checksum;
u32 src_ip;
u32 dst_ip;
};
struct tcp_header {
u16 src_port;
u16 dst_port;
u32 seq_num;
u32 ack_num;
u16 off_flags;
u16 window_size;
u16 checksum;
u16 urgent_ptr;
struct {
struct {
u8 id; /* 0x02 = MSS */
u8 len; /* 0x04 */
u16 data; /* MSS value (1460) */
} mss;
u8 nop; /* 0x01 */
struct {
u8 id; /* 0x03 = Window Scale */
u8 len; /* 0x03 */
u8 data; /* Window Scale value (8) */
} window_scale;
u8 nop2; /* 0x01 */
u8 nop3; /* 0x01 */
struct {
u8 id; /* 0x04 = SACK */
u8 data; /* 0x02 */
} sack;
} options;
};
#ifdef _MSC_VER
#pragma pack(pop)
#else
#pragma pack(0)
#endif
這也是我如何對它們進行初始化:
/* set ethernet header */
memcpy(ethhdr.dst_mac, dst_mac_address, 6);
memcpy(ethhdr.src_mac, src_mac_address, 6);
ethhdr.type = htons(ETHERTYPE_IPV4);
/* set ipv4 header */
ipv4hdr.ver_ihl |= 0x40; /* version is IPv4 */
ipv4hdr.ver_ihl |= 0x5; /* header size is 20 bytes */
ipv4hdr.tos = 0;
ipv4hdr.length = htons(sizeof(ipv4hdr) + sizeof(tcphdr));
ipv4hdr.id = 0;
ipv4hdr.flags_fo |= IP_CONTROL_FLAG_DF;
ipv4hdr.ttl = 128;
ipv4hdr.protocol = IPPROTOCOL_TCP;
ipv4hdr.checksum = 0;
ipv4hdr.src_ip = spoof_ip_address();
ipv4hdr.dst_ip = inet_addr("127.0.0.1");
/* calculate the checksum of a IP header */
ipv4hdr.checksum = calculate_checksum(&ipv4hdr,
sizeof(ipv4hdr));
/* set tcp header */
tcphdr.src_port = htons(60450);
tcphdr.dst_port = htons(32600);
tcphdr.seq_num = 0;
tcphdr.ack_num = 0;
tcphdr.off_flags |= 0x80; /* header size is 32 bytes */
tcphdr.off_flags |= TCP_CONTROL_FLAG_SYN;
tcphdr.window_size = htons(8192);
tcphdr.checksum = 0;
tcphdr.urgent_ptr = 0;
/* set TCP options */
tcphdr.options.mss.id = 0x02;
tcphdr.options.mss.len = 0x04;
tcphdr.options.mss.data = htons(1460);
tcphdr.options.nop = 0x01;
tcphdr.options.window_scale.id = 0x03;
tcphdr.options.window_scale.len = 0x03;
tcphdr.options.window_scale.data = 2;
tcphdr.options.nop2 = 0x01;
tcphdr.options.nop3 = 0x01;
tcphdr.options.sack.id = 0x04;
tcphdr.options.sack.data = 0x02;
/* calculate the checksum of a TCP header + options */
tcphdr.checksum = calculate_checksum(&tcphdr, sizeof(tcphdr));
的src_mac_address和dst_mac_address被設置爲相同的值,即我正在使用的網絡接口適配器的MAC地址。 spoof_ip_address()函數以網絡字節順序返回一個隨機IPv4地址。根據Wireshark,其他字段(校驗和,TCP選項等)似乎是正確的。
我知道我的路由器將MAC地址和IP地址字段覆蓋到自己的MAC和IP地址時,發送數據包發往另一個網段,以便我的IP欺騙是無用的,但我正在運行測試TCP服務器與積壓環回地址上的值爲1,但它不接收SYN數據包。我究竟做錯了什麼?
在此先感謝。
是的,我知道,但我的意思是說服務器沒有收到我的SYN數據包是服務器應掛起,不接受任何新的連接。當我運行我的flooder並嘗試使用Wireshark監控我的網絡流量時,我必須在1秒內啓動並單擊停止捕獲,否則它將因爲我的flooder從欺騙IP地址發送的流量而掛起並崩潰。但服務器非常完美這意味着我的SYN數據包沒有被服務器接收到? – oriyon