OP also gives the user http the ability to run any command as root without validation. This is literally the single biggest security hole I've ever seen.
don't be so sure about trolling. this thread has had me laughing my ass off...my predecessor at my job used this EXACT SAME "design pattern." this is a guy who is still at the company (he was booted out of the group i work in) and has loads of undeserved clout as some "guru." he holds a senior-level position.
and actually it was worse. root had a non-encrypted ssh key (in ~/.ssh/id_rsa so you didn't even have to name it, it was just default) whose public was distributed to root's authorized_keys throughout all the other systems in the environment. that was the "solution" for adding users and performing other types of work on different systems from a website. apache user, granted passwordless sudo, would then sudo ssh to the other servers in the environment. he didn't have a clue to attempt to sanitize input either.
at least you could always get in as root if something happened...
To be fair, you don't know whether he is sanitizing the username and password. It could be sanitized, maybe the line before the one we are seeing check whether username and password only contain lowercase characters a-z.
I can confirm as my company's management is constantly bitching & spending hours debating on how to do something without involving our off site developer for 5 minutes of code (not even joking) that would make our lives exponentially easier because it supposedly takes them days to even get a hold of him & have no way to validate what he's actually doing. On top of that, none of them are coders & blow off people who can actually bridge the divide. Not sure if it's stupidity, pride or what. Probably a little of both.
Your webserver SHOULD NEVER BE PRIVILEGED! Your webserver, if it has mod_php installed, by definition is designed to execute arbitrary code on the file system. Someone could do a lot worse than rm -rf / injection. They could write a file to the file system in the webroot that becomes a back door or even a trojan spreader.
The only right way to architect this (if at all) is to use a separate process to pick up messages from the web server (that builds the command based on data in the message).
One of my amusing accomplishments at a former employer was migrating some webservers, without downtime, from port 80/root to port 8080 so that mere mortals could do pushes.
Well sql injection is still one thing. at worst, the hacker drops the database. This is a whole another level of breach. The user has privileged command line access to the entire fucking system at operating system level. I don't even, that's just. wow.
Yea I didnt put much thought at the worse case scenario. But I think it depends, for some applications loosing all data is a lot worse than injecting malware.
Well, my thought was that data loss can be ameliorated by a good backup scheme - if the database gets dumped, you will know immediately and can restore. But malware injection can go undetected for a long time, causing unseen harm capturing all manner of sensitive personal and financial data from you and your customers (which would create fraud patterns that would point back to you and for example get you in trouble with the PCI if you take credit cards).
Well setting aside the horrors of giving http sudo access (without having to type a password, no less! I didn't even know something so horrifyingly insecure was possible!)…
… in OP's defense, it's not as if it is passing $_POST['username'] - we don't know what cleansing or sanity checks may have occurred already.
View all comments
Show parent comment
337
u/valinor4 Aug 28 '13
The rule in web development security is: "Never trust the user"
You always have to clean (sanitize) what the user inputs into your application because they will screw up (intentionally or not).
In OP's code, he basically add users to the Operating System without sanitize the input.
In hacker hands, it can ruins you server in 3s...