08 - Unix Security
08 - Unix Security
COMPUTER SECURITY
08 - UNIX SECURITY
These slides are prepared from Prof Pavel Laskov‘s lecture slide Version 2.0
MULTICS
Multiplexed Information
and Computing Service
a high-availability,
modular, multi-component
system
secure design from
ground up: implementation
of B-LP model
initial development from
1963 to 1969; continued
until 1985; last system
decommissioned in 2000
1
UNIX
Initial assembler
implementation by Ken
Thompson and Dennis
Ritchie for PDP-7 and PDP-
11
Rewritten in C in 1973: the
first operating system
written in a high-level
language
Continuous evolution of
various dialects of UNIX
and its routines for almost
40 years
MULTICS VS UNIX
MULTICS (Multiplexed Information and
Computing Service)
a high-availability, modular, multi-component system
secure design from ground up: implementation of BLP
initial development from 1963 to 1969; continued until
1985; last system decommissioned in 2000
UNIX: the opposite of MULTICS
initial assembler implementation by Ken Thompson
and Dennis Ritchie for PDP-7 and PDP-11
rewritten in C in 1973: the first operating system
written in a high-level language
continuous evolution of various dialects of UNIX and
its routines for almost 40 years
2
SECURITY ARCHITECTURE
SECURITY ARCHITECTURE
NONE!
UNIX DOES NOT HAVE
SECURITY
ARCHITECTURE
3
SECURITY AND UNIX DESIGN
4
PRINCIPALS
5
SHADOW PASSWORD FILE
Username: the user name
Passwd: the encrypted password
Last: days since Jan 1, 1970 that password was last
changed
May: days before password may be changed
Must: days after which password must be changed
Warn: days before password is to expire that user is warned
Expire: days after password expires that account is disabled
Disable: days since Jan 1, 1970 that account is disabled
Examples:
DES
prepend password with 2-bit salt
take 7 lowest bits from first 8 characters
encrypt a fixed 64-bit string with DES using 56 bits as
a key
convert the resulting 64 bits into 11 ASCII characters
using 6 bits for character (2 bits padded with zeros)
MD5
originally written for FreeBSD to avoid export
restrictions
no limit on password size
is indicated by the starting $1$ in the shadow file
6
GROUP FILE
Groupname: the group name
Password: an x indicates that a password is set
and if left blank no password has been set
GID: the group ID number
Members: current members of the group separated
by a comma
Examples:
root:x:0
adm:x:4:laskov
laskov:x:1000:
ROOT PRIVILEGES
7
SUBJECTS
The subjects in UNIX are processes identified by a process
ID (PID).
New process creation
fork: spawns a new child process which is an identical process to
the parent except for a new PID
vfork: the same as fork except that memory is shared between the
two processes
exec family: replaces the current process with a new process
image
Processes are mapped to UIDs (principal-subject mapping)
in either of the following ways:
real UID is always inherited from the parent process
effective UID is either inherited from the parent process or from the
owner of the file to be executed
OBJECTS
8
INODE STRUCTURE
OBJECTS
9
MODE FIELD IN DETAIL
File/resource type
Examples
-rw-r--r– 1 laskov laskov 10652... 80-unix.tex
lrwxrwxrwx 1 root root 15 ... stdin -> /proc/self/fd/0
crw------- 1 laskov tty 136 ... /dev/pts/1
DIRECTORY PERMISSIONS
10
MANAGING PERMISSIONS
UNIX PERMISSIONS
11
DEFAULT PERMISSIONS
DEFAULT PERMISSIONS –
AN EXAMPLE
12
CONTROLLED INVOCATION
Certain actions, e.g. using system ports (1-1023) or
changing a password, require root privileges.
We don’t want to give users a general root privilege
by telling them a root password, but only the right to
run selected commands as root.
Solution: set a special flag indicating that a program
can be run under the privilege of its owner rather
than that of a calling user.
Disadvantage:this right cannot be given to selected
users: all users in the “world” (or in a group) can run
a program under its owner’s privilege.
13
SUID, SGID AND STICKY FLAGS -
EXAMPLE
Privilege escalation
chmod 7700 bad-script.sh
chown root:root bad-script.sh
./bad-script.sh
Ownership transfer to root is forbidden!
Exploitation automatically receives root
privileges
14
SECURE MOUNTING OF
FILE SYSTEMS
By mounting an external file system we cannot
guaranteethat it is free from malicious programs,
e.g. SUID to root programs.
As a result, access control setting may need to be
redefined for mounted media:
Security options to the mount command:
-r : read-only mount
-o nosuid : turn off SUID flags for all data in a mounted
file system
-o noexec : no program can be run from a mounted file
system
-o nodev : no character or block device can be
accessed from a mounted file system
SEARCH PATHS
A potential danger lies attacker’s diverting of
execution of a wrong program with the same
name.
Rules of conduct:
If possible, specify full paths when calling programs,
e.g. /bin/sh instead of sh
The same applied to programs to be run locally: use
./program instead of program
Make sure . is the first symbol in the PATH variable.
This will at least prevent calling a “remote” version of a
program if what you really want is a “local” invocation.
15
PATH AND SUID COMBINED
$ cat /home/nick/bin
...#!/bin/bash
.../bin/sh #this script will execute /bin/sh
$ ls -al /usr/local/date
---s--x--x 1 root root 21673 Mar 9 18:36 date
$ PATH=/home/nick:${PATH}
$ export PATH
$ IFS=/
$ export IFS
$ /usr/local/date
# whoami
root
16
KEY POINTS
Thank You
17