找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 4064|回复: 2

【DLL劫持】用NASM汇编语言实现32位dsound.dll的劫持

[复制链接]

1112

主题

1653

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
245
威望
744 点
宅币
24257 个
贡献
46222 次
宅之契约
0 份
在线时间
2298 小时
注册时间
2014-1-26
发表于 2014-7-22 01:55:43 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
原理很简单。弄一个导出表和原dsound.dll一致的自定义DLL,里面的函数就都可以劫持了。
dsound.dll是使用DirectSound必不可少的DLL,通过使用它,游戏可以播放各种各样的音效。就比如《光环2》这个游戏,它就是使用DirectSound进行声音的播放的。
我觉得《光环2》的精英战士长得比较萌,而且声音也铿锵有力(虽然四个下颌让它们吐字不清)。通过劫持dsound.dll可以实现游戏音效的截取。
当然不能急,要一步一步来。写的函数名字和调用约定以及参数个数必须和原DLL完全一致,才能保证完全加载。
我这里给的源代码是自己写了个dsound.dll,然后它引用了原始的dsound.dll。做法就是用LoadLibrary加载原始DLL,调用原始的函数,然后对其进行处理。
先看ds.def
  1. LIBRARY
  2.     EXPORTS
  3. DirectSoundCreate               @1
  4. DirectSoundEnumerateA           @2
  5. DirectSoundEnumerateW           @3
  6. DllCanUnloadNow                 @4
  7. DllGetClassObject               @5
  8. DirectSoundCaptureCreate        @6
  9. DirectSoundCaptureEnumerateA    @7
  10. DirectSoundCaptureEnumerateW    @8
  11. GetDeviceID                     @9
  12. DirectSoundFullDuplexCreate     @10
  13. DirectSoundCreate8              @11
  14. DirectSoundCaptureCreate8       @12
复制代码
你会发现它和原始的dsound.dll一致。然后就是源码部分。因为是汇编写的所以代码略丑。
  1. ;DllMain用到的常数
  2. %define DLL_PROCESS_ATTACH 1
  3. %define DLL_THREAD_ATTACH  2
  4. %define DLL_THREAD_DETACH  3
  5. %define DLL_PROCESS_DETACH 0

  6. ;要用到的函数
  7. extern __imp__Beep@8
  8. extern __imp__LoadLibraryA@4
  9. extern __imp__GetProcAddress@8
  10. extern __imp__FreeLibrary@4

  11. ;导出的函数
  12. global _DllMain@12
  13. global _DirectSoundCreate@12
  14. global _DirectSoundEnumerateA@8
  15. global _DirectSoundEnumerateW@8
  16. global _DllCanUnloadNow@0
  17. global _DllGetClassObject@12
  18. global _DirectSoundCaptureCreate@12
  19. global _DirectSoundCaptureEnumerateA@8
  20. global _DirectSoundCaptureEnumerateW@8
  21. global _GetDeviceID@8
  22. global _DirectSoundFullDuplexCreate@40
  23. global _DirectSoundCreate8@12
  24. global _DirectSoundCaptureCreate8@12

  25. ;代码段
  26. segment .text
  27. ;==============================================================================
  28. ;加载原始DLL的宏
  29. ;------------------------------------------------------------------------------
  30. %macro LoadOrg 0
  31. push OrgDllName;DLL路径字符串
  32. call [__imp__LoadLibraryA@4]
  33. mov [OrgDllHMod],eax;存储返回值
  34. %endmacro

  35. ;==============================================================================
  36. ;调用原始函数的宏,参数是GetProcAddress的函数名那个参数。
  37. ;------------------------------------------------------------------------------
  38. %macro CallOrg 1
  39. push %1;函数名
  40. push dword[OrgDllHMod];DLL句柄
  41. call [__imp__GetProcAddress@8];取得函数地址
  42. call eax;调用函数
  43. %endmacro

  44. ;==============================================================================
  45. ;卸载原始DLL的宏
  46. ;------------------------------------------------------------------------------
  47. %macro FreeOrg 0
  48. push dword[OrgDllHMod];DLL句柄
  49. call [__imp__FreeLibrary@4]
  50. %endmacro

  51. ;==============================================================================
  52. ;发出蜂鸣的宏
  53. ;------------------------------------------------------------------------------
  54. %macro Beep 2
  55. push %2;时长
  56. push %1;频率
  57. call [__imp__Beep@8];蜂鸣
  58. %endmacro

  59. ;==============================================================================
  60. ;DllMain
  61. ;Dll的入口点
  62. ;------------------------------------------------------------------------------
  63. _DllMain@12:
  64. ;判断是DLL加载还是DLL卸载
  65. cmp dword[esp+8],DLL_PROCESS_ATTACH
  66. jz .ProcAttach
  67. cmp dword[esp+8],DLL_PROCESS_DETACH
  68. jz .ProcDetach
  69. jmp .EOFunc

  70. ;DLL卸载
  71. .ProcDetach:
  72. Beep 500,100;发出音高比较低的蜂鸣
  73. jmp .EOFunc

  74. ;DLL加载
  75. .ProcAttach:
  76. Beep 1000,100;发出音高比较高的蜂鸣

  77. .EOFunc:
  78. mov eax,1
  79. ret 12

  80. ;==============================================================================
  81. ;DirectSoundCreate
  82. ;------------------------------------------------------------------------------
  83. _DirectSoundCreate@12:
  84. LoadOrg
  85. push dword[esp+12]
  86. push dword[esp+12]
  87. push dword[esp+12]
  88. CallOrg dword 1
  89. FreeOrg
  90. ret 12

  91. ;==============================================================================
  92. ;DirectSoundEnumerateA
  93. ;------------------------------------------------------------------------------
  94. _DirectSoundEnumerateA@8:
  95. LoadOrg
  96. push dword[esp+8]
  97. push dword[esp+8]
  98. CallOrg dword 2
  99. FreeOrg
  100. ret 8

  101. ;==============================================================================
  102. ;DirectSoundEnumerateW
  103. ;------------------------------------------------------------------------------
  104. _DirectSoundEnumerateW@8:
  105. LoadOrg
  106. push dword[esp+8]
  107. push dword[esp+8]
  108. CallOrg dword 3
  109. FreeOrg
  110. ret 8

  111. ;==============================================================================
  112. ;DllCanUnloadNow
  113. ;------------------------------------------------------------------------------
  114. _DllCanUnloadNow@0:
  115. LoadOrg
  116. CallOrg dword 4
  117. FreeOrg
  118. ret

  119. ;==============================================================================
  120. ;DllGetClassObject
  121. ;------------------------------------------------------------------------------
  122. _DllGetClassObject@12:
  123. LoadOrg
  124. push dword[esp+12]
  125. push dword[esp+12]
  126. push dword[esp+12]
  127. CallOrg dword 5
  128. FreeOrg
  129. ret 12

  130. ;==============================================================================
  131. ;DirectSoundCaptureCreate
  132. ;------------------------------------------------------------------------------
  133. _DirectSoundCaptureCreate@12:
  134. LoadOrg
  135. push dword[esp+12]
  136. push dword[esp+12]
  137. push dword[esp+12]
  138. CallOrg dword 6
  139. FreeOrg
  140. ret 12

  141. ;==============================================================================
  142. ;DirectSoundCaptureEnumerateA
  143. ;------------------------------------------------------------------------------
  144. _DirectSoundCaptureEnumerateA@8:
  145. LoadOrg
  146. push dword[esp+8]
  147. push dword[esp+8]
  148. CallOrg dword 7
  149. FreeOrg
  150. ret 8

  151. ;==============================================================================
  152. ;DirectSoundCaptureEnumerateW
  153. ;------------------------------------------------------------------------------
  154. _DirectSoundCaptureEnumerateW@8:
  155. LoadOrg
  156. push dword[esp+8]
  157. push dword[esp+8]
  158. CallOrg dword 8
  159. FreeOrg
  160. ret 8

  161. ;==============================================================================
  162. ;GetDeviceID
  163. ;------------------------------------------------------------------------------
  164. _GetDeviceID@8:
  165. LoadOrg
  166. push dword[esp+8]
  167. push dword[esp+8]
  168. CallOrg dword 9
  169. FreeOrg
  170. ret 8

  171. ;==============================================================================
  172. ;DirectSoundFullDuplexCreate
  173. ;------------------------------------------------------------------------------
  174. _DirectSoundFullDuplexCreate@40:
  175. LoadOrg
  176. push dword[esp+40]
  177. push dword[esp+40]
  178. push dword[esp+40]
  179. push dword[esp+40]
  180. push dword[esp+40]
  181. push dword[esp+40]
  182. push dword[esp+40]
  183. push dword[esp+40]
  184. push dword[esp+40]
  185. push dword[esp+40]
  186. CallOrg dword 10
  187. FreeOrg
  188. ret 40

  189. ;==============================================================================
  190. ;DirectSoundCreate8
  191. ;------------------------------------------------------------------------------
  192. _DirectSoundCreate8@12:
  193. LoadOrg
  194. push dword[esp+12]
  195. push dword[esp+12]
  196. push dword[esp+12]
  197. CallOrg dword 11
  198. push eax
  199. FreeOrg
  200. pop eax
  201. ret 12

  202. ;==============================================================================
  203. ;DirectSoundCaptureCreate8
  204. ;------------------------------------------------------------------------------
  205. _DirectSoundCaptureCreate8@12:
  206. LoadOrg
  207. push dword[esp+12]
  208. push dword[esp+12]
  209. push dword[esp+12]
  210. CallOrg dword 12
  211. FreeOrg
  212. ret 12

  213. ;数据段
  214. segment .data
  215. OrgDllName db "c:\windows\system32\dsound.dll";原始DLL路径
  216. OrgDllHMod dd 0;原始DLL句柄
复制代码
这个源码需要用nasm编译,然后用link链接(VC6的link),你需要链接的库是kernel32.lib
SRC: DummyDS.7z (587.41 KB, 下载次数: 9, 售价: 2 个宅币)
我这个帖子只是举一个举一反三的作用。大家看了可以编写别的DLL的劫持程序。
回复

使用道具 举报

1112

主题

1653

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
245
威望
744 点
宅币
24257 个
贡献
46222 次
宅之契约
0 份
在线时间
2298 小时
注册时间
2014-1-26
 楼主| 发表于 2014-7-22 01:57:52 | 显示全部楼层
不知道如何编译链接的,可以下载我提供的源码,它自带了编译器、库、编译批命令。
其实你完全不需要用汇编来写,C语言照样可以。其实严格来说,对于COM的DLL,VB都能编写劫持的东西。
回复 赞! 靠!

使用道具 举报

7

主题

14

回帖

113

积分

用户组: 小·技术宅

UID
245
精华
0
威望
2 点
宅币
86 个
贡献
2 次
宅之契约
0 份
在线时间
6 小时
注册时间
2014-5-3
发表于 2014-7-22 04:16:45 | 显示全部楼层
支持AA55分享精神
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-29 13:23 , Processed in 0.052362 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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