Execute shellcode by casting to function pointer in Visual C++ -
in gcc works fine. code goes like:
unsigned char b[50] = "\xda\xd1 ... \x0"; //some shellcode terminating \x0 ( (void(*)())b )(); //cast b function pointer void void, run
but when put in visual c++, spits out error message:
1>..\test.cpp(132): error c2440: 'type cast' : cannot convert 'unsigned char [50]' 'void (__cdecl *)(void)' 1> there no context in conversion possible
anyone know why so?
a proper debugger tell what's going wrong. can guess code causing access violation because buffer want jump not executable.
probably you're on default-dep-enabled system vista or 7, have make sure shellcode executable. that, first use virtualalloc
allocate new, executable buffer , copy shellcode it, execute it:
void *exec = virtualalloc(0, sizeof b, mem_commit, page_execute_readwrite); memcpy(exec, b, sizeof b); ((void(*)())exec)();
by way, don't need null-terminate shellcode (c++ terminate string literal automatically you, not necessary). don't need specify size:
unsigned char b[] = "\xcc";
Comments
Post a Comment