Final Keyboard Hook

By: chpie

 

Final keyboard hook

2007. 2 - http://chpie.org/ (korean only)

source-code & test-binary is on my vault : 0x60_hook.zip


I love keyboard hook and this article shows you
the most fundamental level keyboard hook.


Everyone knows this

0x60 : keyboard scancode port
0x64 : keyboard status port

If you can monitoring 0x60 port's I/O,
the lowest level hooking is available.

Using processor debug facility, we can monitoring
system's I/O Address space.

pseudo code

DR(0 - 3) = specific I/O Address. (ex 0x60)
DR7.RWn = 10b ( I/O Address space trap )
DR7.LENn = 01b ( one-byte )
DR7.Gn = DR7.Ln = 01b ( DRn Break-point Enable)


But there are some problem.
When context-switching occurs, Windows have it's own
context structure which is different from processor architecture,
all debug-registers are modified immediately.

to prevent our debug register modified,
General-detect (debug facility) needed.

DR7.GD = 01b ( general-detect enable)

general-detect detects any attempt to modify debug registers
and when detect it, raise exception #DB.

general-detect is [ fault-class ] exception,
saved CS and EIP points to instruction caused exception.

mov dr0, eax -- exception occurs and EIP points to it.

to skip instruction, you just modify EIP on the stack.
when exception raised, processor saves some data like CALL instruction.

[ stack (not priviled switch) ]
EFLAGS
CS
EIP ---- we just added 0x3 to this

was saved on the stack.

- dispatch -

I/O address space trap is [ trap-class ] exception.

[code-stream]
nop
in 0x60, al
nop ------ Trap occurs next to the IN instruction.

IN instruction always communicate with device using EAX register,
and exception is trap-class,
you just take a EAX value to get the result of IN 0x60, AL instruction.



It is done, immortal I/O breakpoint was installed on your system!

On multi-processor environment, each processor have it's own Debug registers and IDT.
Multi-processor support code is available on the .http://rootkit.com/.

To call dpc's on the each processor, you can modify each debug registers easily.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值