Security issue? Gaining root is ridiculously easy.

Okay, so I noticed the other day that an app (forget which) that usually prompts for my password to gain root privileges didn't do so — it just continued doing what it needed the privileges for.


I remembered that shortly before, I had used sudo in iTerm to run a command with root privileges, and I know that OS X doesn't ask for your password after the first time you run sudo unless a number of minutes have passed. I had assumed that this behavior would be local to the thread from which you initially provided the password, which would've been the zsh session in iTerm. However, it seemed that it was local to the zsh session, nor to zsh, nor to iTerm. A completely different app had apparently piggy-backed on my sudo "session" and gained root privileges without my approval.


I tested this by issuing a sudo command in zsh in iTerm, and then, after having provided my password, I opened up Terminal with bash and issued a sudo command there. No password prompt, instant root privileges.


Based on this, it's clear that any app which runs as a user who can run sudo to gain root privileges (which is any normal OS X user) can wait for the user to execute sudo, and immediately gain root access to the system. Knowing when the current user runs sudo is easy, as such an event is written to the syslog.


Proof of concept. Quick-n-dirty. Save as a script and run in a terminal window. Then, run sudo in a different terminal window. The script will catch the sudo event and write the empty file "kilroy-was-here", as root:wheel, to the root of the drive.


#!/bin/bash


tail -f -n 0 /var/log/system.log | grep -m 1 -E 'sudo\[[0-9]+\]:\s+'$USER

echo "Gonna play around with root privs ..."

sudo touch /kilroy-was-here


This seems... Wrong... Thoughts?


Daniel

MacBook Air, OS X El Capitan (10.11.6), null

Posted on Jul 26, 2016 2:42 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 19, 2017 4:27 AM

etresoft wrote:


This thread must have been edited because I don't see the quoted line anywhere.


What's really weird is that the OP is using zsh. I thought I was the only one weird enough to use zsh.

ZSH is awesome 🙂


FTR, this thread was moderated, stripped of two or three replies, and the OP (me as another user) was locked out of it after he (I) called out Harris as being untruthful after having tested the distros claimed by him to offer the same behavior as OS X, which they did not.


Good news is that someone with Apple actually read this thread, because the default sudo configuration starting with Sierra is now the same as every other *NIX/*nux distro, which is to prevent this security issue and restrict password-less sudo requests within the grace time to the process which originally received user authentication.


So we can sleep soundly if we're on Sierra, although it may have to be a clean install — I haven't tested if an upgrade retains the insecure default settings made by El Capitan and previous versions.


Cheers 🙂

33 replies
Question marked as Top-ranking reply

Sep 19, 2017 4:27 AM in response to etresoft

etresoft wrote:


This thread must have been edited because I don't see the quoted line anywhere.


What's really weird is that the OP is using zsh. I thought I was the only one weird enough to use zsh.

ZSH is awesome 🙂


FTR, this thread was moderated, stripped of two or three replies, and the OP (me as another user) was locked out of it after he (I) called out Harris as being untruthful after having tested the distros claimed by him to offer the same behavior as OS X, which they did not.


Good news is that someone with Apple actually read this thread, because the default sudo configuration starting with Sierra is now the same as every other *NIX/*nux distro, which is to prevent this security issue and restrict password-less sudo requests within the grace time to the process which originally received user authentication.


So we can sleep soundly if we're on Sierra, although it may have to be a clean install — I haven't tested if an upgrade retains the insecure default settings made by El Capitan and previous versions.


Cheers 🙂

Sep 19, 2017 6:22 AM in response to Dr.Bingo

Hello Dr.Bingo,

Sorry, but you are way off. Bob Harris was not being untruthful. I don't know what you did to get permanently banished from the forums, but it must have been pretty bad. They don't do that lightly.


I don't have access to the same Linux servers that I had this time last year. My current Ubuntu 16.04 works the same was as Sierra. I can't test my old 14.04 machine. Nor can I test the old production servers from around 2010 that my employer used to use, and probably still does. It doesn't really matter, because most people don't have sudo privileges on Linux servers. It doesn't matter much on Macs because 5 minutes of vulnerability 3 times a year isn't that much of a risk anyway.


I can assure you that no one, other than the Apple moderators of course, has read this thread. Sierra was released to beta test a month before this thread was started. It is impossible that any change in Sierra was a result of anything you said in this thread.

Sep 20, 2017 12:51 AM in response to etresoft

Hi, etresoft 🙂


Do you make software? That nick of yours rings a bell in my head somewhere!


Yep, I agree, Sierra now behaves like Ubuntu, and every other distro I've tried (that's what I wrote 😉). The untruthfulness I spoke of on Harris' part was his claim that those two very esoteric distros he mentioned did not, and instead behaved like El Cap and earlier versions of OS X. I signed up for trials, downloaded and tested them, and they did not behave like El Cap and friends, but like Ubuntu and friends 🙂 But I don't want to go down that rabbit hole again, I'll just get blocked again and my responses deleted 😮 Just happy for all of us that Sierra is sanely configured 😊


Cheers!

Jul 26, 2016 7:41 AM in response to Dr. Daniel, M.D.

That does seem like odd behavior from a normal unix, sudo, and security viewpoint.


This is baffling after looking at it.


sudo -V on my stock 10.11.6 system shows:


Sudo version 1.7.10p9



Configure args: --with-password-timeout=0 --disable-setreuid --with-env-editor --with-pam --with-libraries=bsm --with-noexec=no --sysconfdir=/private/etc --with-timedir=/var/db/sudo

...

Authentication timestamp timeout: 5.0 minutes

...

Path to authentication timestamp dir: /var/db/sudo


This, in theory, should be fairly normal behavior. However, I have no timestamp file in /var/db/sudo/$username when I tested sudo. I cannot find any place where this timestamp file may reside, so far.


This is both a mystery and disconcerting.

Jul 26, 2016 9:07 PM in response to Dr. Daniel, M.D.

Dr. Daniel, M.D. wrote:


Well, this is a standard user. The first user created when installing OS X has the ability to use sudo to elevate privileges.

Not what I meant, but the first user created has Admin privileges. A plain, Standard user cannot elevate their privileges using sudo unless you add them to the sudoers file (which can be done in the GUI by marking the allow user to administer the computer).

Jul 26, 2016 9:19 PM in response to Dr. Daniel, M.D.

Hello Dr. Daniel,

The sudo command is for advanced users. The expectation is that they know what else is running on their system at all times. If you are concerned about this, you can always run as a standard user and then you won't have sudo privileges. This what I use. If I need to use sudo, I have to su into my admin user and then run sudo from there.


There are timestamp directories in /var/db/sudo as expected. There just isn't any $username variable.

Jul 28, 2016 1:05 AM in response to Barney-15E

Okay, my bad for improper semantics. What I meant by "standard" was that it's the type of user that is created whenever someone starts using their Mac.


So, to put it properly: Everyone will have this type of user after setting up their computer, and unless they're extremely vigilant and want to jump through hoops on a daily basis, they'll also be logged in as this user 🙂

Jul 28, 2016 1:14 AM in response to etresoft

Hi etresoft,


The sudo command isn't just for advanced users. It is also indirectly called by apps that require root access to do stuff (e.g. write images to USB sticks, mount encrypted partitions, etc.). The fact that it does this via a graphical user interface doesn't change the fact that it triggers a sudo session in the background which can be hijacked very easily (if you're logged in the way that arguably 99+% of Mac users are).


Also, I don't agree with you that, "the expectation is that they know what else is running on their system at all times." That would just be a blanket excuse someone could apply anywhere to not bother dealing with security in one's own code. I don't remember sudo behaving this way when I used to run Linux as a desktop OS.


Don't know what you mean by, "There are timestamp directories in /var/db/sudo as expected. There just isn't any $username variable."?


Cheers 🙂

Jul 28, 2016 4:42 AM in response to Dr. Daniel, M.D.

So, to put it properly: Everyone will have this type of user after setting up their computer, and unless they're extremely vigilant and want to jump through hoops on a daily basis, they'll also be logged in as this user


No hoops to jump through at all. I'm not sure why you think there are some.


However, how does this become an exploit. You have the ability to elevate your user's privileges. How does another user (i.e. Hacker) use your user to exploit this. Another user (i.e. Another process running on the Mac) can't exploit this so I'm not sure how it is a problem. If someone hacks into your Mac and logs in as your user, it doesn't matter whether there is a timeout or not.


In your example script, your user is still running that script, it is not some rogue process.

Jul 28, 2016 5:10 AM in response to Dr. Daniel, M.D.

If a Mac is owned and used in a home one could argue security is less of an issue. Therefore as you have observed the normal behaviour is that the first user account created is automatically given Administrator level privileges and hence is authorised to be a sudoer.


However the proper practice in a business or education environment is the normal users e.g. staff, students, etc. are not given Administrator level accounts only 'standard' level accounts. As a result they do not have sudoer privileges. One could therefore argue the issue is not as big a problem as you perceive.


It would still be worth you reporting it as a security concern because I agree with one aspect of your post, the time window where it caches sudo privileges should be as far as you and I are concerned limited to the original thread and not shared with other processes.


See https://www.apple.com/uk/support/security/

Jul 28, 2016 6:03 AM in response to Dr. Daniel, M.D.

haha... u call that "easy" ? I would have a hard time doing that syntax, and i like to know more than the normal user.


If i can't understand that, how do u expect a average user to know ? This is why Apple does things via Terminal 🙂


to prevent most users getting access, but its there it they need it..


I wouldn't call a "smart user" who can get "easily get root access" easy on the Mac ... Easy for you yes.. but hard for others.. if they must figure it out on themselves.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Security issue? Gaining root is ridiculously easy.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.