ShareWiz Ultra Secure Server Setup

File Security

file

File Security

Check /tmp directory for SUID files

Issue the following command:

sudo find /tmp -perm -4000

The SUID permission causes a script to run as the user who is the owner of the script, rather than the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems. Later versions of the Linux kernel will even prohibit the running of shell scripts that have this attribute set.

The /tmp directory should never have any files with the SETUID bit set. If one is found then the entire system is probably compromised, so additional security checks should be undertaken.

If a file is detected delete it straight away using the command:

sudo rm /tmp/filename

top

Check for world writable SUID files

Issue the following command:

sudo find / -perm -4002 2>/dev/null

The SUID permission causes a script to run as the user who is the owner of the script, rather than the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems. Later versions of the Linux kernel will even prohibit the running of shell scripts that have this attribute set.

There should never be any files that are world writable and have the setuid bit on. If one is found then the entire system is probably compromised, so additional security checks should be undertaken.

If a file is detected delete it straight away using the command:

sudo rm /tmp/filename

top

Check that some Bash files can only be read by root

Issue the following command:

sudo find /etc/master.passwd /etc/shadow /etc/shadow- /etc/gshadow /etc/sudoers /var/log/messages -perm -g+r,o+r 2>/dev/null

These files should never be readable by anyone but root.

top

Find all SUID files

Issue the following command:

sudo find / -perm -4000 2>/dev/null

The SUID permission causes a script to run as the user who is the owner of the script, rather than the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems. Later versions of the Linux kernel will even prohibit the running of shell scripts that have this attribute set.

Files with the setuid bit set are not necessarily evil and can improve your system’s security, however an awfully huge lot of exploits takes advantage of vulnerabilities in setuid files because it is an easy way to escalate privileges especially when exploiting a setuid bit file belonging to root.

Take a very close look at those files and ensure that each one really needs to have the setuid bits on and are known to be secure and stable.

To find SUID files which are owned by root, issue the following command instead:

sudo find / -perm -4000 -user root 2>/dev/null

top

Find all GUID files

Issue the following command:

sudo find / -perm -4000 2>/dev/null

The GUID permission causes a script to run with its group set to the group of the script, rather than the group of the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems. Later versions of the Linux kernel will even prohibit the running of shell scripts that have this attribute set.

setgid folders can be really useful and can improve your system’s security, however an awfully huge lot of exploits takes advantage of vulnerabilities in setgid files because it is an easy way to escalate privileges especially when exploiting a setgid bit file belonging to root.

Take a very close look at those files and ensure that each one really needs to have the setuid bits on and are known to be secure and stable.

To find GUID files which are owned by root, issue the following command instead:

sudo find / -perm -4000 -user root 2>/dev/null

top

Find all World Writable files

Issue the following command:

sudo find / ! -type l -perm -002 2>/dev/null

World writable file owned by root can lead to easy privileges escalation or system corruption.

Take a very close look at those files and ensure that each one really needs to be world writable.

Note: The "! -type l" option is used to avoid to list symlinks (that are described as world writable files).

top

Find all broken Symbolic Links

Issue the following command:

sudo find -L / -type l -maxdepth 8 2>/dev/null

Take a very close look at these links and ensure that each one is really needed.

top

Find all files with Sticky Bit set

Issue the following command:

sudo find / -perm -1000 2>/dev/null

The sticky bit is important. It should always be set on world writable folders to prevent a user from removing a file he doesn’t own.

top

Check that certain directories are not World Writable

Issue the following command:

sudo find /bin /sbin /boot /etc /lib /root /usr ! -type l -perm -002

Certain files should never be world writable or even world readable.

These include the directories /bin, /sbin, /boot, /etc, /lib, /root, /usr. A world writable file in these directories could lead to system trojaning/corruption.

top

Check that World Writable Directories have Sticky Bit set

Issue the following command:

sudo find / -type d -perm -002 ! -perm -1000 2>/dev/null

world writable directories when allowed (such as for /var or /tmp) must have the sticky bit on to prevent unauthorized file deletion.

top

Check that System files are owned by root

Issue the following command:

sudo find /root ! -user root 2>/dev/null

If any files are returned, check why they exist in the /root directory. Only files that actually belong to root should exist in that directory.

Either set the owner of the file to root, or move the file to the correct location, or delete the file.

top

Find files not owned by an existing user

Issue the following command:

sudo find / -nouser 2>/dev/null

Ensure that all files on the system belong to a valid user.

top

Find files not owned by an existing group

Issue the following command:

sudo find / -nogroup 2>/dev/null

Ensure that all files on the system belong to a valid group.

top

Check special files only exist in certain directories

Issue the following command:

sudo find /bin /sbin /lib /boot /etc /home /root /sys /usr /var /tmp /mnt /media /proc -type b -o -type c 2>/dev/null

This should not return any files. If it does then try to determine why. Either move the file elsewhere, or delete it.

top

Check /tmp directory for symlinks

Issue the following command:

sudo find /tmp -type l

Symlinks should also be checked carefully as they are often exploited to gain root privileges.

The presence of a symlink inside the /tmp directory is not dangerous in itself but if that symlink was intentionally created by an attacker to imitate the name of tmp files generated by an insecure program, this symlink could lead to the corruption of a system file or to privilege escalation.

top

Restrict access to dangerous files

Issue the following commands:

sudo chmod 700 /bin/ping

sudo chmod 700 /usr/bin/who

sudo chmod 700 /usr/bin/w

sudo chmod 700 /usr/bin/locate

sudo chmod 700 /usr/bin/whereis

sudo chmod 700 /sbin/ifconfig

sudo chmod 700 /bin/nano

sudo chmod 700 /usr/bin/vi

sudo chmod 700 /usr/bin/which

sudo chmod 700 /usr/bin/gcc

sudo chmod 700 /usr/bin/make

sudo chmod 700 /usr/bin/apt-get

sudo chmod 700 /usr/bin/aptitude

top

Setup File Integrity Monitoring

Install the AIDE file integrity package as per the AIDE Configuration Standards document:

The Advanced Intrusion Detection Environment (AIDE) is a free replacement for the popular file integrity verification tool known as Tripwire. It creates a database from regular expression rules that it finds in a configuration file. Once this database is initialized, it can be used to verify the integrity of critical system and user files.

top Install iWatch -> http://iwatch.sourceforge.net/documentation.html

Continue to the Active Directory Security...