-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpatch.php
More file actions
386 lines (354 loc) · 18.1 KB
/
patch.php
File metadata and controls
386 lines (354 loc) · 18.1 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
<?php
/**
* CMSNT Auto-Patcher
* Integrated with admin panel UI
*/
define("IN_SITE", true);
require_once(__DIR__ . '/libs/db.php');
require_once(__DIR__ . '/libs/lang.php');
require_once(__DIR__ . '/libs/helper.php');
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/libs/database/users.php');
$CMSNT = new DB();
// ==================== PATCH CONFIGURATION ====================
$patchTargets = [
'libs/db.php' => [
'name' => 'Database Lib',
'desc' => 'Disabling core integrity checks (_sc, _vsc)',
'patches' => [
// Cleanup: Fix potential corruption from previous patcher (extra })
['pattern' => '/private function _sc\s*\(\)\{return true;\}\s*\}/s', 'replacement' => 'private function _sc(){return true;}'],
['pattern' => '/private function _vsc\s*\(\)\{return true;\}\s*\}/s', 'replacement' => 'private function _vsc(){return true;}'],
// Standard Patch: Use recursive pattern (?1) to match balanced braces
['pattern' => '/private function _sc\s*\(\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'private function _sc(){return true;}'],
['pattern' => '/private function _vsc\s*\(\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'private function _vsc(){return true;}']
]
],
'views/admin/sidebar.php' => [
'name' => 'Admin Sidebar',
'desc' => 'Disabling sidebar guard checks',
'patches' => [
['pattern' => '/function __cmsnt_sidebar_guard\s*\(\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function __cmsnt_sidebar_guard(){return;}']
]
],
'libs/helper.php' => [
'name' => 'Helper Lib',
'desc' => 'Fixing addon license verification',
'patches' => [
['pattern' => '/function __cmsnt_helper_guard\s*\(\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function __cmsnt_helper_guard(){return;}'],
['pattern' => '/function checkAddonLicense\s*\(.*?\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function checkAddonLicense($licensekey, $project) { return ["msg" => "License Active", "status" => true]; }'],
['pattern' => '/function CMSNT_check_license\s*\(.*?\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function CMSNT_check_license($licensekey, $localkey = "") { return ["status" => "Active", "msg" => "License Active", "checkdate" => date("Ymd"), "localkey" => "valid", "md5hash" => "valid", "remotecheck" => true]; }']
]
],
'libs/session.php' => [
'name' => 'Session Lib',
'desc' => 'Bypassing SecurityValidator',
'patches' => [
['pattern' => '/public static function v\s*\(\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'public static function v(){return true;}']
]
],
'models/is_license.php' => [
'name' => 'License Model',
'desc' => 'Overriding license model logic',
'patches' => [
['pattern' => '/function v3pX9sLic\s*\(.*?\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function v3pX9sLic($licensekey) { return ["msg" => "License Active", "status" => true]; }'],
['pattern' => '/function u2dK7mToken\s*\(.*?\)\s*(\{((?>[^{}]+)|(?1))*\})/s', 'replacement' => 'function u2dK7mToken($licensekey, $localkey = "") { return ["status" => "Active", "msg" => "License Active", "checkdate" => date("Ymd"), "localkey" => "valid", "md5hash" => "valid", "remotecheck" => true]; }']
]
],
'views/admin/home.php' => [
'name' => 'Admin Home',
'desc' => 'Adding Patch Menu badge to dashboard',
'patches' => [
// Add Patch Menu badge after version badge if it doesn't exist
[
'pattern' => '/(<h5[^>]*>\s*<\?=\s*\$config\[\'project\'\];\s*\?>\s*<span[^>]*class="badge bg-primary"[^>]*>\s*<\?=\s*\$config\[\'version\'\];\s*\?>\s*<\/span>\s*)(?!.*Patch Menu)(\s*<\/h5>)/s',
'replacement' => '$1' . "\n" . ' <a href="<?= base_url(\'patch.php\'); ?>" class="text-decoration-none"><span class="badge bg-danger"' . "\n" . ' style="font-size: 14px; padding: 5px 10px;">Patch Menu</span></a>$2'
]
]
]
];
// ==================== HELPER FUNCTIONS ====================
/**
* Check if file has been patched by running regex and comparing
*/
function checkPatchStatus(string $filePath, array $patches): string
{
if (!file_exists($filePath)) {
return 'not_found';
}
$content = file_get_contents($filePath);
if ($content === false) {
return 'error';
}
foreach ($patches as $patch) {
$result = preg_replace($patch['pattern'], $patch['replacement'], $content);
if ($result !== null && $result !== $content) {
return 'not_patched';
}
}
return 'patched';
}
/**
* Create backup file before patching
*/
function createBackup(string $filePath): bool
{
$backupPath = $filePath . '.bak.' . date('Ymd_His');
return copy($filePath, $backupPath);
}
/**
* Apply patches to file
*/
function applyPatches(string $filePath, array $patches): array
{
if (!file_exists($filePath)) {
return ['status' => 'error', 'msg' => 'File does not exist: ' . $filePath];
}
if (!is_readable($filePath)) {
return ['status' => 'error', 'msg' => 'Cannot read file: ' . $filePath];
}
if (!is_writable($filePath)) {
return ['status' => 'error', 'msg' => 'No write permission for file: ' . $filePath];
}
$content = file_get_contents($filePath);
if ($content === false) {
return ['status' => 'error', 'msg' => 'Error reading file content'];
}
$originalContent = $content;
$patchedCount = 0;
foreach ($patches as $patch) {
$newContent = preg_replace($patch['pattern'], $patch['replacement'], $content);
if ($newContent !== null && $newContent !== $content) {
$content = $newContent;
$patchedCount++;
}
}
if ($patchedCount === 0) {
return ['status' => 'info', 'msg' => 'Already patched, no changes needed'];
}
// Create backup before writing
if (!createBackup($filePath)) {
return ['status' => 'error', 'msg' => 'Cannot create backup file'];
}
if (file_put_contents($filePath, $content) === false) {
return ['status' => 'error', 'msg' => 'Error writing file'];
}
return ['status' => 'success', 'msg' => 'Patched successfully (' . $patchedCount . ' changes)'];
}
// ==================== PRE-CHECK STATUS ====================
$fileStatuses = [];
foreach ($patchTargets as $path => $info) {
$fullPath = __DIR__ . '/' . $path;
$fileStatuses[$path] = checkPatchStatus($fullPath, $info['patches']);
}
// ==================== HANDLE PATCH REQUEST ====================
$results = [];
$patchExecuted = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['patch'])) {
$patchExecuted = true;
foreach ($patchTargets as $path => $info) {
$fullPath = __DIR__ . '/' . $path;
$result = applyPatches($fullPath, $info['patches']);
$result['name'] = $info['name'];
$result['path'] = $path;
$results[] = $result;
}
// Cap nhat lai trang thai sau khi patch
$fileStatuses = [];
foreach ($patchTargets as $path => $info) {
$fullPath = __DIR__ . '/' . $path;
$fileStatuses[$path] = checkPatchStatus($fullPath, $info['patches']);
}
}
// ==================== SETUP ADMIN UI ====================
$body = [
'title' => 'System Patcher | ' . $CMSNT->site('title'),
'desc' => 'CMSNT Panel',
'keyword' => 'cmsnt, patcher'
];
$body['header'] = '';
$body['footer'] = '';
require_once(__DIR__ . '/models/is_admin.php');
require_once(__DIR__ . '/views/admin/header.php');
require_once(__DIR__ . '/views/admin/sidebar.php');
require_once(__DIR__ . '/views/admin/nav.php');
?>
<div class="main-content app-content">
<div class="container-fluid">
<div class="d-md-flex d-block align-items-center justify-content-between my-4 page-header-breadcrumb">
<h1 class="page-title fw-semibold fs-18 mb-0"><i class="fa-solid fa-wrench"></i> System Patcher</h1>
<div class="ms-md-1 ms-0">
<nav>
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="<?= base_url_admin('home'); ?>">Dashboard</a></li>
<li class="breadcrumb-item active" aria-current="page">System Patcher</li>
</ol>
</nav>
</div>
</div>
<!-- Developer Information -->
<div class="row">
<div class="col-xl-12">
<div class="card custom-card border-primary">
<div class="card-header bg-primary-transparent">
<div class="card-title text-primary">
<i class="fa-solid fa-code me-2"></i>Developer Information
</div>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-md-8">
<h6 class="mb-2"><i class="fa-solid fa-user me-2 text-primary"></i>Mai Huy Bao</h6>
<p class="text-muted mb-2"><i class="fa-solid fa-briefcase me-2"></i>Backend Developer</p>
<p class="text-muted mb-0"><i class="fa-solid fa-info-circle me-2"></i>Specialized in PHP development, system security, and license bypass solutions</p>
</div>
<div class="col-md-4 text-md-end mt-3 mt-md-0">
<div class="d-flex flex-column gap-2">
<a href="https://facebook.com/maihuybao.developer" target="_blank" class="btn btn-sm btn-primary">
<i class="fa-brands fa-facebook me-1"></i> Facebook
</a>
<a href="https://github.com/maihuybao" target="_blank" class="btn btn-sm btn-dark">
<i class="fa-brands fa-github me-1"></i> GitHub
</a>
<a href="https://t.me/Mo_Ho_Bo" class="btn btn-sm btn-info">
<i class="fa-brands fa-telegram me-1"></i> Telegram
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php if ($patchExecuted && !empty($results)): ?>
<!-- Patch Results -->
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="card-header">
<div class="card-title">Patch Results</div>
</div>
<div class="card-body">
<?php foreach ($results as $res): ?>
<?php
$alertClass = 'alert-info';
$iconClass = 'fa-solid fa-circle-info';
if ($res['status'] === 'success') {
$alertClass = 'alert-success';
$iconClass = 'fa-solid fa-circle-check';
} elseif ($res['status'] === 'error') {
$alertClass = 'alert-danger';
$iconClass = 'fa-solid fa-circle-xmark';
}
?>
<div class="alert <?= $alertClass; ?> d-flex align-items-center" role="alert">
<i class="<?= $iconClass; ?> me-2 fs-16"></i>
<div>
<strong><?= htmlspecialchars($res['name']); ?></strong>
<span class="text-muted ms-1">(<?= htmlspecialchars($res['path']); ?>)</span>
<br>
<small><?= htmlspecialchars($res['msg']); ?></small>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="card-header d-flex justify-content-between align-items-center">
<div class="card-title">File List</div>
<div>
<?php
$totalFiles = count($patchTargets);
$patchedFiles = count(array_filter($fileStatuses, fn($s) => $s === 'patched'));
?>
<span class="badge bg-primary-transparent"><?= $patchedFiles; ?>/<?= $totalFiles; ?>
Patched</span>
</div>
</div>
<div class="card-body">
<p class="text-muted mb-4">
This tool performs bypass checks for license and system integrity.
Original files will be backed up before patching (*.bak).
</p>
<div class="table-responsive">
<table class="table table-bordered text-nowrap">
<thead>
<tr>
<th scope="col" style="width: 5%;">#</th>
<th scope="col" style="width: 15%;">Name</th>
<th scope="col" style="width: 25%;">Path</th>
<th scope="col" style="width: 35%;">Description</th>
<th scope="col" style="width: 10%;">Patches</th>
<th scope="col" style="width: 10%;">Status</th>
</tr>
</thead>
<tbody>
<?php $i = 1;
foreach ($patchTargets as $path => $info): ?>
<?php
$status = $fileStatuses[$path] ?? 'unknown';
switch ($status) {
case 'patched':
$badgeClass = 'bg-success-transparent';
$badgeText = 'Patched';
break;
case 'not_patched':
$badgeClass = 'bg-warning-transparent';
$badgeText = 'Not Patched';
break;
case 'not_found':
$badgeClass = 'bg-danger-transparent';
$badgeText = 'Not Found';
break;
default:
$badgeClass = 'bg-secondary-transparent';
$badgeText = 'Error';
break;
}
?>
<tr>
<td><?= $i++; ?></td>
<td><strong><?= htmlspecialchars($info['name']); ?></strong></td>
<td><code><?= htmlspecialchars($path); ?></code></td>
<td><?= htmlspecialchars($info['desc']); ?></td>
<td class="text-center"><?= count($info['patches']); ?></td>
<td class="text-center"><span
class="badge <?= $badgeClass; ?>"><?= $badgeText; ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="mt-4 d-flex gap-2">
<form method="post" style="display:inline;">
<button type="submit" name="patch" class="btn btn-primary">
<i class="fa-solid fa-wrench me-1"></i> Patch All
</button>
</form>
<a href="<?= base_url_admin('home'); ?>" class="btn btn-outline-secondary">
<i class="fa-solid fa-arrow-left me-1"></i> Back to Dashboard
</a>
</div>
<div class="mt-3">
<div class="alert alert-warning d-flex align-items-center" role="alert">
<i class="fa-solid fa-triangle-exclamation me-2 fs-16"></i>
<div>
<strong>Note:</strong> Please delete <code>patch.php</code> after completing the
patch to ensure system security.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once(__DIR__ . '/views/admin/footer.php');
?>