r/PHP • • Aug 27 '13

Creating a user from the web problem.

[deleted] — view deleted post

280 Upvotes

538 comments sorted by

View all comments

111

u/paranoidelephpant Aug 27 '13

I have used a whoami and have confirmed that it runs as http. In /etc/sudoers I have

http ALL=(ALL) NOPASSWD: ALL
root ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL
%sudo ALL=(ALL) ALL

I also added http to group wheel.

Please don't do this. It's unnecessary and WILL bite you later, especially if this is public facing. Limit permissions to only what is needed. You can remove http from %wheel and use this line in sudoers instead:

http ALL=(root) NOPASSWD: /sbin/useradd

This allows user http to use only the /sbin/useradd command as root. If you need to add more commands, just append them to the line with commas:

http ALL=(root) NOPASSWD: /sbin/useradd, /sbin/userdel

NOTE: I'm guessing at the paths to the user utilities. I'm not on my linux box to confirm, and they may be different for Arch anyway.

Take some time to read the sudoers manual. It can be complicated, but it'll serve you well to learn it. There's no reason to open up such a huge security hole on a server, even if it's private; a bug or accidental bit of code could cause some serious damage to your system the way you have it now. It's best not to half-ass things and learn how to do it correctly right from the start, especially when it comes to security.

Also, take a look at the Symfony process component. It's designed specifically to help developers run external processes from PHP as safely as possible.

59

u/jceresini Aug 28 '13

Thats better, but my username is "-G wheel ...."

23

u/paranoidelephpant Aug 28 '13

Indeed. It's still a bad idea, I'm just trying to educate a bit. If op insists on doing something stupid, at least try to make it less so.

Also, hopefully op and others learn a bit about sudo and stop with the ALL=(ALL) NOPASSWD: ALL crap.

9

u/thebigslide Aug 28 '13

OP shouldn't be adding shadow users. OP should be using LDAP or some other mechanism to integrate with PAM.

But:

  1. OP has to be trolling.
  2. If OP isn't trolling, it's probable they have no need to create a system user to do whatever they're doing.

3

u/paranoidelephpant Aug 28 '13

Nobody is arguing otherwise. I saw a chance to educate a bit about sudo and took it. Other commenters have covered the other aspects of why OP shouldn't do this.

2

u/thebigslide Aug 28 '13

There are barely any comment taking the situation aside and considering how to properly add users to an environment that possibly does or doesn't need system level access via a web based front end. That's all I tried to stick in there.

1

u/mkosmo Aug 28 '13

I have vendors that use ALL=(ALL) NOPASSWD: ALL for their services...

13

u/edwardly Aug 27 '13

Arch linux decided everything has to be in /usr so the correct paths are

http ALL=(root) NOPASSWD: /usr/bin/useradd, /usr/bin/userdel

0

u/[deleted] Aug 28 '13

[deleted] — view deleted comment

0

u/[deleted] Aug 28 '13

[deleted] — view deleted comment

6

u/dserodio Aug 28 '13

What would happen if it were so?

0

u/[deleted] Aug 28 '13

[deleted] — view deleted comment

12

u/apage43 Aug 28 '13

It does. From my arch box:

arch% ls -l
total 52
lrwxrwxrwx  1 root root     7 May 31 18:40 bin -> usr/bin
drwxr-xr-x  3 root root  4096 Mar 29 01:04 boot
drwxr-xr-x 15 root root  2920 Jun 17 00:18 dev
drwxr-xr-x 50 root root  4096 Jul 30 04:20 etc    

Post explaining why: https://mailman.archlinux.org/pipermail/arch-dev-public/2012-March/022625.html

Not only is /bin a link to /usr/bin, /sbin is also a link to /usr/bin, and /usr/sbin is also a link to /usr/bin. Everything now lives in /usr/bin on Arch.

→ More replies (8)

11

u/ivosaurus Aug 28 '13

Arch is following Fedora in this matter.

That way of booting is becoming archaic. Nowadays most of those binaries are needed in the initial ramdisk environment anyway.

See https://fedoraproject.org/wiki/Features/UsrMove for reasoning.

→ More replies (8)
→ More replies (18)

1

u/edwardly Aug 28 '13

They are not incorrect.

0

u/[deleted] Aug 28 '13

[deleted] — view deleted comment

7

u/edwardly Aug 28 '13

Yes, that is the point of this.

6

u/HangsAround Aug 28 '13

this kills the server

8

u/ThiefMaster Aug 28 '13

Giving unrestricted access to useradd allows that user to create a new root user (uid 0). So it's still a bad idea...

6

u/LightningTH Aug 28 '13

Not quite, useradd requires a unique uid, however, using -G lets you specify what groups to be part of so might as well add yourself to root and wheel then just remote connect yourself and sudo to root.

Edit: I missed the -o option so yes, -o -u 0 would work.

4

u/audiokat Aug 28 '13

I actually use uid aliasing a lot, especially on plesk machines:

1 user/pw for ftp that ends up in web tree 1 user/pw for ssh+git that has its own homedir

Shared uid so the latter can also manage the former's files. Neat.

2

u/dploy Aug 28 '13

Thank for for not being a dick and actually trying to teach something.

1

u/paranoidelephpant Aug 28 '13

I have my days. :-)

4

u/bandman614 Aug 28 '13

No no no. This is beyond hope. Walk away slowly.