Multithreading a password checker in C
pCurrently attempting to get this program to use multithreading using
codepthread_create/code, codepthread_join/code, codepthread_exit/code, and
codepthread_self/code. I then intend to use codecrypt_r/code in place of
codecrypt/code in my code./p pIt will only be able to go up to 8 threads,
but I don't even know how to get started with two. I just have one line
that declares codepthread_t t1,t2,t3,t4,t5,t6,t7,t8/code./p pThe plan with
these is to put them in to codepthread_create/code but besides
initializing these values, I don't know where to go from here./p pI know
that pthread_create's input would be something like codepthread_create(t1,
NULL, ... , ...)/code but I do not know how to go about making the 3rd
input or what the 4th input even is. I then have to make sure to split up
the range of letters that each thread is checking based on the number of
threads specified by a command line arg. I've designed this so far to work
on one thread only, planning on moving it to codecrypt_r/code with
multithreading.../p pReally confused as to how I could get to make this
work.. If possible./p pI know some sort of void function is the third
entry in to codepthread_create/code.. but does that function have to be
what my passwordChecker is? Or what?/p precode/* crack.exe */ /* g++ -o
crack crack.c -lcrypt -lpthread */ //#define _GNU_SOURCE #include
lt;crypt.hgt; #include lt;unistd.hgt; #include lt;stdio.hgt; #include
lt;stdlib.hgt; #include lt;errno.hgt; #include lt;pthread.hgt; #include
lt;string.hgt; #include lt;math.hgt; void *passwordLooper(int ks, char
target[9], char s[10]); void *threadFunction(void *threads); int main(int
argc, char *argv[]){ /* usage = crack threads keysize target */ int i = 0;
/* arg[0] = crack, arg[1] = #of threads arg[2] = size of password, arg[3]
= hashed password being cracked */ if (argc != 4) { fprintf(stderr, Too
few/many arguements give.\n); fprintf(stderr, Proper usage: ./crack
threads keysize target\n); exit(0); } int threads = *argv[1]-'0'; //
threads is now equal to the second command line argument number int
keysize = *argv[2]-'0'; // keysize is now equal to the third command line
argument number char target[9]; strcpy(target, argv[3]); char salt[10];
while ( i lt; 2 ){ //Takes first two characters of the hashed password and
assigns them to the salt variable salt[i] = target[i]; i++; }
printf(threads = %d\n, threads); /*used for testing */ printf(keysize =
%d\n, keysize); printf(target = %s\n, target); printf(salt = %s\n, salt);
if (threads lt; 1 || threads gt; 8){ fprintf(stderr, 0 lt; threads lt;=
8\n); exit(0); } /*Checks to be sure that threads and keysize are*/ if
(keysize lt; 1 || keysize gt; 8){ /*of the correct size */ fprintf(stderr,
0 lt; keysize lt;= 8\n); exit(0); } pthread_t t1,t2,t3,t4,t5,t6,t7,t8; if
( threads = 1 ){ pthread_create(amp;t1, NULL, *threadFunction, threads); }
char unSalted[30]; int j = 0; for (i = 2; target[i] != '\0'; i++){
/*generates variable from target that does not include salt*/ unSalted[j]
= target[i]; j++; } printf(unSalted = %s\n, unSalted); //unSalted is the
variable target without the first two characters (the salt) char
password[9] = {0}; passwordLooper(keysize, target, salt); }
/*_____________________________________________________________________________________________________________*/
/*_____________________________________________________________________________________________________________*/
void *passwordLooper(int ks, char target[9], char s[10]){ char password[9]
= {0}; struct crypt_data cd; cd.initialized = 0; int result; for (;;){ int
level = 0; while (level lt; ks amp;amp; strcmp( crypt(password, s), target
) != 0) { if (password[level] == 0){ password[level] = 'a'; break; } if
(password[level] gt;= 'a' amp;amp; password[level] lt; 'z'){
password[level]++; break; } if (password[level] == 'z'){ password[level] =
'a'; level++; } } char *cryptPW = crypt(password, s); result =
strcmp(cryptPW, target); if (result == 0){ //if result is zero, cryptPW
and target are the same printf(result = %d\n, result); printf (Password
found: %s\n, password); printf(Hashed version of password is %s\n,
cryptPW); break; } if (level gt;= ks){ //if level ends up bigger than the
keysize, break, no longer checking for passwords printf(Password not
found\n); break; } } return 0; } /code/pre
No comments:
Post a Comment