日期:2014-05-17 浏览次数:21071 次
8: LoadLibrary("user32.dll");
00401028 mov esi,esp
0040102A push offset string "user32.dll" (0041f01c)
0040102F call dword ptr [__imp__LoadLibraryA@4 (00424138)]
00401035 cmp esi,esp
00401037 call __chkesp (00401080)
9: int *ret;
10: ret=(int*)&ret+2;
0040103C lea eax,[ebp+4] //得到局部变量ret地址
0040103F mov dword ptr [ebp-4],eax//根据堆栈的结构,取得ret上面第二个字节的地址
11: (*ret)=(int)ourshellcode;
00401042 mov ecx,dword ptr [ebp-4]
00401045 mov dword ptr [ecx],offset ourshellcode (00421a30) //从ret上面第二个地址填充shellCode代码,因为代码的长度大于了12个字节,破坏了堆栈的平衡
12: return;
13: }
0040104B pop edi
0040104C pop esi
0040104D pop ebx
0040104E add esp,44h
00401051 cmp ebp,esp
00401053 call __chkesp (00401080)
00401058 mov esp,ebp
0040105A pop ebp
0040105B ret
------解决方案--------------------
借用了3#的代码,对他的代码重新注释一下
0040103C lea eax,[ebp+4] // [ebp + 4]是main函数上层函数的返回地址
0040103F mov dword ptr [ebp-4],eax// [ebp - 4]是ret这个变量的地址,也就是把ret这个指针指向了main函数返回后的下一条地址
11: (*ret)=(int)ourshellcode;
00401042 mov ecx,dword ptr [ebp-4]
00401045 mov dword ptr [ecx],offset ourshellcode (00421a30) //这里是把返回地址指向了你的那个字符串的首地址