傳送自定義IP包(測試中 第二版)

2021-09-05 15:35:41 字數 3014 閱讀 6838

傳送自定義ip包:

public struct ip_hdr   //ip頭

public struct tcp_hdr  //tcp頭

public struct psd_hdr    //tcp偽首部,用來計算校驗和,無意義

//開始

private void button1_click(object sender, eventargs e)

if (radiobutton2.checked && t_count.text == "")

return;

//建立原始套接字

socket s;

trycatch (socketexception ee)

//建立ip頭

ip_hdr myip_hdr = new ip_hdr();

tcp_hdr mytcp_hdr = new tcp_hdr();

myip_hdr.h_lenver = (byte)(4 << 4 | marshal.sizeof(myip_hdr) / sizeof(uint));

myip_hdr.total_len = (ushort)(marshal.sizeof(myip_hdr) + marshal.sizeof(mytcp_hdr));

myip_hdr.ident = 1;

myip_hdr.frag_and_flags = 0;

myip_hdr.ttl = 128;

myip_hdr.proto = 6;

myip_hdr.checksum = 0;

myip_hdr.sourceip=(uint)ipaddress.parse(t_locip.text).address;

myip_hdr.destip = (uint)ipaddress.parse(t_remoip.text).address;

//建立tcp頭

mytcp_hdr.th_sport = convert.touint16(t_locport.text);

mytcp_hdr.th_dport = convert.touint16(t_remoport.text);

mytcp_hdr.th_seq=0x12345678;//32位序列號

mytcp_hdr.th_ack = 0;

mytcp_hdr.th_lenres = (byte)(marshal.sizeof(mytcp_hdr) / 4 << 4 | 0);

mytcp_hdr.th_flag = 2;//修改這裡來實現不同的標誌位探測,2是syn,1是fin,16是ack探測 等等

mytcp_hdr.th_win = 512;

mytcp_hdr.th_urp = 0;

mytcp_hdr.th_sum = 0;

//偽tcp頭

psd_hdr mypsd_hdr = new psd_hdr();

mypsd_hdr.saddr = myip_hdr.sourceip;

mypsd_hdr.daddr = myip_hdr.destip;

mypsd_hdr.mbz = 0;

mypsd_hdr.ptcl = 6;

mypsd_hdr.tcpl =(ushort) marshal.sizeof(mytcp_hdr);

//計算校驗和

byte psdbytes = structtobytes(mypsd_hdr);

byte tcpbytes = structtobytes(mytcp_hdr);

byte buffer=new byte[psdbytes.length+tcpbytes.length];

psdbytes.copyto(buffer, 0);

tcpbytes.copyto(buffer, psdbytes.length);

uint16 myarray1 = bytetouint16(buffer);

mytcp_hdr.th_sum = checksum(myarray1, myarray1.length);

byte ipbytes = structtobytes(myip_hdr);

buffer=new byte[ipbytes.length+tcpbytes.length];

ipbytes.copyto(buffer,0);

tcpbytes.copyto(buffer, ipbytes.length);

uint16 myarray2 = bytetouint16(buffer);

myip_hdr.checksum = checksum(myarray2,myarray2.length);

ipbytes = structtobytes(myip_hdr);

ipbytes.copyto(buffer, 0);    //buffer即為要傳送的偽ip包

//傳送ip包

ipendpoint remoend = new ipendpoint(ipaddress.parse(t_remoip.text), convert.toint16(t_remoport.text));

trycatch (socketexception ex)

}//計算校驗和

public uint16 checksum(uint16 buffer, int size)

cksum = (cksum >> 16) + (cksum & 0xffff);

cksum += (cksum >> 16);

return (uint16)(~cksum);

} //struct型別轉換成byte

public static byte structtobytes(object structobj)

finally

}  

//byte轉換成uint16

public static uint16 bytetouint16(byte putin)

return retarray;

}//顯示byte的內容

public static string displaybyte(byte putin)

C VC自定義發IP包例子

自定義發ip包例子 tcp ip包傳送 給目標主機的埠傳送乙個 syn請求,注意目標主機的資訊會發給傳送ip位址的主機 這說明tcp ip協議本身有ip期騙的漏洞 這種方運可以自己寫成特殊的基於ip協議上層的自定義協議 include include include include include ...

C VC自定義發IP包例子

自定義發ip包例子 tcp ip包傳送 給目標主機的埠傳送乙個 syn請求,注意目標主機的資訊會發給傳送ip位址的主機 這說明tcp ip協議本身有ip期騙的漏洞 這種方運可以自己寫成特殊的基於ip協議上層的自定義協議 include include include include include ...

Python3中自定義包和匯入自定義包

第一篇部落格,寫得質量可能會不高,但希望能開個好頭,努力成為優秀的程式設計師!今天在惡補python基礎知識,發現我對包,庫,模組的定義非常模糊,於是我回頭看了一下基礎知識,也是一時興起想讓跟我一樣一開始有些困惑的人避坑!要想知道什麼是包,得先了解一下模組的概念!知道了模組,那緊接著看看包 上面是我...