增加读取CFLAGS环境变量

修复加密后编译输出的二进制程序不能读取参数
增加upx压缩二进制输出文件
This commit is contained in:
aixiao 2022-09-13 12:49:32 +08:00
parent a3d68f9fd9
commit fd5efa86e2
6 changed files with 121 additions and 29 deletions

View File

@ -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)

18
README.md Normal file
View File

@ -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

BIN
aes.o Normal file

Binary file not shown.

BIN
sha Normal file

Binary file not shown.

126
sha.c
View File

@ -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;

BIN
sha.o Normal file

Binary file not shown.