41
Computer Security: Computer Security: Principles and Principles and Practice Practice Based on the first edition Based on the first edition by William Stallings and by William Stallings and Lawrie Brown Lawrie Brown (And based on Brown’s lecture (And based on Brown’s lecture slides) slides) Linux Security Linux Security

Computer Security: Principles and Practice

  • Upload
    tauret

  • View
    36

  • Download
    1

Embed Size (px)

DESCRIPTION

Computer Security: Principles and Practice. Linux Security. Based on the first edition by William Stallings and Lawrie Brown (And based on Brown ’ s lecture slides). Linux Security. Linux has evolved into one of the most popular and versatile operating systems - PowerPoint PPT Presentation

Citation preview

Page 1: Computer Security: Principles and Practice

Computer Security: Computer Security: Principles and PracticePrinciples and Practice

Based on the first editionBased on the first edition

by William Stallings and Lawrie Brownby William Stallings and Lawrie Brown

(And based on Brown’s lecture slides)(And based on Brown’s lecture slides)

Linux SecurityLinux Security

Page 2: Computer Security: Principles and Practice

Linux SecurityLinux Security

Linux has evolved into one of the most Linux has evolved into one of the most popular and versatile operating systemspopular and versatile operating systems

many features mean broad attack surfacemany features mean broad attack surface can create highly secure Linux systemscan create highly secure Linux systems will review:will review:

Discretionary Access ControlsDiscretionary Access Controls typical vulnerabilities and exploits in Linuxtypical vulnerabilities and exploits in Linux best practices for mitigating those threatsbest practices for mitigating those threats new improvements to Linux security modelnew improvements to Linux security model

Page 3: Computer Security: Principles and Practice

Linux Security ModelLinux Security Model

Linux’s traditional security model is:Linux’s traditional security model is: people or proceses with “root” privileges can people or proceses with “root” privileges can

do anythingdo anything other accounts can do much lessother accounts can do much less

hence attacker’s want to get root privilegeshence attacker’s want to get root privileges can run robust, secure Linux systemscan run robust, secure Linux systems crux of problem is use of crux of problem is use of Discretionary Discretionary

Access ControlsAccess Controls (DAC) (DAC)

Page 4: Computer Security: Principles and Practice

Linux Security TransactionsLinux Security Transactions

Page 5: Computer Security: Principles and Practice

File System SecurityFile System Security

in Linux in Linux everythingeverything as a file as a file e.g. memory, device-drivers, named pipes, e.g. memory, device-drivers, named pipes,

and other system resourcesand other system resources hence why filesystem security is so importanthence why filesystem security is so important

I/O to devices is via a “special” fileI/O to devices is via a “special” file e.g. e.g. /dev/cdrom/dev/cdrom

have other special files like named pipeshave other special files like named pipes a conduit between processes / programsa conduit between processes / programs

Page 6: Computer Security: Principles and Practice

Users and GroupsUsers and Groups

a user-account (user)a user-account (user) represents someone capable of using filesrepresents someone capable of using files associated both with humans and processesassociated both with humans and processes

a group-account (group)a group-account (group) is a list of user-accountsis a list of user-accounts users have a main group users have a main group may also belong to other groupsmay also belong to other groups

users & groups are users & groups are notnot files files

Page 7: Computer Security: Principles and Practice

Users and GroupsUsers and Groups

user's details are kept in user's details are kept in /etc/password/etc/passwordmaestro:x:200:100:Maestro Edward maestro:x:200:100:Maestro Edward Hizzersands:/home/maestro:/bin/bashHizzersands:/home/maestro:/bin/bash

additional group details in additional group details in /etc/group/etc/groupconductors:x:100:conductors:x:100:

pianists:x:102:maestro,volodyapianists:x:102:maestro,volodya

use use useradduseradd, , usermodusermod, , userdel userdel to alterto alter

Page 8: Computer Security: Principles and Practice

File PermissionsFile Permissions

files have two owners: a user & a groupfiles have two owners: a user & a group each with its own set of permissionseach with its own set of permissions with a third set of permissions for otherwith a third set of permissions for other permissions are to read/write/execute in permissions are to read/write/execute in

order user/group/other, cf.order user/group/other, cf.-rw-rw-r-- 1 maestro user 35414 -rw-rw-r-- 1 maestro user 35414 Mar 25 01:38 baton.txtMar 25 01:38 baton.txt

set using chmod commandset using chmod command

Page 9: Computer Security: Principles and Practice

Directory PermissionsDirectory Permissions

read = list contentsread = list contents write = create or delete files in directorywrite = create or delete files in directory execute = use anything in or change execute = use anything in or change

working directory to this directoryworking directory to this directory e.g.e.g.

$ chmod g+rx extreme_casseroles$ chmod g+rx extreme_casseroles$ ls -l extreme_casseroles$ ls -l extreme_casseroles drwxr-x--- 8 biff drummers 288 drwxr-x--- 8 biff drummers 288 Mar 25 01:38 extreme_casserolesMar 25 01:38 extreme_casseroles

Page 10: Computer Security: Principles and Practice

Sticky BitSticky Bit

originally used to lock file in memoryoriginally used to lock file in memory now used on directories to limit deletenow used on directories to limit delete

if set must own file or dir to deleteif set must own file or dir to delete other users cannot delete even if have writeother users cannot delete even if have write

set using chmod command with +t flag, e.g.set using chmod command with +t flag, e.g.chmod +t extreme_casseroleschmod +t extreme_casseroles

directory listing includes t or T flagdirectory listing includes t or T flagdrwxrwx--T 8 biff drummers 288 Mar drwxrwx--T 8 biff drummers 288 Mar 25 01:38 extreme_casseroles25 01:38 extreme_casseroles

only apply to specific directory not child dirsonly apply to specific directory not child dirs

Page 11: Computer Security: Principles and Practice

SetUID and SetGIDSetUID and SetGID

setuid bit means program "runs as" ownersetuid bit means program "runs as" owner no matter who executes itno matter who executes it

setgid bit means run as a member of the setgid bit means run as a member of the group which owns itgroup which owns it again regardless of who executes itagain regardless of who executes it

"run as" = "run with same privileges as”"run as" = "run with same privileges as” are very dangerousare very dangerous if set on file owned by if set on file owned by

root or other privileged account or grouproot or other privileged account or group only used on executable files, not shell scriptsonly used on executable files, not shell scripts

Page 12: Computer Security: Principles and Practice

SetGID and DirectoriesSetGID and Directories

setuid has no effect on directoriessetuid has no effect on directories setgid does and causes any file created in setgid does and causes any file created in

a directory to inherit the directory's groupa directory to inherit the directory's group useful if users belong to other groups and useful if users belong to other groups and

routinely create files to be shared with routinely create files to be shared with other members of those groupsother members of those groups instead of manually changing its groupinstead of manually changing its group

Page 13: Computer Security: Principles and Practice

Numeric File PermissionsNumeric File Permissions

Page 14: Computer Security: Principles and Practice

Kernel vs User SpaceKernel vs User Space

Kernel spaceKernel space refers to memory used by the Linux kernel refers to memory used by the Linux kernel

and its loadable modules (e.g., device drivers)and its loadable modules (e.g., device drivers) User spaceUser space

refers to memory used by all other processesrefers to memory used by all other processes since kernel enforces Linux DAC and since kernel enforces Linux DAC and

security critical to isolate kernel from usersecurity critical to isolate kernel from user so kernel space never swapped to diskso kernel space never swapped to disk only root may load and unload kernel modulesonly root may load and unload kernel modules

Page 15: Computer Security: Principles and Practice

setuid root Vulnerabilitiessetuid root Vulnerabilities

a a setuid rootsetuid root program runs as root program runs as root no matter who executes itno matter who executes it

used to provide unprivileged users with access used to provide unprivileged users with access to privileged resourcesto privileged resources

must be very carefully programmedmust be very carefully programmed if can be exploited due to a software bugif can be exploited due to a software bug

may allow otherwise-unprivileged users to use it to may allow otherwise-unprivileged users to use it to wield unauthorized root privilegeswield unauthorized root privileges

distributions now minimise setuid-root programsdistributions now minimise setuid-root programs system attackers still scan for them!system attackers still scan for them!

Page 16: Computer Security: Principles and Practice

Web VulnerabilitiesWeb Vulnerabilities a very broad category of vulnerabilitiesa very broad category of vulnerabilities

because of ubiquity of world wide web have big and because of ubiquity of world wide web have big and visible attack surfacesvisible attack surfaces

when written in scripting languageswhen written in scripting languages not as prone to classic buffer overflowsnot as prone to classic buffer overflows can suffer from poor input-handlingcan suffer from poor input-handling

few “enabled-by-default” web applicationsfew “enabled-by-default” web applications but users install vulnerable web applicationsbut users install vulnerable web applications or write custom web applications having easily-or write custom web applications having easily-

identified and easily-exploited flaws identified and easily-exploited flaws

Page 17: Computer Security: Principles and Practice

RootkitsRootkits

allow attacker to cover their tracksallow attacker to cover their tracks if successfully installed before detection, all is if successfully installed before detection, all is

very nearly lostvery nearly lost originally collections of hacked commandsoriginally collections of hacked commands

hiding attacker’s files, directories, processeshiding attacker’s files, directories, processes now use loadable kernel modulesnow use loadable kernel modules

intercepting system calls in kernel-spaceintercepting system calls in kernel-space hiding attacker from standard commandshiding attacker from standard commands

may be able to detect with chkrootkitmay be able to detect with chkrootkit generally have to wipe and rebuild systemgenerally have to wipe and rebuild system

Page 18: Computer Security: Principles and Practice

Linux System HardeningLinux System Hardening

consider how to mitigate Linux security consider how to mitigate Linux security risks at system and application levelsrisks at system and application levels

first look at OS-level security tools and first look at OS-level security tools and techniques that protect the entire systemtechniques that protect the entire system

Page 19: Computer Security: Principles and Practice

OS InstallationOS Installation security begins with O/S installationsecurity begins with O/S installation especially what software is runespecially what software is run

since unused applications liable to be left in default, un-since unused applications liable to be left in default, un-hardened and un-patched statehardened and un-patched state

generally should not run:generally should not run: X Window system, RPC services, R-services, inetd, SMTP X Window system, RPC services, R-services, inetd, SMTP

daemons, telnet etcdaemons, telnet etc also have some initial system s/w configuration:also have some initial system s/w configuration:

setting root passwordsetting root password creating a non-root user accountcreating a non-root user account setting an overall system security level setting an overall system security level enabling a simple host-based firewall policyenabling a simple host-based firewall policy enabling SELinux enabling SELinux

Page 20: Computer Security: Principles and Practice

Patch ManagementPatch Management

installed server applications must be:installed server applications must be: configured securelyconfigured securely kept up to date with security patcheskept up to date with security patches

patching can never win “patch rat-race”patching can never win “patch rat-race” have tools to automatically download and have tools to automatically download and

install security updatesinstall security updates e.g. up2date, YaST, apt-gete.g. up2date, YaST, apt-get note should not run automatic updates on note should not run automatic updates on

change-controlled systems without testingchange-controlled systems without testing

Page 21: Computer Security: Principles and Practice

Network Access ControlsNetwork Access Controls

network a key attack vector to securenetwork a key attack vector to secure TCP wrappers a key tool to check accessTCP wrappers a key tool to check access

originally tcpd inetd wrapper daemonoriginally tcpd inetd wrapper daemon before allowing connection to service checksbefore allowing connection to service checks

• if requesting host explicitly in hosts.allow is okif requesting host explicitly in hosts.allow is ok• if requesting host explicitly in hosts.deny is blockedif requesting host explicitly in hosts.deny is blocked• if not in either is okif not in either is ok

checks on service, source IP, usernamechecks on service, source IP, username now often part of app using libwrappersnow often part of app using libwrappers

Page 22: Computer Security: Principles and Practice

Network Access ControlsNetwork Access Controls also have the very powerful also have the very powerful netfilternetfilter Linux Linux

kernel native firewall mechanismkernel native firewall mechanism and and iptablesiptables user-space front end user-space front end

as useful on firewalls, servers, desktopsas useful on firewalls, servers, desktops direct config tricky, steep learning curvedirect config tricky, steep learning curve do have automated rule generatorsdo have automated rule generators typically for “personnal” firewall use will:typically for “personnal” firewall use will:

allow incoming requests to specified servicesallow incoming requests to specified services block all other inbound service requestsblock all other inbound service requests allow all outbound (locally-originating) requestsallow all outbound (locally-originating) requests

if need greater security, manually configif need greater security, manually config

Page 23: Computer Security: Principles and Practice

Antivirus SoftwareAntivirus Software historically Linux not as vulnerable to viruseshistorically Linux not as vulnerable to viruses more to lesser popularity than securitymore to lesser popularity than security prompt patching was effective for wormsprompt patching was effective for worms but viruses abuse users privilegesbut viruses abuse users privileges non-root users have less scope to exploitnon-root users have less scope to exploit

but can still consume resourcesbut can still consume resources growing Linux popularity mean exploitsgrowing Linux popularity mean exploits hence antivirus software will more importanthence antivirus software will more important

various commercial and free Linux A/Vvarious commercial and free Linux A/V

Page 24: Computer Security: Principles and Practice

User ManagementUser Management

guiding principles in user-account security:guiding principles in user-account security: need care setting file / directory permissionsneed care setting file / directory permissions use groups to differentiate between roles use groups to differentiate between roles use extreme care in granting / using root privsuse extreme care in granting / using root privs

commands: chmod, useradd/mod/del, commands: chmod, useradd/mod/del, groupadd/mod/del, passwd, chagegroupadd/mod/del, passwd, chage

info in files /etc/passwd & /etc/groupinfo in files /etc/passwd & /etc/group manage user’s group membershipsmanage user’s group memberships set appropriate password agesset appropriate password ages

Page 25: Computer Security: Principles and Practice

Root DelegationRoot Delegation have "root can to anything, users do little” issuehave "root can to anything, users do little” issue ““su” command allows users to run as rootsu” command allows users to run as root

either root shell or single commandeither root shell or single command must supply root passwordmust supply root password means likely too many people know thismeans likely too many people know this

SELinux RBAC can limit root authority, complexSELinux RBAC can limit root authority, complex ““sudo” allows users to run as rootsudo” allows users to run as root

but only need their password, not root passwordbut only need their password, not root password /etc/sudoers file specifies what commands allowed/etc/sudoers file specifies what commands allowed

or configure user/group perms to allow, trickyor configure user/group perms to allow, tricky

Page 26: Computer Security: Principles and Practice

LoggingLogging effective logging a key resourceeffective logging a key resource Linux logs using syslogd or Syslog-NGLinux logs using syslogd or Syslog-NG

receive log data from a variety of sourcesreceive log data from a variety of sources sorts by sorts by facilityfacility (category) and (category) and severityseverity writes log messages to local/remote log fileswrites log messages to local/remote log files

Syslog-NG preferable because it has:Syslog-NG preferable because it has: variety of log-data sources / destinationsvariety of log-data sources / destinations much more flexible “rules engine” to configuremuch more flexible “rules engine” to configure can log via TCP which can be encryptedcan log via TCP which can be encrypted

should check and customized defaultsshould check and customized defaults

Page 27: Computer Security: Principles and Practice

Log ManagementLog Management

balance number of log files usedbalance number of log files used size of few to finding info in manysize of few to finding info in many

manage size of log filesmanage size of log files must rotate log files and delete old copiesmust rotate log files and delete old copies typically use logrotate utility run by crontypically use logrotate utility run by cron to manage both system and application logsto manage both system and application logs

must also configure application loggingmust also configure application logging

Page 28: Computer Security: Principles and Practice

Application SecurityApplication Security

this is a large topicthis is a large topic many security features are implemented in many security features are implemented in

similar ways across different applicationssimilar ways across different applications will review issues such as:will review issues such as:

running as unprivileged user/grouprunning as unprivileged user/group running in chroot jailrunning in chroot jail modularitymodularity encryptionencryption logginglogging

Page 29: Computer Security: Principles and Practice

Running As Unprivileged Running As Unprivileged User/GroupUser/Group

every process “runs as” some userevery process “runs as” some user extremely important this user is not rootextremely important this user is not root

since any bug can compromise entire systemsince any bug can compromise entire system may need root privileges, e.g. bind portmay need root privileges, e.g. bind port

have root parent perform privileged functionhave root parent perform privileged function but main service from unprivileged childbut main service from unprivileged child

user/group used should be dedicateduser/group used should be dedicated easier to identify source of log messageseasier to identify source of log messages

Page 30: Computer Security: Principles and Practice

Running in chroot JailRunning in chroot Jail chroot confines a process to a subset of /chroot confines a process to a subset of /

maps a virtual “/” to some other directorymaps a virtual “/” to some other directory useful if have a daemon that should only useful if have a daemon that should only

access a portion of the file system, e.g. FTPaccess a portion of the file system, e.g. FTP directories outside the chroot jail aren’t visible directories outside the chroot jail aren’t visible

or reachable at allor reachable at all contains effects of compromised daemoncontains effects of compromised daemon complex to configure and troubleshootcomplex to configure and troubleshoot

must mirror portions of system in chroot jailmust mirror portions of system in chroot jail

Page 31: Computer Security: Principles and Practice

ModularityModularity

applications running as a single, large, applications running as a single, large, multipurpose process can be:multipurpose process can be: more difficult to run as an unprivileged usermore difficult to run as an unprivileged user harder to locate / fix security bugs in source harder to locate / fix security bugs in source harder to disable unnecessary functionalityharder to disable unnecessary functionality

hence modularity a highly prized featurehence modularity a highly prized feature providing a much smaller attack surfaceproviding a much smaller attack surface

cf. postfix vs sendmail, Apache modulescf. postfix vs sendmail, Apache modules

Page 32: Computer Security: Principles and Practice

EncryptionEncryption sending logins & passwords or application sending logins & passwords or application

data over networks in clear text exposes data over networks in clear text exposes them to network eavesdropping attacksthem to network eavesdropping attacks

hence many network applications now hence many network applications now support encryption to protect such datasupport encryption to protect such data often using OpenSSL libraryoften using OpenSSL library

may need own X.509 certificates to usemay need own X.509 certificates to use can generate/sign using openssl commandcan generate/sign using openssl command may use commercial/own/free CAmay use commercial/own/free CA

Page 33: Computer Security: Principles and Practice

LoggingLogging

applications can usually be configured to applications can usually be configured to log to any level of detail (debug to none)log to any level of detail (debug to none)

need appropriate settingneed appropriate setting must decide if use dedicated file or system must decide if use dedicated file or system

logging facility (e.g. syslog)logging facility (e.g. syslog) central facility useful for consistent usecentral facility useful for consistent use

must ensure any log files are rotatedmust ensure any log files are rotated

Page 34: Computer Security: Principles and Practice

Mandatory Access ControlsMandatory Access Controls

Linux uses a DAC security modelLinux uses a DAC security model but Mandatory Access Controls (MAC) impose a but Mandatory Access Controls (MAC) impose a

global security policy on all usersglobal security policy on all users users may not set controls weaker than policyusers may not set controls weaker than policy normal admin done with accounts without authority to normal admin done with accounts without authority to

change the global security policychange the global security policy but MAC systems have been hard to managebut MAC systems have been hard to manage

Novell’s SuSE Linux has AppArmorNovell’s SuSE Linux has AppArmor RedHat Enterprise Linux has SELinuxRedHat Enterprise Linux has SELinux pure SELinux for high-sensitivity, high-securitypure SELinux for high-sensitivity, high-security

Page 35: Computer Security: Principles and Practice

SELinuxSELinux is NSA's powerful implementation of mandatory is NSA's powerful implementation of mandatory

access controls for Linuxaccess controls for Linux Linux DACs still applies, but if it allows the action Linux DACs still applies, but if it allows the action

SELinux then evaluates it against its own SELinux then evaluates it against its own security policiessecurity policies

"subjects" are processes (run user cmds)"subjects" are processes (run user cmds) actions are "permissions”actions are "permissions” objects not just files & dirsobjects not just files & dirs to manage complexity SELinux has:to manage complexity SELinux has:

"that which is not expressly permitted, is denied”"that which is not expressly permitted, is denied” groups of subjects, permissions, and objectsgroups of subjects, permissions, and objects

Page 36: Computer Security: Principles and Practice

Security ContextsSecurity Contexts each individual subject & object in SELinux is each individual subject & object in SELinux is

governed by a governed by a security contextsecurity context being a: being a: user - individual user (human or daemon)user - individual user (human or daemon)

• SELinux maintains its own list of usersSELinux maintains its own list of users• user labels on subjects specify account's privileges user labels on subjects specify account's privileges • user labels on objects specify its owneruser labels on objects specify its owner

role - like a group, assumed by usersrole - like a group, assumed by users• a user may only assume one role at a time, a user may only assume one role at a time, • may only switch roles if and when authorized to do somay only switch roles if and when authorized to do so

domain (type) - a sandbox being a combination of domain (type) - a sandbox being a combination of subjects and objects that may interact with each othersubjects and objects that may interact with each other

this model is called this model is called Type EnforcementType Enforcement (TE) (TE)

Page 37: Computer Security: Principles and Practice

Decision Making in SELinuxDecision Making in SELinux

two types of decisions: two types of decisions: accessaccess decisions decisions

when subjects do things to objects that already exist, when subjects do things to objects that already exist, or create new things in expected domainor create new things in expected domain

transitiontransition decisions decisions invocation of processes in different domains than the invocation of processes in different domains than the

one in which the subject-process is runningone in which the subject-process is running creation of objects in different types (domains) than creation of objects in different types (domains) than

their parent directoriestheir parent directories transitions must be authorized by SELinux policytransitions must be authorized by SELinux policy

Page 38: Computer Security: Principles and Practice

RBAC and MLS ControlsRBAC and MLS Controls

havehave Role Based Access Control Role Based Access Control (RBAC) (RBAC) rules specify rules specify roles roles a user may assumea user may assume other rules specify circumstances when a user other rules specify circumstances when a user

may may transitiontransition from one role to another from one role to another and and Multi Level SecurityMulti Level Security (MLS) (MLS)

concerns handling of classified dataconcerns handling of classified data• ““no read up, no write down”no read up, no write down”

MLS is enforced via file system labelingMLS is enforced via file system labeling

Page 39: Computer Security: Principles and Practice

SELinux Policy ManagementSELinux Policy Management

creating and maintaining SELinux policies creating and maintaining SELinux policies is complicated and time-consumingis complicated and time-consuming

a single SELinux policy may consist of a single SELinux policy may consist of hundreds of lines of texthundreds of lines of text

RHEL has a default “targeted” policyRHEL has a default “targeted” policy defines types for selected network appsdefines types for selected network apps allows everything else to use DAC controlsallows everything else to use DAC controls

have a range of SELinux commandshave a range of SELinux commands see additional references for detailssee additional references for details

Page 40: Computer Security: Principles and Practice

Novell AppArmorNovell AppArmor Novell’s MAC for SuSE LinuxNovell’s MAC for SuSE Linux

enforced at kernel levelenforced at kernel level using Linux Security Modulesusing Linux Security Modules

restricts behavior of selected applications restricts behavior of selected applications in a very granular but targeted wayin a very granular but targeted way hence a compromised root application's hence a compromised root application's

access will be containedaccess will be contained has no controls addressing data classificationhas no controls addressing data classification hence only a partial MAC implementationhence only a partial MAC implementation

non-protected apps just use Linux DACnon-protected apps just use Linux DAC

Page 41: Computer Security: Principles and Practice

SummarySummary

reviewed Linux security model and DACreviewed Linux security model and DAC vulnerabilitiesvulnerabilities O/S and application hardeningO/S and application hardening MAC, SELinux and AppArmorMAC, SELinux and AppArmor