Re: security(8) setuid checks and space character in file name

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: MERIGHI Marcus
Date: Thursday, December 30, 2010 - 8:02 am

Hello Ingo, 

schwarze@usta.de (Ingo Schwarze), 2010.12.30 (Thu) 00:08 (CET):
 
Would have taken me ages to come up with that.

 
Solve the problem ;-)

To me it looks like the core of the problem is ls(1) having spaces as
field delimiter. 

Clean solution would be to use null byte throughout the chained
commands, far beyond what I could come up with patches for:
- A ``-0'' switch to ls(1). Would have a different meaning than in
  xargs(1) and find(1) (field vs. record delimiter). 
- Teach sort(1) -t switch to take nul as delimiter
- Teach join(1) -t switch to take nul as delimiter

Or what I can do:
- use pipe as delimiter
- downside: it changes the format of 
  CUR=/var/backups/device.current
  BACK=/var/backups/device.backup
  which currently is just the output of ``ls -ldgT'' and cannot be
  easily restored after the suggested transformations.

--- security.orig	Thu Dec 30 15:09:55 2010
+++ security	Thu Dec 30 15:33:55 2010
@@ -427,14 +427,17 @@
 	\) -a -prune -o \
 	-type f -a \( -perm -u+s -o -perm -g+s \) -print0 -o \
 	! -type d -a ! -type f -a ! -type l -a ! -type s -a ! -type p \
-	-print0 | xargs -0 -r ls -ldgT | sort +9 > $LIST
+	-print0 | xargs -0 -r ls -ldgT | tr ' ' '|' | \
+	sed 'h;s,[^/]*,,;s,|, ,g;x;s,/.*,,;G;s/\n//' | \
+	tr -s '|' | sort -t '|' +9 > $LIST
 )
 
 # Display any changes in the setuid/setgid file list.
 next_part "Checking setuid/setgid files and devices:"
 FIELDS1=1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,0
 FIELDS2=2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,0
-egrep -av '^[bc]' $LIST | join -o $FIELDS2 -110 -210 -v2 /dev/null - > $TMP1
+egrep -av '^[bc]' $LIST | \
+	join -t '|' -o $FIELDS2 -110 -210 -v2 /dev/null - > $TMP1
 if [ -s $TMP1 ] ; then
 	# Check to make sure uudecode isn't setuid.
 	if grep -aw uudecode $TMP1 > /dev/null ; then
@@ -449,23 +452,24 @@
 			:
 		else
 			next_part "Setuid additions:"
-			join -o $FIELDS2 -110 -210 -v2 $CUR $TMP1 | \
-				tee $TMP2 | column -t
+			join -t '|' -o $FIELDS2 -110 -210 -v2 $CUR $TMP1 | \
+				tee $TMP2 | column -s '|' -t
 
 			next_part "Setuid deletions:"
-			join -o $FIELDS1 -110 -210 -v1 $CUR $TMP1 | \
-				tee -a $TMP2 | column -t
+			join -t '|' -o $FIELDS1 -110 -210 -v1 $CUR $TMP1 | \
+				tee -a $TMP2 | column -s '|' -t
 
 			next_part "Setuid changes:"
-			sort +9 $TMP2 $CUR $TMP1 | \
-			    sed -e 's/[	 ][	 ]*/ /g' | uniq -u | column -t
+			sort -t '|' +9 $TMP2 $CUR $TMP1 | \
+			    sed -e 's/[	 ][	 ]*/ /g' | uniq -u | \
+			    column -s '|' -t
 
 			cp $CUR $BACK
 			cp $TMP1 $CUR
 		fi
 	else
 		next_part "Setuid additions:"
-		column -t $TMP1
+		column -s '|' -t $TMP1
 		cp $TMP1 $CUR
 	fi
 fi


schwarze@usta.de (Ingo Schwarze), 2010.12.30 (Thu) 00:21 (CET):

Quick testing showed you are partly right; ``cut(1) -d "\0"'' does not
work, whereas ``tr(1) "\0" "\n"'' does.

Isn't ignoring nul as delimiter a bug in join(1) and cut(1)?


That is true. Let's talk about probability. I suggest 174, pipe, ``|''. 

Bye, 

Marcus
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: security(8) setuid checks and space character in file name, MERIGHI Marcus, (Thu Dec 30, 8:02 am)