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

全部博文(12)

文章存档

2011年(12)

我的朋友
最近访客

分类: Delphi

2011-02-27 20:42:33

;※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
;   ShellCodeTest.exe
;※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
; Author: Goly
; Email: 
; QQ: 402295354
;★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
; Core:
;  1._GetKernel32Base 动态获取kenrnel32.dll基地址
;  2._GetCallBaseByName 通过函数名动态获取函数地址
;★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
 
  1. .386
  2. .model flat,stdcall
  3. option casemap:none
  4. .const
  5. SZ_LoadLibraryA db 'LoadLibraryA',0
  6. SZ_MessageBoxA db 'MessageBoxA',0
  7. SZ_ExitProcess db 'ExitProcess',0
  8. AppName db 'ShellCode',0
  9. user32 db 'user32.dll',0
  10. .data?
  11. API_LoadLibraryA dd ?
  12. API_MessageBoxA dd ?
  13. .code
  14. _StrLenA proc pStr:DWORD
  15. mov esi,pStr
  16. xor eax,eax
  17. .while(byte ptr[esi]!=0)
  18. inc eax
  19. inc esi
  20. .endw
  21. ret
  22. _StrLenA endp
  23. _StrEqualA proc uses ecx esi edi pStr1:DWORD,pStr2:DWORD
  24. invoke _StrLenA,pStr1
  25. mov ecx,eax
  26. invoke _StrLenA,pStr2
  27. .if(ecx
  28. mov ecx,eax
  29. .endif
  30. mov esi,pStr1
  31. mov edi,pStr2
  32. LOOP2:
  33. mov al,byte ptr[esi]
  34. mov ah,byte ptr[edi]
  35. cmp al,ah
  36. jne NQ
  37. inc esi
  38. inc edi
  39. loop LOOP2
  40. mov eax,1
  41. ret
  42. NQ: xor eax,eax
  43. ret
  44. _StrEqualA endp
  45. _GetKernel32Base proc uses ecx ;根据FS:0处的TEB结构找到UnhandledExceptionFilter函数的地址,UnhandledExceptionFilter函数位于kernerl32.dll中,因此可由此查询得到kernel32.dll的基地址。
  46. assume fs:nothing
  47. mov eax,fs:[0]
  48. FindUEF:;通过TEB查找kernel32.dll中的UnhandledExceptionFilter函数的地址
  49. cmp dword ptr[eax],0ffffffffh
  50. je FoundUEF
  51. mov eax,[eax]
  52. jmp FindUEF
  53. FoundUEF:
  54. mov eax,[eax+4];获得UnhandledExceptionFilter函数的地址
  55. FindPeTag:;循环查找kernel32.dll的PE标志
  56. and eax,0ffff0000h
  57. cmp word ptr[eax],05A4Dh;'MZ'标志
  58. jne RollUp
  59. mov ecx,[eax+03ch]
  60. add ecx,eax
  61. cmp word ptr[ecx],4550h;'PE'标志
  62. je FoundPeTag
  63. RollUp:
  64. sub eax,0ffffh
  65. jmp FindPeTag
  66. FoundPeTag:
  67. ret
  68. _GetKernel32Base endp
  69. _GetCallBaseByName proc ImageBase:DWORD,pCallName:DWORD
  70. LOCAL ExportEntryAddr:DWORD
  71. ;LOCAL hList:DWORD
  72. LOCAL pName:DWORD
  73. LOCAL index:DWORD
  74. ;invoke GetDlgItem,hWnd,IDC_LIST
  75. ;mov hList,eax
  76. mov eax,ImageBase
  77. add eax,03ch
  78. mov eax,[eax]
  79. add eax,ImageBase
  80. mov ebx,[eax]
  81. cmp ebx,00004550h
  82. jne NotPe;'MZ'验证出错,ImageBase出错引起
  83. mov eax,[eax+078h]
  84. add eax,ImageBase
  85. ;mov eax,[eax]
  86. ;add eax,ImageBase
  87. mov ExportEntryAddr,eax
  88. mov eax,[eax+020h]
  89. add eax,ImageBase;eax为函数名所在数组的首地址
  90. mov ecx,ExportEntryAddr
  91. mov ecx,[ecx+018h];funcs个数
  92. dec ecx
  93. mov esi,ecx
  94. xor ecx,ecx
  95. .while(ecx<=esi)
  96. push eax
  97. push ecx
  98. mov eax,[eax+4*ecx]
  99. add eax,ImageBase
  100. mov index,ecx
  101. mov pName,eax
  102. ;函数名处理
  103. ;invoke SendMessage,hList,LB_ADDSTRING,0,pName
  104. invoke _StrEqualA,pName,pCallName
  105. .if(eax==1)
  106. mov eax,ExportEntryAddr
  107. mov eax,[eax+01ch]
  108. mov ecx,index
  109. shl ecx,2
  110. add eax,ecx
  111. add eax,ImageBase
  112. mov eax,[eax]
  113. add eax,ImageBase
  114. pop ecx
  115. pop ecx
  116. ret
  117. .endif
  118. pop ecx
  119. inc ecx
  120. pop eax
  121. .endw
  122. xor eax,eax
  123. ret
  124. NotPe:
  125. xor eax,eax
  126. ret
  127. _GetCallBaseByName endp
  128. start:
  129. invoke _GetKernel32Base
  130. invoke _GetCallBaseByName,eax,offset SZ_LoadLibraryA;eax=07c800000h
  131. .if(eax!=0)
  132. mov API_LoadLibraryA,eax
  133. push offset user32
  134. call API_LoadLibraryA
  135. push offset SZ_MessageBoxA
  136. push eax
  137. call _GetCallBaseByName
  138. .if(eax!=0)
  139. mov API_MessageBoxA,eax
  140. push 0
  141. push offset AppName
  142. push offset AppName
  143. push 0
  144. call API_MessageBoxA
  145. ;invoke MessageBox,0,offset buffer,offset AppName,MB_OK
  146. .endif
  147. .endif
  148. invoke _GetCallBaseByName,07c800000h,offset SZ_ExitProcess
  149. push 0
  150. call eax
  151. end start
阅读(1822) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~