LINUX SECURITY QUICK REFERENCE Controlling File Permissions & Attributes:
Monitoring the permissions on system files is crucial to maintain host integrity.
• Regularly audit your systems for any unauthorized and unnecessary use of the setuid or setgid permissions. “Set-user-ID root” programs run as the root user, regardless of who is executing them, and are a frequent cause of buffer overflows. Many programs are setuid and setgid to enable a normal user to perform operations that would otherwise require root, and can be removed if your users do not need such permission. Find all setuid and setgid programs on your host and descriminately remove the setuid or setgid permissions on a suspicious program with chmod:
root# find / -type f -perm +6000 -ls
59520 30 -rwsr-xr-x 1 root root 30560 Apr 15 1999 /usr/bin/chage
59560 16 -r-sr-sr-x 1 root lp 15816 Jan 6 2000 /usr/bin/lpq
root# chmod -s /usr/bin/chage /usr/bin/lpq
root# ls -l /usr/bin/lpq /usr/bin/chage
-rwxr-xr-x 1 root root 30560 Apr 15 1999 /usr/bin/chage
-r-xr-xr-x 1 root lp 15816 Jan 6 2000 /usr/bin/lpq
• World-writable files are easily altered or removed. Locate all world-writable files on your system:
root# find / -perm -2 ! -type l -ls
In the normal course of operation, several files will be world-writable, including some from /dev and the /tmp directory itself.
• Locate and identify all files that do not have an owner or belong to a group. Unowned files may also be an indication an intruder has accessed your system.
root# find / -nouser -o -nogroup
• Using the lsattr and chattr commands, administrators can modify characteristics of files and directories, including the ability to control deletion and modification above what normal chmod
provides. The use of “append-only” and “immutable” attributes can be particularly effective in preventing log files from being deleted, or Trojan Horses from being placed on top of trusted
binaries. While not a guarantee a system file or log won’t be modified, only root has the ability to remove this protection. The chattr command is used to add or remove these properties, while the lsattr can be used to list them.
Log files can be protected by only permitting appending to them. Once the data has been written, it cannot be removed. While this will require modifications to your log rotation scripts, this can provide additional protection from a cracker attempting to remove his tracks. Once rotated, they should be changed to immutable. Files suitable for these modifications include /bin/login, /bin/rpm,
/etc/shadow, and others that should not change frequently.
# chattr +i /bin/login
# chattr +a /var/log/messages
# lsattr /bin/login /var/log/messages
----i--- /bin/login
-----a-- /var/log/messages
• There should never be a reason for user’s to be able to run setuid programs from their home directories. Use the nosuid option in /etc/fstab for partitions that are writable by others than root. You may also wish to use the nodev and noexec on user’s home partitions, as well as /var, which prohibits execution of programs, and creation of character or block devices, which should never be necessary anyway. See the mount man page for more information.
Disable Unnecessary Services:
Disabling or removing unused programs and services from your host is the most effective way to limit threats originating from a remote host. Use your distributions package management tools to scan the list of installed packages, then remove those that are unnecessary.
• Many of the services running from inetd are legacy programs, which are hardly ever required, yet typically enabled by default. The file /etc/inetd.conf is used to specify which services are offered. Disable all services that you do not want to provide by commenting them out using the # character in the first column of the line.
• The /etc/rc*.d or /etc/rc.d/rc* directories contains shell scripts that control the execution of network and system services during runlevels. Rename or otherwise disable any that are not required or remove the package entirely. RedHat users can use /sbin/chkconfig --list to list which services run in which
runlevel, and /sbin/chkconfig --del <name> to disable a service.
If you don’t understand what a particular service does, disable it until you find out. Use netstat and ps to confirm they have not been started after a reboot. Use /bin/netstat -a -p --inet to determine which are available and the process ID associated with them. A port scanner should also be used to get a view of what remote hosts see.
Checking Package Integrity:
The md5sum command is used to compute a 128-bit fingerprint that is strongly dependant upon the contents of the file to which it is applied. It can be used to compare against a previously-generated sum to determine whether the file has changed. It is commonly used to ensure the integrity of updated packages distributed by a vendor:
# md5sum package-name
995d4f40cda13eacd2beaf35c1c4d5c2 package-name
The string of numbers can then be compared against the MD5 checksum published by the packager. While it does not take into account the possibility that the same person that may have modified a package also may have modified the published checksum, it is especially useful for establishing a great deal of assurance in the integrity of a package before installing it
Install and Configure OpenSSH:
OpenSSH is a replacement for telnet and ftp that eliminates eavesdropping, connection hijacking, and encrypts all communication between hosts. One of the most indepensible free security tools in existence.
• Install the OpenSSH and OpenSSL Packages:
openssh-<current-version>.rpm
openssh-server-<current-version>.rpm
openssh-clients-<current-version>.rpm
openssl-<current-version>.rpm
• Generate Public/Private Key Pair:
OpenSSH uses public key cryptography to provide secure authorization. Generating the public key, which is shared with remote systems, and the private key which is kept on the local system, is done first to configure OpenSSH.
orion$ ssh-keygen
Generating RSA keys: ...ooooooO... .ooooooO
Key generation complete.
Enter file in which to save the key (/home/dave/.ssh/identity): Created directory '/home/dave/.ssh'.
Enter passphrase (empty for no passphrase): <passphrase> Enter same passphrase again: <passphrase>
Your identification has been saved in /home/dave/.ssh/identity. Your public key has been saved in /home/dave/.ssh/identity.pub. The key fingerprint is:
ac:42:11:c8:0d:b6:7e:b4:06:6a:a3:a7:e8:2c:b0:12 dave@orion
• Copy Public Key to Remote Host:
host2 $ mkdir -m 700 ~dave/.ssh
host2 $ cp /mnt/floppy/identity.pub ~dave/.ssh/authorized_keys
• Log in to Remote Host:
The SSH client (/usr/bin/ssh) is a drop-in replacement for rlogin and rsh. It can be used to securely login to a remote host:
orion$ ssh host2
Enter passphrase for RSA key 'dave@orion': <passphrase>
Last login: Sat Aug 15 17:13:01 2000 from orion
No mail.
host2 $
• Copy Files to Remote Host:
The OpenSSH package also includes scp, a secure and improved replacement for rcp. This allows you to securely copy files over a network.
orion$ scp /tmp/file.tar.gz host2:/tmp
Enter passphrase for RSA key 'dave@orion:
file.tar.gz 100% |*** ***| 98304 00:00
It is also possible to encapsulate ordinarily insecure protocols such as IMAP and
POP within SSH to prevent transmitting clear text passwords to your mail server. Additionally, the rsync incremental file transfer utility can use SSH to securely synchronize two hosts or backup data to a log server securely. SSH can even be used to securely connect two subnets across the Internet, effectively creating a
virtual private network. Disable remote root logins and emtpy password ability.
Bài viết cùng chủ đề: