Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

c++ - running shellcode + vs2010

I just tried the following code snippet for shellcode testing purposes:-

#include<iostream>

using namespace std;

char sc[] = ""; #i've removed the shellcode
int main() {
    int (*func)();
    func = (int(*)())sc;
    (int)(*func)();
}

I get a build error on compilation :-

------ Build started: Project: shellcoderunner, Configuration: Debug Win32 ------
Build started 10/15/2011 12:51:16 PM.
InitializeBuildStatus:
  Touching "Debugshellcoderunner.unsuccessfulbuild".
ClCompile:
  blah.cpp
c:users
everserdocumentsvisual studio 2010projectsshellcoderunnershellcoderunnerlah.cpp(7): error C2440: 'type cast' : cannot convert from 'char [149]' to 'int (__cdecl *)(void)'
          There is no context in which this conversion is possible

Build FAILED.

Time Elapsed 00:00:01.99
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Something obvious that I'm doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To execute a shellcode in your C/C++ program with VS, the simplest way is embedding an Assembly code like this example below:

char* buffer="blah blah blah";
int main() {
    __asm{
        lea eax, buffer
        call    eax
    }
}

Hope this help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...