home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / procscan.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-03-01  |  9.6 KB  |  340 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. Sysmap=`ls /boot | grep System`
  7.  
  8. # if you wish to use the kernel from the boot directory, uncomment the line below which starts with "kernel". 
  9. # Make sure an uncompressed kernel does reside in the boot directory.
  10. # while this operation will in most cases work, it is not recommanded since 
  11. # if the system was compromised the kernel itself might have been changed to avoid detection.
  12. # it is recommanded that instead a fresh backup is used.
  13. #kernel=`ls /boot | grep vmlinux`
  14. # if you uncomment the line above please make sure to comment out the next line
  15. kernel=`ls | grep vmlinux`
  16.  
  17. if [ -e /boot/System.map ]
  18. then 
  19.     Sysmap=/boot/System.map
  20. else
  21.  
  22.     Sysmap=`ls /boot | grep System`
  23.     Sysmap=`echo /boot/$Sysmap`
  24.  
  25. fi
  26.  
  27.  
  28. if [ ! -e "$kernel" ]
  29. then
  30.     kernel=`ls /boot | grep vmlinux`
  31.     kernel=`echo /boot/$kernel`
  32.     for check in $kernel
  33.     do
  34.         if  [ -e "$check" ] 
  35.         then
  36.             kernel=$check
  37.         fi 
  38.     done 
  39. fi
  40.  
  41. if [ `echo $Sysmap | grep .gz` == `echo $Sysmap` ]
  42. then
  43.      rm -f ./system.map.tmp*
  44.         cp `echo $Sysmap` ./system.map.tmp.gz
  45.         gzip -d system.map.tmp.gz
  46.         Sysmap="./system.map.tmp"
  47. fi
  48. if [ ! -e "$Sysmap" ]
  49. then
  50.      Sysmap=`ls /boot | grep System | grep default`
  51.      Sysmap=`echo /boot/$Sysmap`
  52. fi
  53.  
  54. if [ ! -e "$Sysmap" ]
  55. then
  56.         echo "TRUE:"
  57.         echo "AddListItem([[[]]],[[[Error]]])"
  58.         echo "AddListItem([[[Error]]],[[[Unable to find a suitable sysmap, make sure you read the complete documentation of this check]]])"
  59.         echo "!!SCRIPT_FINISHED!!"
  60.         exit
  61. fi
  62.  
  63.  
  64. if [ `echo $kernel | grep .gz` == `echo $kernel` ]
  65. then
  66.      rm -f ./vmlinux.tmp*
  67.         cp `echo $kernel` ./vmlinux.tmp.gz
  68.         gzip -d vmlinux.tmp.gz
  69.         kernel="./vmlinux.tmp"
  70. fi
  71. if [ "$kernel" == "/boot/" ]
  72. then
  73.     kernel=""
  74. fi
  75.  
  76. if [ ! -e "$kernel" ]
  77. then 
  78.     echo "TRUE:"
  79.     echo "AddListItem([[[]]],[[[Error]]])"
  80.     echo "AddListItem([[[Error]]],[[[Unable to find Kernel, make sure you read the complete documentation of this check]]])"
  81.      echo "!!SCRIPT_FINISHED!!"
  82.     exit
  83. fi 
  84.  
  85. kernelloc=`cat $Sysmap | grep sys_call_table`
  86. kernelloc=`echo $kernelloc | awk '{ print $1 }'`
  87. sysmaploc=`nm $kernel | grep sys_call_table`
  88. sysmaploc=`echo $sysmaploc | awk '{ print $1 }'`
  89.  
  90. #compare kernel table location with sysmap
  91. if [ "$kernelloc" != "$sysmaploc" ]
  92. then
  93.     echo "TRUE:"
  94.     echo "AddListItem([[[]]],[[[Kernel sys_call_table doesn't match SystemMap sys_call_table -> 0x$kernelloc : 0x$sysmaploc]]])"
  95.     echo "!!SCRIPT_FINISHED!!"
  96.     exit
  97. fi
  98.  
  99. cat << EOF > gdb-kernel
  100. #!/usr/bin/expect -f
  101. set timeout -1
  102. set height 5000
  103. spawn gdb -q ./vmlinux-2.6.4-52-smp [lrange \$argv 1 1]
  104. match_max 100000
  105. expect "(gdb) "
  106. send -- "set height 5000\r"
  107. expect "(gdb) "
  108. send -- "disass [lrange \$argv 0 0]"
  109. expect -exact "[lrange \$argv 0 0]"
  110. send -- "\r"
  111. expect "(gdb) "
  112. send -- "q\r"
  113. expect eof
  114. EOF
  115.  
  116. chmod u+x gdb-kernel
  117. ./gdb-kernel sys_read > function-stored.raw
  118. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  119. rm -f function-stored.raw
  120. ./gdb-kernel sys_read /proc/kcore > function-running.raw
  121. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  122. rm -f function-running.raw
  123.  
  124. result=`diff function-stored function-running`
  125. results=FALSE
  126. if [ "$result" != "" ]
  127. then
  128.     results=TRUE
  129. fi
  130.  
  131. ./gdb-kernel sys_write > function-stored.raw
  132. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  133. rm -f function-stored.raw
  134. ./gdb-kernel sys_write /proc/kcore > function-running.raw
  135. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  136. rm -f function-running.raw
  137.  
  138. result=`diff function-stored function-running`
  139. if [ "$result" != "" ]
  140. then
  141.         results=TRUE
  142. fi
  143.  
  144. ./gdb-kernel sys_open > function-stored.raw
  145. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  146. rm -f function-stored.raw
  147. ./gdb-kernel sys_open /proc/kcore > function-running.raw
  148. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  149. rm -f function-running.raw
  150.  
  151. result=`diff function-stored function-running`
  152. if [ "$result" != "" ]
  153. then
  154.         results=TRUE
  155. fi
  156.  
  157. ./gdb-kernel sys_getdents > function-stored.raw
  158. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  159. rm -f function-stored.raw
  160. ./gdb-kernel sys_getdents /proc/kcore > function-running.raw
  161. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  162. rm -f function-running.raw
  163.  
  164. result=`diff function-stored function-running`
  165. results=FALSE
  166. if [ "$result" != "" ]
  167. then
  168.         results=TRUE
  169. fi
  170.  
  171. ./gdb-kernel sys_dents64 > function-stored.raw
  172. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  173. rm -f function-stored.raw
  174. ./gdb-kernel sys_dents64 /proc/kcore > function-running.raw
  175. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  176. rm -f function-running.raw
  177.  
  178. result=`diff function-stored function-running`
  179. results=FALSE
  180. if [ "$result" != "" ]
  181. then
  182.         results=TRUE
  183. fi
  184.  
  185. ./gdb-kernel sys_socketcall > function-stored.raw
  186. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  187. rm -f function-stored.raw
  188. ./gdb-kernel sys_socketcall /proc/kcore > function-running.raw
  189. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  190. rm -f function-running.raw
  191.  
  192. result=`diff function-stored function-running`
  193. results=FALSE
  194. if [ "$result" != "" ]
  195. then
  196.         results=TRUE
  197. fi
  198.  
  199. ./gdb-kernel sys_query_module > function-stored.raw
  200. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  201. rm -f function-stored.raw
  202. ./gdb-kernel sys_query_module /proc/kcore > function-running.raw
  203. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  204. rm -f function-running.raw
  205.  
  206. result=`diff function-stored function-running`
  207. results=FALSE
  208. if [ "$result" != "" ]
  209. then
  210.         results=TRUE
  211. fi
  212.  
  213. ./gdb-kernel sys_setuid > function-stored.raw
  214. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  215. rm -f function-stored.raw
  216. ./gdb-kernel sys_setuid /proc/kcore > function-running.raw
  217. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  218. rm -f function-running.raw
  219.  
  220. result=`diff function-stored function-running`
  221. results=FALSE
  222. if [ "$result" != "" ]
  223. then
  224.         results=TRUE
  225. fi
  226.  
  227. ./gdb-kernel sys_getuid > function-stored.raw
  228. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  229. rm -f function-stored.raw
  230. ./gdb-kernel sys_getuid /proc/kcore > function-running.raw
  231. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  232. rm -f function-running.raw
  233.  
  234. result=`diff function-stored function-running`
  235. results=FALSE
  236. if [ "$result" != "" ]
  237. then
  238.         results=TRUE
  239. fi
  240.  
  241. ./gdb-kernel sys_execve > function-stored.raw
  242. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  243. rm -f function-stored.raw
  244. ./gdb-kernel sys_execve /proc/kcore > function-running.raw
  245. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  246. rm -f function-running.raw
  247.  
  248. result=`diff function-stored function-running`
  249. results=FALSE
  250. if [ "$result" != "" ]
  251. then
  252.         results=TRUE
  253. fi
  254.  
  255. ./gdb-kernel sys_chdir > function-stored.raw
  256. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  257. rm -f function-stored.raw
  258. ./gdb-kernel sys_chdir /proc/kcore > function-running.raw
  259. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  260. rm -f function-running.raw
  261.  
  262. result=`diff function-stored function-running`
  263. results=FALSE
  264. if [ "$result" != "" ]
  265. then
  266.         results=TRUE
  267. fi
  268.  
  269. ./gdb-kernel sys_fork > function-stored.raw
  270. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  271. rm -f function-stored.raw
  272. ./gdb-kernel sys_fork /proc/kcore > function-running.raw
  273. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  274. rm -f function-running.raw
  275.  
  276. result=`diff function-stored function-running`
  277. results=FALSE
  278. if [ "$result" != "" ]
  279. then
  280.         results=TRUE
  281. fi
  282.  
  283. ./gdb-kernel sys_clone > function-stored.raw
  284. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  285. rm -f function-stored.raw
  286. ./gdb-kernel sys_clone /proc/kcore > function-running.raw
  287. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  288. rm -f function-running.raw
  289.  
  290. result=`diff function-stored function-running`
  291. results=FALSE
  292. if [ "$result" != "" ]
  293. then
  294.         results=TRUE
  295. fi
  296.  
  297. ./gdb-kernel sys_ioctl > function-stored.raw
  298. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  299. rm -f function-stored.raw
  300. ./gdb-kernel sys_ioctl /proc/kcore > function-running.raw
  301. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  302. rm -f function-running.raw
  303.  
  304. result=`diff function-stored function-running`
  305. results=FALSE
  306. if [ "$result" != "" ]
  307. then
  308.         results=TRUE
  309. fi
  310.  
  311. ./gdb-kernel sys_kill > function-stored.raw
  312. grep 0x function-stored.raw | grep -v \#0 | grep -v Core > function-stored
  313. rm -f function-stored.raw
  314. ./gdb-kernel sys_kill /proc/kcore > function-running.raw
  315. grep 0x function-running.raw | grep -v \#0 | grep -v Core > function-running
  316. rm -f function-running.raw
  317.  
  318. rm -f gdb-kernel
  319. result=`diff function-stored function-running`
  320. results=FALSE
  321. if [ "$result" != "" ]
  322. then
  323.         results=TRUE
  324. fi
  325.  
  326.  
  327. if [ "$results" = TRUE ]
  328. then
  329.     echo TRUE:
  330.     echo "AddListItem([[[]]],[[[Possible RootKit Detected]]])"
  331.     echo "AddListItem([[[Possible RootKit Detected]]],[[[One or more of the System Call functions code was changed in the running kernel.]]])" 
  332.     echo "AddListItem([[[Possible RootKit Detected]]],[[[This is usually the result of a root kit or other malicious software that tries to hide its processes and files.]]])"
  333. else
  334.     echo FALSE:
  335.     rm -f kernel-stored
  336.     rm -f kernel-running
  337. fi
  338.  
  339. echo "!!SCRIPT_FINISHED!!"
  340.