1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
void encoder(char* input, unsigned char key, int display_flag)
{
int i = 0, len = 0;
FILE* fp;
unsigned char * output;
len = strlen(input);
output = (unsigned char*)malloc(len + 1);
if(!output)
{
printf("memory error!\n");
exit(0);
}
// encode shellcode
for(i = 0; i < len; i++)
{
output[i] = input[i] ^ key;
}
if(!(fp=fopen("encode.txt", "w+")))
{
printf("output file create error!");
exit(0);
}
fprintf(fp, "\"");
for(i = 0; i< len; i++)
{
fprintf(fp, "\\x%0.2x", output[i]);
if((i + 1 % 16 == 0))
{
fprintf(fp, "\"\n\"");
}
}
fprintf(fp, "\";");
fclose(fp);
printf("dump the encoded shellcode to encode.txt OK!\n");
if(display_flag)
{
for(i = 0; i < len; i++)
{
printf("%0.2x ", output[i]);
if((i + 1) % 16 == 0)
{
printf("\n");
}
}
}
free(output);
}
|