From 2a3d35e3284b73fca1151485fb9910ee6d599310 Mon Sep 17 00:00:00 2001 From: aixiao Date: Thu, 29 Dec 2022 18:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B8=AE=E5=8A=A9=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++- sha.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 123 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2e5c446..54abbcf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # sha Shell Stript AES加密工具 + 理论支持所有解析类脚本语言加密 + 测试通过的脚本: + sh + bash + python3 # Build git clone https://git.aixiao.me/aixiao/sha @@ -10,9 +15,18 @@ make uninstall # Help Information + SHA + Shell Strict AES 128 bit encryption tool + AUTHOR: AIXIAO@AIXIAO.ME + + Usage: + -k : key + -f : Script file + + 静态链接: - CFLAGS="-static" sha test.sh + CFLAGS="-static" sha -k aixiao.me -f test.sh 动态链接: - sha test.sh + sha -k aixiao.me -f test.sh \ No newline at end of file diff --git a/sha.c b/sha.c index 96de691..eff318b 100644 --- a/sha.c +++ b/sha.c @@ -632,6 +632,30 @@ char *source_c[] = { " return 0;", "}", "", + +"", +"void reverse_string(char *str, int len)", +"{", +" char *p1;", +" char *p2;", +"", +" p1 = str;", +" p2 = str + len - 1; //p2指向字符串尾地址", +" if (str == NULL) {", +" printf(\"Null pointer error!\");", +" return;", +" }", +" while (p1 < p2) //当p1地址小于p2地址时执行循环", +" {", +" char c = *p1;", +" *p1 = *p2; //完成指针指向地址的值的交换", +" *p2 = c;", +" p1++; //交换完毕后p1指针指向下一个字符地址", +" p2--; //交换完毕后p2指针指向上一个字符地址", +" }", +"", +"}", +"", "#define BUFFER_SIZE 270", "", "int main(int argc, char *argv[])", @@ -639,15 +663,18 @@ char *source_c[] = { " char *argvs[BUFFER_SIZE];", " int l=1;", " int i=4;", -" static uint8_t key[16] = \"aixiao.me\";", +" //static uint8_t key[16] = \"aixiao.me\";", " struct AES_ctx ctx;", " uint8_t *Hex_string = (uint8_t *) malloc(encrypted_text_len*2);", " char *shbin = NULL;", "", + + +" reverse_string((char *)Encrypted_data, encrypted_text_len*2);", +" memset(Hex_string, 0, encrypted_text_len*2);", +"", "", " AES_init_ctx(&ctx, key);", - -" memset(Hex_string, 0, encrypted_text_len*2);", " HexString2Hex((char *)Encrypted_data, (char *)Hex_string, sizeof(Encrypted_data));", " AES_ECB_decrypt(&ctx, Hex_string);", @@ -686,20 +713,79 @@ char *source_c[] = { 0 }; +void reverse_string(char *str) +{ + int length; + char *p1; + char *p2; + + length = strlen(str); //获取字符串长度 + p1 = str; //p1指向字符串首地址 + p2 = str + length - 1; //p2指向字符串尾地址 + if (str == NULL) { + printf("空指针错误!"); + return; + } + while (p1 < p2) //当p1地址小于p2地址时执行循环 + { + char c = *p1; + *p1 = *p2; //完成指针指向地址的值的交换 + *p2 = c; + p1++; //交换完毕后p1指针指向下一个字符地址 + p2--; //交换完毕后p2指针指向上一个字符地址 + } + +} + +void usage(void) +{ + printf(" SHA\n"); + printf(" Shell Strict AES 128 bit encryption tool\n"); + printf("AUTHOR: AIXIAO@AIXIAO.ME\n"); + printf("\n"); + printf("Usage:\n"); + printf(" -k : key\n"); + printf(" -f : Script file\n"); + printf("\n"); + exit(0); +} int main(int argc, char *argv[]) { + static uint8_t key[16] = "aixiao.me"; + char sh_file[1024]; + int opt; + char optstrs[] = ":k:f:h?"; + while (-1 != (opt = getopt(argc, argv, optstrs))) { + switch (opt) { + case 'k': + strcpy((char *)key, optarg); + break; + case 'f': + strcpy((char *)sh_file, optarg); + break; + + case ':': + //printf("\nMissing argument after: -%c\n", optopt); + usage(); + case 'h': + case '?': + //printf("\nInvalid argument: %c\n", optopt); + usage(); + default: + usage(); + } + } - if (argv[1] == NULL) - { - printf("%s \"shell script file\"\n", argv[0]); + if (strlen((char *)key) < 8) { + printf("Key must be at least 8 digits!\n"); exit(1); } - open_file(argv[1]); + open_file(sh_file); struct AES_ctx ctx; - static uint8_t key[16] = "aixiao.me"; + //static uint8_t key[16] = "aixiao.me"; uint8_t text_content[file_size * 2]; uint8_t text_content_out[file_size * 2]; uint16_t text_content_length = file_size; @@ -736,18 +822,27 @@ int main(int argc, char *argv[]) //转16进制字符串 hex2str(text_content, file_size, (char *)hexString); //printf("%s\n", hexString); - + + reverse_string((char *)hexString); + //printf("%s\n", hexString); //拼接 strcat((char *)encrypted_text, "char Encrypted_data[]=\""); strcat((char *)encrypted_text, (const char *)hexString); strcat((char *)encrypted_text, "\";"); + char encrypted_key[1024]; + memset(encrypted_key, 0, 1024); + strcpy(encrypted_key, "const char key[16] = \""); + strcat((char *)encrypted_key, (char *)key); + strcat((char *)encrypted_key, "\";"); + + // 长度 sprintf(encrypted_text_len, "int encrypted_text_len=%d;\n", text_content_length); - strcpy(sourcefile, argv[1]); + strcpy(sourcefile, sh_file); strcat(sourcefile, ".c"); // 写入文件 @@ -760,6 +855,7 @@ int main(int argc, char *argv[]) fprintf(sfile, "%s\n", encrypted_text); fprintf(sfile, "%s\n", encrypted_text_len); + fprintf(sfile, "%s\n", encrypted_key); fflush(sfile); for (indx=0; source_c[indx]; indx++) fprintf(sfile, "%s\n", source_c[indx]); @@ -785,7 +881,7 @@ int main(int argc, char *argv[]) } - remove(sourcefile); + //remove(sourcefile); free(buff); // 压缩