增加帮助信息,支持参数
This commit is contained in:
parent
ca84c836be
commit
2a3d35e328
18
README.md
18
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
|
||||
|
116
sha.c
116
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;
|
||||
|
||||
if (argv[1] == NULL)
|
||||
{
|
||||
printf("%s \"shell script file\"\n", argv[0]);
|
||||
case ':':
|
||||
//printf("\nMissing argument after: -%c\n", optopt);
|
||||
usage();
|
||||
case 'h':
|
||||
case '?':
|
||||
//printf("\nInvalid argument: %c\n", optopt);
|
||||
usage();
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@ -737,17 +823,26 @@ int main(int argc, char *argv[])
|
||||
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);
|
||||
|
||||
// 压缩
|
||||
|
Loading…
Reference in New Issue
Block a user