freedombone-base-tripwire 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. echo '*** Installing intrusion detection ***'
  52. debconf-set-selections <<< "tripwire tripwire/use-sitekey boolean false"
  53. debconf-set-selections <<< "tripwire tripwire/use-localkey boolean false"
  54. apt-get -yq install tripwire qrencode
  55. apt-get -yq autoremove
  56. cd /etc/tripwire
  57. echo 'ROOT =/usr/sbin' > /etc/tripwire/twcfg.txt
  58. echo 'POLFILE =/etc/tripwire/tw.pol' >> /etc/tripwire/twcfg.txt
  59. echo 'DBFILE =/var/lib/tripwire/$(HOSTNAME).twd' >> /etc/tripwire/twcfg.txt
  60. echo 'REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr' >> /etc/tripwire/twcfg.txt
  61. echo 'SITEKEYFILE =/etc/tripwire/$(HOSTNAME)-site.key' >> /etc/tripwire/twcfg.txt
  62. echo 'LOCALKEYFILE =/etc/tripwire/$(HOSTNAME)-local.key' >> /etc/tripwire/twcfg.txt
  63. echo 'EDITOR =/usr/bin/editor' >> /etc/tripwire/twcfg.txt
  64. echo 'LATEPROMPTING =false' >> /etc/tripwire/twcfg.txt
  65. echo 'LOOSEDIRECTORYCHECKING =false' >> /etc/tripwire/twcfg.txt
  66. echo 'MAILNOVIOLATIONS =false' >> /etc/tripwire/twcfg.txt
  67. echo 'EMAILREPORTLEVEL =3' >> /etc/tripwire/twcfg.txt
  68. echo 'REPORTLEVEL =3' >> /etc/tripwire/twcfg.txt
  69. echo 'SYSLOGREPORTING =false' >> /etc/tripwire/twcfg.txt
  70. echo 'MAILMETHOD =SENDMAIL' >> /etc/tripwire/twcfg.txt
  71. echo 'MAILPROGRAM =/usr/lib/sendmail -oi -t' >> /etc/tripwire/twcfg.txt
  72. echo 'SMTPHOST =localhost' >> /etc/tripwire/twcfg.txt
  73. echo 'SMTPPORT =25' >> /etc/tripwire/twcfg.txt
  74. echo 'TEMPDIRECTORY =/tmp' >> /etc/tripwire/twcfg.txt
  75. echo 'MAILFROMADDRESS =tripwire@$(HOSTNAME)' >> /etc/tripwire/twcfg.txt
  76. echo '
  77. ' | twadmin --generate-keys -L /etc/tripwire/${HOSTNAME}-local.key -S /etc/tripwire/${HOSTNAME}-site.key
  78. echo '
  79. ' | twadmin --create-cfgfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twcfg.txt
  80. # make a script for easy resetting of the tripwire
  81. echo '#!/bin/sh' > /usr/bin/reset-tripwire
  82. echo 'tripwire -m i' >> /usr/bin/reset-tripwire
  83. chmod +x /usr/bin/reset-tripwire
  84. sed -i '/# These files change the behavior of the root account/,/}/ s/.*//g' /etc/tripwire/twpol.txt
  85. sed -i 's|/etc/rc.boot.*||g' /etc/tripwire/twpol.txt
  86. # Don't show any changes to /proc
  87. sed -i 's|/proc.*||g' /etc/tripwire/twpol.txt
  88. # Don't report log changes
  89. sed -i 's|/var/log.*||g' /etc/tripwire/twpol.txt
  90. # Ignore /etc/tripwire
  91. if ! grep -q '!/etc/tripwire' /etc/tripwire/twpol.txt; then
  92. sed -i '\|/etc\t\t->.*|a\ !/etc/tripwire ;' /etc/tripwire/twpol.txt
  93. fi
  94. # Ignore /etc/freedombone
  95. if ! grep -q '!/etc/freedombone' /etc/tripwire/twpol.txt; then
  96. sed -i '\|/etc\t\t->.*|a\ !/etc/freedombone ;' /etc/tripwire/twpol.txt
  97. fi
  98. # Ignore /etc/pihole
  99. if ! grep -q '!/etc/pihole' /etc/tripwire/twpol.txt; then
  100. sed -i '\|/etc\t\t->.*|a\ !/etc/pihole ;' /etc/tripwire/twpol.txt
  101. fi
  102. # ignore tt-rss cache
  103. if ! grep -q '!/etc/share/tt-rss/cache' /etc/tripwire/twpol.txt; then
  104. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/cache ;' /etc/tripwire/twpol.txt
  105. fi
  106. if ! grep -q '!/etc/share/tt-rss/lock' /etc/tripwire/twpol.txt; then
  107. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/lock ;' /etc/tripwire/twpol.txt
  108. fi
  109. # Not much is in /usr/local/bin other than project commands and avoiding it removes
  110. # problems with updates. This is a tradeoff, but not by much.
  111. sed -i '/\/usr\/local\/bin/d' /etc/tripwire/twpol.txt
  112. # Avoid logging the changed database
  113. sed -i 's|$(TWETC)/tw.pol.*||g' /etc/tripwire/twpol.txt
  114. # site key name
  115. sed -i 's|$(TWETC)/site.key|$(TWETC)/$(HOSTNAME)-site.key|g' /etc/tripwire/twpol.txt
  116. # create the policy
  117. echo '
  118. ' | twadmin --create-polfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twpol.txt
  119. # create the database
  120. echo '
  121. ' | tripwire --init --cfgfile /etc/tripwire/tw.cfg --polfile /etc/tripwire/tw.pol --dbfile /var/lib/tripwire/${HOSTNAME}.twd
  122. if [ ! -f /var/lib/tripwire/${HOSTNAME}.twd ]; then
  123. echo $'tripwire database was not created'
  124. exit 72925
  125. fi
  126. # recreate the configuration
  127. echo '
  128. ' | reset-tripwire
  129. mark_completed $FUNCNAME
  130. }
  131. # NOTE: deliberately no exit 0