Question: outputTask 2 . 2 B: Spoof an ICMP Echo Request. Spoof an ICMP echo request packet on behalf of another machine ( i . e
outputTask B: Spoof an ICMP Echo Request. Spoof an ICMP echo request packet on behalf of another
machine ie using another machine's IP address as its source IP address This packet should be sent to a
remote machine on the Internet the machine must be alive You should turn on your Wireshark, so if your
spoofing is successful, you can see the echo reply coming back from the remote machine.
Questions. Please answer the following questions.
Question Can you set the IP packet length field to an arbitrary value, regardless of how big the
actual packet is
Question Using the raw socket programming, do you have to calculate the checksum for the IP
header?
Question Why do you need the root privilege to run the programs that use raw sockets? Where
does the program fail if executed without the root privilege? please write the code for icmp echo and answer question the spoofing code #include
#include
#include
#include
#include
#include
#include
Note: This code is for educational or testing purposes only and should not be used maliciously.
The IP header's structure
struct ipheader
unsigned char iphihl: iphver:; Adjusted the bit fields
unsigned char iphtos;
unsigned short int iphlen;
unsigned short int iphident;
unsigned short int iphflagsoffset; Changed name and type for flags and offset
unsigned char iphttl;
unsigned char iphprotocol;
unsigned short int iphchksum;
unsigned int iphsourceip;
unsigned int iphdestip;
;
Simple checksum function, might be needed for some headers
unsigned short csumunsigned short buf int nwords
unsigned long sum;
for sum ; nwords ; nwords
sum buf;
sum sum sum & xffff;
sum sum ;
return unsigned short~sum;
int main
int sd;
char buffer;
struct ipheader ip struct ipheader buffer;
char data buffer sizeofstruct ipheader; Pointer to the data portion after the IP header
Create a raw socket with IP protocol. The IPPROTORAW parameter tells the system
sd socketAFINET, SOCKRAW, IPPROTORAW;
if sd
perrorsocket error";
exit;
Set the fields in the IP header
ipiphver ; Version bits: IPv
ipiphihl ; IHL bits: Number of bit words in header
ipiphtos ; Type of service
Include the length of IP header and message in total length
ipiphlen htonssizeofstruct ipheader strlendata;
ipiphident htons; Identification
ipiphflagsoffset htonsx; Don't fragment flag, offset
ipiphttl ; Time to live
ipiphprotocol IPPROTOTCP; Protocol
ipiphchksum ; Checksum temporarily set to
Source IP address, can be spoofed
ipiphsourceip inetaddr;
Destination IP address
ipiphdestip inetaddr;
Copy the message into the buffer after the IP header
strcpydata "Hello";
Calculate the IP checksum now that the header is filled out
ipiphchksum csumunsigned short buffer sizeofstruct ipheader;
Inform the kernel that headers are included in the packet
int one ;
const int val &one;
if setsockoptsd IPPROTOIP IPHDRINCL, val, sizeofone
perrorsetsockopt error";
exit;
Destination address structure
struct sockaddrin sin;
sinsinfamily AFINET;
sinsinport htons; Port number if needed
sinsinaddr.saddr ipiphdestip;
Send the packet
if sendtosd buffer, ntohsipiphlenstruct sockaddr &sin sizeofsin
perrorsendto error";
exit;
closesd;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
