freedombone-base-tripwire 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Intrusion detection application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. function backup_local_tripwire {
  31. echo -n ''
  32. }
  33. function backup_remote_tripwire {
  34. echo -n ''
  35. }
  36. function remove_tripwire {
  37. if ! grep -Fxq "tripwire" $COMPLETION_FILE; then
  38. return
  39. fi
  40. apt-get -yq remove --purge tripwire
  41. if [ -d /etc/tripwire ]; then
  42. rm -rf /etc/tripwire
  43. fi
  44. rm /usr/bin/reset-tripwire
  45. sed -i '/tripwire/d' $COMPLETION_FILE
  46. }
  47. function install_tripwire {
  48. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  49. return
  50. fi
  51. apt-get -yq install tripwire
  52. apt-get -yq autoremove
  53. cd /etc/tripwire
  54. cp site.key $DEFAULT_DOMAIN_NAME-site.key
  55. echo '*** Installing intrusion detection ***'
  56. echo '
  57. ' | tripwire --init
  58. # make a script for easy resetting of the tripwire
  59. echo '#!/bin/sh' > /usr/bin/reset-tripwire
  60. echo 'tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt' >> /usr/bin/reset-tripwire
  61. chmod +x /usr/bin/reset-tripwire
  62. sed -i 's/SYSLOGREPORTING.*/SYSLOGREPORTING =false/g' /etc/tripwire/twcfg.txt
  63. # only send emails if something has changed
  64. sed -i 's|MAILNOVIOLATIONS.*|MAILNOVIOLATIONS = false|g' /etc/tripwire/twcfg.txt
  65. sed -i '/# These files change the behavior of the root account/,/}/ s/.*//g' /etc/tripwire/twpol.txt
  66. sed -i 's|/etc/rc.boot.*||g' /etc/tripwire/twpol.txt
  67. # Don't show any changes to /proc
  68. sed -i 's|/proc.*||g' /etc/tripwire/twpol.txt
  69. # Don't report log changes
  70. sed -i 's|/var/log.*||g' /etc/tripwire/twpol.txt
  71. # Ignore /etc/tripwire
  72. if ! grep -q '!/etc/tripwire' /etc/tripwire/twpol.txt; then
  73. sed -i '\|/etc\t\t->.*|a\ !/etc/tripwire ;' /etc/tripwire/twpol.txt
  74. fi
  75. # ignore tt-rss cache
  76. if ! grep -q '!/etc/share/tt-rss/cache' /etc/tripwire/twpol.txt; then
  77. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/cache ;' /etc/tripwire/twpol.txt
  78. fi
  79. if ! grep -q '!/etc/share/tt-rss/lock' /etc/tripwire/twpol.txt; then
  80. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/lock ;' /etc/tripwire/twpol.txt
  81. fi
  82. # Avoid logging the changed database
  83. sed -i 's|$(TWETC)/tw.pol.*||g' /etc/tripwire/twpol.txt
  84. # recreate the configuration
  85. echo '
  86. ' | twadmin --create-cfgfile -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt
  87. # reset
  88. echo '
  89. ' | reset-tripwire
  90. mark_completed $FUNCNAME
  91. }
  92. # NOTE: deliberately no exit 0