Search code examples
cgccopensslmingw32rc4-cipher

fatal error: openssl/opensslconf.h: No such file or directory


I try to compile a C file which decrypts and executes an rc-4 encryped shellcode with virtual alloc.

Now I get an error:

"In file included from rc-4.c:2: rc4.h:62:11: fatal error: openssl/opensslconf.h: No such file or directory #include <openssl/opensslconf.h>/* OPENSSL_NO_RC4, RC4_INT */"

My compile command is: i586-mingw32msvc-gcc rc-4.c -o test.exe -lcrypto

At first mingw32 gave me the error that rc-4.h could not be found. I fixed this by copying the rc-4.h in my current directory and included it with #include "rc-4.h"

the first two lines of the code

```
#include <windows.h>
#include "rc4.h"
```

how the rc-4 shellcode should be decrypted and executed:

int lpBufSize = sizeof(int) * PAYLOADSIZE;
        LPVOID lpBuf = VirtualAlloc(NULL, lpBufSize, MEM_COMMIT, 0x04);
        memset(lpBuf, '\0', lpBufSize);
        RC4(RC4KEY, payload, (char*) lpBuf, PAYLOADSIZE);
        MessageBox(NULL, (char*) lpBuf, "Test", MB_OK);
        return 0;

the expected output should be the compiled test.exe file


Solution

  • I'm using MinGW64 because that's what is installed here. I'm aware of the tag "mingw32", hoping it's OK.

    1. Compiling

    The header file rc4.h lives in the path <path-of-installation>/<version>/mingw64/opt/include, so this has to be given as an argument to -I:

    i586-mingw32msvc-gcc -c -I "<path-of-installation>/<version>/mingw64/opt/include" rc-4.c -o rc-4.o
    

    You could as well set CPATH or C_INCLUDE_PATH, see The C Preprocessor: Environment Variables.

    2. Linking

    Note: Because you didn't provide enough source code I could not try this.

    The library file libcrypto.a lives in the path <path-of-installation>/<version>/mingw64/opt/lib, so this has to be given as an argument to -L:

    i586-mingw32msvc-gcc -L "<path-of-installation>/<version>/mingw64/opt/lib" rc-4.o -lcrypto -o test.exe