首页
社区
课程
招聘
[旧帖] 那位朋友帮忙看看为什么驱动卸载不了 0.00雪花
发表于: 2016-3-31 21:05 3499

[旧帖] 那位朋友帮忙看看为什么驱动卸载不了 0.00雪花

2016-3-31 21:05
3499
DriverUnload proc pDriverObject:PDRIVER_OBJECT
local @lDelay:LARGE_INTEGER

invoke RtlConvertLongToLargeInteger, 5000000 * -10

lea ecx,@lDelay.QuadPart
mov DWORD ptr [ecx],eax
mov DWORD ptr [ecx+4],edx

push eax
invoke DbgPrint, $CTA0("edx %x\n"),edx

pop eax
invoke DbgPrint, $CTA0("eax %x\n"),eax

invoke IoDetachDevice,dwTargetDeviceObject

invoke KeDelayExecutionThread,KernelMode, FALSE, addr @lDelay

invoke _a1,addr szSymbolicLinkName,addr stUnicodeRing
invoke IoDeleteSymbolicLink, addr stUnicodeRing
invoke DbgPrint, $CTA0("删除SymbolicLink.\n")
mov eax, pDriverObject
assume eax:ptr DRIVER_OBJECT
invoke IoDeleteDevice, [eax].DeviceObject
assume eax:nothing
ret
DriverUnload endp

_IrpMxaimumFunction proc pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP

IoGetCurrentIrpStackLocation pIrp
movzx ecx,(IO_STACK_LOCATION PTR [EAX]).MajorFunction
.if !ecx
push ecx
invoke PsGetCurrentProcessId
invoke DbgPrint, $CTA0("进程ID %x\n"),eax
pop ecx
invoke DbgPrint, $CTA0("MajorFunction %x\n"),ecx
.endif

IoSkipCurrentIrpStackLocation pIrp
invoke IoCallDriver,dwTargetDeviceObject,pIrp

ret

mov eax,pIrp
mov (_IRP ptr [eax]).IoStatus.Status,STATUS_INVALID_PARAMETER
invoke DbgPrint, $CTA0("PDEVICE_OBJECT %x\n"),pDeviceObject
IoGetCurrentIrpStackLocation pIrp
movzx ecx,(IO_STACK_LOCATION PTR [EAX]).MajorFunction
invoke DbgPrint, $CTA0("MajorFunction %x\n"),ecx
invoke IoCompleteRequest,pIrp,IO_NO_INCREMENT
mov eax,STATUS_INVALID_PARAMETER
ret

_IrpMxaimumFunction endp

_ControlDevice proc pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP

ret
_ControlDevice endp

DriverEntry proc pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING

invoke _a1,addr szDeviceName,addr stUnicodeRing
invoke DbgPrint, $CTA0("MajorFunction地址 %wZ\n"),addr stUnicodeRing

invoke IoCreateDevice, pDriverObject,0, addr stUnicodeRing, FILE_DEVICE_UNKNOWN, 0, FALSE, addr dwDeviceObject
.if eax
invoke DbgPrint, $CTA0("建立设备失败.\n")
mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
ret
.endif
invoke _a1,addr szSymbolicLinkName,addr stUnicodeRing1
invoke IoCreateSymbolicLink,addr stUnicodeRing1,addr stUnicodeRing
.if eax
push eax
invoke DbgPrint, $CTA0("建立符号名失败.\n")
invoke IoDeleteDevice,dwDeviceObject
pop eax
ret
.endif

mov eax,dwDeviceObject
mov (DEVICE_OBJECT ptr [eax]).Flags,DO_DIRECT_IO

mov edx,pDriverObject
mov ecx,IRP_MJ_MAXIMUM_FUNCTION+1
mov eax,offset _IrpMxaimumFunction
push edi
lea edi,(DRIVER_OBJECT ptr [edx]).MajorFunction
cld
rep STOSd
pop edi

mov eax,pDriverObject
mov (DRIVER_OBJECT ptr [eax]).DriverUnload,offset DriverUnload

;mov edx,pDriverObject
;mov (DRIVER_OBJECT ptr [edx]).MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL* (sizeof PVOID)], offset _ControlDevice

invoke _a1,addr szTcpDeviceName,addr stUnicodeRing1
invoke IoAttachDevice,dwDeviceObject,addr stUnicodeRing1,addr dwTargetDeviceObject

.if eax
invoke IoDeleteDevice,dwDeviceObject
invoke _a1,addr szSymbolicLinkName,addr stUnicodeRing
invoke IoDeleteSymbolicLink, addr stUnicodeRing
invoke DbgPrint, $CTA0("附加失败.\n")
mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
.endif
ret
DriverEntry endp

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (15)
雪    币: 6
活跃值: (1509)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
额  看到了 。。。。。
2016-3-31 23:08
0
雪    币: 6
活跃值: (1509)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
没用  汇编写过驱动   给你发个 Easy Code  的驱动代码  你参考下
.Const

ECDrvName                        Equ                <ECPDriver>
NT_DEVICE_NAME                CatStr        <"\Device\>,ECDrvName,<">
DOS_DEVICE_NAME                CatStr        <"\DosDevices\>,ECDrvName,<">

.Data?

DEVICE_EXTENSION Struct
        ;This structure is driver-defined.
        ;It must be filled depending on
        ;the driver to be programmed.

        ;Until filled with necessary
        ;data, define a DD value in
        ;order to avoid compiler errors
        DD        ?
DEVICE_EXTENSION EndS

.Data

.Code

DriverEntry Proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
        Local usDeviceName:UNICODE_STRING, usSymbolicLinkName:UNICODE_STRING
        Local pDeviceObject:PDEVICE_OBJECT

        Invoke RtlInitUnicodeString, Addr usDeviceName, TextStrW(%NT_DEVICE_NAME)
        Invoke RtlInitUnicodeString, Addr usSymbolicLinkName, TextStrW(%DOS_DEVICE_NAME)

        Invoke IoCreateDevice, pDriverObject, SizeOf DEVICE_EXTENSION, Addr usDeviceName,
                                                   FILE_DEVICE_UNKNOWN, 0, TRUE, Addr pDeviceObject
        .If Eax != STATUS_SUCCESS
                Mov Eax, STATUS_DEVICE_CONFIGURATION_ERROR
                Ret
        .EndIf

        Invoke IoCreateSymbolicLink, Addr usSymbolicLinkName, Addr usDeviceName
        .If Eax != STATUS_SUCCESS
                Invoke IoDeleteDevice, pDriverObject
                Mov Eax, STATUS_DEVICE_CONFIGURATION_ERROR
                Ret
        .EndIf

        Mov Eax, pDriverObject
        Mov [Eax].DRIVER_OBJECT.DriverUnload, Offset DriverUnload

        Mov [Eax].DRIVER_OBJECT.MajorFunction[IRP_MJ_CREATE * (SizeOf PVOID)], Offset DriverDispatch
        Mov [Eax].DRIVER_OBJECT.MajorFunction[IRP_MJ_CLOSE * (SizeOf PVOID)], Offset DriverDispatch
        Mov [Eax].DRIVER_OBJECT.MajorFunction[IRP_MJ_DEVICE_CONTROL * (SizeOf PVOID)], Offset DriverDispatch
        Mov [Eax].DRIVER_OBJECT.MajorFunction[IRP_MJ_READ * (SizeOf PVOID)], Offset DriverDispatch
        Mov [Eax].DRIVER_OBJECT.MajorFunction[IRP_MJ_WRITE * (SizeOf PVOID)], Offset DriverDispatch

        Mov Eax, STATUS_SUCCESS
        Ret
DriverEntry EndP

DriverUnload Proc pDriverObject:PDRIVER_OBJECT
        Local usSymbolicLinkName:UNICODE_STRING

        Invoke RtlInitUnicodeString, Addr usSymbolicLinkName, TextStrW(%DOS_DEVICE_NAME)
        Invoke IoDeleteSymbolicLink, Addr usSymbolicLinkName

        Mov Eax, pDriverObject
        Invoke IoDeleteDevice, [Eax].DRIVER_OBJECT.DeviceObject
        Ret
DriverUnload EndP

DriverDispatch Proc Uses Ecx Edx pDeviceObject:PDEVICE_OBJECT, pIrp:PIRP
        Local Status:NTSTATUS, Info:DWord, IO_S_L:DWord
        Local RBufPtr:DWord           ; Buffer
        Local RBufLen:SDWord          ; Buffer Len

        Mov Info, 0H
        Mov Eax, pIrp
        Mov Eax, [Eax]._IRP.Tail.Overlay.CurrentStackLocation
        Mov IO_S_L, Eax

        Movzx Eax, [Eax].IO_STACK_LOCATION.MajorFunction

        .If Eax == IRP_MJ_CREATE
                Mov Status, STATUS_SUCCESS
        .ElseIf Eax == IRP_MJ_CLOSE
                Mov Status, STATUS_SUCCESS
        .ElseIf Eax == IRP_MJ_DEVICE_CONTROL
                Mov Status, STATUS_SUCCESS
        .ElseIf Eax == IRP_MJ_READ
                Mov Eax, pIrp
                Move RBufPtr, [Eax]._IRP.UserBuffer                   ; Buff Ptr
                Mov Eax, IO_S_L
                Move RBufLen, [Eax].IO_STACK_LOCATION.Parameters.Read.dwLength  ; READ Out Buff Len
                Invoke RtlZeroMemory, RBufPtr, RBufLen
                Invoke GetProcess, RBufPtr, RBufLen
                Mov Info, Eax ; RBufLen
                Mov Status, STATUS_SUCCESS
        .ElseIf Eax == IRP_MJ_WRITE
                Mov Status, STATUS_SUCCESS
        .Else
                Mov Status, STATUS_NOT_IMPLEMENTED
        .EndIf

        Mov Eax, pIrp
        Mov Ecx, Status
        Mov [Eax]._IRP.IoStatus.Status, Ecx
        Mov Ecx, Info
        Mov [Eax]._IRP.IoStatus.Information, Ecx

        Invoke IoCompleteRequest, pIrp, IO_NO_INCREMENT
        Mov Eax, Status
        Ret
DriverDispatch EndP

GetProcess Proc RBufPtr:DWord, RBufLen:DWord
        Local BufLenReq:SDWord, BufLen:SDWord, BufPtr:DWord
        Local Result:SDWord

        Mov Result, -1
        Mov BufLenReq, 0
        Invoke ZwQuerySystemInformation, SystemProcessInformation, NULL, NULL, Addr BufLenReq
        .If (BufLenReq <= 0)
                Mov BufLenReq, 32768
        .EndIf
        Shl BufLenReq, 1    ;BufLenReq * 2 (Por seguridad)
        Move BufLen, BufLenReq
        Invoke ExAllocatePool, NonPagedPool, BufLen
        .If Eax != 0
                Mov BufPtr, Eax
                Invoke ZwQuerySystemInformation, SystemProcessInformation, BufPtr, BufLen, Addr BufLenReq
                .If Eax == STATUS_INFO_LENGTH_MISMATCH

                .ElseIf Eax != 0

                .Else
                        Mov Eax, BufLenReq
                        .If Eax < RBufLen
                                Mov Result, Eax
                                Invoke RtlMoveMemory, RBufPtr, BufPtr, BufLenReq
                        .EndIf
                .EndIf
                Invoke ExFreePool, BufPtr
        .EndIf
        Mov Eax, Result
        Ret
GetProcess EndP

End DriverEntry
2016-3-31 23:12
0
雪    币: 248
活跃值: (3789)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
纯汇编写代码的都是高手
2016-4-1 00:02
0
雪    币: 290
活跃值: (76)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
rep STOSd
这行代码不加上去就能正常卸栽!不知道是不是哪个IRP要自己处要自己处理,有知道的朋友吱一声!
2016-4-1 01:26
0
雪    币: 155
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
你仔细一点在看看
2016-4-1 15:15
0
雪    币: 290
活跃值: (76)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
上面的朋友!俺笨想不出来了!你可否教一下俺!谢谢了
2016-4-1 16:44
0
雪    币: 33
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
这个是高手
2016-4-1 18:40
0
雪    币: 209
活跃值: (778)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
用Win32汇编写驱动,楼主也算是个奇葩了...
2016-4-1 19:13
0
雪    币: 290
活跃值: (76)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
无聊乱写一通让你见笑了!这个问题自己解决了!把DO_DEVICE_INITIALIZING清了就好了!
2016-4-2 23:22
0
雪    币: 95
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
有点看不懂的
2016-4-7 15:54
0
雪    币: 5
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
还真没太看懂..
2016-4-8 00:13
0
雪    币: 112
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
这有点太乱了吧
2016-4-8 13:18
0
雪    币: 290
活跃值: (76)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
是啊!一开始想实现一些功能!后来发现不能卸载就没写了!现在卸载是能卸载,就是有时会蓝屏!没招了!学驱动太麻烦了!一天蓝屏N次!又没人教不想玩这个了!
2016-4-8 16:39
0
雪    币: 722
活跃值: (2254)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
15
汇编写驱动丧心病狂。。。。。为什么不用WDK?
2016-4-8 16:55
0
雪    币: 290
活跃值: (76)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
我只会一点汇编,能看懂一点C和C++但不会写!
2016-4-8 17:00
0
游客
登录 | 注册 方可回帖
返回
//