freedombone-base-tripwire 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Intrusion detection application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. function backup_local_tripwire {
  29. echo -n ''
  30. }
  31. function backup_remote_tripwire {
  32. echo -n ''
  33. }
  34. function remove_tripwire {
  35. if ! grep -Fxq "tripwire" "$COMPLETION_FILE"; then
  36. return
  37. fi
  38. apt-get -yq remove --purge tripwire
  39. if [ -d /etc/tripwire ]; then
  40. rm -rf /etc/tripwire
  41. fi
  42. rm /usr/bin/reset-tripwire
  43. sed -i '/tripwire/d' "$COMPLETION_FILE"
  44. }
  45. function install_tripwire {
  46. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  47. return
  48. fi
  49. echo '*** Installing intrusion detection ***'
  50. debconf-set-selections <<< "tripwire tripwire/use-sitekey boolean false"
  51. debconf-set-selections <<< "tripwire tripwire/use-localkey boolean false"
  52. apt-get -yq install tripwire qrencode
  53. apt-get -yq autoremove
  54. cd /etc/tripwire || exit 246852845
  55. { echo 'ROOT =/usr/sbin';
  56. echo 'POLFILE =/etc/tripwire/tw.pol';
  57. echo "DBFILE =/var/lib/tripwire/\$(HOSTNAME).twd";
  58. echo "REPORTFILE =/var/lib/tripwire/report/\$(HOSTNAME)-\$(DATE).twr";
  59. echo "SITEKEYFILE =/etc/tripwire/\$(HOSTNAME)-site.key";
  60. echo "LOCALKEYFILE =/etc/tripwire/\$(HOSTNAME)-local.key";
  61. echo 'EDITOR =/usr/bin/editor';
  62. echo 'LATEPROMPTING =false';
  63. echo 'LOOSEDIRECTORYCHECKING =false';
  64. echo 'MAILNOVIOLATIONS =false';
  65. echo 'EMAILREPORTLEVEL =3';
  66. echo 'REPORTLEVEL =3';
  67. echo 'SYSLOGREPORTING =false';
  68. echo 'MAILMETHOD =SENDMAIL';
  69. echo 'MAILPROGRAM =/usr/lib/sendmail -oi -t';
  70. echo 'SMTPHOST =localhost';
  71. echo 'SMTPPORT =25';
  72. echo 'TEMPDIRECTORY =/tmp';
  73. echo "MAILFROMADDRESS =tripwire@\$(HOSTNAME)"; } > /etc/tripwire/twcfg.txt
  74. echo '
  75. ' | twadmin --generate-keys -L "/etc/tripwire/${HOSTNAME}-local.key" -S "/etc/tripwire/${HOSTNAME}-site.key"
  76. echo '
  77. ' | twadmin --create-cfgfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twcfg.txt
  78. # make a script for easy resetting of the tripwire
  79. echo '#!/bin/sh' > /usr/bin/reset-tripwire
  80. echo 'tripwire -m i' >> /usr/bin/reset-tripwire
  81. chmod +x /usr/bin/reset-tripwire
  82. sed -i '/# These files change the behavior of the root account/,/}/ s/.*//g' /etc/tripwire/twpol.txt
  83. sed -i 's|/etc/rc.boot.*||g' /etc/tripwire/twpol.txt
  84. # Don't show any changes to /proc
  85. sed -i 's|/proc.*||g' /etc/tripwire/twpol.txt
  86. # Don't report log changes
  87. sed -i 's|/var/log.*||g' /etc/tripwire/twpol.txt
  88. # Ignore /etc/tripwire
  89. if ! grep -q '!/etc/tripwire' /etc/tripwire/twpol.txt; then
  90. sed -i '\|/etc\t\t->.*|a\ !/etc/tripwire ;' /etc/tripwire/twpol.txt
  91. fi
  92. # Ignore /etc/freedombone
  93. if ! grep -q '!/etc/freedombone' /etc/tripwire/twpol.txt; then
  94. sed -i '\|/etc\t\t->.*|a\ !/etc/freedombone ;' /etc/tripwire/twpol.txt
  95. fi
  96. # Ignore /etc/pihole
  97. if ! grep -q '!/etc/pihole' /etc/tripwire/twpol.txt; then
  98. sed -i '\|/etc\t\t->.*|a\ !/etc/pihole ;' /etc/tripwire/twpol.txt
  99. fi
  100. # ignore tt-rss cache
  101. if ! grep -q '!/etc/share/tt-rss/cache' /etc/tripwire/twpol.txt; then
  102. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/cache ;' /etc/tripwire/twpol.txt
  103. fi
  104. if ! grep -q '!/etc/share/tt-rss/lock' /etc/tripwire/twpol.txt; then
  105. sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/lock ;' /etc/tripwire/twpol.txt
  106. fi
  107. # ignore global node modules
  108. if ! grep -q '!/usr/local/lib/node_modules' /etc/tripwire/twpol.txt; then
  109. sed -i '\|/etc\t\t->.*|a\ !/usr/local/lib/node_modules ;' /etc/tripwire/twpol.txt
  110. fi
  111. if ! grep -q '!/root/.npm-global/lib/node_modules' /etc/tripwire/twpol.txt; then
  112. sed -i '\|/etc\t\t->.*|a\ !/root/.npm-global/lib/node_modules ;' /etc/tripwire/twpol.txt
  113. fi
  114. # Events here are likely due to USB HRNG activity
  115. if ! grep -q '!/dev/char' /etc/tripwire/twpol.txt; then
  116. sed -i '\|/dev\t\t->.*|a\ !/dev/char ;' /etc/tripwire/twpol.txt
  117. fi
  118. if ! grep -q '!/dev/bus/usb' /etc/tripwire/twpol.txt; then
  119. sed -i '\|/dev\t\t->.*|a\ !/dev/bus/usb ;' /etc/tripwire/twpol.txt
  120. fi
  121. # Not much is in /usr/local/bin other than project commands and avoiding it removes
  122. # problems with updates. This is a tradeoff, but not by much.
  123. sed -i '/\/usr\/local\/bin/d' /etc/tripwire/twpol.txt
  124. # Avoid logging the changed database
  125. sed -i "s|\$(TWETC)/tw.pol.*||g" /etc/tripwire/twpol.txt
  126. # site key name
  127. sed -i "s|\$(TWETC)/site.key|\$(TWETC)/\$(HOSTNAME)-site.key|g" /etc/tripwire/twpol.txt
  128. # create the policy
  129. echo '
  130. ' | twadmin --create-polfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twpol.txt
  131. mark_completed "${FUNCNAME[0]}"
  132. }
  133. # NOTE: deliberately no exit 0