The idea
Kwame has an authorised engagement against Ashbourne Studios, a photographers' portfolio where members upload their work. Letting strangers put files on your server is dangerous, and the studio knows it: the upload gate refuses anything that is not an image.
But a gate is only as good as the question it asks. The studio's gate asks "does the name end in .jpg?". Later, a separate pipeline looks at the file's bytes to decide what to do with it. The two never compare notes. If the name says "photo" while the bytes say "run me", the gate waves the file through and the pipeline runs it. A file accepted as data and later treated as code: that is how an upload becomes code execution on the server.
This target keeps that execution inert. The "run me" path does one harmless thing, standing in for the arbitrary commands a real site would let you run. The lesson is the gap, not the payload.
Steps
-
Members upload photos
You are on Kwame's box,
kali, with the studio at10.0.1.20. Open it in the Viewer to see the gallery, then upload a photo the normal way: the studio takes the file's bytes as the request body and its name in the?name=parameter. Make a small stand-in image and send it.kali:~# curl -s --data-binary @/tmp/holiday.jpg "http://10.0.1.20/api/photos?name=holiday.jpg" kali:~# curl -s http://10.0.1.20/api/gallery
-
The gate only reads the name
Probe what the gate actually checks. Send the same bytes you uploaded a moment ago, but call the file
shell.php, a name no photo site should accept. Then decide what the gate is really looking at.kali:~# curl -s --data-binary @/tmp/holiday.jpg "http://10.0.1.20/api/photos?name=shell.php"
-
Smuggle a job past the gate
Now exploit the gap. The pipeline recognises a studio "job" by its first line and runs it, whatever the file is named. So give the file a name the gate loves,
portrait.jpg, and a body the pipeline will run. The job here asks the server to identify itself: an inert stand-in for the command execution a real upload hole would give, enough to prove your file ran inside the server.kali:~# curl -s --data-binary @/tmp/portrait.jpg "http://10.0.1.20/api/photos?name=portrait.jpg"
-
Swap seats: validate content, never run uploads
Now you run Ashbourne. A longer list of banned extensions won't fix this: attackers have
.phtml,.pht, double extensions, trailing dots and null bytes. The fix is to judge the file by its bytes, never to run an upload, and to keep uploads off any path that can execute. The safe endpoint,/api/photos-safe, does this. Send it the very job that ran a moment ago and watch it refused.kali:~# curl -s --data-binary @/tmp/portrait.jpg "http://10.0.1.20/api/photos-safe?name=portrait.jpg"
Run these steps on real machines