暴力工具上的未知分割错误 //gcc-o输出输入.c-lcrypt //Ubuntu 18.04 LTS #包括 #包括 #包括 #包括 #包括 #包括 #定义_XOPEN_源 int findShadowIndex(char*inputUserName,char shadow[][500]){ int i=0;//临时循环变量 字符*用户名; while(shadow[i]!=NULL){ strcpy(用户名,shadow[i]); 用户名=strtok(用户名“:”); 如果(!strcmp(输入用户名,用户名)) 返回i+1; i++; } 返回0; } void setBFValue(字符BFValue[]){ int i,j=0; BFValue[j++]='\0'; 对于(i=48;i=58&&i=91&&i修复

暴力工具上的未知分割错误 //gcc-o输出输入.c-lcrypt //Ubuntu 18.04 LTS #包括 #包括 #包括 #包括 #包括 #包括 #定义_XOPEN_源 int findShadowIndex(char*inputUserName,char shadow[][500]){ int i=0;//临时循环变量 字符*用户名; while(shadow[i]!=NULL){ strcpy(用户名,shadow[i]); 用户名=strtok(用户名“:”); 如果(!strcmp(输入用户名,用户名)) 返回i+1; i++; } 返回0; } void setBFValue(字符BFValue[]){ int i,j=0; BFValue[j++]='\0'; 对于(i=48;i=58&&i=91&&i修复,c,segmentation-fault,brute-force,crypt,C,Segmentation Fault,Brute Force,Crypt,我已经修复了您的代码,我将首先向您展示我的修改,然后解释它们: 您的findShadowIndex函数变为: // gcc -o OUTPUT Input.c -lcrypt // Ubuntu 18.04 LTS #include<stdio.h> #include<stdlib.h> #include<fcntl.h> #include<string.h> #include<unistd.h> #include<crypt.

我已经修复了您的代码,我将首先向您展示我的修改,然后解释它们:

您的
findShadowIndex
函数变为:

// gcc -o OUTPUT Input.c -lcrypt
// Ubuntu 18.04 LTS

#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<crypt.h>

#define _XOPEN_SOURCE

int findShadowIndex(char *inputUserName, char shadow[][500]) {
    int i = 0; // Tempory Loop variable

    char *userName;

    while (shadow[i] != NULL) {

        strcpy(userName, shadow[i]);
        userName = strtok(userName, ":");

        if (!strcmp(inputUserName, userName))
            return i + 1;

        i++;
    }

    return 0;
}

void setBFValue(char BFValue[]) {
    int i, j = 0;

    BFValue[j++] = '\0';

    for (i = 48; i < 123; i++) {
        if (i >= 58 && i <= 64)
            continue;

        else if (i >= 91 && i <= 96)
            continue;

        BFValue[j] = i;

        j++;
    }

    BFValue[j++] = '!';
    BFValue[j++] = '@';
    BFValue[j++] = '#';
    BFValue[j++] = '$';
    BFValue[j++] = '%';
    BFValue[j] = '^';

    return;
}

int bruteForcing(char *originHash, char *cryptSalt, char *userName) {

    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;// Brute Force Loop variable

    char passwd[7] = "";

    char BFValue[100] = { NULL, }; // Brute Force Value
    setBFValue(BFValue);

    for (a = 0; a < 69; a++) {
        passwd[5] = BFValue[a];

        for (b = 0; b < 69; b++)
        {
            passwd[4] = BFValue[b];

            for (c = 0; c < 69; c++)
            {
                passwd[3] = BFValue[c];
                for (d = 0; d < 69; d++) {
                    passwd[2] = BFValue[d];

                    for (e = 0; e < 69; e++) {
                        passwd[1] = BFValue[e];

                        for (f = 1; f < 69; f++) {
                            passwd[0] = BFValue[f];

                            //printf("\nPasswd : %s\n\n", passwd);
                            //printf("\ncryptSalt : %s\n\n", cryptSalt);
                            //printf("\userName : %s\n\n", hashID);
                            //printf("\noroginHash : %s\n\n", originHash);

                            printf("%s, %s\n", passwd, userName);

                            //printf("%d, \n", strcmp(originHash, crypt(passwd, cryptSalt)));

                            if (!strcmp(originHash, crypt(passwd, cryptSalt))) {
                                printf("\n");
                                printf("[-] User Name : %s, Password : %s\n", userName, passwd);
                                printf("\n");

                                return 1;
                            }

                        }

                    }

                }

            }

        }
    }

    return 0;
    //printf("\n[-] Decryption Failed\n\n");

}

int main(int argc, char* argv[]) {
    FILE* fd = NULL; // Shadow File Descripter

    int i = 0; // Tempory Loop variable

    char shadow[100][500] = { {NULL, } }; // List of Shadow File

    char userName[30]; // User Name
    int shadowIdx; // User name index in Shadow File

    char* ptr; // Tempory char pointer

    char *id; // User ID
    char *hash, *hashID, *hashSalt, *hashValue;

    char cryptSalt[100] = "$";
    char originHash[100];

    if (argc < 3) {
        printf("\n[!] Usage >>> sudo ./yu_cracker [Shadow File] [User Name]\n\n");
        exit(1);
    }

    else if (argc == 3) {
        fd = fopen(argv[1], "r");

        if (fd == NULL) {
            printf("\n[!] Can't find Shadow File!!!\n\n");
            exit(1);
        }

        while (!feof(fd)) {
            fgets(shadow[i], 500, fd);
            i++;
        }

        strcpy(userName, argv[2]); // Get User name

        shadowIdx = findShadowIndex(userName, shadow);

        if (!shadowIdx) {
            printf("\n[!] Can't find user name in Shadow File\n\n");
            exit(1);
        }

        ptr = strtok(shadow[shadowIdx - 1], ":");
        id = ptr;

        ptr = strtok(NULL, ":");
        hash = ptr;
        strcpy(originHash, hash);

        ptr = strtok(hash, "$");
        hashID = ptr;

        ptr = strtok(NULL, "$");
        hashSalt = ptr;

        strcat(cryptSalt, hashID);
        strcat(cryptSalt, "$");
        strcat(cryptSalt, hashSalt);

        ptr = strtok(NULL, "$");
        hashValue = ptr;

        printf("[+] Origin Hash >>> %s\n\n", originHash);

        printf("[+] Hash ID >>> %s\n", hashID);
        printf("[+] Salt >>> %s\n", cryptSalt);
        printf("[+] Hash Value >>> %s\n\n", hashValue);

        int result = bruteForcing(originHash, cryptSalt, userName);
    }

    else {
        return 1;
    }

}
char-originHash[100];
变成
char-originHash[500];

解释 在
findShadowIndex
在您的oginal
findShadowIndex
中,在第一次迭代时,当您调用
strcpy(用户名,shadow[i]);
时,您正在从地址
shadow[i]复制字符
写入内存位置
userName
。问题是
char*userName;
不代表您分配的内存,因此
strcpy
正在写入您不拥有的内存,导致segfault

“我的版本”将要检查的当前阴影线复制到本地缓冲区(
char currentShadowRow[500];
)中,然后在副本上调用
strtok``以避免修改以后使用的
shadow``数组

originHash
放大到500字节
originHash
数组不够大,无法容纳所有哈希值(我的密码哈希值大于100个字符)

工作版本 如果要复制/粘贴工作代码,请执行以下操作:

//gcc-o输出输入.c-lcrypt
//Ubuntu 18.04 LTS
#包括
#包括
#包括
#包括
#包括
#包括
int findShadowIndex(char*inputUserName,char shadow[][500]){
int i=0;//临时循环变量
while(shadow[i]!=NULL){
字符行[500];
strcpy(currentShadowRow,shadow[i]);
如果(!strcmp(输入用户名,strtok(currentShadowRow,“:”)){
返回i+1;
}
i++;
}
返回0;
}
void setBFValue(字符BFValue[]){
int i,j=0;
BFValue[j++]='\0';
对于(i=48;i<123;i++){

如果(i>=58&&i=91&&i Hi.你可以
malloc
你的
username
来保留内存空间。你能把文本输出代替图片吗?顺便说一句,试试valgind,它会立即发现错误
int findShadowIndex(char *inputUserName, char shadow[][500]) {
    int i = 0; // Tempory Loop variable

    while (shadow[i] != NULL) {
        char currentShadowRow[500];
        strcpy(currentShadowRow, shadow[i]);

        if (!strcmp(inputUserName, strtok(currentShadowRow, ":"))) {
            return i + 1;
        }

        i++;
    }

    return 0;
}