導航:首頁 > 編程語言 > 發送tcpsyn代碼

發送tcpsyn代碼

發布時間:2023-02-03 11:32:30

⑴ 怎麼用C/C++編寫發送tcp/ip協議中的syn包

要先裝pcap,用Winpcap構造 SYN的數據包

#include<iostream>
usingnamespacestd;
#include<pcap/pcap.h>
#pragmacomment(lib,"wpcap.lib")//要先裝pcap,用Winpcap構造SYN的數據包

#include<winsock2.h>
#pragmacomment(lib,"ws2_32.lib")

#include"Packet_Header.h"

#defineMSG_MAXLEN58

USHORTchecksum(USHORT*buf,intsize)
{
ULONGcksum=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);
}

intmain()
{
pcap_if_t*alldevs;
charerrbuf[PCAP_ERRBUF_SIZE]={};

if(-1==pcap_findalldevs(&alldevs,errbuf))
{
cout<<"Getdevlisterror"<<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<<"Opendeverror"<<endl;
return-1;
}

UCHARSendMsg[MSG_MAXLEN]={0};

PETHERHDRpethhdr=(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);

/*IPheader*/
PIPHDRpiphdr=(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
//發送給網路(ip119.75.217.109:80)
piphdr->ipCheckSum=checksum((USHORT*)piphdr,sizeof(IPHDR));

/*TCPheader*/
PTCPHDRptcphdr=(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=newUCHAR[sizeof(SendMsg)-sizeof(ETHERHDR)-sizeof(IPHDR)+sizeof(PSDHDR)];
memset(tmpbuf,0,sizeof(TCPHDR)+sizeof(PSDHDR));
PPSDHDRppsdhdr=(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");
return0;
}

⑵ 乙太網數據幀的監聽與分析

樓上說的對,這不是一句兩句話能說玩的,問題也不是一分鍾兩分鍾能解決的了的,編寫代碼不是一天兩天能搞定的。。。樓主,我勸你還是不要對這里報希望了

閱讀全文

與發送tcpsyn代碼相關的資料

熱點內容
iphone5國際漫遊設置 瀏覽:107
ipodwatch如何安裝app 瀏覽:114
誰有微信搶紅包的群號 瀏覽:872
word07頁碼從任意頁開始 瀏覽:791
js禁止滑動事件 瀏覽:800
蘋果查序號怎麼看不是 瀏覽:61
linux在txt文件 瀏覽:568
ps如何導入文件匹配 瀏覽:201
轉轉app怎麼把自己的賬號租出去 瀏覽:828
福昕閱讀器合並照片pdf文件 瀏覽:591
vhd文件有什麼用 瀏覽:482
編程小朋友看什麼書 瀏覽:623
經營如何讓數據說話 瀏覽:258
如何在手機上升級opop 瀏覽:614
coreldrawx5免費視頻教程 瀏覽:725
網站引導頁面源碼 瀏覽:234
個人簡歷範文word 瀏覽:220
uc下載的視頻怎樣提取到文件 瀏覽:499
英雄下載下載最新版本2015下載安裝 瀏覽:433
NX深孔鑽編程替換面如何操作 瀏覽:725

友情鏈接