-
Notifications
You must be signed in to change notification settings - Fork 11
/
find-elf4tmp
executable file
·86 lines (78 loc) · 2.48 KB
/
find-elf4tmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# find_elf4tmp utility
# Copyright (c) 2010-12 Steve Grubb. ALL RIGHTS RESERVED.
#
# This software may be freely redistributed under the terms of the GNU
# public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# This script will search a directory and its subdirectories for all elf
# executables. It will then search for the use of the tmp directory. If it finds
# this is true, it will then check to see if XXX is being used which would
# indicate that the path is going to be randomized.
if [ $# -ge 2 ] ; then
echo "Usage: find_elf4tmp [directory]" 1>&2
exit 1
fi
if [ ! -x /usr/bin/eu-strings ] ; then
echo "Skipping due to missing /usr/bin/eu-strings utility"
exit 1
fi
if [ -h /bin ] ; then
DIRS="/usr/bin /usr/sbin /usr/libexec /usr/kerberos /usr/games /usr/lib /usr/lib64 /usr/local"
else
DIRS="/bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/kerberos /usr/games /lib /lib64 /usr/lib /usr/lib64 /usr/local"
fi
if [ $# -eq 1 ] ; then
if [ -d "$1" ] ; then
DIRS="$1"
else
echo "Option passed in was not a directory" 1>&2
exit 1
fi
fi
source ./is_elf
FOUND=0
for d in $DIRS
do
if [ ! -d $d ] ; then
continue
fi
# echo "Scanning files in $d..."
for f in `/usr/bin/find $d -type f 2>/dev/null`
do
# Get just the elf executables
if is_elf "$f" ; then
# Remove strings that look like they mean to be random
# ie /tmp/fileXXXXXX
test_res=`/usr/bin/eu-strings $f 2>/dev/null | /bin/grep '/tmp/' | /bin/grep -vE 'XX|/tmp/$|[ .,:]/tmp/|%'`
if [ x"$test_res" = "x" ] ; then
continue
fi
# If safe tempfile operations are used, we assume things will
# be OK (this will certainly produce false negatives)
syms=`/usr/bin/readelf -sW $f 2>/dev/null | grep -E ' mkstemp@.*GLIBC| tempnam@.*GLIBC| tmpfile@.*GLIBC'`
if [ x"$syms" != "x" ] ; then
continue
fi
# Well its a bad one...out with it
FOUND=1
# Get the package
RPM=`/bin/rpm -qf --queryformat "%{NAME}-%{VERSION}" $f 2>/dev/null | /bin/grep -v 'not owned' | /bin/sort | /usr/bin/uniq`
if [ x"$RPM" = "x" ] ; then
RPM="<unowned>"
fi
# For each tmp string, output the line
echo $test_res | /usr/bin/tr '\b' '\n' | /bin/awk 'NF >= 1 { printf "%-46s\t%-30s\t%s\n", f, r, $1 }' r=$RPM f=$f
fi
done
done
if [ $FOUND -eq 0 ] ; then
# Nothing to report, just exit
echo "No problems found" 1>&2
exit 0
fi
exit 1