-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
177 lines (163 loc) · 4.26 KB
/
main.c
File metadata and controls
177 lines (163 loc) · 4.26 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void mode_detection(char **argv);
void get_payload(void);
char **check_all(char **argv);
char *change_dll_name(char *dllname);
void check_dirs(void);
void show_help(char *pname);
int main(int argc, char **argv)
{
if (argc < 2)
{
printf("ERROR: No arguments given\n");
show_help(argv[0]);
return(0);
}
if (argc > 5)
{
printf("ERROR: Too many arguments\n");
return(0);
}
if (argv[1][0] != '-')
{
printf("ERROR: Invalid option\n");
return(0);
}
mode_detection(argv);
}
void mode_detection(char **argv)
{
char *orig;
char **save;
char buf[10000];
if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))
show_help(argv[0]);
else if (!strcmp(argv[1], "--get-payload") || !strcmp(argv[1], "-gp"))
get_payload();
else
{
save = check_all(argv);
check_dirs();
orig = save[0];
save[0] = change_dll_name(save[0]);
snprintf(buf, sizeof(buf), "cp %s generated/%s", orig, save[0]);
system(buf);
snprintf(buf, sizeof(buf), "cd generated && python3 ../scripts/script.py %s > ../defs/geng.def", save[0]);
system(buf);
snprintf(buf, sizeof(buf), "i686-w64-mingw32-gcc -shared -o generated/%s %s defs/geng.def -s", orig, save[1]);
system(buf);
printf("DLLs generated succesfully, check generated dir ;)\n");
return ;
}
}
void get_payload(void)
{
system("echo \"void payload(void)\n{\n //Write here your Payload...\n}\n\n\n\nBOOL WINAPI\nDllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)\n{\n switch (dwReason)\n {\n case DLL_PROCESS_ATTACH:\n payload();\n break;\n }\n return TRUE;\n}\" > payload.c");
}
char **check_all(char **argv)
{
int i;
int specified[2];
int exist[2];
char **save;
int error;
specified[0] = 0;
specified[1] = 0;
exist[0] = 0;
exist[1] = 0;
error = 0;
save = malloc(2 * sizeof(char *));
for (i = 1; i < 5; i += 2)
{
if (argv[i] && !strcmp(argv[i], "-d"))
{
if (argv[i+1] && access(argv[i+1], F_OK))
{
printf("ERROR: DLL file does not exits\n");
exist[0]++;
}
else
save[0] = argv[i+1];
specified[0]++;
}
else if (argv[i] && !strcmp(argv[i], "-p"))
{
if (argv[i+1] && access(argv[i+1], F_OK))
{
printf("ERROR: Payload file does not exits\n");
exist[1]++;
}
else
save[1] = argv[i+1];
specified[1]++;
}
else if (argv[i])
{
printf("ERROR: Invalid argument: %s\n", argv[i]);
error++;
}
}
if (specified[0] != 1 && !exist[0])
printf("ERROR: DLL file not specified\n");
if (specified[1] != 1 && !exist[1])
printf("ERROR: Payload file not specified\n");
if (error || specified[0] != 1 || specified[1] != 1 || exist[0] || exist[1])
{
free(save);
exit(1);
}
return(save);
}
char *change_dll_name(char *dllname)
{
int len;
char *new;
len = 0;
len = strlen(dllname);
new = malloc((len + 7) * sizeof(char));
strncpy(new, dllname, len - 4);
strcat(new, "_orig.dll");
new[len + 5] = 0;
return(new);
}
void check_dirs(void)
{
//Checks defs/ dir
if (!access("defs/", F_OK))
{
if (access("defs/", R_OK) && access("defs/", W_OK))
{
printf("Dont have permission to r/w onto defs/ folder");
exit(1);
}
}
else
system("mkdir defs/");
//Checks generated/ dir
if (!access("generated/", F_OK))
{
if (access("generated/", R_OK) && access("generated/", W_OK))
{
printf("Dont have permission to r/w onto generated/ folder");
exit(1);
}
}
else
system("mkdir generated/");
}
void show_help(char *pname)
{
printf("\nUsage: %s [options ...]\n\n", pname);
printf("SUPPORT INSTRUCTIONS:\n");
printf("-h, --help Shows this help text\n");
printf("-gp, --get-payload Generates a .c file containing basic payload info\n\n");
printf("PROXYING INSTRUCTIONS: (all of them must be passed)\n");
printf("-d <DLL file name (.dll)> Specifies the original DLL file name\n");
printf("-p <Payload file name (.c)> Specifies the payload file name\n\n");
printf("EXAMPLE OF USAGE:\n");
printf("%s -d my_dll_file.dll -p my_payload_file.c\n\n", pname);
printf("ATTENTION:\nIts important that the DLL file is located IN THE SAME DIRECTORY as the binary (\"%s\" file)\n\n", pname + 2);
}