Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // printf/fprintf
- #include <stdlib.h>
- #include <string.h>
- #include <netinet/ip.h> // struct ip
- #include <sys/socket.h> // socket()
- #include <netinet/in.h> // struct sockadd
- #define __FAVOR_BSD
- #define _USE_BSD
- #include <netinet/udp.h> // struct udp
- void udp(char *, int , char * , char * , int );
- unsigned short int in_chksum (unsigned short int *, int);
- unsigned long hasard(unsigned long, unsigned long);
- char * hexToAscii(char *hex_a_convertir){
- int taille;
- int i;
- char *data;
- char hex[5], *stop;
- hex[0] = '0';
- hex[1] = 'x';
- hex[4] = 0;
- taille = strlen(hex_a_convertir);
- data = (char *)malloc(taille);
- for(i=0;i<taille /2;i++){
- hex[2] = hex_a_convertir[i*2];
- hex[3] = hex_a_convertir[(i*2)+1];
- *(data+i) = (char) strtol(hex, &stop, 16);
- }
- return data;
- }
- main(int argc , char *arg[]) {
- printf("initialisation......... \n" );
- /*if( strcmp(arg[1] , "") == 0
- while((c = getopt(argc,argv,"s:d:p:h")) != -1)
- {
- switch(c)
- {
- case 's':
- src = optarg;
- printf("\\nIP source:\\t\\t%s",src);
- break;
- case 'd':
- dest = optarg;
- printf("\\nIP de destination:\\t\\t%s",dest);
- break;
- case 'p':
- port = atoi(optarg);
- printf("\\nPort:\\t\\t%d",port);
- break;
- case 'h':
- case '?':
- printf(VERSION"Usage:\\n\\t-s\\tAdresse IP source\\n\\t-d\\tAdresse IP de destination\\n\\t-p\\tNuméro de port\\n");
- exit(0);
- break;
- }
- }
- printf("test......... \n" );*/
- int port;
- sscanf(arg[2],"%i",&port);
- udp(arg[1] , port , arg[3] , hexToAscii(arg[4]) , strlen(arg[4]) /2 );
- }
- void udp(char *cible, int port , char *spoofed , char *donne , int taille_donne ) {
- int sd;
- sd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
- if (sd == -1) {
- fprintf(stderr,"socket() error, root ?\n");
- }
- unsigned long ip_src = inet_addr(spoofed);; //->spoof adresse
- unsigned long ip_dst = inet_addr(cible);
- unsigned short p_src = 10;
- unsigned short p_dst = port;
- char *data;
- struct sockaddr_in sin;
- sin.sin_family = AF_INET;
- sin.sin_port = p_dst;
- sin.sin_addr.s_addr = ip_dst; // dst
- struct ip *ip;
- struct udphdr *udp;
- char *dgm;
- char *interface;
- int pksize = sizeof(struct ip) + sizeof(struct udphdr) + taille_donne;
- dgm = (char *) malloc(pksize);
- ip = (struct ip *) dgm;
- udp = (struct udphdr *) (dgm + sizeof(struct ip));
- data = (char *) (dgm + sizeof(struct ip) + sizeof(struct udphdr));
- memset(dgm, 0, pksize);
- memcpy((char *) data, donne, taille_donne);
- int un = 1;
- if (setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (char *)&un, sizeof(un)) == -1)
- {
- fprintf(stderr,"setsockopt()");
- exit(-1);
- }
- //entete ip
- ip->ip_hl = 0x5;
- ip->ip_v = 0x4;
- ip->ip_tos = 0x0;
- ip->ip_len = sizeof(pksize);
- ip->ip_ttl = 64;
- ip->ip_off = 0x0;
- ip->ip_id = htons(12830);
- ip->ip_p = IPPROTO_UDP;
- ip->ip_sum = 0x0; // a remplir aprés
- ip->ip_src.s_addr = ip_src;
- ip->ip_dst.s_addr = ip_dst;
- //entete udp
- udp->uh_sport = htons(p_src);
- udp->uh_dport = htons(p_dst);
- udp->uh_ulen = htons(sizeof(struct udphdr ) + taille_donne);
- udp->uh_sum = 0;
- interface = (char *)malloc(4);
- strncpy(interface, "ppp0\0",5);
- /*if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, interface , strlen(interface)+1 ) == -1)
- {
- fprintf(stderr,"pb a la specification de l'option\n");
- exit(-1);
- }*/
- // envoi
- printf("Envoie du paquet........... \n");
- if (sendto(sd, dgm, pksize, 0, (struct sockaddr *) &sin,
- sizeof(struct sockaddr)) == -1) {
- fprintf(stderr,"oops, sendto() error\n");
- }
- printf("Envoie OK\n");
- //libere la memoire
- free(dgm);
- free(donne);
- close(sd);
- }
- u_short in_chksum (u_short *addr, int len) // taken from papasmurf.c
- {
- register int nleft = len;
- register u_short *w = addr;
- register int sum = 0;
- u_short answer = 0;
- while (nleft > 1)
- {
- sum += *w++;
- nleft -= 2;
- }
- if (nleft == 1)
- {
- *(u_char *)(&answer) = *(u_char *)w;
- sum += answer;
- }
- sum = (sum >> 16) + (sum + 0xffff);
- sum += (sum >> 16);
- answer = ~sum;
- return(answer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement