News for hackers. Stuff that matters.
Re:Kids, this is story of How I Met... my VPS hacked by jlgaddis on Monday January 20, 2014 @02:33PM (#7091336)
Yep, this can be a lesson to developers who read this. If your web application must write to files, keep them outside of the DocumentRoot!

edit: I know a lot of HN'ers are fans of Ubuntu but, FWIW, SELinux (default on RHEL and derivatives) would have prevented this.

Re:Kids, this is story of How I Met... my VPS hacked by drdaeman on Monday January 20, 2014 @02:40PM (#7091379)
Outside of any executable location, not only DocumentRoot. Latter is just an easier and more popular target.

I mean, all writeable directories (if any) must not only be not runnable by some server (like Apache with mod_php), but also be on devices mounted with noexec, like this is the case with /tmp.

Re:Kids, this is story of How I Met... my VPS hacked by jlgaddis on Monday January 20, 2014 @02:50PM (#7091417)
I'm not sure that'll help like you think it will.

I can't verify it at the moment, but create a /tmp/phpinfo.php file with "<?php phpinfo(); ?>" in it and then run "php /tmp/phpinfo.php". Regardless of whether /tmp is mounted noexec I think you'll find that it executes (because the php binary is under /usr which almost certainly isn't mounted noexec).

Re:Kids, this is story of How I Met... my VPS hacked by drdaeman on Monday January 20, 2014 @03:03PM (#7091475)
Whoops, seems that you're right, I was wrong about interpreters taking noexec into account - either I misremembered something or things changed, but the fact is they don't. Sorry.

Anyway, it's also better to have noexec than not. :)

At least, it'll help if there's no complete shell access but only ability to run some binary by name, without args, or modify environment variables when running some executable.

Re:Kids, this is story of How I Met... my VPS hacked by mhurron on Monday January 20, 2014 @02:50PM (#7091416)
BTW, is there any reason not to hook something like ClamAV into your upload function and scan files before they are saved?
Re:Kids, this is story of How I Met... my VPS hacked by trippy_biscuits on Monday January 20, 2014 @11:24PM (#7093425)
Obligatory xkcd: http://xkcd.com/463/

Why add more moving parts when they don't do anything but make more work? Scanning is a helpful idea, but not AV scanning. Regular vulnerability scanning can assess the platform security. At the very least, it can warn about potential security holes. It might also be plagued with false positives, causing more work for no added benefit. Safely running services on the internet is hard.

Re:Kids, this is story of How I Met... my VPS hacked by mhurron on Tuesday January 21, 2014 @02:01PM (#7097428)
> Why add more moving parts when they don't do anything but make more work?

Because in this case we're talking about intentionally accepting files from users to either integrate into the system or offer to other users. Why would you not at least check files for cleanness and reject any that fail instead of blindly accepting them because you wanted to enable file uploads.

Vulnerability scanning isn't going to tell you much when you want to accept files from users.

Re:Kids, this is story of How I Met... my VPS hacked by blueskin_ on Wednesday January 22, 2014 @05:13AM (#7101791)
CentOS/RHEL guy here, and I have to say, SELinux FTW. So many times I've been frustrated and annoyed when people's first reaction is 'disable it' when they hit some problem (almost always due to using stuff in a wrong or nonstandard way)* instead of spending 5 min to get it working and having far more security.

* (That, and custom programs that use perversely wrong paths, e.g. web content in /home, logs in the application directory, etc.)

Re:Kids, this is story of How I Met... my VPS hacked by Apes on Monday January 20, 2014 @03:58PM (#7091696)
Ubuntu has AppArmor, which could also do the task. The problem is that no one actually uses SELinux or AppArmor.
Re:Kids, this is story of How I Met... my VPS hacked by derekp7 on Monday January 20, 2014 @04:32PM (#7091884)
For SELinux on RHEL, you have to take explicit action to disable it. Now it is probably likely that admins who haven't added any SELinux skills to their skillset only learn how to turn it off and not set permissions correctly. However, that is almost as bad as running chmod 777 on everything (which I've seen plenty of people do). The minimum that anyone admining a RHEL-derived system should learn is the chcon (change security context) command, and running the tools to diagnose SELinux issues.

If you must, start off with setting SELinux to "Permissive" instead of disabling it completely. Then after a few days of running, go through your audit logs, fix any of the errors that come up, then set it back to Enforcing.

Re:Kids, this is story of How I Met... my VPS hacked by blueskin_ on Wednesday January 22, 2014 @05:19AM (#7101814)
>If you must, start off with setting SELinux to "Permissive" instead of disabling it completely. Then after a few days of running, go through your audit logs, fix any of the errors that come up, then set it back to Enforcing.

This is the best bet for something that's in production already, but ideally, you want to have SELinux set to enforcing in testing environments and create the policies there in the first place.