check-auditd-package.sh 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. #The hole idea of how to get the origin files' permission is learned from http://sysadminnotebook.blogspot.com/2012/06/how-to-reset-folder-permissions-to.html
  3. TDIR=`mktemp -d`
  4. cd $TDIR
  5. aptitude download auditd
  6. FILES=`dpkg -c auditd*.deb | sed -e '/^d/d' | \
  7. sed '/audit.rules$/p;s/\/etc\/audit\/rules.d\/audit.rules$/\/etc\/audit\/audit.rules/'`
  8. DIRECTORY=`dpkg -c auditd*.deb | sed -n '/^d/p' | \
  9. sed -e '/\/usr\/share\/man/d'`
  10. case $1 in
  11. permission)
  12. echo "$FILES" | while read FILE;
  13. do
  14. echo "$FILE" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  15. do
  16. ORIGIN=$(echo "$FILE" | awk '{print $1}')
  17. CURRENT=$(ls -l "$line" | awk '{print $1}')
  18. if [ "$CURRENT" != "$ORIGIN" ];then
  19. echo "ORIGIN:$FILE"
  20. echo "CURRENT:$(ls -l $line)"
  21. exit 1
  22. fi
  23. done
  24. done
  25. echo "$DIRECTORY" | while read DIR;
  26. do
  27. echo "$DIR" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  28. do
  29. ORIGIN=$(echo "$DIR" | awk '{print $1}' )
  30. CURRENT=$(ls -dl "$line" | awk '{print $1}' )
  31. if [ "$CURRENT" != "$ORIGIN" ];then
  32. echo "$ORIGIN:$DIR"
  33. echo "$CURRENT:$(ls -dl $line)"
  34. exit 1
  35. fi
  36. done
  37. done
  38. ;;
  39. owner)
  40. echo "$FILES" | while read FILE;
  41. do
  42. echo "$FILE" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  43. do
  44. ORIGIN=$(echo "$FILE" | awk '{print $2}' | awk -F '/' '{print $1}')
  45. CURRENT=$(ls -l "$line" | awk '{print $3}')
  46. if [ "$CURRENT" != "$ORIGIN" ];then
  47. echo "ORIGIN:$FILE"
  48. echo "CURRENT:$(ls -l $line)"
  49. exit 1
  50. fi
  51. done
  52. done
  53. echo "$DIRECTORY" | while read DIR;
  54. do
  55. echo "$DIR" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  56. do
  57. ORIGIN=$(echo "$DIR" | awk '{print $2}' | awk -F '/' '{print $1}' )
  58. CURRENT=$(ls -dl "$line" | awk '{print $3}' )
  59. if [ "$CURRENT" != "$ORIGIN" ];then
  60. echo "$ORIGIN:$DIR"
  61. echo "$CURRENT:$(ls -dl $line)"
  62. exit 1
  63. fi
  64. done
  65. done
  66. ;;
  67. group-owner)
  68. echo "$FILES" | while read FILE;
  69. do
  70. echo "$FILE" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  71. do
  72. ORIGIN=$(echo "$FILE" | awk '{print $2}' | awk -F '/' '{print $2}')
  73. CURRENT=$(ls -l "$line" | awk '{print $4}')
  74. if [ "$CURRENT" != "$ORIGIN" ];then
  75. echo "ORIGIN:$FILE"
  76. echo "CURRENT:$(ls -l $line)"
  77. exit 1
  78. fi
  79. done
  80. done
  81. echo "$DIRECTORY" | while read DIR;
  82. do
  83. echo "$DIR" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  84. do
  85. ORIGIN=$(echo "$DIR" | awk '{print $2}' | awk -F '/' '{print $2}' )
  86. CURRENT=$(ls -dl "$line" | awk '{print $4}' )
  87. if [ "$CURRENT" != "$ORIGIN" ];then
  88. echo "$ORIGIN:$DIR"
  89. echo "$CURRENT:$(ls -dl $line)"
  90. exit 1
  91. fi
  92. done
  93. done
  94. ;;
  95. file-hashes)
  96. dpkg-deb -R audit*.deb .
  97. echo "$FILES" | grep "bin/" | while read FILE;
  98. do
  99. echo "$FILE" | awk '{print $6}' | sed -e 's/^.//g' | while read line;
  100. do
  101. ORIGIN=$(sha512sum "$(echo "$line" | sed -e 's/^.\///g')" | awk '{print $1}')
  102. CURRENT=$(sha512sum "$line" | awk '{print $1}')
  103. if [ "$CURRENT" != "$ORIGIN" ];then
  104. echo "ORIGIN:$FILE"
  105. echo "CURRENT:$(ls -l $line)"
  106. exit 1
  107. fi
  108. done
  109. done
  110. ;;
  111. esac