Lecture 4: Unix Security Basics: Asoc. Prof. Guntis Barzdins Asist. Girts Folkmanis
Lecture 4: Unix Security Basics: Asoc. Prof. Guntis Barzdins Asist. Girts Folkmanis
Source: http://www.sans.org/top20/#threats
Favourite TCP Ports
20 FTP (data) 7-19 echo, discard, daytime, chargen, netstat
22 SSH
21 FTP (control)
42 wins
23 Telnet
53 dns
25 SMTP (mail) 111 sun rpc
70 Gopher 113 identd
79 Finger 123 ntp
80 HTTP also 8000 or 8001 or 8080 135 loc-srv/epmap – used to attack wintel
110 Pop3 137-139 netbios
119 NNTP (news) 161 snmp
143 Imap 512-517 rexec, rlogin, rsh, talk, syslog, who
635 mountd – Linux
2049 nfs
6670 Deepthroat
31337 BackOrifice
No system is perfectly secure,
but still we need security
A number of toolkits exist that allow total amateurs
to become holy terrors.
The good news is that if you can beat the popular
intrusion toolkits, 90 percent of the bad guys will
go bother somebody else who's less secure.
Protection
Permissions
UID
GID
Superuser
SUID, SGID
Sticky bit
Umask
Filesystem restrictions
Domain Implementation in UNIX
UID User
permissions
Subjects = processes
GID-main+ Group
permissions
GID-list
Others Others
permissions
inodes
inodes contain a lot of information about a file
mode and type of file
number of links to the file
owner's UID
owners GID
number of bytes in file
times (last accessed, modified, inode changed)
physical disk addresses (direct and indirect blocks)
number of blocks
access information
Unix File System (UFS) Structure
Directory
Under UNIX directories are special (OS writable only) files.
The directory file is an unsorted linked list of filenames to file-inode
(attributes and location of file on hard disk)
Directory size will always increase to be large enough to hold all
the file entries. If the number of files latter shrinks the directory
size WILL NOT!
5 apples
4 oranges
5 aboli
2 .
7 ..
ls -l
> ls -l foo
-rw-rw---- 1 hollingd grads 13 Jan 10 23:05 foo
time
File Time Attributes
Time Attributes:
when the file was last changed ls -l
when the file was created* ls -lc
when the file was last read (accessed) ls -ul
Regular Files
binary
GIF, JPEG, Executable etc.
text
scripts, program source code, documentation
Supports sequential and random access
Types of Files (cont.)
Directory
Can contain ANY kind of files
. (Dot) The special name for the current directory.
.. (Dot) (Dot) The special name for the directory above
the current directory.
Device File
Allows programs to communicate with hardware.
Kernel modules handles device management.
Types of Files (cont.)
Block Device
Information stored in fixed-sized block
It is addressable, therefore seek operation is possible.
Types of Files (cont.)
Hard links
Linking files by reference
System maintains a count of the number of links
Does not work across file systems.
Soft links
Linking files by name
No counter is maintained
Work across file system
From “man ln”
There are two concepts of `link' in Unix, usually called
hard link and soft link
A hard link is just a name for a file. (And a file can have
several names. It is deleted from disk only when the last name
is removed. The number of names is given by ls(1). There isno
such thing as an `original' name: all names have the same
status.
A soft link (or symbolic link, or symlink) is an entirely different
animal: it is a small special file that contains a pathname.
Creating a Link
hollid2 scully
Disk mount options
-rwxr--r--
Access granted to owner Access granted to
r : read / w : write / x : execute group member
Permissions for Files
But when I use vi, its real uid is dkl (not root), so I can only
edit my files.
Effective uids
Programs can change to use the effective uid
the uid of the program owner
e.g. the passwd program changes to use its effective uid
(root) so that it can edit the /etc/passwd file
manually
edit /etc/passwd, etc/shadow, etc/group
remember to lock these files while editing - vipw
run “passwd [user]”
create home directory
chown, chgrp, chmod
copy defaults (e.g umod) from
/etc/skel
/etc/profile
username
A username is (typically) a sequence of alphanumeric
characters of length no more than 8.
username the primary identifying attribute of your
account.
username is (usually) used as a part of email address
the name of your home directory is usually related to
your username.
password
a password is a secret string that only the user
knows (not even the system knows!)
When you enter your password the system
calculates a hash (one-way) function and
compares it to a stored string.
passwords are (usually) no less than 8
characters long.
It's a good idea to include numbers and/or
special characters (don't use an english word!)
userid
sh Bourne Shell
ksh Korn Shell
csh C Shell
bash Bourne-Again Shell
Startup files
sh,ksh:
/etc/profile (system defaults)
~/.profile
bash:
~/.bash_profile
~/.bashrc
~/.bash_logout
csh:
~/.cshrc
~/.login
~/.logout
Additional Password Security
Later versions of Unix have improved the security for password
encryption as follows:
Passwords no longer restricted to 8 characters
Use MD5 instead of DES; gives 128-bit output
Use “salt”
Furthermore, the encrypted (hashed) password is removed from
the /etc/passwd file and instead is placed in /etc/shadow
Restricted access to /etc/shadow – no requirement for it to be world-
readable; only readable by Root
Much more difficult to launch off-line (dictionary) attack
/etc/shadow contains additional password information (number of days
before expiry, etc)
passwd, shadow, group files
unix etc # ls -l passwd shadow group tikai “wheel” grupa
-rw-r--r-- 1 root root 705 Sep 23 15:36 group
-rw-r--r-- 1 root root 1895 Sep 24 18:20 passwd var su uz root;
-rw------- 1 root root 634 Sep 24 18:22 shadow skat /etc/pam.d/
unix etc #
command interpreter
home directory
“real” name
group ID
user ID
[encrypted password]
login name
/etc/group
Information about system groups
faculty:x:23:maria,eileen,dkl
UID of 0
Any username can be the superuser.
Normal security checks and constraints are
ignored for the superuser.
Superuser is not for casual use.
Do not login as superuser, use ‘/bin/su’ with “-” option
instead.
Simple trap to steal superuser
All Files
Text: Readable
Binary: Uses all
characters
characters
Executable
Files
to new files
umask: Calculations (2)
If you want a file permission of 644 (by default, without
manually executing chmod) on a regular file, the umask
would need to be 022.
Default Mode 666
umask -022
New File Mode 644
Bit level: new_mask = mode & ~umask
umask = 000010010 = ---rw-rw = 0022
~umask = 111101101
mode = 110110110 = rw-rw-rw = 0666
new_mask = 111100100 = rw------ = 0600
Advanced: Capabilities
For the purpose of performing permission checks, traditional Unix
implementations distinguish two categories of processes: privi-
leged processes (whose effective user ID is 0, referred to as
superuser or root), and unprivileged processes (whose effective
UID is non-zero). Privileged processes bypass all kernel permis-
sion checks, while unprivileged processes are subject to full per-
mission checking based on the process's credentials (usually:
effective UID, effective GID, and supplementary group list).
Modification of the file permission bits results in the modification of the permissions in
the associated ACL entries. Modification of the permissions in the ACL entries results in
the modification of the file permission bits.
Example:
user::rw-
user:lisa:rw-
group::r--
group:toolies:rw-
mask::r--
other::r--
Advanced: TCP/IP Firewalls