| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,165 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+/** |
|
| 4 |
+ * "System Health and Security Probe" is a program that runs periodically to |
|
| 5 |
+ * investigate general system health and security problems and to send report |
|
| 6 |
+ * emails to admins. It's designed to be used as part of RED SCARF Suite. |
|
| 7 |
+ * It requires at least an abridged version of RED SCARF Suite and Postfix, |
|
| 8 |
+ * installed and configured on a Debian server as described in the "Complete |
|
| 9 |
+ * Guide to a Complete Linux Server". For more details, please see the |
|
| 10 |
+ * "README.txt" file. |
|
| 11 |
+ * |
|
| 12 |
+ * Copyright (C) 2024 Double Bastion LLC <www.doublebastion.com> |
|
| 13 |
+ * |
|
| 14 |
+ * This file is part of "System Health and Security Probe". |
|
| 15 |
+ * |
|
| 16 |
+ * "System Health and Security Probe" is free software: you can redistribute |
|
| 17 |
+ * it and/or modify it under the terms of the GNU General Public License as |
|
| 18 |
+ * published by the Free Software Foundation, either version 3 of the License, |
|
| 19 |
+ * or (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 General Public License for more details. |
|
| 25 |
+ * |
|
| 26 |
+ * You should have received a copy of the GNU General Public License |
|
| 27 |
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 28 |
+ */ |
|
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+ |
|
| 32 |
+/**** Edit each parameter value between double quotes ****/ |
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+/** Set the timespan in hours between two consecutive runs of the script (the "run interval"). **/ |
|
| 36 |
+ |
|
| 37 |
+// IMPORTANT !!! The ban time in seconds set for every jail in '/etc/fail2ban/jail.local', |
|
| 38 |
+// must be greater than the run interval that you set below. Also, in '/etc/fail2ban/jail.local' |
|
| 39 |
+// it's necessary to specify a ban time for every jail, even for the jails that use the default ban |
|
| 40 |
+// time. Therefore, in every jail block a 'bantime' parameter (Eg.: bantime = 432000) should exist. |
|
| 41 |
+// |
|
| 42 |
+// IMPORTANT !!! If you change the run interval here, don't forget to change the cron job accordingly. |
|
| 43 |
+// To run the script every 8 hours, at 5 minutes past, the cron job should be: |
|
| 44 |
+// 5 */8 * * * php /srv/scripts/system-health-and-security-probe.php > /dev/null 2>&1 |
|
| 45 |
+ |
|
| 46 |
+$time_in_hours = "8"; |
|
| 47 |
+ |
|
| 48 |
+ |
|
| 49 |
+/** Set the database name, user and password (they shouldn't contain double quotes). **/ |
|
| 50 |
+ |
|
| 51 |
+$db_name = ""; |
|
| 52 |
+$db_user = ""; |
|
| 53 |
+$db_password = ""; |
|
| 54 |
+ |
|
| 55 |
+ |
|
| 56 |
+/** Set the sender's email address, the recipient's email address and the subject line, for the email reports. **/ |
|
| 57 |
+ |
|
| 58 |
+// For multiple recipients write all the email addresses separated by comma, like this: $report_to = "admin1@example1.com,admin2@example2.info,admin3@example3.org". |
|
| 59 |
+ |
|
| 60 |
+$report_from = ""; |
|
| 61 |
+$report_to = ""; |
|
| 62 |
+$report_subject = ""; |
|
| 63 |
+ |
|
| 64 |
+ |
|
| 65 |
+/** Set the log paths for the services monitored by Fail2ban. **/ |
|
| 66 |
+ |
|
| 67 |
+// For WordPress, you can specify multiple log files, separated by commas, like this: |
|
| 68 |
+// wordpresslog = "/var/log/sites/example.com/access.log, /var/log/sites/secondsite.net/access.log, /var/log/sites/thirdsite.info/access.log |
|
| 69 |
+ |
|
| 70 |
+$phpmyadmin_log = ""; |
|
| 71 |
+$mailman_log = ""; |
|
| 72 |
+$dolibarr_log = ""; |
|
| 73 |
+$phplist_log = ""; |
|
| 74 |
+$roundcube_log = ""; |
|
| 75 |
+$matomo_log = ""; |
|
| 76 |
+$looladmin_log = ""; |
|
| 77 |
+$postfix_admin_log = ""; |
|
| 78 |
+$roundpin_log = ""; |
|
| 79 |
+$mybb_log = ""; |
|
| 80 |
+$friendica_log = ""; |
|
| 81 |
+$redscarfsuite_panel_log = ""; |
|
| 82 |
+$wordpress_log = ""; |
|
| 83 |
+ |
|
| 84 |
+// The following are standard log paths. If you haven't changed them to some custom paths, leave them as they are. |
|
| 85 |
+ |
|
| 86 |
+$asterisk_log = "/var/log/asterisk/messages"; |
|
| 87 |
+$bind_log = "/var/log/named/security.log"; |
|
| 88 |
+$nextcloud_log = "/var/log/nextcloud/nextcloud.log"; |
|
| 89 |
+$dovecot_log = "/var/log/mail.log"; |
|
| 90 |
+$postfix_log = "/var/log/mail.log"; |
|
| 91 |
+$postfix_sasl_log = "/var/log/mail.log"; |
|
| 92 |
+$proftpd_log = "/var/log/proftpd/proftpd.log"; |
|
| 93 |
+$sshd_log = "/var/log/auth.log"; |
|
| 94 |
+$openvpn_log = "/var/log/openvpn/openvpn.log"; |
|
| 95 |
+ |
|
| 96 |
+ |
|
| 97 |
+/** Set the threshold for the disk free space in kibibytes. **/ |
|
| 98 |
+ |
|
| 99 |
+// If the free disk space becomes smaller than the threshold, it will be included in the email report as a system health problem. The default is 3145728 kibibytes (3 GiB). |
|
| 100 |
+ |
|
| 101 |
+$disk_threshold = "3145728"; |
|
| 102 |
+ |
|
| 103 |
+ |
|
| 104 |
+/** Set the directory where the ClamAV antivirus will store the two periodic scan reports: 'clamav_mail_report' and 'clamav_nextcloud_report'. **/ |
|
| 105 |
+ |
|
| 106 |
+// If you change the default directory, which is '/srv/scripts/detections', remember to enter the same directory in the two cronjobs that have to be set up, to tell ClamAV where |
|
| 107 |
+// to store the scan reports. When using the default directory (/srv/scripts/detections) the two cronjobs should look like this: |
|
| 108 |
+// 5 3 */3 * * cat /dev/null > /srv/scripts/detections/clamav_nextcloud_report && clamdscan --fdpass --quiet /var/www/cloud.example.com/data -l /srv/scripts/detections/clamav_nextcloud_report |
|
| 109 |
+// 40 3 */3 * * cat /dev/null > /srv/scripts/detections/clamav_mail_report && clamdscan --fdpass --quiet /var/vmail -l /srv/scripts/detections/clamav_mail_report |
|
| 110 |
+ |
|
| 111 |
+// The two sample cronjobs from above will first erase the previous detections in the '/srv/scripts/detections/clamav_nextcloud_report' and '/srv/scripts/detections/clamav_mail_report' |
|
| 112 |
+// files and then get ClamAV to scan the Nextcloud 'data' directory and 'vmail' directory and store the new detections in the mentioned files, at 3:05 a.m. and 3:40 a.m. respectively, |
|
| 113 |
+// once every three days. Adjust these cron jobs according to your needs. |
|
| 114 |
+ |
|
| 115 |
+$clamav_report_dir = "/srv/scripts/detections"; |
|
| 116 |
+ |
|
| 117 |
+ |
|
| 118 |
+/** Set the backup directory where the current database will be saved when the number of rows of the 'bannedipstable' table will exceed 100000000. **/ |
|
| 119 |
+ |
|
| 120 |
+// After the current database is saved, the oldest 5000000 records of the 'bannedipstable' table will be trimmed. |
|
| 121 |
+ |
|
| 122 |
+$backup_directory = "/srv/shas-probe-db-backup"; |
|
| 123 |
+ |
|
| 124 |
+ |
|
| 125 |
+/** Specify if the script will send automatic abuse report emails to the Internet Service Providers (ISPs) of the offending IPs. **/ |
|
| 126 |
+ |
|
| 127 |
+// The default is "no". If you want 'System Health and Security Proble' to automatically send the abuse report emails (also included in the periodic email report sent to the admin) |
|
| 128 |
+// to the ISPs of the offensing IPs, when the offending IPs have been banned more than once, each time the number of bans increases by 1, change "no" to "yes". |
|
| 129 |
+ |
|
| 130 |
+$automatic_emails_to_isp = "yes"; |
|
| 131 |
+ |
|
| 132 |
+ |
|
| 133 |
+/** If the preceding "$automatic_emails_to_isp" parameter is set to "yes", specify the list of log parameters separated by commas, that you want to exclude from the automatic emails |
|
| 134 |
+ sent to the Internet Service Providers of the offending IPs. You can take any log parameter from the "Set the log paths for the services monitored by Fail2ban." section from |
|
| 135 |
+ above. **/ |
|
| 136 |
+ |
|
| 137 |
+// If you list a log parameter below, the automatic abuse report emails will NOT be sent to the ISPs of the offending IPs that attacked the corresponding jail. It's recommended to |
|
| 138 |
+// list here all the log parameters for which the log entries may contain usernames for HTTP authentication or other sensitive data that you don't want included in emails |
|
| 139 |
+// automatically sent to ISPs. Thus, add or remove any log parameter to/from the list from below. |
|
| 140 |
+ |
|
| 141 |
+$excluded_jails = [$phpmyadmin_log, $wordpress_log, $roundcube_log, $dolibarr_log]; |
|
| 142 |
+ |
|
| 143 |
+ |
|
| 144 |
+/** If the "$automatic_emails_to_isp" parameter from above is set to "yes", specify the list of IPs, separated by commas, that you want to exclude from the list of IPs for which the |
|
| 145 |
+ abuse email will be automatically sent to the Internet Service Providers. **/ |
|
| 146 |
+ |
|
| 147 |
+$excluded_ips = ""; |
|
| 148 |
+ |
|
| 149 |
+ |
|
| 150 |
+/** If the "$automatic_emails_to_isp" parameter from above is set to "yes", specify the sysadmin name that will appear in the signature of the emails sent to ISPs. **/ |
|
| 151 |
+ |
|
| 152 |
+// Eg: $sysadmin_name = "John"; |
|
| 153 |
+ |
|
| 154 |
+$sysadmin_name = ""; |
|
| 155 |
+ |
|
| 156 |
+ |
|
| 157 |
+/** If the "$automatic_emails_to_isp" parameter from above is set to "yes", specify if you want the recipient of the email reports (the "$report_to" address from above) to receive |
|
| 158 |
+ copies of all the abuse reports sent to the ISPs of the offending IPs. **/ |
|
| 159 |
+ |
|
| 160 |
+// The default is "no". If you want the "$report_to" address(es) to receive, in addition to the regular email reports, copies of the abuse reports sent to the ISPs of the IPs that |
|
| 161 |
+// attacked the server and have been banned more than once, change "no" to "yes". |
|
| 162 |
+ |
|
| 163 |
+$abuse_reports_to_admin = "yes"; |
|
| 164 |
+ |
|
| 165 |
+?> |
|
| 0 | 166 |
\ No newline at end of file |