Reputation: 25
I am new to programming in C.I am trying to make a simple password cracking program but when I try to run it I get Segmentation Fault as an error. Can someone solve the issue. Thanks in advance.
#define _XOPEN_SOURCE
#include<stdio.h>
#include<crypt.h>
#include<unistd.h>
#include<string.h>
int main(int argc, char *argv[])
{
if(argc != 3)
{
printf("Usage: ./craken salt hash\n");
return 0;
}
FILE *fPointer;
fPointer = fopen("wordlist.txt", "r");
char singleLine[150];
while(fgets(singleLine, 150, fPointer) != NULL)
{
if(!strcmp(argv[2], crypt(singleLine, argv[1])))
{
printf("Password found! %s is the password\n", singleLine);
fclose(fPointer);
return 0;
}
}
printf("Not found\n");
fclose(fPointer);
return 0;
}
Upvotes: 0
Views: 582
Reputation: 11
I guess the problem is that if you read out possible passwords out of you're file there is an newline at the end. The crypt() function as I understand can only handle the set [a-zA-Z0-9./] (crypt man page) that might result in an NULL pointer being returned. This NULL pointer than leads to a segmentation fault inside the strcmp() function. So try to remove that newline char at the end of each input line. Hope this works
Upvotes: 1