改用AES256

This commit is contained in:
aixiao 2023-07-07 17:36:36 +08:00
parent d420e58926
commit 9c77d9ecc2
4 changed files with 35 additions and 41 deletions

View File

@ -7,7 +7,7 @@ OBJ := sha
all: aes.o sha.o
$(CC) $(CFLAGS) -o $(OBJ) $^ $(LDFLAGS)
$(STRIP) $(OBJ)
: $(STRIP) $(OBJ)
.c.o:
$(CC) $(CFLAGS) -c $<

View File

@ -18,15 +18,13 @@
## Help Information
SHA
SHA
Shell Strict AES 128 bit encryption tool
Author: AIXIAO@AIXIAO.ME
AUTHOR: AIXIAO@AIXIAO.ME
Usage:
sha [-kfh?]
-k : Key
-f : Script File
-h -? : Print Help
-k : key
-f : Script file
静态链接:

4
aes.h
View File

@ -21,9 +21,9 @@
#define CTR 1
#endif
#define AES128 1
//#define AES128 1
//#define AES192 1
//#define AES256 1
#define AES256 1
#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only

60
sha.c
View File

@ -21,7 +21,7 @@ long file_size;
static void hex2str(uint8_t * input, uint16_t input_len, char *output)
{
char *hexEncode = "0123456789ABCDEF";
const char *hexEncode = "0123456789ABCDEF";
int i = 0, j = 0;
for (i = 0; i < input_len; i++) {
@ -84,9 +84,9 @@ char *source_c[] = {
"#define CTR 1",
"#endif",
"",
"#define AES128 1",
"//#define AES128 1",
"//#define AES192 1",
"//#define AES256 1",
"#define AES256 1",
"",
"#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only",
"",
@ -603,7 +603,8 @@ char *source_c[] = {
" if (0 == strncmp(shbin, \"#!\", 2))",
" {",
" p1 = strchr(shbin, '/');",
" strcpy(shbin, p1);",
" memcpy(shbin, p1, (p - shll_text) - 2);",
" shbin[(p - shll_text) - 2] = '\\0';",
" }",
" else if (0 == strncmp(shbin, \":\", 1))",
" {",
@ -656,14 +657,14 @@ char *source_c[] = {
"int main(int argc, char *argv[])",
"{",
" char *argvs[BUFFER_SIZE];",
" char *shbin = NULL;",
" int l=1;",
" int i=4;",
"",
" 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);",
"",
@ -722,28 +723,21 @@ char *source_c[] = {
0
};
void reverse_string(char *str)
void reverse_string(char *str, int length)
{
int length;
char *p1;
char *p2;
length = strlen(str); //获取字符串长度
p1 = str; //p1指向字符串首地址
p2 = str + length - 1; //p2指向字符串尾地址
if (!str) {
if (str == NULL) {
printf("空指针错误!");
return;
}
while (p1 < p2) //当p1地址小于p2地址时执行循环
{
char c = *p1;
*p1 = *p2; //完成指针指向地址的值的交换
*p2 = c;
p1++; //交换完毕后p1指针指向下一个字符地址
p2--; //交换完毕后p2指针指向上一个字符地址
}
char *start = str;
char *end = str + length - 1;
while (start < end) {
char temp = *start;
*start++ = *end;
*end-- = temp;
}
}
void usage(void)
@ -774,12 +768,12 @@ char pool[] = {
int rand_key(char *key)
{
int PASSWD_LEN = 16;
int PASSWD_LEN = 32;
struct timeval tpstart;
char password[17];
char password[33];
int i = 0;
memset(password, 0, 17);
memset(password, 0, 33);
gettimeofday(&tpstart, NULL);
srand(tpstart.tv_usec);
@ -794,7 +788,7 @@ int rand_key(char *key)
int main(int argc, char *argv[])
{
static uint8_t key[17] = "";
static uint8_t key[33] = "";
char sh_file[1024];
int indx = 0;
@ -866,15 +860,15 @@ int main(int argc, char *argv[])
//转16进制字符串
hex2str(text_content, file_size, (char *)hexString);
reverse_string((char *)hexString);
reverse_string((char *)hexString, text_content_length*2);
//拼接
strcat((char *)encrypted_text, "char Encrypted_data[]=\"");
strcat((char *)encrypted_text, (const char *)hexString);
strncat((char *)encrypted_text, "char Encrypted_data[]=\"", 24);
strncat((char *)encrypted_text, (const char *)hexString, text_content_length*2);
strcat((char *)encrypted_text, "\";");
strcpy(encrypted_key, "const char key[17] = \"");
strcat((char *)encrypted_key, (char *)key);
memcpy(encrypted_key, "const char key[33] = \"", 23);
strncat((char *)encrypted_key, (char *)key, 32);
strcat((char *)encrypted_key, "\";");
// 长度
@ -916,6 +910,8 @@ int main(int argc, char *argv[])
//remove(sourcefile);
free(buff);
free(hexString);
// 压缩
if (system("which upx 1> /dev/null") == 0) {