Latest Uploads
Extraterre ... .0.1 (zip)

dantheman363

Monty Teas ... Screenie 1

steve_ancell

Santa Clau ... ed his bag

waroffice

manic_platdude.png

spinal

Tetris Clone

steve_ancell

Super blues bros.

spinal

Forum Home

Upload Down

UserMessage
Posted : Monday, 11 June 2012, 15:19 | Permalink | Mark Here
Jayenkai


WW Entries : 103
Due to MASSIVE security flaw, upload is temporarily down.. It’ll be back once I feel up to fixing it. Apologies. But thanks to DD for letting me know.

-----
Posted : Monday, 11 June 2012, 15:19 | Permalink | Mark Here
shroom_monk


WW Entries : 8
Once it's fixed, any chance of explaining what it was / how it worked, from an educational standpoint?

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Monday, 11 June 2012, 17:49 | Permalink | Mark Here
JL235


WW Entries : 7
If Jay doesn't mind, then I'd be happy to explain.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Monday, 11 June 2012, 18:24 | Permalink | Mark Here
JL235


WW Entries : 7
I've also just PM'd Jay a simple fix for the problem, which should solve it. Once you know, it's pretty easy to implement.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Tuesday, 12 June 2012, 05:49 | Permalink | Mark Here
Jayenkai


WW Entries : 103
Yeah, go ahead and explain it, DD. It's another of those "why the hell would they make it do that?" Server issues that don't seem obvious.

-----
Posted : Tuesday, 12 June 2012, 11:28 | Permalink | Mark Here
Stealth


File uploaders are scary. You never know what flaw someone can find and exploit.

-----
Andrew // stealth
"Some people see things as they are and say why? I dream things that never were and say why not?" - Robert Kennedy
Posted : Tuesday, 12 June 2012, 14:37 | Permalink | Mark Here
JL235


WW Entries : 7
It relates to how Apache handlers work. If you have a file called 'index.php', it will run it as a PHP script, because of the extension. In the early days of the web, it made sense to have multiple extensions. For example 'index.html.en' could be the English version of a HTML file, and so should be served as a HTML file. This is intended behaviour, and so not a bug. This means you can have multiple file extensions.

What I did on SoCoder, was I uploaded a file called 'test.php.zip'. It then ran the PHP handler, because of the .php extension, and so allowed me to execute arbituary PHP on the server.

We could just grep for .php, however what if I want to zip up a php file, and then upload it? 'test.php.zip' is a perfectly legitimate name for a .zip file. Plus checking the file extension is a really flakey way of validating a file. If you want to allow only .png files, then open it up and have a look if it's a .png. Never rely on the file extension!

So a better way to solve this is to place all uploads inside a sub-folder, and at the root, add a .htaccess file which turns off serving HTML and PHP from that folder. Such as:

-->

You need to turn off html too, so it's served as a plain text file, instead of a page on that website. This is so people can't inject script tags, and get access to your session cookie, or navigate the site as you (which you can with JS).

I did some testing on local environment. There 'test.php.zip' is served as a zip file, but 'test.php.foo' is served as HTML. I am able to serve HTML files without a HTML extension at the end, but cannot do this with PHP. So I'm guessing that either SoCoder is setup incorrectly, or that it's running on an older version of Apache and PHP, and this behaviour has changed. However that is a total guess.

In short: always .htaccess off upload areas!

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Tuesday, 12 June 2012, 15:06 | Permalink | Mark Here
shroom_monk


WW Entries : 8
If you use HTML file inputs with PHP, are they uploaded to a temporary folder and deleted when the script finishes, or do they remain? I assume that doesn't suffer from the same issue, or does it?

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Tuesday, 12 June 2012, 15:16 | Permalink | Mark Here
HoboBen


WW Entries : 9
Wow. I'm surprised in the case of ".php.zip" later handlers (e.g. .zip) don't (always) take priority over earlier handlers.

You'd expect ".zip" to be detected, and served with a header identifying it as binary, just like you'd expect ".html" to be sent with a "text/html" header. It means even a white-listed set of extensions are vulnerable.

If you want to make this foolproof though, do the disabling in httpd.conf and disallow overrides for the directory (bonus -- you can use regex and be protected if a future version of php comes out with .php6 or something). Drawback is "foo.php.zip" no longer becomes a valid file.

This should really be highlighted in PHP's file uploading documentation.

In any case, thanks! I learnt something new!


-----
github
Posted : Tuesday, 12 June 2012, 15:49 | Permalink | Mark Here
JL235


WW Entries : 7
That is what I was thinking Ben. Maybe it just ran the handlers in the order they were defined in older Apache, but newer Apache runs them based on right to left in the filename.

The other advantage of using htaccess to corner off a section is that it allows uploading html and php files, such as 'index.php', and they get served as pure text. For a generic upload manager, like what we have on SoCoder, this is handy.`

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Latest Posts
Coder's Block
Jayenkai Thu 09:01
Consumer Lockout
9572AD Thu 06:09
Professor Oak, Honest!!
spinal Wed 23:24
Position in Mind
steve_ancell Wed 20:11
Sonic Adventure v0.x
Jayenkai Wed 07:08
FIRST!!!
steve_ancell Wed 03:55
Noel's Graduation
waroffice Wed 02:55
Monkey vs iOS tweaks
spinal Tue 22:51
Fucking Pound Sign Unicode Bullshit Bollocks
Dabz Tue 13:00
Progress / Location Bars
dna Tue 08:55
More

Latest Items
News : Newsletter #176
Jayenkai Sat 04:49
News : Newsletter #175
Dabz Tue 09:38
Blog : Snow: More Material Junk
Cower Sat 23:17
Dev-Diary : Mutant Monty: Amstrad CPC to Windows conversion
rockford Fri 13:14
Techy : AppleTV
Jayenkai Thu 09:40
Blog : Graphviz
steve_ancell Sat 14:17
Pets : Top-Down Shadow Hack
Jayenkai Tue 05:52
Snippet : JNKrunch v1.0
Jayenkai Sat 07:20
News : Newsletter #173
waroffice Fri 04:47
Blog : Material Loading
Cower Fri 02:08
Pets : I Done Won A Thing
shroom_monk Sun 11:31
Pets : Repurposing A Lexer
Cower Mon 22:06
Bah : Feeling a Little Angry
spinal Mon 11:26
News : Newsletter #170
Dabz Sat 00:34
Showcase : sbfgen
Cower Sat 16:57
More

Who's Online
Dabz
Thu, at 23:11
spinal
Thu, at 23:10
Jayenkai
Thu, at 19:46
HoboBen
Thu, at 18:50
CodersRule
Thu, at 18:29
Cower
Thu, at 18:21
Evil Roy Ferguson
Thu, at 17:34
dna
Thu, at 17:30
9572AD
Thu, at 17:28
steve_ancell
Thu, at 17:19
Link to this page
Site : Jayenkai 2006-Infinity |
MudChat's origins, BBCode's former life, Image Scaler.