看流星社区

 找回密码
 注册账号
查看: 4495|回复: 3

[汇编] 分享逆向分析并重组源码的过程

[复制链接]

该用户从未签到

发表于 2011-8-11 09:12:43 | 显示全部楼层 |阅读模式
又屈服在goldberg的淫威下了。麻痹,一提到此人我就性趣勃勃。或许是他给俺力量,刚和他聊完,就怀上了这篇文章,由此可见,goldberg的能力之强。废话少说了,文章开始临盆。

  1. .text:0001045A
  2. .text:0001045A ; Attributes: bp-based frame
  3. .text:0001045A
  4. .text:0001045A                public start
  5. .text:0001045A start          proc near
  6. .text:0001045A                push    ebp  ;很多时候,我们把push 一个数据作为一个
  7. ;函数的参数对待。但是push也可以保存临时值。

  8. .text:0001045B                mov    ebp, esp        ; 把esp保存到ebp中去,开始进入函数体
  9. .text:0001045D                push    offset s_PI    ; "驱动入口/r/n"
  10. .text:00010462                call    DbgPrint        ; 格式化输出
  11. .text:00010462
  12. .text:00010467                add    esp, 4          ; 堆栈由函数自己清除
  13. .text:0001046A                call    sub_10260      ; 调用一个子函数
  14. .text:0001046A
  15. .text:0001046F                call    sub_10309      ; 调用一个子函数
  16. .text:0001046F
  17. .text:00010474                call    sub_10397      ; 调用一个子函数
  18. .text:00010474
  19. .text:00010479                push    offset asc_1068C ; "执行完退出/r/n/r/n"
  20. .text:0001047E                call    DbgPrint        ; 函数执行完毕
  21. .text:0001047E
  22. .text:00010483                add    esp, 4          ; 这里和上面一样,C的规则,由函数自己清空堆栈。汇编和C都沿用stdcall,必须这样
  23. .text:00010486                mov    eax, 0C0000182h ; 这里是驱动程序的返回,即 mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
  24. .text:0001048B                leave
  25. .text:0001048C                retn    8
  26. .text:0001048C
  27. .text:0001048C start          endp



  28.   这里,我们已经构造出整个程序的结构。即:格式化打印信息-----分别调用三个子函数-------程序返回。这样一来,就可以重组出这个代码的框架:


  29. Copy code
  30. .386
  31. .model flat, stdcall
  32. option casemap:none
  33. ;
  34. ;这里包含用到的头文件和库。具体是哪个,还得进一步分析这个程序到底有到哪些函数

  35. .data?
  36. .
  37. .data
  38. .
  39. .const

  40. .code
  41. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  42. DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING

  43. Invoke DbgPrint,CTXT(“驱动入口”)

  44. call    sub_10260 ;调用第一个子函数,姑且这么写
  45. call    sub_10309
  46. call    sub_10397

  47. Invoke DbgPrint,CTXT(“程序结束”)
  48. mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
  49. ret
  50. DriverEntry endp
  51. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  52. end DriverEntry

复制代码


就像建筑一栋大楼,把主干已经弄好,现在轮到添枝加叶。先看第一个子函数sub_10260。这里直接call调用了,所以就不存在任何参数传递。

  1. .text:00010260 sub_10260      proc near         
  2. .text:00010260
  3. .text:00010260 Handle          = dword ptr -24h ; 参数定义。如果是正的,就是局部变量
  4. .text:00010260 IoStatusBlock  = _IO_STATUS_BLOCK ptr -20h ;参数。这里IDA也已经给出结构
  5. .text:00010260 ObjectAttributes= OBJECT_ATTRIBUTES ptr -18h
  6. .text:00010260
  7. .text:00010260                push    ebp
  8. .text:00010261                mov    ebp, esp
  9. .text:00010263                add    esp, 0FFFFFFDCh
  10. .text:00010266                push    ds:off_10538
  11. .text:0001026C                push    offset Format  ; "创建目录: %ws /r/n"
  12. .text:00010271                call    DbgPrint        ; %ws是Unicode,在内核中是使用Unicode
  13. .text:00010271
  14. .text:00010276                add    esp, 8
  15. .text:00010279                lea    ecx, [ebp+ObjectAttributes] ; 初始化OBJ_CASE_INSENSITIV
  16. .text:0001027C                mov    dword ptr [ecx], 18h
  17. .text:00010282                and    dword ptr [ecx+4], 0
  18. .text:00010286                mov    dword ptr [ecx+0Ch], 240h
  19. .text:0001028D                and    dword ptr [ecx+10h], 0
  20. .text:00010291                mov    dword ptr [ecx+8], offset asc_10534 ; " /""
  21. .text:00010298                and    dword ptr [ecx+14h], 0
  22. .text:0001029C                push    0              ; EaLength
  23. .text:0001029E                push    0              ; EaBuffer
  24. .text:000102A0                push    21h            ; CreateOptions
  25. .text:000102A2                push    3              ; CreateDisposition
  26. .text:000102A4                push    0              ; ShareAccess
  27. .text:000102A6                push    80h            ; FileAttributes
  28. .text:000102AB                push    0              ; AllocationSize
  29. .text:000102AD                lea    eax, [ebp+IoStatusBlock]
  30. .text:000102B0                push    eax            ; IoStatusBlock
  31. .text:000102B1                lea    eax, [ebp+ObjectAttributes]
  32. .text:000102B4                push    eax            ; ObjectAttributes
  33. .text:000102B5                push    100000h        ; DesiredAccess
  34. .text:000102BA                lea    eax, [ebp+Handle]
  35. .text:000102BD                push    eax            ; FileHandle
  36. .text:000102BE                call    ZwCreateFile    ; 打开。内核中创建目录,
  37.                                                       ;创建文件都使用这个函数
  38. .text:000102BE
  39. .text:000102C3                or      eax, eax        ; 返回值是否成功
  40. .text:000102C5                jnz    short loc_102F9 ; 不成功就跳到这里,
  41.                                                       ;恰恰它格式化的代码已经提示我们,
  42.                                                       ;目录创建失败
  43. .text:000102C5
  44. .text:000102C7                cmp    [ebp+IoStatusBlock.Information], 2 ; 这里查看文件的属性。
  45.                                                                           ;2代表FILE_CREATED
  46. .text:000102CB                jnz    short loc_102DC ; 跳到 loc_102DC
  47. .text:000102CB
  48. .text:000102CD                push    offset s_I      ; "目录创建/r/n"
  49. .text:000102D2                call    DbgPrint
  50. .text:000102D2
  51. .text:000102D7                add    esp, 4          ; 恢复堆栈
  52. .text:000102DA                jmp    short loc_102EF ; 目录创建之后,就要关闭句柄
  53. .text:000102DA
  54. .text:000102DC ; ---------------------------------------------------------------------------
  55. .text:000102DC
  56. .text:000102DC loc_102DC:                          
  57. .text:000102DC                cmp    [ebp+IoStatusBlock.Information], 1 ; 测试文件的FILE_OPENED                                                                          ;属性。很明显,是.if--                                                                            ;-.elseif--.endif的结构
  58. .text:000102E0                jnz    short loc_102EF
  59. .text:000102E0
  60. .text:000102E2                push    offset s_KJ    ; "目录共享/r/n"
  61. .text:000102E7                call    DbgPrint
  62. .text:000102E7
  63. .text:000102EC                add    esp, 4
  64. .text:000102EC
  65. .text:000102EF
  66. .text:000102EF loc_102EF:                           
  67. .text:000102EF                                       
  68. .text:000102EF                push    [ebp+Handle]    ; Handle
  69. .text:000102F2                call    ZwClose        ; 两个属性测试完毕,目录才真正创建成功~!
  70. .text:000102F2
  71. .text:000102F7                jmp    short locret_10307 ; 函数返回
  72. .text:000102F7
  73. .text:000102F9 ; ---------------------------------------------------------------------------
  74. .text:000102F9
  75. .text:000102F9 loc_102F9:                           
  76. .text:000102F9                push    eax
  77. .text:000102FA                push    offset s_IIAI08x ; "无法创建目录,错误代码 %08X/r/n"
  78. .text:000102FF                call    DbgPrint
  79. .text:000102FF
  80. .text:00010304                add    esp, 8
  81. .text:00010304
  82. .text:00010307
  83. .text:00010307 locret_10307:                          
  84. .text:00010307                leave                  ; 程序返回
  85. .text:00010308                retn
  86. .text:00010308
  87. .text:00010308 sub_10260      endp

复制代码


首先这个子函数初始化OBJ_CASE_INSENSITIV结构。这个结构是这样的:
ObjectAttributes  OBJECT_ATTRIBUTES<?>。接着打印要创建的目录名。代码:

.const
CCOUNTED_UNICODE_STRING "//??//c://fuck", g_usDirName, 4
.
.
invoke DbgPrint, $CTA0("/创建目录: %ws /n"), g_usDirName.Buffer

在创建目录后同时测试其属性,分别打印。下面是重组的代码:


  1. CreateDirectory proc
  2. local oa:OBJECT_ATTRIBUTES
  3. local iosb:IO_STATUS_BLOCK
  4. local hDirectory:HANDLE
  5. ;------------------------------------------------------------
  6. ;Unicode格式化输出目录名。在内核使用Unicode
  7. ;------------------------------------------------------------
  8. invoke DbgPrint, $CTA0("创建目录: %ws "), g_usDirName.Buffer
  9.   ;------------------------------------------------------------
  10. ; 初始化OBJ_CASE_INSENSITIVE,oa作为参数传递给ZwCreateFile
  11. ;------------------------------------------------------------
  12. InitializeObjectAttributes addr oa, addr g_usDirName, /
  13.       OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL   
  14. invoke ZwCreateFile, addr hDirectory, SYNCHRONIZE, addr oa, addr iosb, 0, FILE_ATTRIBUTE_NORMAL, /
  15.       0, FILE_OPEN_IF, FILE_DIRECTORY_FILE + FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0
  16. .if eax == STATUS_SUCCESS
  17.   ;------------------------------------------------------------
  18.   ;文件创建属性
  19.   ;------------------------------------------------------------
  20.   .if iosb.Information == FILE_CREATED
  21.   invoke DbgPrint, $CTA0("目录创建")
  22.   ;------------------------------------------------------------
  23.   ;文件共享属性      
  24.   ;------------------------------------------------------------
  25.   .elseif iosb.Information == FILE_OPENED
  26.   invoke DbgPrint, $CTA0("目录共享")
  27.   .endif
  28.   invoke ZwClose, hDirectory
  29. .else
  30.   ;------------------------------------------------------------
  31.   ;格式化输出,创建目录失败!
  32.   ;------------------------------------------------------------
  33.   invoke DbgPrint, $CTA0("无法创建目录,错误代码 %08X"), eax
  34. .endif
  35. ret
  36. CreateDirectory endp



  37.   现在来看第二个子函数sub_10309。


  38. Copy code
  39. .text:00010309 sub_10309      proc near              
  40. .text:00010309
  41. .text:00010309 Handle          = dword ptr -24h  ;函数句柄
  42. .text:00010309 IoStatusBlock  = _IO_STATUS_BLOCK ptr -20h ;IO_STATUS_BLOCK结构
  43. .text:00010309 ObjectAttributes= OBJECT_ATTRIBUTES ptr -18h ;OBJECT_ATTRIBUTES结构
  44. .text:00010309
  45. .text:00010309                push    ebp
  46. .text:0001030A                mov    ebp, esp
  47. .text:0001030C                add    esp, 0FFFFFFDCh
  48. .text:0001030F                push    ds:off_1050C
  49. .text:00010315                push    offset s_IWs_0  ; "创建文件 %ws /r/n"
  50. .text:0001031A                call    DbgPrint        ; 这段代码很熟悉吧 :)
  51. .text:0001031A
  52. .text:0001031F                add    esp, 8
  53. .text:00010322                lea    ecx, [ebp+ObjectAttributes] ; 这段是不是也很熟悉 :)
  54. .text:00010325                mov    dword ptr [ecx], 18h
  55. .text:0001032B                and    dword ptr [ecx+4], 0
  56. .text:0001032F                mov    dword ptr [ecx+0Ch], 240h
  57. .text:00010336                and    dword ptr [ecx+10h], 0
  58. .text:0001033A                mov    dword ptr [ecx+8], offset s_24 ; "24"
  59. .text:00010341                and    dword ptr [ecx+14h], 0
  60. .text:00010345                push    0              ; EaLength
  61. .text:00010347                push    0              ; EaBuffer
  62. .text:00010349                push    20h            ; CreateOptions
  63. .text:0001034B                push    2              ; CreateDisposition
  64. .text:0001034D                push    0              ; ShareAccess
  65. .text:0001034F                push    80h            ; FileAttributes
  66. .text:00010354                push    0              ; AllocationSize
  67. .text:00010356                lea    eax, [ebp+IoStatusBlock]
  68. .text:00010359                push    eax            ; IoStatusBlock
  69. .text:0001035A                lea    eax, [ebp+ObjectAttributes]
  70. .text:0001035D                push    eax            ; ObjectAttributes
  71. .text:0001035E                push    100000h        ; DesiredAccess
  72. .text:00010363                lea    eax, [ebp+Handle]
  73. .text:00010366                push    eax            ; FileHandle
  74. .text:00010367                call    ZwCreateFile    ; 刚多说了,创建目录和创建文件都使用这个
  75. .text:00010367
  76. .text:0001036C                or      eax, eax
  77. .text:0001036E                jnz    short loc_10387
  78. .text:0001036E
  79. .text:00010370                push    offset s_IJ    ; "文件创建成功/r/n"
  80. .text:00010375                call    DbgPrint        ; 他已经提示我们文件创建成功了
  81. .text:00010375
  82. .text:0001037A                add    esp, 4
  83. .text:0001037D                push    [ebp+Handle]    ; Handle
  84. .text:00010380                call    ZwClose        ; 关闭句柄
  85. .text:00010380
  86. .text:00010385                jmp    short locret_10395 ; 交还控制权
  87. .text:00010385
  88. .text:00010387 ; ---------------------------------------------------------------------------
  89. .text:00010387
  90. .text:00010387 loc_10387:                          
  91. .text:00010387                push    eax
  92. .text:00010388                push    offset s_IZAI08x ; "文件创建失败,错误代码: %08X/r/n"
  93. .text:0001038D                call    DbgPrint
  94. .text:0001038D
  95. .text:00010392                add    esp, 8          ; 清除堆栈
  96. .text:00010392
  97. .text:00010395
  98. .text:00010395 locret_10395:                        
  99. .text:00010395                leave                  ; 每一个程序的最后都要把控制权交给主程序
  100. .text:00010396                retn
  101. .text:00010396
  102. .text:00010396 sub_10309      endp

复制代码


和创建目录的一样,创建文件也是初始化OBJECT_ATTRIBUTES,调用ZwCreateFile。下面是源码:

  1. CreateFile proc
  2. local oa:OBJECT_ATTRIBUTES
  3. local iosb:IO_STATUS_BLOCK
  4. local hFile:HANDLE
  5. ;-----------------------------------------------------------
  6. ;
  7. ;格式化输出创建的文件名。在内核中使用Unicode
  8. ;Buffer缓冲区保存着文件路径
  9. ;
  10. ;-----------------------------------------------------------
  11. invoke DbgPrint, $CTA0("创建文件 %ws "), g_usFileName.Buffer
  12. ;-----------------------------------------------------------
  13.   ;初始化OBJ_CASE_INSENSITIVE结构
  14.   ;-----------------------------------------------------------
  15. InitializeObjectAttributes addr oa, addr g_usFileName, /
  16.       OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL
  17. ;-----------------------------------------------------------   
  18.   ;打开文件
  19.   ;-----------------------------------------------------------
  20. invoke ZwCreateFile, addr hFile, SYNCHRONIZE, addr oa, addr iosb, 0, FILE_ATTRIBUTE_NORMAL, /
  21.       0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0
  22. .if eax == STATUS_SUCCESS
  23.   invoke DbgPrint, $CTA0("文件创建成功")
  24.   invoke ZwClose, hFile
  25. .else
  26.   invoke DbgPrint, $CTA0("文件创建失败,错误代码: %08X"), eax
  27. .endif
  28. ret
  29. CreateFile endp



  30.   最后一个子函数sub_10397


  31. Copy code
  32. .text:00010397 sub_10397      proc near        
  33. .text:00010397
  34. .text:00010397 Handle          = dword ptr -24h
  35. .text:00010397 IoStatusBlock  = _IO_STATUS_BLOCK ptr -20h
  36. .text:00010397 ObjectAttributes= OBJECT_ATTRIBUTES ptr -18h
  37. .text:00010397
  38. .text:00010397                push    ebp
  39. .text:00010398                mov    ebp, esp
  40. .text:0001039A                add    esp, 0FFFFFFDCh
  41. .text:0001039D                push    offset s_KI    ; "打开文件准备写入数据/r/n"
  42. .text:000103A2                call    DbgPrint
  43. .text:000103A2
  44. .text:000103A7                add    esp, 4
  45. .text:000103AA                lea    ecx, [ebp+ObjectAttributes]
  46. .text:000103AD                mov    dword ptr [ecx], 18h
  47. .text:000103B3                and    dword ptr [ecx+4], 0
  48. .text:000103B7                mov    dword ptr [ecx+0Ch], 240h
  49. .text:000103BE                and    dword ptr [ecx+10h], 0
  50. .text:000103C2                mov    dword ptr [ecx+8], offset s_24 ; "24"
  51. .text:000103C9                and    dword ptr [ecx+14h], 0
  52. .text:000103CD                push    0              ; EaLength
  53. .text:000103CF                push    0              ; EaBuffer
  54. .text:000103D1                push    20h            ; CreateOptions
  55. .text:000103D3                push    1              ; CreateDisposition
  56. .text:000103D5                push    1              ; ShareAccess
  57. .text:000103D7                push    0              ; FileAttributes
  58. .text:000103D9                push    0              ; AllocationSize
  59. .text:000103DB                lea    eax, [ebp+IoStatusBlock]
  60. .text:000103DE                push    eax            ; IoStatusBlock
  61. .text:000103DF                lea    eax, [ebp+ObjectAttributes]
  62. .text:000103E2                push    eax            ; ObjectAttributes
  63. .text:000103E3                push    100002h        ; DesiredAccess
  64. .text:000103E8                lea    eax, [ebp+Handle]
  65. .text:000103EB                push    eax            ; FileHandle
  66. .text:000103EC                call    ZwCreateFile    ; 打开我们刚创建的文件
  67. .text:000103EC
  68. .text:000103F1                or      eax, eax
  69. .text:000103F3                jnz    short loc_1044A ; 无法写入文件
  70. .text:000103F3
  71. .text:000103F5                push    offset s_KJ_0  ; "文件打开成功/r/n"
  72. .text:000103FA                call    DbgPrint
  73. .text:000103FA
  74. .text:000103FF                add    esp, 4
  75. .text:00010402                push    0              ; Key
  76. .text:00010404                push    0              ; ByteOffset
  77. .text:00010406                push    4Dh            ; Length
  78. .text:00010408                push    offset Buffer  ; "这里是文件的内容"
  79. .text:0001040D                lea    eax, [ebp+IoStatusBlock]
  80. .text:00010410                push    eax            ; IoStatusBlock
  81. .text:00010411                push    0              ; ApcContext
  82. .text:00010413                push    0              ; ApcRoutine
  83. .text:00010415                push    0              ; Event
  84. .text:00010417                push    [ebp+Handle]    ; FileHandle
  85. .text:0001041A                call    ZwWriteFile    ; 写入数据。
  86. .text:0001041A
  87. .text:0001041F                or      eax, eax
  88. .text:00010421                jnz    short loc_10432
  89. .text:00010421
  90. .text:00010423                push    offset s_IJ_0  ; "文件写入成功/r/n"
  91. .text:00010428                call    DbgPrint
  92. .text:00010428
  93. .text:0001042D                add    esp, 4
  94. .text:00010430                jmp    short loc_10440
  95. .text:00010430
  96. .text:00010432 ; ---------------------------------------------------------------------------
  97. .text:00010432
  98. .text:00010432 loc_10432:                           
  99. .text:00010432                push    eax
  100. .text:00010433                push    offset s_IIAI08x_0 ; "无法写入文件,错误代码: %08X/r/n"
  101. .text:00010438                call    DbgPrint
  102. .text:00010438
  103. .text:0001043D                add    esp, 8
  104. .text:0001043D
  105. .text:00010440
  106. .text:00010440 loc_10440:                           
  107. .text:00010440                push    [ebp+Handle]    ; Handle
  108. .text:00010443                call    ZwClose
  109. .text:00010443
  110. .text:00010448                jmp    short locret_10458
  111. .text:00010448
  112. .text:0001044A ; ---------------------------------------------------------------------------
  113. .text:0001044A
  114. .text:0001044A loc_1044A:                           
  115. .text:0001044A                push    eax
  116. .text:0001044B                push    offset s_IKAI08x ; "无法打开文件,错误代码: %08X/r/n"
  117. .text:00010450                call    DbgPrint
  118. .text:00010450
  119. .text:00010455                add    esp, 8
  120. .text:00010455
  121. .text:00010458
  122. .text:00010458 locret_10458:                          ;提交控制权
  123. .text:00010458                leave
  124. .text:00010459                retn
  125. .text:00010459
  126. .text:00010459 sub_10397      endp

复制代码


到此,三个未知的子函数已经逐一逆向出源码。程序的流程我们已经很清楚---创建目录----创建文件----写入数据到文件。现在整理一下得出完整代码:

  1. ;-----------------------------------------------
  2. ;
  3. ;code by  asm
  4. ;
  5. ;-----------------------------------------------
  6. .386
  7. .model flat, stdcall
  8. option casemap:none
  9. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  10. include w2k/ntstatus.inc
  11. include w2k/ntifs.inc
  12. include w2k/ntoskrnl.inc
  13. includelib ntoskrnl.lib
  14. include Strings.mac
  15. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  16. ;利用宏定义文件路径和目录,还可以这样做:
  17. ;g_usFileName dw '/','?','?','c',':','/','F','i','l','e','W','o','r','k','s','/','t','e','s','t','.','t','x','t',0
  18. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  19. .const
  20. CCOUNTED_UNICODE_STRING "//??//c://fuck//test.txt", g_usFileName, 4
  21. CCOUNTED_UNICODE_STRING "//??//c://fuck", g_usDirName, 4
  22. ;CTA0 "fuck the world", g_szData,4
  23. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  24. .code
  25. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  26. ;创建目录函数                                            
  27. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  28. CreateDirectory proc
  29. local oa:OBJECT_ATTRIBUTES
  30. local iosb:IO_STATUS_BLOCK
  31. local hDirectory:HANDLE
  32. ;------------------------------------------------------------
  33. ;Unicode格式化输出目录名。在内核使用Unicode
  34. ;------------------------------------------------------------
  35. invoke DbgPrint, $CTA0("创建目录: %ws "), g_usDirName.Buffer
  36.   ;------------------------------------------------------------
  37. ; 初始化OBJ_CASE_INSENSITIVE,oa作为参数传递给ZwCreateFile
  38. ;------------------------------------------------------------
  39. InitializeObjectAttributes addr oa, addr g_usDirName, /
  40.       OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL   
  41. invoke ZwCreateFile, addr hDirectory, SYNCHRONIZE, addr oa, addr iosb, 0, FILE_ATTRIBUTE_NORMAL, /
  42.       0, FILE_OPEN_IF, FILE_DIRECTORY_FILE + FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0
  43. .if eax == STATUS_SUCCESS
  44.   ;------------------------------------------------------------
  45.   ;文件创建属性
  46.   ;------------------------------------------------------------
  47.   .if iosb.Information == FILE_CREATED
  48.   invoke DbgPrint, $CTA0("目录创建")
  49.   ;------------------------------------------------------------
  50.   ;文件共享属性      
  51.   ;------------------------------------------------------------
  52.   .elseif iosb.Information == FILE_OPENED
  53.   invoke DbgPrint, $CTA0("目录共享")
  54.   .endif
  55.   invoke ZwClose, hDirectory
  56. .else
  57.   ;------------------------------------------------------------
  58.   ;格式化输出,创建目录失败!
  59.   ;------------------------------------------------------------
  60.   invoke DbgPrint, $CTA0("无法创建目录,错误代码 %08X"), eax
  61. .endif
  62. ret
  63. CreateDirectory endp
  64. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  65. ;
  66. ;打开创建一个文件
  67. ;
  68. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  69. CreateFile proc
  70. local oa:OBJECT_ATTRIBUTES
  71. local iosb:IO_STATUS_BLOCK
  72. local hFile:HANDLE
  73. ;-----------------------------------------------------------
  74. ;
  75. ;格式化输出创建的文件名。在内核中使用Unicode
  76. ;Buffer缓冲区保存着文件路径
  77. ;
  78. ;-----------------------------------------------------------
  79. invoke DbgPrint, $CTA0("创建文件 %ws "), g_usFileName.Buffer
  80. ;-----------------------------------------------------------
  81.   ;初始化OBJ_CASE_INSENSITIVE结构
  82.   ;-----------------------------------------------------------
  83. InitializeObjectAttributes addr oa, addr g_usFileName, /
  84.       OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL
  85. ;-----------------------------------------------------------   
  86.   ;打开文件
  87.   ;-----------------------------------------------------------
  88. invoke ZwCreateFile, addr hFile, SYNCHRONIZE, addr oa, addr iosb, 0, FILE_ATTRIBUTE_NORMAL, /
  89.       0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0
  90. .if eax == STATUS_SUCCESS
  91.   invoke DbgPrint, $CTA0("文件创建成功")
  92.   invoke ZwClose, hFile
  93. .else
  94.   invoke DbgPrint, $CTA0("文件创建失败,错误代码: %08X"), eax
  95. .endif
  96. ret
  97. CreateFile endp

  98. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99. ;
  100. ;开始把内容写入这个文件当中      
  101. ;
  102. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  103. WriteFile proc
  104. local oa:OBJECT_ATTRIBUTES
  105. local iosb:IO_STATUS_BLOCK
  106. local hFile:HANDLE
  107.   ;相当于C中的printf
  108. invoke DbgPrint, $CTA0("打开文件准备写入数据")

  109. InitializeObjectAttributes addr oa, addr g_usFileName, /
  110.       OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL
  111.   ;-----------------------------------------------------------
  112.   ;
  113.   ; ZwCreateFile 用来打开文件,所以属性必须指定.
  114.   ; 如果要对文件进行写操作,可以指定FILE_WRITE_DATA权限,这个和ring3一样
  115.   ;
  116.   ;-----------------------------------------------------------
  117. invoke ZwCreateFile, addr hFile, FILE_WRITE_DATA + SYNCHRONIZE, addr oa, addr iosb, /
  118.       0, 0, FILE_SHARE_READ, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0
  119. .if eax == STATUS_SUCCESS
  120.   invoke DbgPrint, $CTA0("文件打开成功")
  121.   ;-----------------------------------------------------------
  122.   ;
  123.       ;这里是文件内容,使用了CTA0 宏,也可以在.const段来定义
  124.       ;CTA0 "Data can be written to an open file", g_szData,4
  125.       ;使用何种定义,都是个人偏好。下面代码就没什么好注释的了
  126.       ;
  127.       ;-----------------------------------------------------------
  128.       
  129.       CTA0 "看KmdKit爽爽中,其内附一代码,其内容过于复杂,删几段修改测试之,成功,乃大喜,记之.",g_szData,4
  130.   invoke ZwWriteFile, hFile, 0, NULL, NULL, addr iosb, /
  131.       addr g_szData, sizeof g_szData - 1, NULL, NULL
  132.   .if eax == STATUS_SUCCESS
  133.   invoke DbgPrint, $CTA0("文件写入成功")
  134.   .else
  135.   invoke DbgPrint, $CTA0("无法写入文件,错误代码: %08X"), eax
  136.   .endif

  137.   invoke ZwClose, hFile
  138. .else
  139.   invoke DbgPrint, $CTA0("无法打开文件,错误代码: %08X"), eax
  140. .endif

  141. ret

  142. WriteFile endp                                          
  143. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  144. ;
  145. ;驱动程序入口处
  146. ;
  147. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

  148. DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING

  149. invoke DbgPrint, $CTA0("驱动入口")
  150. ;---------------------------------------------------------------------
  151. ;调用函数创建一个目录.刚测试了一下,要创建一个文件,必须先创建其目录.
  152. ;这个ZwCreateFile不像ring3的一样,必须要创建文件的目录后,才能创建文件.
  153. ;---------------------------------------------------------------------
  154. invoke CreateDirectory
  155. invoke CreateFile      ;创建一个文件
  156. invoke WriteFile      ;把内容写到此文件中

  157. invoke DbgPrint, $CTA0("执行完退出")
  158. mov eax, STATUS_DEVICE_CONFIGURATION_ERROR ;获取失败消息返回
  159. ret
  160. DriverEntry endp
  161. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  162. end DriverEntry

复制代码


很简单的一个驱动程序。关于文件操作的。俺喜欢用IDA对程序进行白箱测试,有牛人说,学汇编最好的方法就是反汇编别人的程序。这句话俺深有体会。逆向技术在商业领域用途更广,并且逆向技术已经合法话,玩这个的更有发挥的空间。俺曾经听过一句铞言:给我一个可执行文件,我可以还你一份源码。可见威力。可惜俺的逆向功底不深,对驱动的逆向难免存在遗漏,请大大们指出,俺一定会改正。

    当然,要对驱动的结构有很深的了解才能够分析。但是有些程序是exe的,但是却使用ntdll.dll里的函数,比如系统进程 lsass.exe。这里我简陋分析一下:

  1. .text:010014EC                push    esi            ; 保存寄存器值
  2. .text:010014ED                push    esi            
  3. .text:010014EE                push    1              ;千万别把1当作一个参数。
  4. .text:010014F0                call    loc_10013EF    ; 调用子函数

  5. ---------------------------------------------------------------------------
  6. ;看到这里就应该明白,这个子函数并没有任何参数传递。所以我也不明白 push 1 是什么意思
  7. loc_10013EF:


  8. .text:010013EF loc_10013EF:                        
  9. .text:010013EF                mov    edi, edi
  10. .text:010013F1                push    ebp
  11. .text:010013F2                mov    ebp, esp
  12. .text:010013F4                push    ecx
  13. .text:010013F5                push    esi            ; 上面这些操作都是保存寄存器的值,而非参数。即pushad
  14. .text:010013F6                push    1              ; SEM_NOGPFAULTERRORBOX
  15. .text:010013F8                call    ds:SetErrorMode ; 设置错误代码,如果程序出现异常,不提供任何提示
  16. .text:010013FE                push    offset loc_10011DD
  17. .text:01001403                call    ds:SetUnhandledExceptionFilter ; 程序错误则取其错误地址.这是一个回调函数
  18. .text:01001409                push    4
  19. .text:0100140B                lea    eax, [ebp-4]
  20. .text:0100140E                push    eax
  21. .text:0100140F                push    5
  22. .text:01001411                push    0FFFFFFFFh
  23. .text:01001413                mov    dword ptr [ebp-4], 9
  24. .text:0100141A                call    ds:NtSetInformationProcess ; 把与调度优先级有关的信息设置到目标进程对象中去。具体是什么,我也不清楚
  25. .text:01001420                mov    esi, eax        ; 保存函数返回值到esi
  26. .text:01001422                test    esi, esi        ; 为0否?
  27. .text:01001424                jl      short loc_1001486 ; 这里的esi是NtSetInformationProcess函数的返回值。通过堆栈直接传给这个子函数

  28. ------------------------------------------------------------------------------------

  29. loc_1001486:


  30. .text:01001486 loc_1001486:                           
  31. .text:01001486                                       
  32. .text:01001486                                       
  33. .text:01001486                                      
  34. .text:01001486                                       
  35. .text:01001486                                       
  36. .text:01001486                push    esi            ; 这里的esi是NtSetInformationProcess函数的返回值。通过堆栈直接传给这个子函数
  37. .text:01001487                call    sub_10011EE
  38. .text:01001487
  39. .text:0100148C                push    esi
  40. .text:0100148D                call    ds:ExitThread


  41. ----------------------------------------------------------------------------------

  42. sub_10011EE:



  43. .text:010011EE sub_10011EE    proc near            
  44. .text:010011EE
  45. .text:010011EE var_48          = dword ptr -48h
  46. .text:010011EE var_44          = dword ptr -44h
  47. .text:010011EE var_40          = dword ptr -40h
  48. .text:010011EE var_38          = dword ptr -38h
  49. .text:010011EE var_34          = dword ptr -34h
  50. .text:010011EE var_30          = dword ptr -30h
  51. .text:010011EE var_2C          = dword ptr -2Ch
  52. .text:010011EE var_28          = dword ptr -28h
  53. .text:010011EE var_24          = dword ptr -24h
  54. .text:010011EE var_20          = dword ptr -20h
  55. .text:010011EE hObject        = dword ptr -1Ch
  56. .text:010011EE pSid            = dword ptr -18h
  57. .text:010011EE var_14          = dword ptr -14h
  58. .text:010011EE var_10          = dword ptr -10h
  59. .text:010011EE pIdentifierAuthority= _SID_IDENTIFIER_AUTHORITY ptr -0Ch
  60. .text:010011EE var_4          = dword ptr -4
  61. .text:010011EE arg_0          = dword ptr  8 ;传递过来的NtSetInformationProcess函数句柄
  62. .text:010011EE
  63. .text:010011EE                mov    edi, edi
  64. .text:010011F0                push    ebp
  65. .text:010011F1                mov    ebp, esp
  66. .text:010011F3                sub    esp, 48h
  67. .text:010011F6                mov    eax, dword_1003004
  68. .text:010011FB                push    ebx
  69. .text:010011FC                push    esi
  70. .text:010011FD                mov    esi, [ebp+arg_0]
  71. .text:01001200                xor    ebx, ebx
  72. .text:01001202                cmp    esi, ebx
  73. .text:01001204                mov    [ebp+var_4], eax
  74. .text:01001207                push    edi
  75. .text:01001208                mov    [ebp+var_10], ebx
  76. .text:0100120B                jl      loc_1001298
  77. .text:0100120B
  78. .text:01001211                push    offset s_Sam_service_s ; "//SAM_SERVICE_STARTED"
  79. .text:01001216                lea    eax, [ebp+var_40] ; 由此可见,var_40 是一个局部缓冲区变量
  80. .text:01001219                push    eax
  81. .text:0100121A                call    ds:RtlInitUnicodeString
  82. .text:01001220                push    ebx
  83. .text:01001221                lea    eax, [ebp+var_40]
  84. .text:01001224                mov    [ebp+var_2C], eax
  85. .text:01001227                push    ebx
  86. .text:01001228                lea    eax, [ebp+var_34]
  87. .text:0100122B                push    eax
  88. .text:0100122C                mov    esi, 100002h
  89. .text:01001231                push    esi
  90. .text:01001232                lea    eax, [ebp+var_10]
  91. .text:01001235                push    eax
  92. .text:01001236                mov    [ebp+var_34], 18h
  93. .text:0100123D                mov    [ebp+var_30], ebx
  94. .text:01001240                mov    [ebp+var_28], ebx
  95. .text:01001243                mov    [ebp+var_24], ebx
  96. .text:01001246                mov    [ebp+var_20], ebx
  97. .text:01001249                call    ds:NtCreateEvent ; 创建互拆对象,内核中代表着事件对象的数据结构是KEVENT
  98. .text:0100124F                cmp    eax, ebx        ; eax >= ebx ?
  99. .text:01001251                jge    short loc_1001278 ; 如果是,就跳
  100. .text:01001251
  101. .text:01001253                cmp    eax, 40000000h  ; eax == 40000000h ?
  102. .text:01001258                jz      short loc_1001261
  103. .text:01001258
  104. .text:0100125A                cmp    eax, 0C0000035h ; eax != 0C0000035h ?
  105. .text:0100125F                jnz    short loc_1001270
  106. .text:0100125F
  107. .text:01001261
  108. .text:01001261 loc_1001261:                          
  109. .text:01001261                lea    eax, [ebp+var_34]
  110. .text:01001264                push    eax
  111. .text:01001265                push    esi
  112. .text:01001266                lea    eax, [ebp+var_10]
  113. .text:01001269                push    eax
  114. .text:0100126A                call    ds:NtOpenEvent  ; 打开一个内核对象
  115. .text:0100126A
  116. .text:01001270
  117. .text:01001270 loc_1001270:                          
  118. .text:01001270                cmp    eax, ebx
  119. .text:01001272                jl      loc_10013DB
  120. .text:01001272
  121. .text:01001278
  122. .text:01001278 loc_1001278:                          
  123. .text:01001278                push    ebx
  124. .text:01001279                push    [ebp+var_10]
  125. .text:0100127C                call    ds:NtSetEvent  ; 设置内核对象
  126. .text:01001282                test    eax, eax
  127. .text:01001284                jge    loc_10013DB
  128. .text:01001284
  129. .text:0100128A                push    [ebp+var_10]
  130. .text:0100128D                call    ds:NtClose      ; 关闭
  131. .text:01001293                jmp    loc_10013DB
  132. .text:01001293
  133. .text:01001298 ; ---------------------------------------------------------------------------
  134. .text:01001298
  135. .text:01001298 loc_1001298:                           
  136. .text:01001298                push    2              ; ImpersonationLevel
  137. .text:0100129A                call    ds:ImpersonateSelf
  138. .text:010012A0                xor    edi, edi
  139. .text:010012A2                inc    edi
  140. .text:010012A3                test    eax, eax
  141. .text:010012A5                jz      loc_100133F
  142. .text:010012A5
  143. .text:010012AB                lea    eax, [ebp+hObject]
  144. .text:010012AE                push    eax            ; TokenHandle
  145. .text:010012AF                push    edi            ; OpenAsSelf
  146. .text:010012B0                push    8              ; DesiredAccess
  147. .text:010012B2                call    ds:GetCurrentThread ; 获取自身进程PID
  148. .text:010012B8                push    eax            ; ThreadHandle
  149. .text:010012B9                call    ds:OpenThreadToken ; Open the access token associated with a thread
  150. .text:010012BF                test    eax, eax
  151. .text:010012C1                jz      short loc_1001339
  152. .text:010012C1
  153. .text:010012C3                lea    eax, [ebp+pSid]
  154. .text:010012C6                push    eax            ; pSid
  155. .text:010012C7                push    ebx            ; nSubAuthority7
  156. .text:010012C8                push    ebx            ; nSubAuthority6
  157. .text:010012C9                push    ebx            ; nSubAuthority5
  158. .text:010012CA                push    ebx            ; nSubAuthority4
  159. .text:010012CB                push    ebx            ; nSubAuthority3
  160. .text:010012CC                push    ebx            ; nSubAuthority2
  161. .text:010012CD                push    ebx            ; nSubAuthority1
  162. .text:010012CE                push    12h            ; nSubAuthority0
  163. .text:010012D0                push    edi            ; nSubAuthorityCount
  164. .text:010012D1                lea    eax, [ebp+pIdentifierAuthority]
  165. .text:010012D4                push    eax            ; pIdentifierAuthority
  166. .text:010012D5                mov    [ebp+var_14], edi
  167. .text:010012D8                mov    [ebp+pSid], ebx
  168. .text:010012DB                mov    [ebp+pIdentifierAuthority.Value], bl
  169. .text:010012DE                mov    [ebp+pIdentifierAuthority.Value+1], bl
  170. .text:010012E1                mov    [ebp+pIdentifierAuthority.Value+2], bl
  171. .text:010012E4                mov    [ebp+pIdentifierAuthority.Value+3], bl
  172. .text:010012E7                mov    [ebp+pIdentifierAuthority.Value+4], bl
  173. .text:010012EA                mov    [ebp+pIdentifierAuthority.Value+5], 5
  174. .text:010012EE                call    ds:AllocateAndInitializeSid ; Allocate and initializes a security
  175. .text:010012EE                                        ; identifier with up to eight subauthorities
  176. .text:010012F4                test    eax, eax
  177. .text:010012F6                jz      short loc_100131F
  178. .text:010012F6
  179. .text:010012F8                lea    eax, [ebp+var_38]
  180. .text:010012FB                push    eax
  181. .text:010012FC                push    [ebp+pSid]
  182. .text:010012FF                push    [ebp+hObject]
  183. .text:01001302                call    CheckTokenMembership
  184. .text:01001302
  185. .text:01001307                test    eax, eax
  186. .text:01001309                jz      short loc_1001311
  187. .text:01001309
  188. .text:0100130B                mov    eax, [ebp+var_38]
  189. .text:0100130E                mov    [ebp+var_14], eax
  190. .text:0100130E
  191. .text:01001311
  192. .text:01001311 loc_1001311:                          
  193. .text:01001311                cmp    [ebp+pSid], ebx
  194. .text:01001314                jz      short loc_100131F
  195. .text:01001314
  196. .text:01001316                push    [ebp+pSid]      ; pSid
  197. .text:01001319                call    ds:FreeSid
  198. .text:01001319
  199. .text:0100131F
  200. .text:0100131F loc_100131F:                          
  201. .text:0100131F                                       
  202. .text:0100131F                push    [ebp+hObject]  ; hObject
  203. .text:01001322                call    ds:CloseHandle
  204. .text:01001328                call    ds:RevertToSelf ; Terminate the impersonation
  205. .text:01001328                                        ; of a client application
  206. .text:0100132E                cmp    [ebp+var_14], ebx
  207. .text:01001331                jz      loc_10013DB
  208. .text:01001331
  209. .text:01001337                jmp    short loc_100133F
  210. .text:01001337
  211. .text:01001339 ; ---------------------------------------------------------------------------
  212. .text:01001339
  213. .text:01001339 loc_1001339:                          
  214. .text:01001339                call    ds:RevertToSelf ; Terminate the impersonation
  215. .text:01001339                                        ; of a client application
  216. .text:01001339
  217. .text:0100133F
  218. .text:0100133F loc_100133F:                          
  219. .text:0100133F                                       
  220. .text:0100133F                lea    eax, [ebp+var_48]
  221. .text:01001342                push    eax
  222. .text:01001343                push    edi
  223. .text:01001344                lea    eax, [ebp+var_44]
  224. .text:01001347                push    eax
  225. .text:01001348                push    ebx
  226. .text:01001349                push    edi
  227. .text:0100134A                or      esi, 10000000h
  228. .text:01001350                push    esi
  229. .text:01001351                mov    [ebp+var_44], 10010h
  230. .text:01001358                call    ds:NtRaiseHardError
  231. .text:0100135E                mov    esi, eax
  232. .text:01001360                call    LsaISetupWasRun
  233. .text:01001360
  234. .text:01001365                test    al, al
  235. .text:01001367                jz      short loc_10013B4 ; 关闭计算机
  236. .text:01001367
  237. .text:01001369                push    offset s_Setup_failed ; "//SETUP_FAILED"
  238. .text:0100136E                lea    eax, [ebp+var_40]
  239. .text:01001371                push    eax
  240. .text:01001372                call    ds:RtlInitUnicodeString
  241. .text:01001378                lea    eax, [ebp+var_40]
  242. .text:0100137B                mov    [ebp+var_2C], eax
  243. .text:0100137E                lea    eax, [ebp+var_34]
  244. .text:01001381                push    eax
  245. .text:01001382                push    100002h
  246. .text:01001387                lea    eax, [ebp+var_10]
  247. .text:0100138A                push    eax
  248. .text:0100138B                mov    [ebp+var_34], 18h
  249. .text:01001392                mov    [ebp+var_30], ebx
  250. .text:01001395                mov    [ebp+var_28], ebx
  251. .text:01001398                mov    [ebp+var_24], ebx
  252. .text:0100139B                mov    [ebp+var_20], ebx
  253. .text:0100139E                call    ds:NtOpenEvent
  254. .text:010013A4                test    eax, eax
  255. .text:010013A6                jl      short loc_10013DB
  256. .text:010013A6
  257. .text:010013A8                push    ebx
  258. .text:010013A9                push    [ebp+var_10]
  259. .text:010013AC                call    ds:NtSetEvent
  260. .text:010013B2                jmp    short loc_10013DB
  261. .text:010013B2
  262. .text:010013B4 ; ---------------------------------------------------------------------------
  263. .text:010013B4
  264. .text:010013B4 loc_10013B4:                          
  265. .text:010013B4                cmp    esi, ebx
  266. .text:010013B6                jl      short loc_10013DB
  267. .text:010013B6
  268. .text:010013B8                mov    esi, ds:RtlAdjustPrivilege
  269. .text:010013BE                lea    eax, [ebp+var_14]
  270. .text:010013C1                push    eax
  271. .text:010013C2                push    ebx
  272. .text:010013C3                push    edi
  273. .text:010013C4                push    13h
  274. .text:010013C6                call    esi ; RtlAdjustPrivilege
  275. .text:010013C8                push    edi            ; edi == 2 ?
  276. .text:010013C9                call    ds:NtShutdownSystem
  277. .text:010013CF                lea    eax, [ebp+var_14]
  278. .text:010013D2                push    eax
  279. .text:010013D3                push    ebx
  280. .text:010013D4                push    [ebp+var_14]
  281. .text:010013D7                push    13h
  282. .text:010013D9                call    esi ; RtlAdjustPrivilege
  283. .text:010013D9
  284. .text:010013DB
  285. .text:010013DB loc_10013DB:                          
  286. .text:010013DB                                       
  287. .text:010013DB                                       
  288. .text:010013DB                                       
  289. .text:010013DB                                       
  290. .text:010013DB                                       
  291. .text:010013DB                mov    ecx, [ebp+var_4]
  292. .text:010013DE                pop    edi
  293. .text:010013DF                pop    esi
  294. .text:010013E0                pop    ebx
  295. .text:010013E1                call    sub_10015C5
  296. .text:010013E1
  297. .text:010013E6                leave
  298. .text:010013E7                retn    4
  299. .text:010013E7
  300. .text:010013E7 sub_10011EE    endp

复制代码


下面是lsass.exe的部分代码。俺写得不伦不类。哎,继续加强俺的汇编功底。代码:
  1. ;--------------------------------------------------------
  2. ;
  3. ;code By Asm
  4. ;
  5. ;---------------------------------------------------------
  6. .386
  7. .model flat, stdcall
  8. option casemap:none

  9. ;--------------------------------------------------------
  10. ;
  11. ;未编写完成的lsass.exe的代码,就算写完,估计还需要大面积调式
  12. ;所以这里不好把头文件和库写出。不过我们总算了解一点东西,
  13. ;就是为什么结束了lsass.exe,系统会关机。原来是调用NtRaiseHardError
  14. ;来检查错误,发现了,就调用NtShutdownSystem。
  15. ;
  16. ;----------------------------------------------------------

  17. .data
  18. dword_1003004 dd 0BB40h
  19. .const
  20. CCOUNTED_UNICODE_STRING    "//SAM_SERVICE_STARTED",g_usSam, 4
  21. .code
  22. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  23. Lsasses proc lpRet:LPSTR
  24. local hEvent1:HANDLE
  25. local hEvent:HANDLE
  26. local szTYPE:EVENT_TYPE
  27. local Message[1024]:DWORD
  28. local Error:HARDERROR_RESPONSE_OPTION
  29. local Response:HARDERROR_RESPONSE
  30. local en:DWORD

  31. mov esi,lpRet
  32. xor ebx,ebx
  33. cmp esi,ebx
  34. mov hEvent1,eax
  35. push edi  ;edi是什么,还未知
  36. mov ebx,hEvent
  37. jl      loc_1001298

  38. invoke RtlInitUnicodeString,addr lpBuff,addr g_usSam
  39. invoke NtCreateEvent,hEvent,100002h,CTXT("LsassEvent"),szTYPE.SynchronizationEvent,sizeof szTYPE.SynchronizationEvent;这个函数的写得有点牵强
  40. .if eax>=ebx  ;ebx到底是什么?有待进一步分析!
  41. invoke NTSetEvent,hEvent,ebx
  42. .elseif eax==40000000h
  43. invoke NtOpenEvent,hEvent,100002h,CTXT("LsassEvent")
  44. .elseif eax
  45. invoke NtClose,hEvent
  46. .endif

  47. loc_1001298:
  48.             invoke ImpersonateSelf,2
  49.             xor edi,edi
  50.             inc edi
  51.             .if eax==NULL
  52.             jmp loc_100133F
  53.             .endif
  54.             
  55. loc_100133F:  
  56.           or  esi, 10000000h
  57.           invoke NtRaiseHardError,esi,edi,ebx,addr Message,addr Error,addr Response
  58.           mov esi,eax ;esi是在堆栈中,这里典型的通过寄存器传递参数
  59.           call LsaISetupWasRun
  60.           test al,al
  61.           jz NtShutdown
  62.          
  63. NtShutdown:
  64.           invoke RtlAdjustPrivilege,SE_SHUTDOWN_PRIVILEGE,2,2,addr en
  65.           invoke NtShutdownSystem,2
  66.           invoke RtlAdjustPrivilege,SE_SHUTDOWN_PRIVILEGE,addr en,2,addr en
  67. ret
  68. Lsasses endp
  69. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  70. loc_10013EF proc
  71. local Handel:HANDLE
  72. local dwRet:DWORD
  73. invoke SetErrorMode,SEM_FAILCRITICALERRORS
  74. invoke SetUnhandledExceptionFilter,EXCEPTION_ACCESS_VIOLATION
  75. invoke NtSetInformationProcess,0FFFFFFFFh,5,addr Handel,4
  76. .if eax<NULL
  77. mov dwRet,eax
  78. jmp loc_1001486
  79. .endif

  80. loc_1001486:
  81.           invoke Lsasses,dwRet ;执行完这个函数,还不知道到底是做了什么的。
  82.           invoke ExitThread,0
  83. loc_10013EF endp
  84. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  85. DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
  86. invoke  loc_10013EF;调用第一个子函数,姑且这么写
  87. mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
  88. ret
  89. DriverEntry endp
  90. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  91. end DriverEntry

复制代码

该用户从未签到

发表于 2013-9-28 08:15:48 | 显示全部楼层
呵呵,我是进来帮顶一下的哈,辛苦了。。

该用户从未签到

发表于 2013-9-28 16:36:04 | 显示全部楼层
好东西啊,真是好东西,感谢楼主分享!谢谢!

该用户从未签到

发表于 2013-9-28 16:36:27 | 显示全部楼层
回答了那么多,没有加分了,郁闷。
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-4-20 15:18

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表