Chinaunix首页 | 论坛 | 博客
  • 博客访问: 22309
  • 博文数量: 12
  • 博客积分: 287
  • 博客等级: 二等列兵
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-26 00:05
文章分类

全部博文(12)

文章存档

2011年(12)

我的朋友
最近访客

分类: C/C++

2011-05-02 05:53:02

拜读DiA/rrlf/29A.8.008的《Capture the desktop - scan .LNK files for victims》一文,原文中代码为fasm编写。于是顺手改写为自己常用的masm了。改写的过程中才发现原文中关于lnk文件结构部分有误,代码自然也是错的了。微软并没有公开lnk文件结构,因而也无可厚非了。在这里贴出来修改后的masm代码,并附一个人分析后认为比较可靠的lnk结构资料(http://www.stdlib.com/art6-Shortcut-File-Format-lnk.html)。

 

  1. ;※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  2. ; LinkScan.exe
  3. ;※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  4. ; Author: Goly
  5. ; Email: bh.yang@163.com
  6. ; QQ: 402295354
  7. ; Site:
  8. ;★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
  9. ; Core Code:
  10. .386
  11. .model flat, stdcall
  12. option casemap:none
  13. include windows.inc
  14. include user32.inc
  15. include kernel32.inc
  16. include advapi32.inc
  17. include gdi32.inc
  18. includelib user32.lib
  19. includelib kernel32.lib
  20. includelib gdi32.lib
  21. includelib advapi32.lib
  22. .const
  23. szDesktopSubkey db 'Software\Microsoft\',
  24. 'Windows\CurrentVersion\',
  25. 'Explorer\Shell Folders',0
  26. szDesktopValue db 'Desktop',0
  27. szERROR db 'Error!',0
  28. szLnkFiles db '*.lnk',0
  29. .data
  30. dwRegHandle dd ?
  31. szDesktopPath db 260 dup(?)
  32. dwDesktopSize dd 260
  33. szRegType db 'REG_SZ',0
  34. stWin32FindData WIN32_FIND_DATA
  35. dwFindHandle dd ?
  36. dwFileHandle dd ?
  37. dwMapHandle dd ?
  38. dwMapAddress dd ?
  39. dwItemSize dw ?
  40. dtVictim db 255 dup(?)
  41. .code
  42. ;-------get desktop path from registry-----
  43. _GetDesktopPath proc
  44. invoke RegOpenKeyEx,\
  45. HKEY_CURRENT_USER,\
  46. offset szDesktopSubkey,\
  47. 0,\
  48. KEY_ALL_ACCESS,\
  49. offset dwRegHandle
  50. cmp eax,ERROR_SUCCESS
  51. jnz _Error
  52. invoke RegQueryValueEx,\
  53. dwRegHandle,\
  54. offset szDesktopValue,\
  55. 0,\
  56. offset szRegType,\
  57. offset szDesktopPath,\
  58. offset dwDesktopSize
  59. cmp eax,ERROR_SUCCESS
  60. jnz _Error
  61. invoke RegCloseKey,\
  62. dwRegHandle
  63. ;check if path is valid,if not,make it valid
  64. mov esi,offset szDesktopPath
  65. @GetZero:
  66. cmp byte ptr[esi],0
  67. je @GotZero
  68. inc esi
  69. jmp @GetZero
  70. @GotZero:
  71. dec esi
  72. cmp byte ptr[esi],5ch;'\'
  73. je @HaveSlash
  74. inc esi
  75. mov byte ptr[esi],5ch
  76. mov byte ptr[esi+1],0
  77. @HaveSlash:
  78. ret
  79. _GetDesktopPath endp
  80. ;-------get desktop path from registry-----END
  81. _ScanLinkFile proc
  82. invoke SetCurrentDirectory,\
  83. offset szDesktopPath
  84. cmp eax,0
  85. je _Error
  86. invoke FindFirstFile,\
  87. offset szLnkFiles,\
  88. offset stWin32FindData
  89. mov dwFindHandle,eax
  90. @FindMoreFiles:
  91. cmp eax,0
  92. je @ExitFunc
  93. invoke CreateFile,\
  94. offset stWin32FindData.cFileName,\
  95. GENERIC_READ+GENERIC_WRITE,\
  96. FILE_SHARE_READ,\
  97. 0,\
  98. OPEN_EXISTING,\
  99. FILE_ATTRIBUTE_NORMAL,\
  100. 0
  101. cmp eax,INVALID_HANDLE_VALUE
  102. je @FindNextLNK
  103. mov dwFileHandle,eax
  104. ;--------Map the file---
  105. invoke CreateFileMapping,\
  106. dwFileHandle,\
  107. 0,\
  108. PAGE_READWRITE,\
  109. 0,\
  110. 0,\
  111. 0
  112. cmp eax,0
  113. je @CloseFile
  114. mov dwMapHandle,eax
  115. invoke MapViewOfFile,\
  116. dwMapHandle,\
  117. FILE_MAP_WRITE,\
  118. 0,\
  119. 0,\
  120. 0
  121. cmp eax,0
  122. je @CloseMap
  123. mov dwMapAddress,eax
  124. ;---------Map the file---END
  125. ;---------Check if .lnk file is valid---
  126. mov esi,dwMapAddress
  127. cmp dword ptr[esi],4ch
  128. jne @CloseMap
  129. ;---------Check if .lnk file is valid---END
  130. add esi,4ch;Jump over the header
  131. mov edi,offset dwItemSize
  132. movsw
  133. xor eax,eax
  134. mov ax,dwItemSize
  135. add esi,eax;Jump over the Shell Item List strcture
  136. push esi
  137. add esi,10h;Jump over FileLocationInfo
  138. mov eax,dword ptr[esi]
  139. pop esi
  140. add esi,eax;Jump over Location Volume Table to the volume label (ASCIZ)
  141. mov edi,offset dtVictim;destination is Victim (esi->edi)
  142. @CopyVictimString:
  143. cmp byte ptr[esi],0
  144. je @HaveVictim
  145. movsb
  146. jmp @CopyVictimString
  147. @HaveVictim:
  148. mov dword ptr[edi],0
  149. ;----check if victim path is valid
  150. mov edx,offset dtVictim
  151. cmp byte ptr[edx+1],3AH
  152. jne @CloseMap
  153. @GetVictimZero:
  154. cmp byte ptr[edx],0
  155. je @HaveVictimZero
  156. inc edx
  157. jmp @GetVictimZero
  158. @HaveVictimZero:
  159. cmp byte ptr[edx-4],'.'
  160. jne @CloseMap
  161. invoke MessageBox,\
  162. 0,\
  163. offset dtVictim,\
  164. offset stWin32FindData.cFileName,\
  165. MB_ICONINFORMATION
  166. invoke UnmapViewOfFile,\
  167. dwMapAddress
  168. @CloseMap:
  169. invoke CloseHandle,\
  170. dwMapHandle
  171. @CloseFile:
  172. invoke CloseHandle,\
  173. dwFileHandle
  174. @FindNextLNK:
  175. invoke FindNextFile,\
  176. dwFindHandle,\
  177. offset stWin32FindData
  178. jmp @FindMoreFiles
  179. @ExitFunc:
  180. ret
  181. _ScanLinkFile endp
  182. _Error:
  183. invoke MessageBox,\
  184. 0,\
  185. offset szERROR,
  186. offset szERROR,
  187. MB_ICONERROR
  188. jmp _Exit
  189. start:
  190. call _GetDesktopPath
  191. call _ScanLinkFile
  192. _Exit:
  193. invoke ExitProcess,\
  194. 0
  195. end start
阅读(913) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~