首页
社区
课程
招聘
大家帮忙看看为什么StartService 总是返回0 失败
发表于: 2007-4-27 16:16 16578

大家帮忙看看为什么StartService 总是返回0 失败

2007-4-27 16:16
16578
刚学KMD, 做了好几个练习都是这样的,StartService 总是返回0 失败
下面是其中一个sys和scp代码:
;@echo off
;goto make
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; simplest - Simplest possible kernel-mode driver
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                I N C L U D E   F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include \masm32\include\w2k\ntstatus.inc
include \masm32\include\w2k\ntddk.inc
include \masm32\include\w2k\ntoskrnl.inc
includelib \masm32\lib\w2k\ntoskrnl.lib
include \masm32\Macros\Strings.mac

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                         C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING  ;;;;;;;;;;;;;;;;;;;int 1 int 3
local pIDT[6]:CHAR  
        sidt fword ptr pIDT             ; 取IDTR内容
        mov eax,dword ptr [pIDT + 2]    ; 获取IDT表的基地址
        add eax,8                       ;  INT 1偏移地址放放
        mov ebx, [eax]                  ; 取int 1的低位偏移
        add eax,16
        mov eax, [eax]                  ; 取int 3的低位偏移
        and eax, 0ffffh               
        and ebx, 0ffffh              
        sub eax,ebx                     ; 计算低位偏移之差
        .if eax == 1eh                    ; 发现跟踪,差值为0x1e
           invoke DbgPrint, $CTA0("SoftICE is active")
        .else   
           invoke DbgPrint, $CTA0("Can't find SoftICE with this method.")
    .endif   
   
    ret

DriverEntry endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                              B U I L D I N G   D R I V E R
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:make
set drv=AntiTest
\masm32\bin\ml /nologo /c /coff %drv%.bat
\masm32\bin\link /nologo /driver /base:0x10000 /align:32 /out:%drv%.sys /subsystem:native %drv%.obj
del %drv%.obj
echo.
pause

scp 代码:
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;  Service Control Program for beeper driver
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                             I N C L U D E   F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\advapi32.lib
include \masm32\Macros\Strings.mac
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
start proc
local hSCManager:HANDLE
local hService:HANDLE
local acDriverPath[MAX_PATH]:CHAR
local acFileName[MAX_PATH]:CHAR
    invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE
    .if eax != NULL
        mov hSCManager, eax
        invoke GetFullPathName, $CTA0("AntiTest.sys"),sizeof acDriverPath,addr acDriverPath,addr acFileName
        invoke CreateService, hSCManager, $CTA0("AntiTest"), $CTA0("Anti Int1 Int3 debug"), \
               SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \
               SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL         
        .if eax != NULL
            mov hService, eax
            invoke StartService, hService, 0, NULL         
            invoke DeleteService, hService
            invoke CloseServiceHandle, hService
        .else
            invoke OpenService, hSCManager, $CTA0("AntiTest"), GENERIC_WRITE  
             .if eax != NULL
              mov hService, eax
              invoke StartService, hService, 0, NULL
              invoke DeleteService, hService              
             .endif            
        .endif
        invoke CloseServiceHandle, hSCManager
    .else
        invoke MessageBox, NULL, $CTA0("Can't connect to Service Control Manager."), \
                            NULL, MB_ICONSTOP
    .endif
    invoke ExitProcess, 0
start endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end start

请大家帮忙看看,错在哪里啊? 无论注册表里是否有注册都是StartService 失败, GetLastError返回0x7f  , 不知是什么错,没找到相关定义。

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 218
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
NaX
2
0x7F -> 找不到指定的设备或程序
错误原因 你的DriverEntry返回值的问题 还有 DriverEntry哪里来了 MessageBox? 建议先找C的驱动程序看看再学汇编的吧?
2007-4-27 18:26
0
雪    币: 207
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
MessageBox 修改撑 DbgPrint  还是一样不能启动,GetLastError 返回5, c++的驱动太繁琐,只针对反编译和写简单内核程序学的,所以选择汇编啦,想尽快入门啊
2007-4-27 20:26
0
雪    币: 207
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
MessageBox 修改撑 DbgPrint  还是一样不能启动,GetLastError 返回5,手工删除注册表再运行就蓝屏啦, 重新启动系统后注册表的键在了,但再运行还是返回错误5,Access is denied. 请问这要如何处理?
2007-4-27 20:54
0
雪    币: 207
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
MessageBox 修改成DbgPrint  还是一样不能启动,GetLastError 返回5,手工删除注册表后重新启动机器,再运行scp  蓝屏了,再重新启动注册表键有在了,但怎么运行scp都是错误5, Access is denied. 请问这要如何处理才能运行起来啊
2007-4-27 20:59
0
雪    币: 218
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
NaX
6
5->拒绝访问 你注册了的驱动 未注销就蓝屏了 注册键当然在
蓝屏的原因肯定是读取了无效地址,你的驱动没写好 运行一次就会蓝屏一次
如果你坚持用汇编,建议KMD kit里面的例子先抄熟 再来创造吧?驱动入门不能马虎 否则蓝屏重启是家常便饭
2007-4-28 08:32
0
雪    币: 796
活跃值: (370)
能力值: ( LV9,RANK:380 )
在线值:
发帖
回帖
粉丝
7
XP_SP2下测试通过:

.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                I N C L U D E   F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include w2k\ntstatus.inc
include w2k\ntddk.inc
include w2k\ntoskrnl.inc
includelib ntoskrnl.lib
include Strings.mac

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                         C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING  ;;;;;;;;;;;;;;;;;;;int 1 int 3
local pIDT[6]:CHAR  
  sidt fword ptr pIDT             ; 取IDTR内容
  mov eax,dword ptr [pIDT + 2]    ; 获取IDT表的基地址
  add eax,8                       ;  INT 1偏移地址放放
  mov ebx, [eax]                  ; 取int 1的低位偏移
  add eax,16
  mov eax, [eax]                  ; 取int 3的低位偏移
  and eax, 0ffffh               
  and ebx, 0ffffh              
  sub eax,ebx                     ; 计算低位偏移之差
  .if eax == 1eh                    ; 发现跟踪,差值为0x1e
     invoke DbgPrint, $CTA0("SoftICE is active")
  .else   
     invoke DbgPrint, $CTA0("Can't find SoftICE with this method.")
    .endif   
mov eax, STATUS_DEVICE_CONFIGURATION_ERROR   ;这里一定要写.否则驱动无法返回  
    ret

DriverEntry endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end DriverEntry
2007-4-28 16:41
0
游客
登录 | 注册 方可回帖
返回
//