代碼很精簡的,不要不相信!
pushad
mov al,10h
out 70h,al
out 71h,al
popad
PS:不要以爲這就完成了 因爲win系統很坑爹的,直接運行會導致程序崩潰
解決方法就是驅動(下面是部分代碼 用的模版我會放上來的的)
.386
.model flat, stdcall
option casemap:none
include cmosp.inc
.const
CCOUNTED_UNICODE_STRING "\\Device\\devVirtToPhys", g_usDeviceName, 4 ;驅動程序名稱
CCOUNTED_UNICODE_STRING "\\??\\slVirtToPhys", g_usSymbolicLinkName, 4;符號連接名稱
.code
GetPhysicalAddress proc uses esi edi pInputBuffer,inBufLength,pOutputBuffer,outBufLength
;四個參數分別爲用戶層的輸入數據指針,輸入長度,輸出數據指針,輸出長度
;你可以在下面的代碼中使用。
;下面的代碼你可能有用
; invoke PsGetCurrentProcess ;取用戶層進程EPROCES
; invoke PsGetCurrentThread ;取用戶層線程EPROCESS
;you code
pushad
mov al,10h
out 70h,al
out 71h,al
popad
;mov eax ,STATUS_BUFFER_TOO_SMALL ;緩衝區長度不足
mov eax,STATUS_SUCCESS
ret
GetPhysicalAddress endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 調度創建關閉
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DispatchCreateClose proc pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP
;當用戶模式用:
; CreateFile, 讓設備處理
; CloseHandle,關閉設備句柄
mov eax, pIrp
assume eax:ptr _IRP
mov [eax].IoStatus.Status, STATUS_SUCCESS
and [eax].IoStatus.Information, 0
assume eax:nothing
fastcall IofCompleteRequest, pIrp, IO_NO_INCREMENT
mov eax, STATUS_SUCCESS
ret
DispatchCreateClose endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;這裏是應用程序發出DeviceIoControl指令時,驅動處理子程序。
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DispatchControl proc uses esi edi ebx pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP
local status:NTSTATUS
LOCAL pInputBuffer,inBufLength,pOutputBuffer,outBufLength
;pIrp
mov esi, pIrp
assume esi:ptr _IRP
;pIrp_Stack
IoGetCurrentIrpStackLocation esi
mov edi, eax
assume edi:ptr IO_STACK_LOCATION
;IoGetCurrentIrpStackLocation宏取出_IRP結構的IO_STACK_LOCATION的指針(指向I/O stack)。
;這個棧的層次取決於這個IRP需要經過多少層的驅動處理。我們的單層驅動程序在這裏只有一個值。
push [edi].Parameters.DeviceIoControl.InputBufferLength
pop inBufLength
push [edi].Parameters.DeviceIoControl.OutputBufferLength
pop outBufLength
push [esi].AssociatedIrp.SystemBuffer
pop pInputBuffer
push [esi].UserBuffer
pop pOutputBuffer
;判斷用戶層的驅動控制碼,這裏設置的是800h,在inc文件裏定義
.if [edi].Parameters.DeviceIoControl.IoControlCode == IOCTL_GET_PHYS_ADDRESS
invoke GetPhysicalAddress,pInputBuffer,inBufLength,pOutputBuffer,outBufLength
mov status, eax
.else
mov status, STATUS_INVALID_DEVICE_REQUEST
.endif
assume edi:nothing
push status
pop [esi].IoStatus.Status
push outBufLength
pop [esi].IoStatus.Information
assume esi:nothing
fastcall IofCompleteRequest, pIrp, IO_NO_INCREMENT
mov eax, status
ret
DispatchControl endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 驅動程序卸載回調函數
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverUnload proc pDriverObject:PDRIVER_OBJECT
invoke IoDeleteSymbolicLink, addr g_usSymbolicLinkName
mov eax, pDriverObject
invoke IoDeleteDevice, (DRIVER_OBJECT PTR [eax]).DeviceObject
ret
DriverUnload endp
.code
;.code INIT
;所有這樣標記的代碼將被放入PE文件的INIT節區中,表明是Discardable的。
;在驅動程序初始化後,這部分代碼就再也用不着了。
;INIT節區中的代碼可以在DriverEntry過程返回後被丟棄,系統會自己決定在合適的時候丟棄它。
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 驅動入口
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
;
local status:NTSTATUS
local pDeviceObject:PDEVICE_OBJECT
mov status, STATUS_DEVICE_CONFIGURATION_ERROR
;創建虛擬設備
invoke IoCreateDevice, pDriverObject, 0, addr g_usDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, addr pDeviceObject
.if eax == STATUS_SUCCESS
;建立符號鏈接
invoke IoCreateSymbolicLink, addr g_usSymbolicLinkName, addr g_usDeviceName
.if eax == STATUS_SUCCESS
mov eax, pDriverObject
assume eax:ptr DRIVER_OBJECT;指定pDriverObject的參數的類型爲DRIVER_OBJECT結構
;指定用戶模式下卸載驅動時的處理地址
mov [eax].DriverUnload, offset DriverUnload
;指定用戶模式調用CreateFile時的處理地址
mov [eax].MajorFunction[IRP_MJ_CREATE*(sizeof PVOID)],offset DispatchCreateClose
;指定用戶模式調用CloseHandle時的處理地址
mov [eax].MajorFunction[IRP_MJ_CLOSE*(sizeof PVOID)],offset DispatchCreateClose
;指定用戶模式調用DeviceIoControl時的處理地址
mov [eax].MajorFunction[IRP_MJ_DEVICE_CONTROL*(sizeof PVOID)],offset DispatchControl
assume eax:nothing
mov status, STATUS_SUCCESS
.else
invoke IoDeleteDevice, pDeviceObject
.endif
.endif
mov eax, status
ret
DriverEntry endp
end DriverEntry
下面是用到的模版代碼(複製代碼到記事本,保存到 RadASM\Masm\Templates)
Driver (.sys)
Driver
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;標準控制驅動框架;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[*BEGINPRO*]
[*BEGINDEF*]
[MakeDef]
Menu=0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
1=4,O,$B\RC.EXE /v,1
2=3,O,$B\ML.EXE /nologo /c /coff /I"$I",2
3=16,O,$B\LINK.EXE /nologo /driver /base:0x10000 /align:32 /subsystem:native /out:"$16",3
4=0,0,,5
5=rsrc.obj,O,$B\CVTRES.EXE,rsrc.res
6=*.obj,O,$B\ML.EXE /c /coff /nologo /I"$I",*.asm
7=0,0,"$E\OllyDbg",5
[MakeFiles]
0=Driver.rap
1=Driver.rc
2=Driver.asm
3=Driver.obj
4=Driver.res
5=Driver.exe
6=Driver.def
7=Driver.dll
8=Driver.txt
9=Driver.lib
10=Driver.mak
11=Driver.hla
12=Driver.com
13=Driver.ocx
14=Driver.idl
15=Driver.tlb
16=Driver.sys
[Resource]
[StringTable]
[Accel]
[VerInf]
[Group]
Group=Added files,Assembly,Resources,Misc,Modules
1=2
2=2
[*ENDDEF*]
[*BEGINTXT*]
Driver.Asm
.386
.model flat, stdcall
option casemap:none
include driver.inc
.const
CCOUNTED_UNICODE_STRING "\\Device\\devVirtToPhys", g_usDeviceName, 4 ;驅動程序名稱
CCOUNTED_UNICODE_STRING "\\??\\slVirtToPhys", g_usSymbolicLinkName, 4;符號連接名稱
.code
GetPhysicalAddress proc uses esi edi pInputBuffer,inBufLength,pOutputBuffer,outBufLength
;四個參數分別爲用戶層的輸入數據指針,輸入長度,輸出數據指針,輸出長度
;你可以在下面的代碼中使用。
;下面的代碼你可能有用
; invoke PsGetCurrentProcess ;取用戶層進程EPROCES
; invoke PsGetCurrentThread ;取用戶層線程EPROCESS
;you code
;mov eax ,STATUS_BUFFER_TOO_SMALL ;緩衝區長度不足
mov eax,STATUS_SUCCESS
ret
GetPhysicalAddress endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 調度創建關閉
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DispatchCreateClose proc pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP
;當用戶模式用:
; CreateFile, 讓設備處理
; CloseHandle,關閉設備句柄
mov eax, pIrp
assume eax:ptr _IRP
mov [eax].IoStatus.Status, STATUS_SUCCESS
and [eax].IoStatus.Information, 0
assume eax:nothing
fastcall IofCompleteRequest, pIrp, IO_NO_INCREMENT
mov eax, STATUS_SUCCESS
ret
DispatchCreateClose endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;這裏是應用程序發出DeviceIoControl指令時,驅動處理子程序。
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DispatchControl proc uses esi edi ebx pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP
local status:NTSTATUS
LOCAL pInputBuffer,inBufLength,pOutputBuffer,outBufLength
;pIrp
mov esi, pIrp
assume esi:ptr _IRP
;pIrp_Stack
IoGetCurrentIrpStackLocation esi
mov edi, eax
assume edi:ptr IO_STACK_LOCATION
;IoGetCurrentIrpStackLocation宏取出_IRP結構的IO_STACK_LOCATION的指針(指向I/O stack)。
;這個棧的層次取決於這個IRP需要經過多少層的驅動處理。我們的單層驅動程序在這裏只有一個值。
push [edi].Parameters.DeviceIoControl.InputBufferLength
pop inBufLength
push [edi].Parameters.DeviceIoControl.OutputBufferLength
pop outBufLength
push [esi].AssociatedIrp.SystemBuffer
pop pInputBuffer
push [esi].UserBuffer
pop pOutputBuffer
;判斷用戶層的驅動控制碼,這裏設置的是800h,在inc文件裏定義
.if [edi].Parameters.DeviceIoControl.IoControlCode == IOCTL_GET_PHYS_ADDRESS
invoke GetPhysicalAddress,pInputBuffer,inBufLength,pOutputBuffer,outBufLength
mov status, eax
.else
mov status, STATUS_INVALID_DEVICE_REQUEST
.endif
assume edi:nothing
push status
pop [esi].IoStatus.Status
push outBufLength
pop [esi].IoStatus.Information
assume esi:nothing
fastcall IofCompleteRequest, pIrp, IO_NO_INCREMENT
mov eax, status
ret
DispatchControl endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 驅動程序卸載回調函數
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverUnload proc pDriverObject:PDRIVER_OBJECT
invoke IoDeleteSymbolicLink, addr g_usSymbolicLinkName
mov eax, pDriverObject
invoke IoDeleteDevice, (DRIVER_OBJECT PTR [eax]).DeviceObject
ret
DriverUnload endp
.code
;.code INIT
;所有這樣標記的代碼將被放入PE文件的INIT節區中,表明是Discardable的。
;在驅動程序初始化後,這部分代碼就再也用不着了。
;INIT節區中的代碼可以在DriverEntry過程返回後被丟棄,系統會自己決定在合適的時候丟棄它。
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 驅動入口
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
;
local status:NTSTATUS
local pDeviceObject:PDEVICE_OBJECT
mov status, STATUS_DEVICE_CONFIGURATION_ERROR
;創建虛擬設備
invoke IoCreateDevice, pDriverObject, 0, addr g_usDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, addr pDeviceObject
.if eax == STATUS_SUCCESS
;建立符號鏈接
invoke IoCreateSymbolicLink, addr g_usSymbolicLinkName, addr g_usDeviceName
.if eax == STATUS_SUCCESS
mov eax, pDriverObject
assume eax:ptr DRIVER_OBJECT;指定pDriverObject的參數的類型爲DRIVER_OBJECT結構
;指定用戶模式下卸載驅動時的處理地址
mov [eax].DriverUnload, offset DriverUnload
;指定用戶模式調用CreateFile時的處理地址
mov [eax].MajorFunction[IRP_MJ_CREATE*(sizeof PVOID)],offset DispatchCreateClose
;指定用戶模式調用CloseHandle時的處理地址
mov [eax].MajorFunction[IRP_MJ_CLOSE*(sizeof PVOID)],offset DispatchCreateClose
;指定用戶模式調用DeviceIoControl時的處理地址
mov [eax].MajorFunction[IRP_MJ_DEVICE_CONTROL*(sizeof PVOID)],offset DispatchControl
assume eax:nothing
mov status, STATUS_SUCCESS
.else
invoke IoDeleteDevice, pDeviceObject
.endif
.endif
mov eax, status
ret
DriverEntry endp
end DriverEntry
[*ENDTXT*]
[*BEGINTXT*]
Driver.Inc
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 要用到的頭文件定義
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include w2k\ntstatus.inc
include w2k\ntddk.inc
include w2k\ntoskrnl.inc
include w2k\w2kundoc.inc
includelib \RadASM\masm32\lib\w2k\ntoskrnl.lib
include \RadASM\masm32\Macros\Strings.mac
;控制代碼
IOCTL_GET_PHYS_ADDRESS equ CTL_CODE(FILE_DEVICE_UNKNOWN, 800h, METHOD_BUFFERED, FILE_READ_ACCESS + FILE_WRITE_ACCESS)
[*ENDTXT*]
[*ENDPRO*]
清除原理:系統BIOS自檢時要檢查CMOS中的數據是否有效,有效的標準是計算CMOS中所有數據的字節累加和是否爲0,爲0表示有效,不爲0,則表示CMOS中的所有數據無效,正常的CMOS設置程序在改變CMOS中的值後都要計算CMOS中的字節累加和是否爲0,如果不爲0,則自動進行調整使之爲0。清除的辦法是直接寫入一隨機數到CMOS的某一單元中,而不調整字節和,只要寫入的數據與原有數據不同,則下次重新啓動時CMOS的字節累加和肯定不爲0,因而其中的數據(包括密碼數據)將無效,從而達到破壞CMOS密碼的目的。
提示:如果是錯誤的CMOS設置導致系統無法工作且有進入CMOS和進入系統密碼,則比較有效的辦法就是放電了。
不過我沒試過,家裏沒有虛擬機