Nov 02
2002
2002
Anonymous ftp scanner

Scans for anonymous ftp hosts in an IP range. To compile, gcc fatap.c -o fatap.
fatap.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /* Pravin Paratey (November 02, 2002) * Searches for anonymous ftp servers in the given range * Range can be of the form 10.2.0-3.* * Wildcards * and range modifier - allowed **/ #include <sys/socket.h> #include <sys/types.h> #include <resolv.h> #include <unistd.h> #include <errno.h> #include <signal.h> #include <pthread.h> #define TIMEOUT 4 #define MAX_THREADS 5 extern int errno; /* this will handle timeouts */ struct sigaction action; /* Stores the current ip, stderr and alarm problem had to make it global:( */ char conString[20]; int numThreads; // Stores the number of threads pthread_cond_t threadFree; // Tells if the no of running threads < MAX_THREADS pthread_mutex_t threadLock; // Mutex which is locked while changing numThreads void tryConnect (void *address); void fillIP (char *string, int array[4]); void timedOut(); int main(int argc, char *argv[]) { int start[4], end[4]; // IP addresses char *pStart, *pEnd; int count; int i,j,k,l; char *bigline="-------------------------------------------------------------------"; pthread_t daThread; // parse (argv); if (argc < 3) { printf ("Usage: %s <start-ip-address> <end-ip-address>\n \ <*ip-address> is of the form x.x.x.x where x is between 0 and 255 both inclusive.\n \ eg. 10.2.1.27\n", argv[0]); exit(2); } printf("%s\n fatap v0.2a - A proggy which scans an ip range for open ftp ports\n\ By Pravin Paratey (pravin@iitb.ac.in)\n%s\n", bigline, bigline); /* Get the start ip address */ fillIP (argv[1], start); /* Get the end ip address */ fillIP (argv[2], end); /* Check if the ranges are correct */ if (!(start[0] <= end[0] && start[1] <= end[1] && start[2] <= end[2] && start[3] <= end[3])) { fprintf(stderr, "%s: Invalid range specified\n", argv[0]); exit(2); } /* Some alarm related stuff */ action.sa_handler = timedOut; action.sa_flags = 0; /* Set sigaction for alarm timeout */ sigaction (SIGALRM, &action, 0); /* Initialise threads */ pthread_mutex_init(&threadLock, NULL); pthread_cond_init(&threadFree, NULL); numThreads = 0; /* Iterate */ for (i=start[0]; i <= end[0]; i++) for (j=start[1]; j <= end[1]; j++) for (k=start[2]; k <= end[2]; k++) for (l=start[3]; l <= end[3]; l++) { sprintf(conString, "%i.%i.%i.%i",i,j,k,l); if (numThreads > 5) { pthread_cond_wait (&threadFree, &threadLock); } pthread_create(&daThread, NULL, tryConnect, (void*) conString); pthread_mutex_lock(&threadLock); numThreads++; pthread_mutex_unlock(&threadLock); start[3] = start[2] = start[1] = 0; } pthread_cond_destroy(&threadFree); pthread_mutex_destroy(&threadLock); return 0; } void fillIP (char *string, int array[4]) { int count; char *pStart, *pEnd; count=0; pStart = pEnd = string; while (*pEnd != 0) { if (*pEnd == '.') { *pEnd = 0; array[count++] = atoi(pStart); pStart = pEnd+1; } *pEnd++; } array[count] = atoi(pStart); } void tryConnect (void *address) { /* Some variables */ int sock1; struct sockaddr_in sa1; char inbuf[1000]; char outbuf[100]; int retval; /* Create socket */ sock1 = socket (AF_INET, SOCK_STREAM, 0); if (sock1 == -1) { perror(address); exit(1); } sa1.sin_family = AF_INET; sa1.sin_port = htons(21); inet_aton (address, &sa1.sin_addr.s_addr); /* Set timeout */ //alarm(TIMEOUT); /* Connect to server and see if alive */ if (connect (sock1,(struct sockaddr *) &sa1, sizeof (sa1)) == -1) { if (errno != 4) // 4 - Interrupted system call (return from signal) fprintf(stderr, "[%s] %s\n",address, strerror(errno)); } else { sprintf(outbuf, "USER anonymous\r\n"); if(send(sock1, outbuf, sizeof(outbuf), 0) == -1) goto CLOSECON; retval = recv(sock1, inbuf, 1000, 0); if(retval == -1) goto CLOSECON; if(send(sock1, "\r\n",2,0) == -1) goto CLOSECON; retval = recv(sock1, inbuf, 1000, 0); sprintf(outbuf,"PASS unknown@unknown.com\r\n"); if(send(sock1, outbuf, sizeof(outbuf), 0) == -1) goto CLOSECON; retval = recv(sock1, inbuf, 1000, 0); if(send(sock1, "\r\n",2,0) == -1) goto CLOSECON; retval = recv(sock1, inbuf, 1000, 0); sscanf(inbuf, "%i %s*",&retval); printf("***%i\n",retval); if(retval == 230 || retval == 220) printf("[%s] Anonymous allowed\n", address); else printf("[%s] Anonymous NOT allowed\n", address); send(sock1, "QUIT\r\n", sizeof("QUIT\r\n"), 0); recv(sock1, inbuf, 1000, 0); } /* Reset alarm */ //alarm(0); CLOSECON: close(sock1); pthread_mutex_lock(&threadLock); numThreads--; pthread_cond_signal(&threadFree); pthread_mutex_unlock(&threadLock); pthread_exit(0); } void timedOut() { fprintf(stderr,"[%s] Connection timed out\n", conString); } |


I have used your fatap.c file code and getting error at compiling time.
Error:
fatap.c: In function ‘main’:
fatap.c:52: warning: incompatible implicit declaration of built-in function ‘exit’
fatap.c:69: warning: incompatible implicit declaration of built-in function ‘exit’
fatap.c:95: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type
fatap.c: In function ‘tryConnect’:
fatap.c:140: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/cclDVrPj.o: In function `main’:
fatap.c:(.text+0x1b8); undefined reference to `pthread_create’
collect2: ld returned 1 exit status
Can you please tell me whether my compiler problem and advice me how to use your code to make it work.
Awaiting for your valuable reply.
Thanks in advance
shankar
Compile using -lpthread like so:
$ gcc -lpthread fatap.c