diff --git a/Makefile b/Makefile index 57bb69c..a14912f 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ all: aes.o sha.o .c.o: $(CC) $(CFLAGS) -c $< +install: + cp $(OBJ) /bin/sha + +uninstall: + rm /bin/$(OBJ) + clean: rm -rf *.o rm $(OBJ) diff --git a/README.md b/README.md new file mode 100644 index 0000000..d89de38 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# sha + Shell Stript AES加密工具 + +# Build + git clone https://git.aixiao.me/aixiao/sha + cd sha + make + make install + + make uninstall + +# Help Information + 静态链接: + CFAGS="-static" sha test.sh + + 动态链接: + sha test.sh + \ No newline at end of file diff --git a/aes.o b/aes.o new file mode 100644 index 0000000..991bcd5 Binary files /dev/null and b/aes.o differ diff --git a/sha b/sha new file mode 100644 index 0000000..904d147 Binary files /dev/null and b/sha differ diff --git a/sha.c b/sha.c index 6d3d007..9291c76 100644 --- a/sha.c +++ b/sha.c @@ -596,40 +596,98 @@ char *source_c[] = { "}", "", +"int is_Resolver(char *shll_text, char *shbin)", +"{", +" char *p, *p1;", +" char temp[270];", +"", +" p = strstr(shll_text, \"\\n\");", +" memcpy(shbin, shll_text, p - shll_text);", +"", +"", +" if (0 == strncmp(shbin, \"#!\", 2))", +" {", +" p1 = strchr(shbin, '/');", +" strcpy(shbin, p1);", +" }", +" else if (0 == strncmp(shbin, \":\", 1))", +" {", +" strcpy(shbin, getenv(\"SHELL\"));", +" }", +" else", +" {", +" printf(\"unknown shell!\\n\");", +" return -1;", +" }", +"", +" memset(temp, 0, 270);", +" strcpy(temp, \"which \");", +" strcat(temp, shbin);", +" strcat(temp, \" 1> /dev/null\");", +" if (0 != system(temp)) // 不存在解析器", +" {", +" printf(\"not found shell!\\n\");", +" return -1;", +" }", +" return 0;", +"}", + "int main(int argc, char *argv[])", "{", " uint8_t *Hex_string = (uint8_t *) malloc(encrypted_text_len*2);", +" char *shbin = (char *) malloc(270);", +"", +" memset(shbin, 0, 270);", " memset(Hex_string, 0, encrypted_text_len*2);", - +"", +"", " static uint8_t key[16] = \"aixiao\";", " struct AES_ctx ctx;", " AES_init_ctx(&ctx, key);", - - - +"", +"", " HexString2Hex((char *)Encrypted_data, (char *)Hex_string, sizeof(Encrypted_data));", - - - +"", +"", " AES_ECB_decrypt(&ctx, Hex_string);", " //printf(\"%s\\n\", Hex_string);", +"", +"", +" if (-1 == is_Resolver((char *)Hex_string, shbin))", +" {", +" goto EXIT;", +" }", +" //printf(\"%s\\n\", shbin);", +"", +" char *argvs[270];", +"", +" argvs[0] = argv[0];", +" argvs[1] = \"-c\";", +" argvs[2] = (char *)Hex_string;", +" argvs[3] = argv[0];", +"", +" int j=1;", +" for(int i=4; i<=argc-1+4; i++)", +" {", +" argvs[i] = argv[j];", +" j++;", -" execlp(\"bash\", argv[0], \"-c\", Hex_string, (char *)0);", - - +" }", +"", +" execvp(shbin, argvs);", +"", +"", +"EXIT:", " free(Hex_string);", - -" return 0;", +" free(shbin);", +"", +" return 0;", "}", 0 }; - - - - int main(int argc, char *argv[]) { @@ -677,7 +735,6 @@ int main(int argc, char *argv[]) //转16进制字符串 - hex2str(text_content, file_size, (char *)hexString); printf("%s\n", hexString); @@ -715,21 +772,32 @@ int main(int argc, char *argv[]) strcat(binfile, ".x"); sleep(1); - sprintf(buildcmd, "gcc -Wall -Os %s -o %s -static", sourcefile, binfile); - system(buildcmd); + if (getenv("CFLAGS") != NULL) + sprintf(buildcmd, "gcc -Wall -Os %s %s -o %s", getenv("CFLAGS"), sourcefile, binfile); + else + sprintf(buildcmd, "gcc -Wall -Os %s -o %s", sourcefile, binfile); - //压缩 - char upxcommand[BUFFER_SIZE]; - memset(upxcommand, 0, BUFFER_SIZE); - strcpy(upxcommand, "upx -9 "); - strcat(upxcommand, binfile); - sleep(1); - system(upxcommand); - //remove(sourcefile); - + // 编译 + if (0 != system(buildcmd)) { + return -1; + } + + remove(sourcefile); free(buff); - + + // 压缩 + if (0 == system("which upx 1> /dev/null")) { + char upxcommand[BUFFER_SIZE]; + memset(upxcommand, 0, BUFFER_SIZE); + strcpy(upxcommand, "upx -9 "); + strcat(upxcommand, binfile); + sleep(1); + if (0 != system(upxcommand)) { + return -1; + } + } + return 0; diff --git a/sha.o b/sha.o new file mode 100644 index 0000000..69898f1 Binary files /dev/null and b/sha.o differ