-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathindex.php
More file actions
585 lines (510 loc) · 19.2 KB
/
index.php
File metadata and controls
585 lines (510 loc) · 19.2 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<?php
declare(strict_types=1);
ini_set('memory_limit', '512M');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" href="favicon.ico">
<title>Batch File Obfuscator</title>
<style type="text/css">
:root {
--bg-primary: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--bg-quaternary: #30363d;
--border-primary: #30363d;
--border-secondary: #21262d;
--text-primary: #f0f6fc;
--text-secondary: #8b949e;
--text-tertiary: #6e7681;
--accent-primary: #238636;
--accent-secondary: #2ea043;
--accent-danger: #da3633;
--accent-warning: #fb8500;
--accent-info: #0969da;
--shadow-primary: rgba(0, 0, 0, 0.3);
--shadow-secondary: rgba(0, 0, 0, 0.15);
--gradient-primary: linear-gradient(135deg, #238636 0%, #2ea043 100%);
--gradient-secondary: linear-gradient(135deg, #0969da 0%, #1f6feb 100%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
outline: none;
}
html, body {
font-family: Arial, Helvetica, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
line-height: 1.6;
}
body {
background-image:
radial-gradient(circle at 20% 50%, rgba(35, 134, 54, 0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(9, 105, 218, 0.1) 0%, transparent 50%),
radial-gradient(circle at 40% 80%, rgba(251, 133, 0, 0.05) 0%, transparent 50%);
background-attachment: fixed;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 2rem;
min-height: 75vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.header {
text-align: center;
margin-bottom: 1rem;
}
.version {
position: fixed;
top: 1rem;
right: 1rem;
background: var(--bg-tertiary);
color: var(--text-secondary);
padding: 0.5rem 1rem;
border-radius: 8px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 0.875rem;
border: 1px solid var(--border-primary);
box-shadow: 0 2px 8px var(--shadow-secondary);
}
h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
background: var(--text-primary);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
color: var(--text-secondary);
font-size: 1.125rem;
margin-bottom: 1rem;
max-width: 600px;
}
.upload-form {
background: var(--bg-secondary);
border: 1px solid var(--border-primary);
border-radius: 16px;
padding: 2rem;
width: 100%;
max-width: 500px;
box-shadow: 0 8px 32px var(--shadow-primary);
backdrop-filter: blur(10px);
}
.form-group {
margin-bottom: 1.5rem;
}
.file-input-wrapper {
position: relative;
display: block;
width: 100%;
min-height: 120px;
border: 2px dashed var(--border-primary);
border-radius: 12px;
background: var(--bg-tertiary);
cursor: pointer;
transition: all 0.3s ease;
overflow: hidden;
}
.file-input-wrapper:hover {
border-color: var(--accent-primary);
background: var(--bg-quaternary);
box-shadow: 0 4px 16px var(--shadow-secondary);
}
.file-input-wrapper.dragover {
border-color: var(--accent-primary);
background: var(--bg-quaternary);
box-shadow: 0 0 0 4px rgba(35, 134, 54, 0.1);
}
.file-input {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
.file-input-content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
padding: 1rem;
text-align: center;
}
.file-icon {
font-size: 2.5rem;
margin-bottom: 0.5rem;
opacity: 0.7;
display: flex;
justify-content: center;
align-items: center;
pointer-events: none;
}
.file-icon img {
width: 2.5rem;
height: 2.5rem;
object-fit: contain;
filter: invert(1);
pointer-events: none;
}
.file-text {
color: var(--text-secondary);
font-size: 0.875rem;
}
.file-text strong {
color: var(--text-primary);
}
.input-field {
width: 100%;
padding: 0.875rem 1rem;
background: var(--bg-tertiary);
border: 1px solid var(--border-primary);
border-radius: 8px;
color: var(--text-primary);
font-size: 1rem;
transition: all 0.3s ease;
}
.input-field:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 0 3px rgba(35, 134, 54, 0.1);
background: var(--bg-quaternary);
}
.input-field::placeholder {
color: var(--text-tertiary);
}
label {
display: block;
margin-bottom: 0.5rem;
color: var(--text-primary);
font-weight: 500;
font-size: 0.875rem;
}
.submit-btn {
width: 100%;
padding: 1rem 2rem;
background: var(--gradient-primary);
color: white;
border: none;
border-radius: 10px;
font-size: 1.125rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.submit-btn:hover {
box-shadow: 0 8px 25px rgba(35, 134, 54, 0.3);
}
.submit-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-container {
margin-top: 2rem;
text-align: center;
}
.download-btn {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 1rem 2rem;
background: var(--gradient-secondary);
color: white;
text-decoration: none;
border-radius: 10px;
font-weight: 600;
transition: all 0.3s ease;
}
.download-btn:hover {
box-shadow: 0 8px 25px rgba(9, 105, 218, 0.3);
text-decoration: none;
color: white;
}
.error-message {
background: var(--bg-tertiary);
border: 1px solid var(--accent-danger);
border-radius: 10px;
padding: 1rem;
color: var(--accent-danger);
text-align: center;
margin-top: 1rem;
}
@media (max-width: 768px) {
.container {
padding: 1rem;
}
h1 {
font-size: 2rem;
}
.upload-form {
padding: 1.5rem;
}
.version {
position: static;
margin-bottom: 2rem;
width: fit-content;
}
}
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* File selected state */
.file-selected {
border-color: var(--accent-primary);
background: var(--bg-quaternary);
}
.file-selected .file-icon {
color: var(--accent-primary);
}
.file-selected .file-text {
color: var(--text-primary);
}
</style>
</head>
<body>
<div class="container">
<span class="version">v2.0 clean</span>
<div class="header">
<h1>Batch Obfuscator</h1>
<p class="subtitle">Easy way to obfuscate Windows batch files</p>
</div>
<form class="upload-form" enctype="multipart/form-data" action="" method="POST">
<div class="form-group">
<label for="file">Select batch file</label>
<div class="file-input-wrapper" id="fileWrapper">
<input type="file" name="batchfile" class="file-input" id="file" accept=".bat" required>
<div class="file-input-content">
<div class="file-icon"><img src="batch_ico.png" alt="Batch file icon"></div>
<div class="file-text">
<strong>Click to browse</strong> or drag and drop<br>
<small>Only .bat files (max: 1MB)</small>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="passage">Obfuscation passes</label>
<input type="number"
min="1"
max="20"
name="passage"
class="input-field"
id="passage"
placeholder="Number of passes (Default: 1, Max: 20)"
value="1">
</div>
<button type="submit" class="submit-btn" id="submitBtn">
<span class="btn-text">Obfuscate file</span>
</button>
</form>
<?php if (isset($_FILES['batchfile'])): ?>
<div class="result-container">
<?php if (is_batch_file_valid($_FILES['batchfile'])): ?>
<?php
$passage = (isset($_POST['passage']) && $_POST['passage'] > 0 && $_POST['passage'] <= 20)
? (int)$_POST['passage']
: 1;
sleep(1);
ensure_data_directory();
/* clean files older than 24 hours */
clean_old_files('data', 86400);
try {
$obfuscated_content = batchfile_obfuscate($_FILES['batchfile']['tmp_name'], $passage);
file_put_contents('data/'.$_FILES['batchfile']['name'], $obfuscated_content);
} catch (RuntimeException $e) {
echo '<div class="error-message"><strong>Error:</strong> '.htmlspecialchars($e->getMessage()).'</div>';
exit;
}
?>
<a class="download-btn" href="./data/<?php echo htmlspecialchars($_FILES['batchfile']['name']); ?>">
Download <strong><?php echo htmlspecialchars($_FILES['batchfile']['name']); ?></strong> (<?php echo $passage; ?>x pass)
</a>
<?php else: ?>
<div class="error-message"><strong>Error:</strong> No file selected, file exceeds 1MB, or file is not a valid .bat file</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<script>
const fileInput = document.getElementById('file');
const fileWrapper = document.getElementById('fileWrapper');
const submitBtn = document.getElementById('submitBtn');
const btnText = submitBtn.querySelector('.btn-text');
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
fileWrapper.classList.add('file-selected');
const content = fileWrapper.querySelector('.file-input-content');
content.innerHTML = `
<div class="file-icon"><img src="batch_ico.png" alt="Batch file icon"></div>
<div class="file-text">
<strong>${file.name}</strong><br>
<small>${(file.size / 1024).toFixed(1)} KB</small>
</div>
`;
}
});
fileWrapper.addEventListener('dragover', function(e) {
e.preventDefault();
fileWrapper.classList.add('dragover');
});
fileWrapper.addEventListener('dragleave', function(e) {
e.preventDefault();
fileWrapper.classList.remove('dragover');
});
fileWrapper.addEventListener('drop', function(e) {
e.preventDefault();
fileWrapper.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
fileInput.files = files;
fileInput.dispatchEvent(new Event('change'));
}
});
document.querySelector('.upload-form').addEventListener('submit', function() {
submitBtn.disabled = true;
btnText.innerHTML = '<span class="loading"></span> Processing...';
});
</script>
</body>
</html>
<?php
function batchfile_obfuscate(string $batchfile, int $pass = 1): string {
$script = file_get_contents($batchfile);
if ($script === false) throw new RuntimeException("Failed to read batch file: {$batchfile}");
$batchfile_obfuscate = '';
for ($i = 0; $i < $pass; $i++) {
/* for subsequent passes, use what has already been obfuscated */
if ($i > 0) $script = $batchfile_obfuscate;
/* clear all previous work for this pass */
$batchfile_obfuscate = '';
$stringVar0 = '@ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$stringVar1 = '_ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$stringVar8 = 'abcdefghijklmnopqrstuvwxyz';
$stringVar2 = '_¯-ஐ→あⓛⓞⓥⓔ。°º¤εïз╬㊗⑪⑫⑬㊀㊁㊂のðabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
/* variable value for this pass */
$stringGen1 = substr(str_shuffle($stringVar1), 0, rand(3, 5));
$stringGen2 = '';
$arrayTable = [];
$arrayVar0 = str_split($stringVar0);
shuffle($arrayVar0);
foreach ($arrayVar0 as $pos => $char) {
$arrayTable[] = [$char, '%'.$stringGen1.':~'.$pos.',1%'];
$stringGen2 .= $char;
}
$arrayText = str_split($script);
$convertWaitVar = false;
$convertWaitLabel = false;
/* track whether we're in % or ! variable */
$varType = '';
/* consider the first line as a line break in case there's a label on the first line */
$sautLigne = true;
if ($i === $pass - 1) $batchfile_obfuscate .= "\xFF\xFE".'&@cls&';
$batchfile_obfuscate .= '@set "'.$stringGen1.'='.$stringGen2.'"'.PHP_EOL;
foreach ($arrayText as &$charOriginal) {
if ($sautLigne === true && $charOriginal === ':') {
/* if we detect a label */
$convertWaitLabel = true;
}
if ($charOriginal === "\n") {
/* remember that we're breaking a line for tests on the next line */
$sautLigne = true;
/* reset to false since we can't be in a variable if we break a line */
$convertWaitVar = false;
/* reset label to false since we're moving to the next line */
$convertWaitLabel = false;
$varType = '';
} else {
$sautLigne = false;
}
if ($charOriginal === ' ') {
/* to resume after a : in a string since a label cannot contain spaces */
$convertWaitLabel = false;
}
/* improved variable detection for consecutive variables like %0%random% */
if ($convertWaitVar === false && ($charOriginal === '%' || $charOriginal === '!')) {
/* if we encounter the first % or ! of a variable to avoid corruption */
$convertWaitVar = true;
/* remember which type of variable delimiter we're using */
$varType = $charOriginal;
} elseif ($convertWaitVar === true && $charOriginal === $varType) {
/* if we encounter the matching end delimiter, close this variable */
$convertWaitVar = false;
/* for cases like [%time:~0,-3%] to resume after the variable */
$convertWaitLabel = false;
$varType = '';
/* immediately check if this might be the start of another variable */
/* this handles cases like %0%random% where % serves dual purpose */
if ($charOriginal === '%' || $charOriginal === '!') {
$convertWaitVar = true;
$varType = $charOriginal;
}
}
if ($convertWaitVar === false && $convertWaitLabel === false && $sautLigne === false) {
/* if we're not in a variable or label, then replace */
$convert = false;
foreach ($arrayTable as [$char1, $char2]) {
if ($charOriginal === $char1) {
if (rand(1, 20) === 8) {
/* replace if found in table + add empty variable (1 in 20 times) */
$batchfile_obfuscate .= $char2.'%'.substr(str_shuffle($stringVar1), 3, 7).'%';
} else {
$batchfile_obfuscate .= $char2;
}
$convert = true;
}
}
if ($convert === false) {
/* if not found in table, don't replace */
$batchfile_obfuscate .= $charOriginal;
}
} else {
/* we are in a variable or label so don't replace anything */
$batchfile_obfuscate .= $charOriginal;
}
}
}
return html_entity_decode($batchfile_obfuscate);
}
function is_batch_file_valid(array $file): bool {
return $file['error'] === 0
&& $file['size'] <= 1000000
&& strtolower(substr($file['name'], -4)) === '.bat';
}
function clean_old_files(string $directory, int $maxAge = 86400): void {
if (!is_dir($directory)) return;
foreach (glob($directory.'/*') as $file) {
if (is_file($file) && filemtime($file) < time() - $maxAge) {
unlink($file);
}
}
}
function ensure_data_directory(): void {
if (!is_dir('data')) {
mkdir('data', 0755, true);
}
}
?>