Forked from angelorodem/Run shellcode (machinecode) from c++ on windows mingw gcc.cpp
Created
June 2, 2023 06:49
-
-
Save servomekanism/d91c82ff87321de67de2eb2edb28d17f to your computer and use it in GitHub Desktop.
Run shellcode (machinecode) from c++ on windows mingw gcc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <iostream> | |
| int main(){ | |
| //code that just returns 5+5 (10) | |
| static const int code_lenght = 44; | |
| unsigned char opcodes[code_lenght] = "\x55\x48\x89\xe5\xb8\x0a\x00\x00\x00\x5d\xc3"; | |
| HANDLE mem_handle = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, code_lenght, NULL); | |
| void* mem_map = MapViewOfFile( mem_handle, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0x0, 0x0, code_lenght); | |
| memcpy(mem_map, opcodes, sizeof(opcodes)); | |
| std::cout << (( int(*)() )mem_map)() << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment