天杀的ring0源代码

;====================================================================
;   Ring0驱动服务代码
; 作者:天杀 QQ:797801 Email:Willok@163.com
;--------------------------------------------------------------------
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.586P   ; 保护模式
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include  w2k/NTDDK.INC
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;=================================================================
; 中断相关数据结构
IDT_REG  STRUCT
 limit WORD ?
 base DWORD ?
IDT_REG  ENDS

; 中断描述符
INT_DESCRIPTOR  STRUCT
 offs0_15 WORD ?
 sel  WORD ?
 paramcnt BYTE ?
 attrs  BYTE ?
 offs16_31 WORD ?
INT_DESCRIPTOR  ENDS
;=================================================================
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
szBuffer db 16 dup(0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
MyIntFunc proc
  push edx
  call eax
  iretd
MyIntFunc endp

;====================================================================
AddMyInt proc uses edi
  local @IDT

  sidt szBuffer
  mov edi,(IDT_REG ptr [szBuffer]).base
  add edi,21h*8

 ; 使用Int21中断,该中断在Win2k下没有使用
;  cli
  mov eax,offset MyIntFunc
  mov [edi],ax
  shr eax,16
  mov [edi+6],ax  ; 设置入口地址
  mov [edi+2],cs  ; 设置段地址
 ; 设置Ring3可以访问
  mov WORD ptr [edi+4],0EE00h
;  sti

  ret
AddMyInt endp
;====================================================================
WdmUnload proc DriverObject:DWORD
  local @IDT

  sidt szBuffer
  mov edi,(IDT_REG ptr [szBuffer]).base
  add edi,21h*8
  xor eax,eax
  mov [edi],ax
  mov [edi+6],ax  ; 设置入口地址
  mov [edi+2],ax  ; 设置段地址
  mov WORD ptr [edi+4],ax

  ret
WdmUnload endp
;====================================================================
DriverEntry proc DriverObj:DWORD,RegistryPath:DWORD


  mov eax,DriverObj
  assume eax:ptr DRIVER_OBJECT
  mov [eax].DriverUnload,offset WdmUnload
  assume eax:nothing
  invoke AddMyInt

  xor eax,eax
  ret
DriverEntry  endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end DriverEntr

 

;=======================================================================

.386p
.Model Flat,StdCall
Option CaseMap :None

Include /Masm32/Include/Windows.inc
Include /Masm32/Include/User32.inc
Include /Masm32/Include/Kernel32.inc
Include /Masm32/Include/Advapi32.inc

IncludeLib /Masm32/Lib/User32.lib
IncludeLib /Masm32/Lib/Kernel32.lib
IncludeLib /Masm32/Lib/Advapi32.lib

.Data
szDriverPath2 db "%SystemRoot%/system32/drivers/Ring0.sys",0
szDriverName db "Ring0 Driver",0


.Data?
szDriverPath db 260 dup(?)
hSCM  dd ?
hService dd ?
lpParam  dd ?


.Code

Ring0Fun Proc _Param:DWORD
  mov eax,cr0
  ret
Ring0Fun EndP


Start:
 invoke ExpandEnvironmentStrings,addr szDriverPath2,addr szDriverPath,260
 invoke OpenSCManager,0,0,SC_MANAGER_ALL_ACCESS
 .if eax
  mov hSCM,eax
  invoke CreateService,hSCM,addr szDriverName,addr szDriverName,/
   SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,/
   SERVICE_ERROR_NORMAL,addr szDriverPath,0,0,0,0,0
  .if eax
   mov hService,eax
  .else
   invoke OpenService,hSCM,addr szDriverName,SERVICE_ALL_ACCESS
   .if eax
    mov hService,eax
   .else
    invoke CloseServiceHandle,hSCM
    invoke MessageBox,0,CTEXT("运行驱动服务时发生错误。"),0,16
    invoke ExitProcess,0
   .endif
  .endif
  invoke StartService,hService,0,0
  invoke CloseServiceHandle,hService
  invoke CloseServiceHandle,hSCM
 .endif

 lea eax,Ring0Fun
 lea edx,lpParam
 int 21h

 invoke MessageBox,0,CTEXT("运行成功"),0,0
 invoke ExitProcess,0
End Start

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值