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
<<
"
成功
"