コード例 #1
0
ファイル: passcrackd.c プロジェクト: ocallesp/crackMe
void schedulePasswords(void)
{
	char buffer[128];
	char tmp[128];
	char hash[] = "$6$b0TQ0PcQ$x9.PZeRaLWDGBtu0WSIZmjzqBFaeTcZk/ex5/UGp6Jyy/Q1H/81cQkOj/hKwBSYnN09UwgI6cDZOjS7idQS1n0";
	size_t passSize = 0;	
	size_t r ;
	char range[4];
	char i, j;
	char noRange;

	logMessage("schedulePasswords");	
	/* r = 6/3 = 2, so the first */
	noSymbols = sizeof(abcSymbols) / sizeof(char);
	logMessage("noSymbols: %d  totalHosts: %d", noSymbols, totalHosts);
	r = noSymbols / totalHosts;
		

	for (i = 0; i < totalHosts; i++) {
		sprintf(tmp,"%c-%c", abcSymbols[r * i], abcSymbols[r * i] + (r - 1));

		strcpy(listOfHosts[i].range, tmp);	
		logMessage("Host[%d].ipAddr: %s", i, listOfHosts[i].range);
		strcpy(listOfHosts[ i ].hash, hash );
		strcpy(passwordToCrack, hash);
		logMessage("Host[%d].hash: %s", i, listOfHosts[i].hash);
		if (i != 0) {
  			sprintf(buffer, "%d %s %s", CRACK, listOfHosts[i].hash, listOfHosts[i].range);
			logMessage("message to distribute: %s", buffer);
			logMessage("remote host");
			sendMessage(listOfHosts[i].ipAddr, buffer);
		} else {		
			logMessage("local host");
			switch (childPid[noProcesses] =  fork()) {
        		case -1: 
            			logMessage("Cannot create process");
            			break;
        		case 0:
				noRange = tmp[2] - tmp[0] + 1;
				for (j = 0; j < noRange; j++)
					listOfHosts[i].range[j] = tmp[0] + j;
				listOfHosts[i].range[j] = '\0';
            			/* This is the child */
            			logMessage("local range: %s", listOfHosts[i].range);	
            			exit(passGen(abcSymbols, noSymbols, listOfHosts[i].range, noRange, 5));
            			break;
        		default:
            			/* This is the parent */
            			logMessage("Parent %d", getpid());
            			break; 
			} 
        	}
	}
return ;	
}
コード例 #2
0
ファイル: passcrackd.c プロジェクト: ocallesp/crackMe
int parseData(char *ipAddr, char *data)
{		
	struct host remote;
	char *tmp;
	int j;
	unsigned char noRange;
	char range[20];

	tmp =  strtok(data, " ");
	remote.comm = atoi(tmp);
	
	remote.local = false;
		
	switch (remote.comm) {
	case REGISTER:
		logMessage("register");
	
		inet_pton(AF_INET, ipAddr, &(listOfHosts[totalHosts].ipAddr));
		logMessage("remote.ipAddr: %d", remote.ipAddr); 

		tmp =  strtok(NULL, " ");
		if (!strcmp(tmp, "free"))
			listOfHosts[totalHosts].free = true;
		else
			listOfHosts[totalHosts].free = false;

		logMessage("remote.free: %d", listOfHosts[totalHosts].free);

		tmp = strtok(NULL, " ");
		listOfHosts[totalHosts].memory = atoi(tmp);
		logMessage("remote.memory: %d", listOfHosts[totalHosts].memory);

		tmp = strtok(NULL, " ");
		listOfHosts[totalHosts].noCores = atoi(tmp);
		logMessage("remote.noCores: %d", listOfHosts[totalHosts].noCores);

		tmp = strtok(NULL, " ");
		listOfHosts[totalHosts].cpuUsage = atof(tmp);
		logMessage("remote.cpuUsage: %f", listOfHosts[totalHosts].cpuUsage);

		totalHosts++;		
		logMessage("total hosts: %d", totalHosts);

		break;
	case CRACK:
		logMessage("crack");

		tmp = strtok(NULL, " ");
		strcpy(passwordToCrack, tmp);
		logMessage("remote.hash: %s", remote.hash);

		strcpy(passwordToCrack, remote.hash);

		tmp = strtok(NULL, " ");
		strcpy(remote.range, tmp);
		logMessage("remote.range: %s", remote.range);

		/* CREATE PROCESS */
		switch (childPid[noProcesses] =  fork()) {
		case -1:
			logMessage("Cannot create process");
			break;
		case 0:
			noRange = remote.range[2] - remote.range[0] + 1;
			for (j = 0; j < noRange; j++)
				range[j] = remote.range[0] + j;
			range[j] = '\0';
			/* This is the child */
			noSymbols = sizeof(abcSymbols) / sizeof(unsigned char);
			noRange = strlen(listOfHosts[0].range);
			exit(passGen(abcSymbols, noSymbols, range, noRange, 5));
			break;
		default:
			/* This is the parent */
			logMessage("Parent %d", getpid());
			break;	
		}

		break;

	case FINISH:
		logMessage("finish");
		/* Give me more work */
		break;

	case FOUND:
		logMessage("found");
		sendBroadcastFound();
		/* stop all processes */
		//tmp = strtok( data, " ");
		//strcpy(remote.password, tmp);
		//logMessage("remote.password: %s", remote.password);
		break;

	default:
		logMessage("command not found");
		break;
	}
	
	return 0;
}
コード例 #3
0
int main(int argc, char *argv[]) {
    int length = 0, pass_count = 0;
    char spCharacter;
    char *pass = NULL;

    int counter = 1;
    int requiredParameter = 0;

    /* Switches */
    bool specialCharacters = false;

    if(argc > 1) {
    	requiredParameter = 1;

        while (counter < argc) {

        	if(strcmp("-s", argv[counter]) == 0) {
        		specialCharacters = true;
        	}
        	else if(strcmp("-n", argv[counter]) == 0) {
        		pass_count = atoi(argv[++counter]);
        	}
        	else {
        		if(requiredParameter == 0) {
        			fprintf(stderr, "Invalid Options Entered \"%s\"\n", argv[counter]);
        		}
        		else {
        			length = atoi(argv[counter]);
        			requiredParameter = 0;
        		}
        	}
        	counter++;
        }
    }else {
    	// Ask Password Length
        printf("Enter Password Length: ");
        scanf("%d",&length);

        // Ask number of Passwords to generate
        printf("Enter No. of Passwords to generate: ");
		scanf("%d", &pass_count);

        // Ask for Special Characters in Password
        printf("Do you want Special Characters to be included? Y/N:");
        scanf("%c",&spCharacter);
        scanf("%c",&spCharacter);

        if(spCharacter == 'Y' || spCharacter == 'y') {
        	specialCharacters = true;
        }

    }
    //return 0;
    if(requiredParameter == 1 || length <= 0) {
    	fprintf(stderr, "Length Required!\n");
    }
    else {
    	requiredParameter = 0;
    	if(pass_count <= 0) {
    		printf("Password is\n");
    		pass = passGen(length, specialCharacters);
    		if(pass == NULL)
    			requiredParameter++;
    		else {
    			printf("%s\n",pass);
    			free(pass);
    		}
    	}
    	else {
    		printf("Passwords are\n");
    		for(counter = 0; counter < pass_count; counter++) {
				pass = passGen(length, specialCharacters);
				if(pass == NULL)
					requiredParameter++;
				else {
					printf("%s\n",pass);
					free(pass);
				}
			}
    	}
    }

    if(length <= 0) {
    	fprintf(stderr, "Failed to Generate %d Password!", pass_count<=0?1:pass_count);
    }
    if(requiredParameter > 0) {
    	fprintf(stderr, "Failed to Generate %d Password!", requiredParameter);
    }

    return EXIT_SUCCESS;
}