Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include <arpa/inet.h>
  2. #include <linux/if_packet.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <net/if.h>
  9. #include <netinet/ether.h>
  10. #define MY_DEST_MAC0    0xff
  11. #define MY_DEST_MAC1    0xff
  12. #define MY_DEST_MAC2    0xff
  13. #define MY_DEST_MAC3    0xff
  14. #define MY_DEST_MAC4    0xff
  15. #define MY_DEST_MAC5    0xff
  16. #define DEFAULT_IF  "eth0"
  17. #define BUF_SIZ     1024
  18. int main(int argc, char *argv[])
  19. {
  20. int sockfd;
  21. struct ifreq if_idx;
  22. struct ifreq if_mac;
  23. int tx_len = 0;
  24. char sendbuf[BUF_SIZ];
  25. struct ether_header *eh = (struct ether_header *) sendbuf;
  26. struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header));
  27. struct sockaddr_ll socket_address;
  28. char ifName[IFNAMSIZ];
  29. /* Get interface name */
  30. if (argc > 1)
  31. strcpy(ifName, argv[1]);
  32. else
  33. strcpy(ifName, DEFAULT_IF);
  34. /* Open RAW socket to send on */
  35. if ((sockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) {
  36. perror("socket");
  37.     }
  38. /* Get the index of the interface to send on */
  39. memset(&if_idx, 0, sizeof(struct ifreq));
  40. strncpy(if_idx.ifr_name, ifName, IFNAMSIZ-1);
  41. if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0)
  42. perror("SIOCGIFINDEX");
  43. /* Get the MAC address of the interface to send on */
  44. memset(&if_mac, 0, sizeof(struct ifreq));
  45. strncpy(if_mac.ifr_name, ifName, IFNAMSIZ-1);
  46. if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0)
  47. perror("SIOCGIFHWADDR");
  48. /* Construct the Ethernet header */
  49. memset(sendbuf, 0, BUF_SIZ);
  50. /* Ethernet header */
  51.     eh->ether_shost[0] = //spoofmac0;
  52.     eh->ether_shost[1] = //spoofmac1;
  53.     eh->ether_shost[2] = //spoofmac2;
  54.     eh->ether_shost[3] = //spoofmac2;
  55.     eh->ether_shost[4] = //spoofmac4;
  56.     eh->ether_shost[5] = //spoofmac5;
  57.     eh->ether_dhost[0] = MY_DEST_MAC0;
  58.     eh->ether_dhost[1] = MY_DEST_MAC1;
  59.     eh->ether_dhost[2] = MY_DEST_MAC2;
  60.     eh->ether_dhost[3] = MY_DEST_MAC3;
  61.     eh->ether_dhost[4] = MY_DEST_MAC4;
  62.     eh->ether_dhost[5] = MY_DEST_MAC5;
  63. /* Ethertype field */
  64.     eh->ether_type = htons(ETH_P_IP);
  65.     tx_len += sizeof(struct ether_header);
  66. /* Packet data */
  67.     sendbuf[tx_len++] = 0xde;
  68.     sendbuf[tx_len++] = 0xad;
  69.     sendbuf[tx_len++] = 0xbe;
  70.     sendbuf[tx_len++] = 0xef;
  71. /* Index of the network device */
  72.     socket_address.sll_ifindex = if_idx.ifr_ifindex;
  73. /* Address length*/
  74.     socket_address.sll_halen = ETH_ALEN;
  75. /* Destination MAC */
  76.     socket_address.sll_addr[0] = MY_DEST_MAC0;
  77.     socket_address.sll_addr[1] = MY_DEST_MAC1;
  78.     socket_address.sll_addr[2] = MY_DEST_MAC2;
  79.     socket_address.sll_addr[3] = MY_DEST_MAC3;
  80.     socket_address.sll_addr[4] = MY_DEST_MAC4;
  81.     socket_address.sll_addr[5] = MY_DEST_MAC5;
  82. /* Send packet */
  83. if (sendto(sockfd, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) < 0)
  84. printf("Send failed\n");
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement