两分钟用C#搭建IE BHO勾子, 窃取密码 (转载)

中文翻译请查看:

http://blog.csdn.net/jackiechen01/archive/2007/08/11/1738010.aspx


Microsoft provided Browser Helper Object (BHO) to let developers "drive" Internet Explorer. The first BHO was introduced in 1997 with IE 4.0. I have been writing programs on BHO for months. It could be quite depressing at the very first beginning to learn all those things. Hereby, I am writing this article to help beginners like me get familiar with BHO as soon as possible.

My personal interest is actually C++. C++ programs can be a lot less memory-consuming than C# program. But C# does provide better service on BHO comparing to C++. My first BHO program was written in C++.  It took me quite a while to figure out what was going on. But C# only takes me few minutes. Besides, C# has lots of pleasant designs such as foreach . It is very easy to handle especially when users want to convert one data type into another, while C++ may take longer.

To set up a BHO Hello World Project, Lets first start a C# Class Library, as BHO is written in .dll attached to IE. You dont need a Visual Studio 2005, C# express is totally enough.


 

After we have this empty project, let's add one folder named BHO and a .cs file into the folder.

The first file has to been named IObjectWithSite to notify that this is a BHO project. To know more about this interface, please refer to http://msdn2.microsoft.com/en-us/library/Aa768220.aspx

We also need to add two functions

GetSite:  Gets the last site set with IObjectWithSite::SetSite. If there is no known site, the object returns a failure code.

SetSite:  Provides the site's IUnknown pointer to the object.

 

Don't forget System.Runtime.InteropServices

Add another .cs file where the main functions located

Add a class called BHO in the newly added file. The class contains the interface IObjectWithSite

 

To use BHO we need to have two references, SHDocVw and MSHTML.You can find them at Windows"System32 folder

SHDocVw is  Microsoft Shell Doc Object and Control Library

MSHTML is:   All interfaces for accessing the Dynamic HTML (DHTML) Object Model are based on IDispatch and are the basis of access to the object model that is also used by scripts. http://msdn2.microsoft.com/en-us/library/bb498651.aspx

have "using SHDocVw" is not enough, you need to add references to the project.

Add SHDocVw 

As later we are going to use MessageBox, we also need to add Windows Form reference

 

Now we add two variables into the class, WebBrowser and HTMLDocument. Just like their name, you could easily figure out what do they do.

Besides, the two methods we defined in the IObjectWithSite interface, we also need to add OnDocumentComplete. You don't need it if you don't use it. OnDocumentComplete is a function of CDHtmlDialog Class http://msdn2.microsoft.com/en-us/library/8bed8k60(VS.80).aspx . It will be triggered if the HTMLDocument downloading is complete, in other words, when your page is loaded. You can also use Navigate() or OnBeforeNavigate(). Please refer to http://msdn2.microsoft.com/en-us/library/8k5z3ekh(VS.80).aspx to find out what you need exactly.

Under the IObjectWithSite.cs you need to point out the GUID of IE for thei program, so it can attach to IE.

Also, you need to assian a GUID for your own program. You can use System.Guid.NewGuid() method to get one, which is really neat comparing to C++.

 

You cannot just leave SetSite and GetSite blank. fill them in. This step is to tell IE that the DocumentCompletent Event is attached to OnDocumentComplete in our program.

Add one more reference

Under BHO.cs we need to write two functions for register/unregister of this DLL.

Now compile, under your release folder, you will find the .dll of your own project.

Then, use regasm /codebase "BHO HelloWorld.dll" to register our dll. We got a problem here. The REGASM told me it's not registerd. WHY?

Because we didn't set the BHO class as public. That's why.

 

now, do it again. It's successful.

open your registry. Find out Browser Helper Object under LOCAL_MACHINE->SOFTWARE->MICROSOFT->WINDOWS->EXPLORER

 

So, now program has been officially attached to your BHO. We need to fillin the OnDocumentComplete function. It's really neat to use C#'s foreach loop rather than for loop in C++. So you won't need to care about the indexer overflow. Besides, as we can see the type conversion is quite easy. This is an example on we want to find out the NAME attributes of an IHTMLInputElement.

An IHTMLInputElement is an Input element on HTML Page.

If the IHTMLInputElement does not have name attributes, we will fetch the ID attribute. Then pop up the content.

There you go, see?

Now, let's try to use BeforeNavigate() rather than OnDocumentComplete().

As we can see, there are BeforeNavigate and BeforeNavigate2(). We go for the latter one. If you are interested, you can use the first one.

 

Add the function prototype.  

Set up the hook.

Now, we want to steal the password on an Input password element

See, how easily, you can get it.

 

In conclusion, its really easy to handle BHO with C#. Thats why many IE add-ons are not safe at all. I hope these are useful. To waive your trouble, you can use the project template I made. Download it and put it under your Visual Studio 2005"Templates"ProjectTemplates folder (its usually under My Document).

转载于:https://www.cnblogs.com/AdmiralSoft/articles/1314711.html

BHO(Browser Helper Object,浏览器辅助对象,简称BHO)   BHO是微软推出的作为浏览器对第三方程序员开放交互接口的业界标准,通过简单的代码就可以进入浏览器领域的“交互接口”(INTERACTIVED Interface)。通过这个接口,程序员可以编写代码获取浏览器的行为,比如“后退”、“前进”、“当前页面”等,利用BHO的交互特性,程序员还可以用代码控制浏览器行为,比如修改替换浏览器工具栏,添加自己的程序按钮等。这些在系统看来都是没有问题的。BHO原来的目的是为了更好的帮助程序员打造个性化浏览器,以及为程序提供更简洁的交互功能,现在很多IE个性化工具就是利用BHO的来实现。 编辑本段 技术优势   “浏览器劫持”是一种不同于普通病毒木马感染途径的网络攻击手段,而是使用各种技术(如DLL插件等)插件对用户的浏览器进行篡改。安装后,它们会成为浏览器的一部分,可以直接控制浏览器进行指定的操作,根据需要,可以让你打开指定的网站,甚至是收集你系统中的各种私密信息。最可怕的是只有当浏览器已经被劫持了,你才会发现,反应过来,原来电脑已经出现了问题。比如IE主页被改,开机就会弹出广告等等。目前,浏览器劫持已经成为Internet用户最大的威胁之一。其实“浏览器劫持”就是通过BHO的技术手段进入你的系统的,而这种技术是合法的。   从某种观点看,Internet Explorer同普通的Win32程序没有什么两样。借助于BHO,你可以写一个进程内COM对象,这个对象在每次启动时都要加载。这样的对象会在与浏览器相同的上下文中运行,并能对可用的窗口和模块执行任何行动。例如,一个BHO能够探测到典型的事件,如GoBack、GoForward、DocumentComplete等;另外BHO能够存取浏览器的菜单与工具栏并能做出修改,还能够产生新窗口来显示当前网页的一些额外信息,还能够安装钩子以监控一些消息和动作。 编辑本段 注册表位置   BHO在注册表中的位置是:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects,有兴趣的朋友可以在这里做做实验。不过一定要记住你更改的每一步,否则会出错的哦!   BHO对象依托于浏览器主窗口。实际上,这意味着一旦一个浏览器窗口产生,一个新的BHO对象实例就要生成。任何 BHO对象与浏览器实例的生命周期是一致的。其次, BHO仅存在于Internet Explorer 4.0及以后版本中。   如果你在使用Microsoft Windows? 98, Windows 2000, Windows 95, or Windows NT版本4.0 操作系统的话,也就一块运行了活动桌面外壳4.71,BHO也被 Windows资源管理器所支持。 BHO是一个COM进程内服务,注册于注册表中某一键下。在启动时,Internet Explorer查询那个键并把该键下的所有对象预以加载。   迅雷中TDAtOnce_Now.dll和xunleiBHO_Now.dll为安全   如何发现BHO里面的危险模块.   首先有一个能够查看进程的软件 冰刃就不错 下面以它为例:   先打开冰刃—会看到一个BHO在这里就可以看到危险BHO进程了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值