1个回答
展开全部
要先装pcap,用Winpcap构造 SYN的数据包
#include <iostream>
using namespace std;
#include <pcap/pcap.h>
#pragma comment(lib,"wpcap.lib") //要先装pcap,用Winpcap构造 SYN的数据包
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#include "Packet_Header.h"
#define MSG_MAXLEN 58
USHORT checksum(USHORT *buf,int size)
{
ULONG cksum = 0;
while(size > 1)
{
cksum += *buf++;
size -= sizeof(USHORT);
}
if(size)
{
cksum += *(USHORT*)buf;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return (USHORT)(~cksum);
}
int main()
{
pcap_if_t *alldevs;
char errbuf[PCAP_ERRBUF_SIZE] = {};
if(-1 == pcap_findalldevs(&alldevs,errbuf))
{
cout<<"Get dev list error"<<endl;
return -1;
}
for(pcap_if_t *d = alldevs;NULL != d;d = d->next)
{
cout<<d->description<<endl;
}
pcap_t *pt = pcap_open_live(alldevs->name,65536,true,20,errbuf);
if(NULL == pt)
{
cout<<"Open dev error"<<endl;
return -1;
}
UCHAR SendMsg[MSG_MAXLEN] = {0};
PETHERHDR pethhdr = (PETHERHDR)SendMsg;
pethhdr->ethDst[0] = 0x00;//mac
pethhdr->ethDst[1] = 0x21;
pethhdr->ethDst[2] = 0x85;
pethhdr->ethDst[3] = 0x02;
pethhdr->ethDst[4] = 0x30;
pethhdr->ethDst[5] = 0x4e;
pethhdr->ethSrc[0] = 0x00;
pethhdr->ethSrc[1] = 0x23;
pethhdr->ethSrc[2] = 0x8b;
pethhdr->ethSrc[3] = 0xb6;
pethhdr->ethSrc[4] = 0xbd;
pethhdr->ethSrc[5] = 0xd7;
pethhdr->ethtype = htons(0x0800);
/*IP header*/
PIPHDR piphdr = (PIPHDR)(SendMsg + sizeof(ETHERHDR));
piphdr->ipv_l = (4<<4 | (sizeof(IPHDR)/sizeof(ULONG)));
piphdr->iptos = 0;
piphdr->iplen = htons(sizeof(SendMsg)-sizeof(ETHERHDR));
//piphdr->ipID = htons(0x1234);//0xede6
piphdr->ipTTL = 58;
piphdr->ipCheckSum = 0;
piphdr->ipProtocol = IPPROTO_TCP;
piphdr->ipSrc = inet_addr("192.168.0.183");
piphdr->ipDst = inet_addr("119.75.217.109");//119.75.217.109
//发送给百度(ip 119.75.217.109:80)
piphdr->ipCheckSum = checksum((USHORT*)piphdr,sizeof(IPHDR));
/*TCP header*/
PTCPHDR ptcphdr = (PTCPHDR)(SendMsg + sizeof(ETHERHDR) + sizeof(IPHDR));
ptcphdr->tcpSrcPort = htons(44523);
ptcphdr->tcpDstPort = htons(80);
ptcphdr->tcpSeq = htonl(0x7d2cb526);//0x7d2cb526
ptcphdr->tcpAck = htonl(0);
ptcphdr->tcpl_r = ((sizeof(TCPHDR)/sizeof(ULONG))<<4 | 0);
ptcphdr->tcpFlags = 2;
ptcphdr->tcpWnd = htons(2048);
ptcphdr->tcpChkSum = 0;
ptcphdr->tcpUrp = 0;
UCHAR *tmpbuf = new UCHAR[sizeof(SendMsg) - sizeof(ETHERHDR) - sizeof(IPHDR) + sizeof(PSDHDR)];
memset(tmpbuf,0,sizeof(TCPHDR)+sizeof(PSDHDR));
PPSDHDR ppsdhdr = (PPSDHDR)tmpbuf;
ppsdhdr->psdSrcAddr = piphdr->ipSrc;
ppsdhdr->psdDstAddr = piphdr->ipDst;
ppsdhdr->psdzero = 0;
ppsdhdr->psdProto = IPPROTO_TCP;
ppsdhdr->psdPackLen = htons(sizeof(SendMsg) - sizeof(ETHERHDR) - sizeof(IPHDR));
memcpy(tmpbuf+sizeof(PSDHDR),SendMsg+sizeof(ETHERHDR)+sizeof(IPHDR),sizeof(tmpbuf+sizeof(PSDHDR)));
ptcphdr->tcpChkSum = checksum((USHORT*)tmpbuf,sizeof(SendMsg)-sizeof(ETHERHDR)-sizeof(IPHDR));
if(0 !=pcap_sendpacket(pt,SendMsg,sizeof(SendMsg)))
{
cout<<"Error"<<endl;
}
system("pause");
return 0;
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询