Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在函数调用期间转储内核,can';找不到什么';这是不对的_C_Cryptography_Core_Shadow - Fatal编程技术网

在函数调用期间转储内核,can';找不到什么';这是不对的

在函数调用期间转储内核,can';找不到什么';这是不对的,c,cryptography,core,shadow,C,Cryptography,Core,Shadow,晚上好,我为我的大学项目编写的C代码有问题 这是一个加密类,我正在制作一个脚本,它将从shadow.txt中获取哈希密码及其salt,然后将哈希密码与.txt中可能的密码进行比较。 在调用decryptwithTXT()函数之前,一切都正常。它只是给了我一个核心转储问题。我在函数中放置了一些打印,以查看它在哪里崩溃,但它从不打印任何东西,这意味着它只是在调用函数时崩溃,但我不知道为什么 如果您有任何关于我做错了什么并导致它崩溃的提示,我将非常感谢。如果你还有关于我的代码质量的任何其他提示,请随时

晚上好,我为我的大学项目编写的C代码有问题

这是一个加密类,我正在制作一个脚本,它将从shadow.txt中获取哈希密码及其salt,然后将哈希密码与.txt中可能的密码进行比较。 在调用decryptwithTXT()函数之前,一切都正常。它只是给了我一个核心转储问题。我在函数中放置了一些打印,以查看它在哪里崩溃,但它从不打印任何东西,这意味着它只是在调用函数时崩溃,但我不知道为什么

如果您有任何关于我做错了什么并导致它崩溃的提示,我将非常感谢。如果你还有关于我的代码质量的任何其他提示,请随时给我一些提示,我正在努力提高C语言的水平,所以我非常愿意接受批评

这是我的主要任务

#include <stdio.h>
#include <crypt.h>
#include <string.h>

int getSaltnPassword(char* name,char* salt,char* pwd);
int decryptwithTXT(char* pwd,char* hpwd,char* salt,char* file);

int main()
{
    int x;
    char salt[8],hashedpwd[18],pwd[255],name[255],answer,flag,filename[25];
    do{
        printf("   Give username of targeted account.\n");
        scanf("%s",name);
        if (getSaltnPassword(name,salt,hashedpwd)==1){
            printf("Salt: %s\nHashed Password: %s\n",salt,hashedpwd);
            printf("   Proceed with attack on selected user? Y/N \n");
            scanf("%c",&answer);
            scanf("%c",&answer);
        }
        else
            printf("User not found, try again.\n"); 
    }while (answer!='Y'&&answer!='y');
    printf("   Choose one of the following:\n");
    printf("   a) Attack using datamined passwords.\n");
    printf("   b) Dictionary attack.\n");
    printf("   c) 4 character brute-force attack\n");
    scanf("%c",&flag);
    scanf("%c",&flag);
    switch(flag){

        case 'a':
            printf("Datamine\n");
            x=decryptwithTXT(pwd,hashedpwd,salt,"tom_datamine.txt");
        case 'b':
            printf("Dictionary.\n");
        case 'c':
            printf("Brute force.\n");
    }
return 0;
}
这是从shadow.txt获取salt和hash密码的函数。它现在按预期工作

int getSaltnPassword(char* name,char* salt, char* pwd){
    FILE *fp;
    char line[255],name_txt[255];
    int i,salta,saltb,pwda,pwdb;
    int j=0;
    fp=fopen("my_shadow.txt","r");
    while(!feof(fp)){
        i=0;
        fgets(line,255,(FILE*) fp);
        while (line[i]!=':'){
            name_txt[i]=line[i];    
            i++;
        }
        name_txt[i] = '\0';
        if (strcmp(name_txt,name)==0){
            printf("User found.\n");
            salta=i+4;
            saltb=i+12;
            for (i=salta;i<saltb;i++){
                salt[j]=line[i];
                j++;
            }
            salt[8]='\0';
            pwda=saltb+1;
            pwdb=pwda+18;
            j=0;
            for (i=pwda;i<pwdb;i++){
                pwd[j]=line[i];
                j++;
            }
            pwd[18]='\0';
            fclose(fp);
            return 1;
        }
      }
    fclose(fp); 
    return 0;
}
这就是我的tom_datamine.txt

tom
marousi
anna
pinkfloyd
bowling
tommarousi
tomarousi
tomanna
tompf
tompinkfloyd
bowlingfloyd
pink floyd
tombowling

因为输出一直位于缓冲区中,直到它通过满、换行或fflush(stdout)释放到设备为止,当程序崩溃时,消息永远不会被打印。请注意,写printf(“我的消息”)而不是printf(“我的消息”)是常见的错误

正因为如此,我放入的调试printf从未打印过,我认为我的函数调用有问题,但毕竟,它是一个错误的文件读取


答案要归功于@WeatherVane,因为他在解决这个问题以及提高我在评论部分的编程知识方面提供了宝贵的帮助。

在那些printf调试中添加一些换行符,否则你会被误导。更好的是,使用适当的调试器。还有:
while(!feof(fp))
==>
while(fgets)(temppwd,255,(FILE*)fp)!=NULL)
。请查看,您甚至不检查文件是否已成功打开就可以
printf(“fopen”);
。好的,很酷,谢谢大家,据我所知(!feof(fp))是一种不好的做法,非常脆弱和不安全。我会确保更改它。为什么使用双
scanf(%c),&answer);scanf(%c),&answer)
(等)?第二个将读取一个
换行符
。替换为单个
扫描(“%c”,&answer);
,在
%c
前面留有空格。
babis:$1$asff83lt$gggggg9nvR6civ7fZP.tt/:
anna:$1$kwif83lt$ZaNUkA9nvR6civ7fZP.tt/:
tom
marousi
anna
pinkfloyd
bowling
tommarousi
tomarousi
tomanna
tompf
tompinkfloyd
bowlingfloyd
pink floyd
tombowling