赞
踩
// 12345.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "windows.h" int main(int argc, char* argv[]) { char *str="test"; printf("begin\n"); HINSTANCE libHandle; char *dll="user32.dll"; libHandle=LoadLibrary(dll); _asm{ sub sp,0x454 //给栈区分配一个空间,没有也可以运行 xor ebx,ebx //因为字符串中不能出现0,所以使用异或运算来规避push 0的出现 push ebx push str //messagebox的四个参数进栈 push str push ebx mov eax,0x77d507ea //messagebox()的绝对地址 call eax mov esp,20 } *///用于平衡堆栈 } return 0; }
这串代码可以成功弹框如下:
接下来我们把它切换到反汇编模式去,提取出它的机器码:
把这些机器码取出来放到一文本文档里,然后每两个给前面加\x
接下来上面的代码我们可以通过这段shellcode来实现:
#include "stdafx.h" #include "stdio.h" #include "windows.h" char shellcode[]="\x66\x81\xEC\x54\x04\x33\xDB\x53\xFF\x75\xFC\xFF\x75\xFC\x53\xB8\xEA\x07\xD5\x77\xFF\xD0\xBC\x14"; int main(int argc, char* argv[]) { char *str="test"; printf("begin\n"); HINSTANCE libHandle; char *dll="user32.dll"; libHandle=LoadLibrary(dll); _asm{ lea eax,shellcode //shellcode地址给eax push eax //eax压栈 ret //ret就会跳到shellcode首地址那里去执行 } return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。