home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / kernelscan.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-03-01  |  3.8 KB  |  129 lines

  1. #!/bin/bash
  2.  
  3. # This script requires a copy of an uncompressed kernel to be placed in the script directory  
  4. # The kernel copy must match the exact version running on this system.  
  5.  
  6. if [ -e /boot/System.map ]
  7. then 
  8.     Sysmap=/boot/System.map
  9. else
  10.  
  11.     Sysmap=`ls /boot | grep System`
  12.     Sysmap=`echo /boot/$Sysmap`
  13.  
  14. fi
  15. if [ `echo "$Sysmap" | grep .gz` == `echo "$Sysmap"` ]
  16. then
  17.      rm -f ./system.map.tmp*
  18.         cp `echo $Sysmap` ./system.map.tmp.gz
  19.         gzip -d system.map.tmp.gz
  20.         Sysmap="./system.map.tmp"
  21. fi
  22. if [ ! -e "$Sysmap" ]
  23. then
  24.      Sysmap=`ls /boot | grep System | grep default`
  25.      Sysmap=`echo /boot/$Sysmap`
  26. fi
  27. if [ ! -e "$Sysmap" ]
  28. then
  29.         echo "TRUE:"
  30.         echo "AddListItem([[[]]],[[[Error]]])"
  31.         echo "AddListItem([[[Error]]],[[[Unable to find a suitable sysmap, make sure you read the complete documentation of this check]]])"
  32.         echo "!!SCRIPT_FINISHED!!"
  33.         exit
  34. fi
  35. # if you wish to use the kernel from the boot directory, uncomment the line below which starts with "kernel". 
  36. # Make sure an uncompressed kernel does reside in the boot directory.
  37. # while this operation will in most cases work, it is not recommanded since 
  38. # if the system was compromised the kernel itself might have been changed to avoid detection.
  39. # it is recommanded that instead a fresh backup is used.
  40. #kernel=`ls /boot | grep vmlinux`
  41. # if you uncomment the line above please make sure to comment out the next line
  42. kernel=`ls | grep vmlinux`
  43. if [ ! -e "$kernel" ]
  44. then
  45.     kernel=`ls /boot | grep vmlinux`
  46.     kernel=`echo /boot/$kernel`
  47.     for check in $kernel
  48.     do
  49.         if  [ -e "$check" ] 
  50.         then
  51.             kernel=$check
  52.         fi 
  53.     done 
  54. fi
  55. if [ `echo $kernel | grep .gz` == `echo $kernel` ]
  56. then
  57.      rm -f ./vmlinux.tmp*
  58.         cp `echo $kernel` ./vmlinux.tmp.gz
  59.         gzip -d vmlinux.tmp.gz
  60.         kernel="./vmlinux.tmp"
  61. fi
  62. if [ "$kernel" == "/boot/" ]
  63. then
  64.     kernel=""
  65. fi
  66. if [ ! -e "$kernel" ]
  67. then 
  68.     echo "TRUE:"
  69.     echo "AddListItem([[[]]],[[[Error]]])"
  70.     echo "AddListItem([[[Error]]],[[[Unable to find Kernel, make sure you read the complete documentation of this check]]])"
  71.      echo "!!SCRIPT_FINISHED!!"
  72.     exit
  73. fi 
  74.  
  75. kernelloc=`cat $Sysmap | grep sys_call_table | grep -v ?`
  76. kernelloc=`echo $kernelloc | awk '{ print $1 }'`
  77. sysmaploc=`nm $kernel | grep sys_call_table | grep -v ?`
  78. sysmaploc=`echo $sysmaploc | awk '{ print $1 }'`
  79.  
  80. #compare kernel table location with sysmap
  81. if [ "$kernelloc" != "$sysmaploc" ]
  82. then
  83.     echo "TRUE:"
  84.     echo "AddListItem([[[]]],[[[Kernel sys_call_table doesn't match SystemMap sys_call_table -> 0x$kernelloc : 0x$sysmaploc]]])"
  85.     echo "!!SCRIPT_FINISHED!!"
  86.     exit
  87. fi
  88.  
  89. cat << EOF > gdb-kernel
  90. #!/usr/bin/expect -f
  91. set timeout -1
  92. spawn gdb -q $kernel [lrange \$argv 1 1]
  93. match_max 100000
  94. expect "(gdb) "
  95. send -- "set height 5000\r"
  96. expect "(gdb) "
  97. send -- "x/255 [lrange \$argv 0 0]"
  98. expect -exact "[lrange \$argv 0 0]"
  99. send -- "\r"
  100. expect "(gdb) "
  101. send -- "q\r"
  102. expect eof
  103. EOF
  104.  
  105. chmod u+x gdb-kernel
  106. ./gdb-kernel 0x$kernelloc > table.raw
  107. grep 0x table.raw | grep -v \#0 | grep -v Core > kernel-stored
  108. rm -f table.raw
  109. ./gdb-kernel 0x$kernelloc /proc/kcore > tablek.raw
  110. grep 0x tablek.raw | grep -v \#0 | grep -v Core > kernel-running
  111. rm -f tablek.raw
  112.  
  113. rm -f gdb-kernel
  114. result=`diff kernel-stored kernel-running`
  115. if [ "$result" != "" ]
  116. then
  117.     echo TRUE:
  118.     echo "AddListItem([[[]]],[[[Possible RootKit Detected]]])"
  119.     echo "AddListItem([[[Possible RootKit Detected]]],[[[Kernel system call table of the provided kernel file does not match table of the current running kernel. This might indicate the presence of a rootkit or other system calls hijacking software]]])"
  120.     echo "AddListItem([[[Possible RootKit Detected]]],[[[Check the file kernel-stored and kernel-running (Stored in the home directory of the user specified in LNSS) to find out which addresses have been tampered with]]])"
  121. else
  122.     echo FALSE:
  123.     rm -f kernel-stored
  124.     rm -f kernel-running
  125. fi
  126.  
  127. echo "!!SCRIPT_FINISHED!!"
  128.  
  129.