Beispiel #1
0
int dmg2john(int argc, char **argv)
{
	int i;

	if (argc < 2) {
		puts("Usage: dmg2john [DMG files]");
		return -1;
	}
	for (i = 1; i < argc; i++)
		hash_plugin_parse_hash(argv[i]);

	return 0;
}
Beispiel #2
0
/* Detect plugin */
hash_stat detect_plugin(char *plugindir,char *file, char *hash)
{
    struct dirent **dentrylist;
    char soname[1024];
    DIR *dir;
    int count=-1,i=0;
    char line[1024];
    FILE *fd;
    char *preferred_plugins[] = { "ntlm","sha1","md5","lm","sha256","sha512","smf","vbulletin","ipb2",NULL };
    char *preferred_special_plugins[] = { "zip","rar","wpa","privkey",NULL };
    char *detected_plugins[128];
    int detected;
    char *detected_list;
    int detected_list_size=0;
    int j,flag;
    char lhash[256]; // Local hashline copy cause some plugins play rough with strtok

    /* We are now detecting plugins, don't be verbose */
    detecting=1;

    /* Init */
    detected=-1;

    /* Is a cmdline hash? */
    i=0;
    if (hash)
    {
	dir=opendir(plugindir);
	if (!dir)
	{
	    elog("Cannot open plugins dir: %s", plugindir);
	    return hash_err;
	}
	closedir(dir);
	count = scandir(plugindir, &dentrylist, 0, alphasort);

	/* First check preferred plugins */
	while (preferred_plugins[i])
	{
	    strcpy(soname,preferred_plugins[i]);
	    set_current_plugin(soname);
	    if (load_plugin() == hash_ok) 
	    if (!hash_plugin_is_special())
	    {
	        strcpy(lhash,hash);
	        if (hash_plugin_parse_hash(lhash,NULL) == hash_ok)
	        {
		    detected++;
		    detected_plugins[detected]=malloc(strlen(preferred_plugins[i]+1));
		    strcpy(detected_plugins[detected],preferred_plugins[i]);
		}
		unload_plugin();
	    }
	    i++;
	}

	/* Then the next, in order */
	i=0;
	do
	{
	    if (strstr(dentrylist[i]->d_name, ".so"))
	    {
		strcpy(soname,dentrylist[i]->d_name);
		soname[strlen(soname)-3]=0;
		set_current_plugin(soname);
		if (load_plugin() == hash_ok) 
		if (!hash_plugin_is_special())
		{
		    strcpy(lhash,hash);
		    if (hash_plugin_parse_hash(lhash,NULL) == hash_ok)
		    {
			flag=0;
			for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1;
			if (flag==0)
			{
			    detected++;
			    detected_plugins[detected]=malloc(strlen(soname)+1);
			    strcpy(detected_plugins[detected],soname);
			}
		    }
		    unload_plugin();
		}
	    }
	    i++;
	} while (i<count);
	free(dentrylist);
    }

    /* Is a hashfile (but hashlist)? */
    i=0;
    if (file)
    {
	fd=fopen(file,"r");
	if (!fd)
	{
	    elog("Cannot open %s\n",file);
	    return hash_err;
	}
	fgets(line,1024,fd);
	line[1023]=0;
	if (strlen(line)<1) fgets(line,1024,fd);
	line[1023]=0;
	fclose(fd);
	if (line[strlen(line)-1]=='\n') line[strlen(line)-1]=0;
	if (line[strlen(line)-1]=='\r') line[strlen(line)-1]=0;

	dir=opendir(plugindir);
	if (!dir)
	{
	    elog("Cannot open plugins dir: %s", plugindir);
	    return hash_err;
	}
	closedir(dir);
	count = scandir(plugindir, &dentrylist, 0, alphasort);

	/* First check preferred plugins */
	while (preferred_plugins[i])
	{
	    strcpy(soname,preferred_plugins[i]);
	    set_current_plugin(soname);
	    if (load_plugin() == hash_ok) 
	    if (!hash_plugin_is_special())
	    {
	        strcpy(lhash,line);
	        if (hash_plugin_parse_hash(lhash,NULL) == hash_ok)
	        {
		    detected++;
		    detected_plugins[detected]=malloc(strlen(preferred_plugins[i]));
		    strcpy(detected_plugins[detected],preferred_plugins[i]);
		}
		unload_plugin();
	    }
	    i++;
	}

	/* Then the next, in order */
	i=0;
	do
	{
	    if (strstr(dentrylist[i]->d_name, ".so"))
	    {
		strcpy(soname,dentrylist[i]->d_name);
		soname[strlen(soname)-3]=0;
		set_current_plugin(soname);
		if (load_plugin() == hash_ok) 
		if (!hash_plugin_is_special())
		{
		    strcpy(lhash,line);
		    if (hash_plugin_parse_hash(lhash,NULL) == hash_ok)
		    {
			flag=0;
			for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1;
			if (flag==0)
			{
			    detected++;
			    detected_plugins[detected]=malloc(strlen(soname)+1);
			    strcpy(detected_plugins[detected],soname);
			}
		    }
		    unload_plugin();
		}
	    }
	    i++;
	} while (i<count);
	free(dentrylist);
    }

    /* Is a hashfile (but not hashlist)? */
    i=0;
    if (file)
    {
	dir=opendir(plugindir);
	if (!dir)
	{
	    elog("Cannot open plugins dir: %s", plugindir);
	    return hash_err;
	}
	closedir(dir);
	count = scandir(plugindir, &dentrylist, 0, alphasort);

	/* First check preferred plugins */
	while (preferred_special_plugins[i])
	{
	    strcpy(soname,preferred_special_plugins[i]);
	    set_current_plugin(soname);
	    if (load_plugin() == hash_ok) 
	    if (hash_plugin_is_special())
	    {
	        if (hash_plugin_parse_hash("dummy",file) == hash_ok)
	        {
		    detected++;
		    detected_plugins[detected]=malloc(strlen(preferred_special_plugins[i])+1);
		    strcpy(detected_plugins[detected],preferred_special_plugins[i]);
		}
		unload_plugin();
	    }
	    i++;
	}

	/* Then the next, in order */
	i=0;
	do
	{
	    if (strstr(dentrylist[i]->d_name, ".so"))
	    {
		strcpy(soname,dentrylist[i]->d_name);
		soname[strlen(soname)-3]=0;
		set_current_plugin(soname);
		if (load_plugin() == hash_ok) 
		if (hash_plugin_is_special())
		{
		    if (hash_plugin_parse_hash("dummy",file) == hash_ok)
		    {
			flag=0;
			for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1;
			if (flag==0)
			{
			    detected++;
			    detected_plugins[detected] = malloc(strlen(soname)+1);
			    strcpy(detected_plugins[detected],soname);
			}
		    }
		    unload_plugin();
		}
	    }
	    i++;
	} while (i<count);
	free(dentrylist);
    }

    detected++;
    detecting=0;
    if (detected > 1)
    {
	for (i=0;i<detected;i++)
	{
	    detected_list_size += strlen(detected_plugins[i])+1;
	}
	detected_list = malloc(detected_list_size+1);
	bzero(detected_list,detected_list_size);
	for (i=0;i<detected;i++)
	{
	    sprintf(detected_list,"%s %s",detected_list,detected_plugins[i]);
	}
	wlog("Warning: multiple plugins match this input!%s\n","");
	wlog("Plugins available:%s\n",detected_list);
	wlog("Choosing %s. If that's not what you meant, use the -p <plugin> switch!\n",detected_plugins[0]);
	set_current_plugin(detected_plugins[0]);
	load_plugin();
	free(detected_list);
	for (i=0;i<detected;i++) free(detected_plugins[i]);
	return hash_ok;
    }
    if (detected == 1)
    {
    	hlog("Loading plugin %s\n",detected_plugins[0]);
    	set_current_plugin(detected_plugins[0]);
	load_plugin();
    	free(detected_plugins[0]);
    	return hash_ok;
    }
    return hash_err;
}