forked from ammarfaizi2/php-integral-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegralobf
More file actions
executable file
·234 lines (201 loc) · 4.98 KB
/
Copy pathintegralobf
File metadata and controls
executable file
·234 lines (201 loc) · 4.98 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env php
<?php
require __DIR__."/src/autoload.php";
use IntegralObfuscator\IntegralObfuscator;
$appName = $_SERVER["argv"][0];
if ($argc === 1) {
usage();
}
array_shift($_SERVER["argv"]);
$tmpDir = "/tmp";
$outputFile = "a.out";
$inputFile = null;
$sheBang = null;
$key = "abc123";
$inv = $hasInputFile = $cq = $skip = false;
foreach ($_SERVER["argv"] as $k => $v) {
if ($skip) {
$skip = false;
continue;
}
if ($v[0] === '-') {
$l = strlen($v);
if ($l === 2) {
if ($v[1] === "-") {
goto invalid_parameter;
} else {
parseOpt1();
}
} else if ($v[1] === "-") {
parseOpt2();
} else {
$cq = true;
parseOpt1();
}
} else {
if ($hasInputFile) {
goto double_input_file;
exit(1);
}
$inputFile = $v;
$hasInputFile = true;
}
if ($inv) {
goto invalid_parameter;
}
}
if (!is_string($inputFile)) {
goto input_file_required;
}
define("TMP_DIR", "/tmp");
try {
if ($key === "") {
printf("Error: Key cannot be empty!\n");
exit(1);
}
$inputFile = realpath($oldInputFile = $inputFile);
if ((!$inputFile)) {
$inputFile = $oldInputFile;
}
unset($oldInputFile);
printf("Initializing obfuscator...\n");
printf("===============================================\n");
printf("Input file\t: %s\n", $inputFile);
$st = new IntegralObfuscator($inputFile, $outputFile);
printf("Output file\t: %s\n", $outputFile = realpath($outputFile));
printf("File Key\t: %s\n", $key);
if (is_string($sheBang)) {
$st->setShebang($sheBang);
printf("Shebang\t\t: %s\n", $sheBang);
} else {
printf("Shebang\t\t: %s\n", "(no shebang)");
}
printf("===============================================\n");
$st->setKey($key);
$st->execute();
printf("Obfuscation finished!\n");
printf("md5sum\t: %s (%s)\n", $outputFile, md5_file($outputFile));
printf("sha1sum\t: %s (%s)\n", $outputFile, sha1_file($outputFile));
} catch (Exception $e) {
printf("\n\nAn error occured: %s\n", $e->getMessage());
exit(1);
}
exit(0);
function parseOpt1(): void
{
global $k, $v, $key, $cq, $inv, $skip, $sheBang, $tmpDir, $inputFile, $outputFile;
if ($v === "-o") {
if ($cq) {
$outputFile = substr($v, 2);
$cq = false;
return;
} else if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -o option required a value\n");
exit(1);
} else {
$outputFile = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "-s") {
if ($cq) {
$sheBang = substr($v, 2);
$cq = false;
return;
} else if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -s option required a value\n");
exit(1);
} else {
$sheBang = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "-k") {
if ($cq) {
$key = substr($v, 2);
$cq = false;
return;
} else if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -k option required a value\n");
exit(1);
} else {
$key = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "-h") {
usage();
}
$v = substr($v, 0, 2);
$inv = true;
}
function parseOpt2(): void
{
global $k, $v, $key, $cq, $inv, $skip, $sheBang, $tmpDir, $inputFile, $outputFile;
if ($v === "--output") {
if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -o option required a value\n");
exit(1);
} else {
$outputFile = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "--shebang") {
if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -s option required a value\n");
exit(1);
} else {
$sheBang = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "--key") {
if (!isset($_SERVER["argv"][$k + 1])) {
printf("Error: -k option required a value\n");
exit(1);
} else {
$key = $_SERVER["argv"][$k + 1];
$skip = true;
return;
}
}
if ($v === "--help") {
usage();
}
$inv = true;
}
function usage(): void
{
global $appName;
printf("Usage: %s [option] <file>\n\n", $appName);
printf("\t-k <key>\t\tGive a key to encrypt the input file (default: abc123).\n");
printf("\t--key <key>\t\tGive a key to encrypt the input file (default: abc123).\n");
printf("\t-o <file>\t\tSave obfuscated PHP code to <file> (default: a.out).\n");
printf("\t--output <file>\t\tSave obfuscated PHP code to <file> (default: a.out).\n");
printf("\t-s <shebang>\t\tAdd a shebang into obfuscated PHP file (default: (no shebang)).\n");
printf("\t--shebang <shebang>\tAdd a shebang into obfuscated PHP file (default: (no shebang)).\n");
printf("\t-h\t\t\tShow this message.\n");
printf("\t--help\t\t\tShow this message.\n");
printf("\n\n");
printf("Example usage:\n");
printf("\t%s --output output.php --key mypassword123 --shebang '/usr/bin/env php' input.php\n", $appName);
printf("\n\n");
printf("Read more:\n\thttps://github.com/ammarfaizi2/php-integral-obfuscator\n");
exit(0);
}
// Errors
invalid_parameter:
printf("Error: Invalid parameter \"%s\"\n", $v);
exit(1);
input_file_required:
printf("Error: Input file required!\n");
exit(1);
double_input_file:
print("Error: Compiling multiple file is not supported!\n");
exit(1);