Corning Community College
UNIX/Linux Fundamentals
Case Study 0xB: Groups and Security
~~TOC~~
To become familiar with groups and some security aspects of the UNIX system.
Security plays an important part in the usage of an operating system. The ability to allow and deny acceptable parties access to information sets up an important hierarchy that is vital to any multi-user system.
Earlier in our journeys, you discovered there were directories on the system that you could not access (namely /root), and yet others that you had limited access (/lost+found).
Let's examine /root:
lab46:~$ ls -ld /root drwx------ 9 root root 4096 Nov 19 17:07 root lab46:~$
That means the owner of the directory (root), has permission to read, write, and execute/search.
The group and anyone else on the system has no permissions whatsoever. So when you (as a regular and non-root user), try to change into the /root directory, you get the message:
lab46:~$ cd /root -bash: cd: /root: Permission denied lab46:~$
Being a multi-user system, wouldn't it be troublesome if everyone had the same amount of access to the machine? A disgruntled user could delete another user's files, or any sort of evil task.
Thankfully, UNIX uses a hierarchy to separate the powers of system-level and user-level access. There is a priviledged, or Super User, account, and then there are regular users.
So for those who do not already know: root is the Super User on the system. That user has complete control over the resources available through the operating system. This is why the administrator of a system possesses this account.
The UNIX filesystem also provides a means of permissions, as we've seen in prior labs. The distinction of user, group, and other provides three different tiers of access.
This is a big reason why viruses are generally non-existant on UNIX- if a regular user gets “infected” with a malicious program, it can only infect the files owned by that user. So long as root doesn't get infected the problem remains generally restricted.
root is not a Super User just because of its name. UNIX relies on a numeric value that represents the user- the operating system simply translates the number into a name so that you don't have to deal with a number.
These numbers are the User ID (UID) and Group ID (GID). In the same fashion as the PID (Process ID) for running processes on the system, the operating system deals with numbers.
The /etc/passwd file contains all the crucial information for determining this information. It is a central file that houses all the user configuration information* for a UNIX system.
NOTE: Traditionally, the encrypted user passwords were also stored in this file. Over time, however, it was realized that this was generally a bad idea, and alternative schemes were developed. One common scheme is what are known as Shadow Passwords, where the encrypted password is stored in /etc/shadow, and that file is inaccessible to non-priviledged users.
A typical line out of the /etc/passwd files is as follows:
username:x:1234:1234:Joe User,,,:/home/students/username:/bin/bash
Each field is delimited by a colon (:). The fields are designated as follows:
1. | Locate the following information: | |
---|---|---|
a. | What are the permissions on your home directory? Show me how you found this. | |
b. | What is your User ID (UID)? How did you determine this? | |
c. | What is your Group ID (GID)? Show me how you found this. | |
d. | What is the name of the default Super User/Administrator account on the system? | |
e. | What is that user's UID and GID? How did you find this? |
When you create a file on a UNIX system, it creates a file with full permissions:
This would pose a problem if left unchecked– forgetful users would have files accessible (both readable and writable) to anyone else on the system. This would not be a desirable thing at all.
Luckily, there exists a mechanism to take care of this. It is known as the un-mask, or umask.
umask takes away permissions from the default file mask. Its actual operation can be explained with binary logic. You take the umask value, invert it, then proceed to AND it with the file mask:
apply the umask to the file mask by a Bitwise-AND:
110 110 110 AND 111 101 101 ----------- 110 100 100
Remember that with an AND, both values must be TRUE (or 1) for the result to be 1.
The final result: 110 100 100 = 644. This same result can be obtained by subtracting the umask from the file mask:
666 - 022 --- 644
So from that point on (for the duration of your login session), all new files created will have 644 permissions. The subtraction trick works so long as you take directories into consideration.
Directories will have a default mask of 777. This is identical to that of regular files, except that regular files do not get their execute bit set by default. So you can do all umask operations with 777 and just drop any execute bits if dealing with ordinary files.
2. | Playing with umask: | |
---|---|---|
a. | What is your current umask? How did you determine this? | |
b. | Using touch(1), create a new file. Do its resultant permissions correlate with your umask? | |
c. | Unset your umask with a value of 000. Create a new file. What are the permissions? Do that correlate with your umask? | |
d. | Derive and set a umask to give you 640 files by default. What value did you use? |
3. | Perform the following umask calculations and show me how you arrived at your answer: | |
---|---|---|
a. | Show me a 077 umask via Bitwise-AND (you can assume a directory) | |
b. | Show me a 777 umask via Bitwise-AND. What is the resulting permission? | |
c. | Show me a 226 umask via Subtraction | |
d. | Show me a 074 umask via Subtraction (you can assume a directory) |
In the past, the telnet program was amongst the most common of methods used to connect to UNIX systems if a direct terminal connection was unavailable (rlogin was another common method). While this program is functional, the protocol that empowers it has one major drawback– it transmits ALL information in plain text. (This includes your password). An evil individual may be sitting out on the internet (at some point between you and the UNIX machine) using a Packet Sniffer to analyze each and every network packet you send. The packets can be reconstructed by a third party an to obtain an exact copy of everything you type and see.
Encryption provides a means of sending data securely through an unsecure medium. Secure Shell (or SSH), was developed as a replacement for telnet- providing similar functionality with several added features– the main one being security.
When you use SSH to connect to a system, all your information is encrypted. A malicious third party does not have immediate access to the data you are sending, providing an extra buffer of security both to yourself and the system.
Be sure to always use Secure Shell for any interactions you have with UNIX machines. You are not only protecting yourself and your data, but you are protecting the security of the system you are logging into.
Although UNIX/Linux systems have not been prone to the virus problem (although proof of concept viruses have been written) that afflicts other operating systems, it is certainly susceptible to trojan horses and worms– the trick is, these malicious programs can only be run under the authority of the user they've managed to infiltrate.
It is for reasons like this why it is critical you use strong passwords (8+ characters), connect using secure means (SSH), consider using key-based authentication, and if you're the administrator, lock down the root account as much as possible- the more you minimize root accessibility and usage, the more difficult it will be for your machine to be “rooted”.
A common practice is to disable remote root logins via SSH, so that only authorized users can connect. Attempts to log in directly as root over the network, even if you know the right password, will automatically fail.
Of course, with every benefit comes a drawback- if you disable remote root logins, the administrator cannot directly log in, even for legitimate means, if they do not have easy access to the main login console.
In addition to intentionally malicious programs, there are other vectors of attack that are hunted for and used. Vulnerabilities, or exploits, are the common names given to these kind of attacks.
A vulnerability or exploit is when an attacker takes advantage of a weakness or flaw in an existing and perceived legitimate program or facility. A successful attack can yield access in various forms where the attacker may not normally be privy to such authorization.
Common attacks:
The UNIX permission hierarchy consists of three tiers: The user that owns a file, the group that is associated with the file, and the access the rest of the world (other) has to the file.
The user and other levels have seen extensive exposure. And they probably make the most sense– every file has an owner, and you have to determine what permissions the owner should have to its file, and what kind of access you wish the rest of the world to have on the file.
But what about group? This level is frequently overlooked, but we must be careful to consider any implications and capabilities it provides. It has its roots in project/teamwork ideas during the development of UNIX. A group essentially lets a team of people working on a project to have common access to important files that need to be shared among several people.
The group ownership of a file can be changed with the chgrp(1) utility. It can be used to change the ownership to any other group that your account is a member.
The /etc/group file defines all the groups and their members on a UNIX system. If you have a local account, searching for your username in this file you can determine what groups you are a part of.
The groups(1) utility can also be used to report the groups you to which you have membership.
4. | Locate the following information: | |
---|---|---|
a. | Determine what groups your account has membership. Tell me what they are. | |
b. | What are the GID's of each group you are a member? How did you find this information? |
5. | Change to the groups/ subdirectory of the UNIX Public Directory. Do the following: | |
---|---|---|
a. | List the directory. What files are there? What are the permissions? | |
b. | What groups own what directories? Are you a member of any of the groups? | |
c. | In the various directories are files containing Secret Codes. Obtain this from as many of the directories as you can and report them to me. | |
d. | What directories/files couldn't you get into? Why? |
This assignment has activities which you should tend to. While there is no formal submission required, it would be prudent to document some of the knowledge and experience gained on your Opus.
As always, the class mailing list and class IRC channel are available for assistance, but not answers.