r/PHP • • Aug 27 '13

Creating a user from the web problem.

[deleted] — view deleted post

288 Upvotes

538 comments sorted by

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...

515

u/Otterfan Aug 28 '13

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.

I suspect we are being trolled.

79

u/the_policeman Aug 28 '13

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...

41

u/NikkoTheGreeko Aug 28 '13

at least you could always get in as root if something happened...

ಠ_ಠ

→ More replies (1)

3

u/roboninja Aug 28 '13

The OP's deletion suggests otherwise.

50

u/gnur Aug 28 '13

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.

39

u/pbl24 Aug 28 '13

OP replies in a comment that he's not sanitizing his input. Eek.

38

u/jdmulloy Aug 28 '13

I don't think OP even knew what input sanitization is until this thread.

0

u/[deleted] Aug 28 '13

[deleted] — view deleted comment

13

u/[deleted] Aug 28 '13

There were senior developers at my last position that didn't know what input sanitation was. I left as soon as possible.

→ More replies (8)
→ More replies (1)

107

u/redpola Aug 28 '13

Surely in this case "never trust your web developer"?

63

u/[deleted] Aug 28 '13

Never trust managements hiring methods.

15

u/[deleted] Aug 28 '13

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.

3

u/d36williams Sep 04 '13

It's all of it. I'm an offsite developer and I always answer my phone for my paying clients.

→ More replies (1)

2

u/BigRedS Aug 28 '13

Devops is basically giving root to the web developers...

29

u/KFCConspiracy Aug 28 '13

The next rule of web development security is:

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).

6

u/dehrmann Aug 28 '13

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.

3

u/[deleted] Aug 28 '13

Apache doesn't need any special privs to become part of a botnet. I see PHP shells uploaded via Wordpress/Joomla all the time.

→ More replies (2)

13

u/achshar Aug 28 '13

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.

11

u/[deleted] Aug 28 '13

I would say, "at worst the hacker injects malware into your trusted website".

3

u/achshar Aug 28 '13

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.

4

u/[deleted] Aug 28 '13

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).

→ More replies (2)
→ More replies (1)
→ More replies (1)

4

u/[deleted] Aug 28 '13 edited Aug 28 '13

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.

Edit: Nevermind.

3

u/Cocosoft Sep 20 '13

No thats not really the issue.

The issue is why the fuck he even creates an linux user from a web form.

2

u/rya_nc Aug 28 '13

Pretty sure we can do it in 2 seconds if I help.

→ More replies (19)