業務用エアコン関連の技術情報、エラーコード、環境問題対策に関する別サイト「エアコンの安全な修理・適切なフロン回収」

AlmaLinux9.7 : Tripwire , Chkrootkit, Logwatch , DNS Update, Disk Usage Check Script

Tripwire

1.Install

2.Passphrase setting

Set site passphrase and local passphrase

------------------------------------------------
The Tripwire site and local passphrases are used to sign a variety of
files, such as the configuration, policy, and database files.

Passphrases should be at least 8 characters in length and contain both
letters and numbers.

See the Tripwire manual for more information.
------------------------------------------------
Creating key files…

(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

Enter the site keyfile passphrase: [site pass]
Verify the site keyfile passphrase: [site pass]
Generating key (this may take several minutes)…Key generation complete.

(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

Enter the local keyfile passphrase: [local pass]
Verify the local keyfile passphrase: [local pass]
Generating key (this may take several minutes)…Key generation complete.

------------------------------------------------
Signing configuration file…
Please enter your site passphrase: [site pass]
Wrote configuration file: /etc/tripwire/tw.cfg

A clear-text version of the Tripwire configuration file:
/etc/tripwire/twcfg.txt
has been preserved for your inspection. It is recommended that you
move this file to a secure location and/or encrypt it in place (using a
tool such as GPG, for example) after you have examined it.

------------------------------------------------
Signing policy file…
Please enter your site passphrase: [site pass]
Wrote policy file: /etc/tripwire/tw.pol

A clear-text version of the Tripwire policy file:
/etc/tripwire/twpol.txt
has been preserved for your inspection. This implements a minimal
policy, intended only to test essential Tripwire functionality. You
should edit the policy file to describe your system, and then use
twadmin to generate a new signed copy of the Tripwire policy.

Once you have a satisfactory Tripwire policy file, you should move the
clear-text version to a secure location and/or encrypt it in place
(using a tool such as GPG, for example).

Now run "tripwire --init" to enter Database Initialization Mode. This
reads the policy file, generates a database based on its contents, and
then cryptographically signs the resulting database. Options can be
entered on the command line to specify which policy, configuration, and
key files are used to create the database. The filename for the
database can be specified as well. If no options are specified, the
default values from the current configuration file are used.

3.Tripwire Configuration

Configuration File Edit

Create a Tripwire configuration file (cryptographically signed version)

Delete Tripwire configuration file (text version)

Policy File Settings

Contents of twpolmake.pl

Policy File Optimizations

Create policy file (cryptographically signed version) based on optimized policy file

Create database and check operation

Create test files

Check Tripwire operation

If it displays as shown below, it's OK.

Delete test files

⑧Create a script for reporting results via email

Contents of tripwire.sh

#!/bin/bash

PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin

#Passphrase Setup
LOCALPASS=xxxxx # local pass
SITEPASS=xxxxx # site pass

#Specify notification email address
MAIL="[your mail address] "

cd /etc/tripwire

#Tripwire Check Execution
tripwire -m c -s -c tw.cfg|mail -s "Tripwire(R) Integrity Check Report in `hostname`" $MAIL

#Policy File Update
twadmin -m p -c tw.cfg -p tw.pol -S site.key > twpol.txt
perl twpolmake.pl twpol.txt > twpol.txt.new
twadmin -m P -c tw.cfg -p tw.pol -S site.key -Q $SITEPASS twpol.txt.new > /dev/null
rm -f twpol.txt* *.bak

#Database Update
rm -f /usr/local/tripwire/lib/tripwire/*.twd*
tripwire -m i -s -c tw.cfg -P $LOCALPASS

Confirmation that the results of the tripwire execution are notified to the specified e-mail address

Chkrootkit

Install the rootkit detection tool chkrootkit to check whether a rootkit has been installed on the Linux server.
Since chkrootkit performs checks using the following command, it becomes ineffective if the command itself has been tampered with by a rootkit. Therefore, it is advisable to install it during the initial stages after Linux installation.

【Commands used by chkrootkit】
awk, cut, echo, egrep, find, head, id, ls, netstat, ps, strings, sed, uname

Note that chkrootkit can only detect known rootkits and cannot detect new rootkits.

Download and install chkrootkit

Create /root/bin directory and move chkrootkit command to that directory

Check chkrootkit.

Create chkrootkit periodic execution script and change permissions

Scheduled Script Contents

Add execution permission to chkrootkit execution script

Backup commands used by chkrootkit

If the commands used by chkrootkit are tampered with, rootkit will not be detected.
Back up these commands.
If necessary, run chkrootkit with the backed up command

Run chkrootkit on the copied command

If nothing is displayed, no problem.

Compresses backed up commands

Send chkrootkit use command (compressed version) to root by e-mail

Download and save chkrootkit_cmd.tar.gz file to Windows

Delete commands on the backed up server

Logwatch

①Install

Edit configuration file

Output Logwatch reports

It will appear as follows

Test to see if the report arrives at the address you set. Check if you receive a log report email like the one above.

DNS Update

Whenever the internet connection is lost or the router reboots, causing the global IP address to change, you must access the dynamic DNS service to notify it of the IP address change.

Create a dedicated Python file and schedule it for regular execution via Cron.
This time, it's about DNS settings on Valudomain.

Contents of ddnset.py

IP Address Log File Creation

Run periodically

Introduce disk usage check script

1.Script Creation

Contents of disk_capacity_check.sh

2. Execution Confirmation

①Check current usage rates

It appears as follows

②Create a dummy file to achieve at least 80% utilization(In the example, a file named dummyfile with a size of about 6GB)

③check again
Verify that it is at least 80% by performing the following:

④Run check scripts

You will receive an email to the email address you have set up, stating something like "Disk usage alert: 86 %".

⑤Delete "dummyfile"

⑥Periodic Execution Setting

Copied title and URL