gcc下MD5破解

#include <stdio.h>

#include <stdlib.h>

#include <openssl/md5.h>

#include <string.h>

#define LINE 1024

//按行读取文件

char *ReadData(FILE *fp, char *buf)  

{

    return fgets(buf, LINE, fp);

}

//MD5加密函数

char* jm(unsigned char *data)

{

    unsigned char md[16];

    int i;

    char tmp[3]={'\0'},*buff;

    buff=malloc(33);

    buff[0]='\0';

    MD5(data,strlen(data),md);

    for (i = 0; i < 16; i++){

        sprintf(tmp,"%2.2x",md[i]);

        strcat(buff,tmp);

    }

    return buff;

}

//字符串过滤函数

void delstr(char* str)

{

    int i=0;

    for(i=0;str[i]!='\0';i++)

    {

        if(str[i]=='\n'){str[i]='\0';break;}

    }

}

void main(int argc,char **argv)  

{

    FILE *fp;  

    char *buf,*p;

    char _md5[33]={'\0'},buff[33]={'\0'};

    if (argc!=3)

        {printf("exp:\ncMD [hash...] [passwd file name...]\nfrom 乔3少 and 食猫鱼 \nblog:qiaoy.net\n");}

    else

        {if ((fp=fopen(argv[2],"r"))==NULL)  

         {

             printf("Cannot open file!\n");  

             exit(0);  

         }  

         buf = (char *)malloc(LINE*sizeof(char));  

         p = ReadData(fp, buf);  //将每行的内容读到buf中  

         while (p)  

         {

             delstr(buf);

             char* _md5=jm(buf);  //对该行的任意操作  

             if (strcmp(argv[1], _md5) == 0)

                 {printf("[%s]---------------->[%s]\n",buf,_md5);

                  exit(0);}

             else

             {p = ReadData(fp, buf);}  //指针移到下一行  

         }

         fclose(fp);

         } 

}

注释已在代码中,编译命令和使用如图:

原文地址:https://www.cnblogs.com/myphoebe/p/2154051.html