home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / sniffit.0.3.5 / sniffit.0.3.5.patch.1 < prev    next >
Encoding:
Text File  |  2002-05-27  |  6.6 KB  |  217 lines

  1. *** sn_defines.h    Fri Apr 18 11:33:58 1997
  2. --- sn_defines.h    Thu Jul 24 16:02:16 1997
  3. ***************
  4. *** 80,90 ****
  5.   #define SYN 2
  6.   #define FIN 1
  7.   
  8. ! #define NO_IP   0
  9. ! #define NO_IP_4 1000
  10. ! #define ICMP    1                       /* Protocol Numbers */
  11. ! #define TCP     6
  12. ! #define UDP     17
  13.   
  14.   #define ICMP_HEADLENGTH 4               /* fixed ICMP header length */
  15.   #define UDP_HEADLENGTH  8               /* fixed UDP header length */
  16. --- 80,91 ----
  17.   #define SYN 2
  18.   #define FIN 1
  19.   
  20. ! #define NO_IP       0
  21. ! #define NO_IP_4     1000
  22. ! #define CORRUPT_IP    1001
  23. ! #define ICMP        1                       /* Protocol Numbers */
  24. ! #define TCP         6
  25. ! #define UDP         17
  26.   
  27.   #define ICMP_HEADLENGTH 4               /* fixed ICMP header length */
  28.   #define UDP_HEADLENGTH  8               /* fixed UDP header length */
  29. *** sn_packets.c    Fri Apr 18 11:33:58 1997
  30. --- sn_packets.c    Thu Aug 22 19:18:51 1985
  31. ***************
  32. *** 43,48 ****
  33. --- 43,49 ----
  34.       struct UDP_header UDPhead;
  35.   
  36.       int i;
  37. +      short int dummy; /* 2 bytes, important */
  38.   
  39.       memcpy(&IPhead,(sp+PROTO_HEAD),sizeof(struct IP_header));
  40.                                                     /* IP header Conversion */
  41. ***************
  42. *** 51,56 ****
  43. --- 52,58 ----
  44.       unwrapped->TCP_len = 0;             /* Reset structure NEEDED!!! */
  45.       unwrapped->UDP_len = 0;
  46.       unwrapped->DATA_len = 0;
  47. +     unwrapped->FRAG_nf = 0;
  48.           
  49.       if(NO_CHKSUM == 0)
  50.           {
  51. ***************
  52. *** 75,106 ****
  53.                       /* restore orig buffer      */
  54.                            /* general programming rule */
  55.           }
  56.       if(IPhead.protocol == TCP )                     /* TCP */
  57.           {
  58. !         memcpy(&TCPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  59.                           sizeof(struct TCP_header));
  60. !         unwrapped->TCP_len = ntohs(TCPhead.offset_flag) & 0xF000;
  61. !         unwrapped->TCP_len >>= 10; 
  62. !         unwrapped->DATA_len = ntohs(IPhead.length) -
  63.                   (unwrapped->IP_len) - (unwrapped->TCP_len); 
  64.           return TCP;
  65.           }
  66.       if(IPhead.protocol == ICMP )                     /* ICMP */
  67.           {
  68. !         memcpy(&ICMPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  69.                           sizeof(struct ICMP_header));
  70. !         unwrapped->ICMP_len = ICMP_HEADLENGTH;
  71. !         unwrapped->DATA_len = ntohs(IPhead.length) -
  72.                   (unwrapped->IP_len) - (unwrapped->ICMP_len); 
  73. !         return ICMP; 
  74.           }
  75.       if(IPhead.protocol == UDP )                       /* UDP */
  76.           {
  77. !         memcpy(&UDPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  78.                           sizeof(struct UDP_header));
  79. !         unwrapped->UDP_len = UDP_HEADLENGTH;
  80. !         unwrapped->DATA_len = ntohs(IPhead.length) -
  81.                   (unwrapped->IP_len) - (unwrapped->UDP_len); 
  82.           return UDP; 
  83.           }
  84.       return -1; 
  85. --- 77,150 ----
  86.                       /* restore orig buffer      */
  87.                            /* general programming rule */
  88.           }
  89. + #ifdef DEBUG_ONSCREEN
  90. +     printf("IPheadlen: %d   total length: %d\n", unwrapped->IP_len,
  91. +                             ntohs(IPhead.length)); 
  92. + #endif
  93. +         dummy=ntohs(IPhead.flag_offset); dummy<<=3;
  94. +         if( dummy!=0 )                            /* we have offset */
  95. +         {
  96. +         unwrapped->FRAG_nf = 1;
  97. +                 }
  98.       if(IPhead.protocol == TCP )                     /* TCP */
  99.           {
  100. !                 if(unwrapped->FRAG_nf == 0)
  101. !                   {  
  102. !           if( (ntohs(IPhead.length)-(unwrapped->IP_len))<20 )
  103. !             {return CORRUPT_IP;};
  104. !           memcpy(&TCPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  105.                           sizeof(struct TCP_header));
  106. !           unwrapped->TCP_len = ntohs(TCPhead.offset_flag) & 0xF000;
  107. !           unwrapped->TCP_len >>= 10; 
  108. !           unwrapped->DATA_len = ntohs(IPhead.length) -
  109.                   (unwrapped->IP_len) - (unwrapped->TCP_len); 
  110. +                   }
  111. +                 else
  112. +                   {
  113. +           unwrapped->DATA_len = ntohs(IPhead.length) - (unwrapped->IP_len);
  114. +                   }
  115.           return TCP;
  116.           }
  117.       if(IPhead.protocol == ICMP )                     /* ICMP */
  118.           {
  119. !                 if(unwrapped->FRAG_nf == 0)
  120. !                   {  
  121. !           if( (ntohs(IPhead.length)-(unwrapped->IP_len))<4 )
  122. !             {return CORRUPT_IP;};
  123. !           memcpy(&ICMPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  124.                           sizeof(struct ICMP_header));
  125. !           unwrapped->ICMP_len = ICMP_HEADLENGTH;
  126. !           unwrapped->DATA_len = ntohs(IPhead.length) -
  127.                   (unwrapped->IP_len) - (unwrapped->ICMP_len); 
  128. !           return ICMP;
  129. !           }
  130. !                 else
  131. !                   {
  132. !                   return -1; /* don't handle fragmented ICMP */
  133. !                   } 
  134.           }
  135.       if(IPhead.protocol == UDP )                       /* UDP */
  136.           {
  137. !                 if(unwrapped->FRAG_nf == 0)
  138. !                   {  
  139. !           if( (ntohs(IPhead.length)-(unwrapped->IP_len))<8 )
  140. !             {return CORRUPT_IP;};
  141. !             memcpy(&UDPhead,(sp+PROTO_HEAD+(unwrapped->IP_len)),
  142.                           sizeof(struct UDP_header));
  143. !           unwrapped->UDP_len = UDP_HEADLENGTH;
  144. !           unwrapped->DATA_len = ntohs(IPhead.length) -
  145.                   (unwrapped->IP_len) - (unwrapped->UDP_len); 
  146. +           }
  147. +                 else
  148. +           {
  149. +           unwrapped->DATA_len = ntohs(IPhead.length)-(unwrapped->IP_len); 
  150. +           }
  151.           return UDP; 
  152.           }
  153.       return -1; 
  154. *** sn_packetstructs.h    Fri Apr 18 11:33:58 1997
  155. --- sn_packetstructs.h    Thu Jul 24 16:17:20 1997
  156. ***************
  157. *** 44,51 ****
  158.       unsigned short length, checksum;
  159.   };
  160.   
  161. ! struct unwrap                                           /* some extra info */
  162.   {
  163.       int IP_len, TCP_len, ICMP_len, UDP_len;         /* header lengths */ 
  164.       int DATA_len;
  165.   };
  166. --- 44,52 ----
  167.       unsigned short length, checksum;
  168.   };
  169.   
  170. ! struct unwrap                                          /* some extra info */
  171.   {
  172.       int IP_len, TCP_len, ICMP_len, UDP_len;         /* header lengths */ 
  173.       int DATA_len;
  174. +     char FRAG_nf;                           /* not the first fragment */
  175.   };
  176. *** sniffit.0.3.5.c    Fri Apr 18 11:33:58 1997
  177. --- sniffit.0.3.5.c    Thu Aug 22 19:19:49 1985
  178. ***************
  179. *** 411,421 ****
  180. --- 411,427 ----
  181.       proto=unwrap_packet(sp, info); 
  182.       if(proto == NO_IP)    return DONT_EXAMINE; /* no use in trying */
  183.       if(proto == NO_IP_4)    return DONT_EXAMINE; /* no use in trying */
  184. +     if(proto == CORRUPT_IP)    
  185. +       {printf("Suspicious Packet detected... (Split header)\n");
  186. +        return DONT_EXAMINE;}
  187.   
  188.           memcpy(&iphead,(sp+PROTO_HEAD),sizeof(struct IP_header));
  189.       so=(unsigned char *)&(iphead.source);
  190.              dest=(unsigned char *)&(iphead.destination);
  191.   
  192. +     if(info->FRAG_nf!=0)
  193. +       {printf("Fragment Skipped...\n"); return DONT_EXAMINE; };
  194.       if((proto==TCP)&&(PROTOCOLS&F_TCP)) 
  195.           {
  196.   #ifdef DEBUG_ONSCREEN
  197. ***************
  198. *** 1220,1225 ****
  199. --- 1226,1235 ----
  200.       proto=unwrap_packet(sp, info);
  201.       if(proto == NO_IP)    return DONT_EXAMINE; /* no use in trying */
  202.       if(proto == NO_IP_4)    return DONT_EXAMINE; /* no use in trying */
  203. +     if(proto == CORRUPT_IP)    return DONT_EXAMINE; /* no use in trying */
  204. +     if(info->FRAG_nf!=0)
  205. +       {return DONT_EXAMINE; };
  206.   
  207.       (*IP_nr_of_packets)++;
  208.       if(proto==ICMP)  
  209.