OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password...

160
OS Security Authentication and Authorization Radboud University, Nijmegen, The Netherlands Winter 2017/2018

Transcript of OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password...

Page 1: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

OS SecurityAuthentication and Authorization

Radboud University, Nijmegen, The Netherlands

Winter 2017/2018

Page 2: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

There was once a programmer who was attached to the court of thewarlord of Wu. The warlord asked the programmer: “Which is easier todesign: an accounting package or an operating system?”

“An operating system,” replied the programmer.

The warlord uttered an exclamation of disbelief. “Surely an accountingpackage is trivial next to the complexity of an operating system,” he said.

“Not so,” said the programmer, “When designing an accounting package,the programmer operates as a mediator between people having differentideas: how it must operate, how its reports must appear, and how itmust conform to the tax laws. By contrast, an operating system is notlimited by outside appearances. When designing an operating system, theprogrammer seeks the simplest harmony between machine and ideas.This is why an operating system is easier to design.”

The warlord of Wu nodded and smiled. “That is all good and well, butwhich is easier to debug?”

The programmer made no reply.—The Tao of Programming, 3.3OS Security – Authentication and Authorization 2

Page 3: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

What does an OS do?

DefinitionAn operating system (OS) is a computer program that manages access ofprocesses (programs) to shared resources.

Examples of shared resourcesI MemoryI Input and Output (I/O) including

I Files on the hard driveI Network

I Computation cycles on the processor(s)I Peripheral hardware (keyboard, screen, . . . )

OS Security – Authentication and Authorization 3

Page 4: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

What does an OS do?

DefinitionAn operating system (OS) is a computer program that manages access ofprocesses (programs) to shared resources.

Examples of shared resourcesI MemoryI Input and Output (I/O) including

I Files on the hard driveI Network

I Computation cycles on the processor(s)I Peripheral hardware (keyboard, screen, . . . )

OS Security – Authentication and Authorization 3

Page 5: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

What does that mean for security?

I Operating system needs to decide whether processes are allowed toperform certain operations

I Obvious security disasters:I One process reading the memory of another processI A process reading a “secret” fileI A process preventing other processes from operatingI One process reading (keyboard) input meant for another process

OS Security – Authentication and Authorization 4

Page 6: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in userI Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 7: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in userI Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 8: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in userI Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 9: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in userI Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 10: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in user

I Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 11: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Wait, what about users?

I Is the process with ID 4321 allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Is user peter allowed to read the file/home/peter/os-security/exam-jan-2018.pdf?

I Need to map between a user (human) and a certain operation

DefinitionAuthentication is the means by which it is determined that a particularentity (typically a human) intends to perform a given operation.

I Typically perform user authentication as a login procedureI Start a shell mapped to the logged-in userI A shell is (basically) an interface to run other programsI All programs run from this shell are mapped to the logged-in userI Worst-case authentication failure: impersonation

OS Security – Authentication and Authorization 5

Page 12: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0

I root may access all filesI root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 13: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all files

I root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 14: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all filesI root may change permissions on all files

I root may bind programs to network sockets with port numbersmaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 15: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all filesI root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 16: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all filesI root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way back

I There are still certain actions that a program run by root cannot do(more later)

I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 17: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all filesI root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)

I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 18: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The user root

I UNIX and Linux have a special superuser called rootI The user ID of root is always 0I root may access all filesI root may change permissions on all filesI root may bind programs to network sockets with port number

smaller than 1024

I root may “impersonate” any other userI A process belonging to root may change its user ID to that of

another userI Once a process has changed from user ID 0 to another user ID,

there is no way backI There are still certain actions that a program run by root cannot do

(more later)I Security nightmare: an attacker who gets root access

OS Security – Authentication and Authorization 6

Page 19: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Classical UNIX/Linux authentication

I Authentication by “what you know”I Init process starts login (runs as root)

I login prompts for username and passwordI Correct password: login changes to new user and executes a shellI Comparison of password hash against info stored in /etc/shadow

(originally /etc/passwd)

OS Security – Authentication and Authorization 7

Page 20: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Classical UNIX/Linux authentication

I Authentication by “what you know”I Init process starts login (runs as root)I login prompts for username and passwordI Correct password: login changes to new user and executes a shell

I Comparison of password hash against info stored in /etc/shadow(originally /etc/passwd)

OS Security – Authentication and Authorization 7

Page 21: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Classical UNIX/Linux authentication

I Authentication by “what you know”I Init process starts login (runs as root)I login prompts for username and passwordI Correct password: login changes to new user and executes a shellI Comparison of password hash against info stored in /etc/shadow

(originally /etc/passwd)

OS Security – Authentication and Authorization 7

Page 22: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Password hashing algorithms

I Traditionally Linux used crypt for password hashingI Truncate the password to 8 characters, 7 bits eachI Encrypt the all-zero string with modified DES with this 56-bit keyI Iterate encryption for 25 times (later: up to 224 − 1)I Incorporate a 12-bit (later: 24-bit) salt

I Use modified DES to prevent attacks with DES hardwareI Originally computing the hash cost ≈ 1 secondI Too weak nowadays to offer strong protectionI Successors: MD5, bcrypt (based on Blowfish), SHA-2I Password hash string indicates which algorithm to use:

I $1$: MD5;I $2a$, $2b$, $2x$, $2y$: variants of bcryptI $5$: SHA-256; $6$: SHA-512

I Better algorithm through https://password-hashing.net/I Winner announced on Nov 2, 2015: ARGON2

OS Security – Authentication and Authorization 8

Page 23: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Password hashing algorithms

I Traditionally Linux used crypt for password hashingI Truncate the password to 8 characters, 7 bits eachI Encrypt the all-zero string with modified DES with this 56-bit keyI Iterate encryption for 25 times (later: up to 224 − 1)I Incorporate a 12-bit (later: 24-bit) saltI Use modified DES to prevent attacks with DES hardwareI Originally computing the hash cost ≈ 1 secondI Too weak nowadays to offer strong protection

I Successors: MD5, bcrypt (based on Blowfish), SHA-2I Password hash string indicates which algorithm to use:

I $1$: MD5;I $2a$, $2b$, $2x$, $2y$: variants of bcryptI $5$: SHA-256; $6$: SHA-512

I Better algorithm through https://password-hashing.net/I Winner announced on Nov 2, 2015: ARGON2

OS Security – Authentication and Authorization 8

Page 24: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Password hashing algorithms

I Traditionally Linux used crypt for password hashingI Truncate the password to 8 characters, 7 bits eachI Encrypt the all-zero string with modified DES with this 56-bit keyI Iterate encryption for 25 times (later: up to 224 − 1)I Incorporate a 12-bit (later: 24-bit) saltI Use modified DES to prevent attacks with DES hardwareI Originally computing the hash cost ≈ 1 secondI Too weak nowadays to offer strong protectionI Successors: MD5, bcrypt (based on Blowfish), SHA-2

I Password hash string indicates which algorithm to use:I $1$: MD5;I $2a$, $2b$, $2x$, $2y$: variants of bcryptI $5$: SHA-256; $6$: SHA-512

I Better algorithm through https://password-hashing.net/I Winner announced on Nov 2, 2015: ARGON2

OS Security – Authentication and Authorization 8

Page 25: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Password hashing algorithms

I Traditionally Linux used crypt for password hashingI Truncate the password to 8 characters, 7 bits eachI Encrypt the all-zero string with modified DES with this 56-bit keyI Iterate encryption for 25 times (later: up to 224 − 1)I Incorporate a 12-bit (later: 24-bit) saltI Use modified DES to prevent attacks with DES hardwareI Originally computing the hash cost ≈ 1 secondI Too weak nowadays to offer strong protectionI Successors: MD5, bcrypt (based on Blowfish), SHA-2I Password hash string indicates which algorithm to use:

I $1$: MD5;I $2a$, $2b$, $2x$, $2y$: variants of bcryptI $5$: SHA-256; $6$: SHA-512

I Better algorithm through https://password-hashing.net/I Winner announced on Nov 2, 2015: ARGON2

OS Security – Authentication and Authorization 8

Page 26: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Password hashing algorithms

I Traditionally Linux used crypt for password hashingI Truncate the password to 8 characters, 7 bits eachI Encrypt the all-zero string with modified DES with this 56-bit keyI Iterate encryption for 25 times (later: up to 224 − 1)I Incorporate a 12-bit (later: 24-bit) saltI Use modified DES to prevent attacks with DES hardwareI Originally computing the hash cost ≈ 1 secondI Too weak nowadays to offer strong protectionI Successors: MD5, bcrypt (based on Blowfish), SHA-2I Password hash string indicates which algorithm to use:

I $1$: MD5;I $2a$, $2b$, $2x$, $2y$: variants of bcryptI $5$: SHA-256; $6$: SHA-512

I Better algorithm through https://password-hashing.net/I Winner announced on Nov 2, 2015: ARGON2

OS Security – Authentication and Authorization 8

Page 27: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters

2. Convert password to all-uppercase3. Pad to 14 bytes4. Split into two 7-byte halves5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 28: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase

3. Pad to 14 bytes4. Split into two 7-byte halves5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 29: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase3. Pad to 14 bytes

4. Split into two 7-byte halves5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 30: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase3. Pad to 14 bytes4. Split into two 7-byte halves

5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 31: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase3. Pad to 14 bytes4. Split into two 7-byte halves5. Use each of the halves as a DES key

6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 32: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase3. Pad to 14 bytes4. Split into two 7-byte halves5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%

7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 33: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

How about Windows?

I Traditionally, Windows uses the LM hash (for “LanMan hash” or“LAN manager hash”)

I Algorithm for LM hash:1. Restrict password to 14 characters2. Convert password to all-uppercase3. Pad to 14 bytes4. Split into two 7-byte halves5. Use each of the halves as a DES key6. Encrypt the fixed ASCII string KGS!@#$%7. Concatenate the two ciphertexts to obtain the LM hash

OS Security – Authentication and Authorization 9

Page 34: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwords

I Can crack the halves independently: 246 for each halfI All characters converted to upper case: 243 for each halfI No salt, rainbow tables are feasibleI Passwords shorter than 8 characters produce hash ending in

0xAAD3B435B51404EEI Cracking LM hashes is fairly easy, there are even online services, e.g.,

http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 35: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwordsI Can crack the halves independently: 246 for each half

I All characters converted to upper case: 243 for each halfI No salt, rainbow tables are feasibleI Passwords shorter than 8 characters produce hash ending in

0xAAD3B435B51404EEI Cracking LM hashes is fairly easy, there are even online services, e.g.,

http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 36: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwordsI Can crack the halves independently: 246 for each halfI All characters converted to upper case: 243 for each half

I No salt, rainbow tables are feasibleI Passwords shorter than 8 characters produce hash ending in

0xAAD3B435B51404EEI Cracking LM hashes is fairly easy, there are even online services, e.g.,

http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 37: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwordsI Can crack the halves independently: 246 for each halfI All characters converted to upper case: 243 for each halfI No salt, rainbow tables are feasible

I Passwords shorter than 8 characters produce hash ending in0xAAD3B435B51404EE

I Cracking LM hashes is fairly easy, there are even online services, e.g.,http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 38: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwordsI Can crack the halves independently: 246 for each halfI All characters converted to upper case: 243 for each halfI No salt, rainbow tables are feasibleI Passwords shorter than 8 characters produce hash ending in

0xAAD3B435B51404EE

I Cracking LM hashes is fairly easy, there are even online services, e.g.,http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 39: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

LM Hash weaknesses

I 14 printable ASCII characters give ≈ 292 passwordsI Can crack the halves independently: 246 for each halfI All characters converted to upper case: 243 for each halfI No salt, rainbow tables are feasibleI Passwords shorter than 8 characters produce hash ending in

0xAAD3B435B51404EEI Cracking LM hashes is fairly easy, there are even online services, e.g.,

http://rainbowtables.it64.com/

OS Security – Authentication and Authorization 10

Page 40: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NT hashes

I LM hash weaknesses were addressed by NT hash (or NTLM)I NTLMv1 uses MD4 to hash passwordsI NTLMv2 uses MD5 to hash passwordsI Passwords are still unsalted

I Until Windows XP, LM hashes were still enabled by default forbackwards compatibility

I Today, Windows uses multiple different approaches for passwords

OS Security – Authentication and Authorization 11

Page 41: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NT hashes

I LM hash weaknesses were addressed by NT hash (or NTLM)I NTLMv1 uses MD4 to hash passwordsI NTLMv2 uses MD5 to hash passwordsI Passwords are still unsaltedI Until Windows XP, LM hashes were still enabled by default for

backwards compatibility

I Today, Windows uses multiple different approaches for passwords

OS Security – Authentication and Authorization 11

Page 42: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NT hashes

I LM hash weaknesses were addressed by NT hash (or NTLM)I NTLMv1 uses MD4 to hash passwordsI NTLMv2 uses MD5 to hash passwordsI Passwords are still unsaltedI Until Windows XP, LM hashes were still enabled by default for

backwards compatibilityI Today, Windows uses multiple different approaches for passwords

OS Security – Authentication and Authorization 11

Page 43: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?

I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 44: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 45: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwerty

I Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 46: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789

I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 47: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456

I Place 15: 18atcskd2wI Exercises in 1st semester course include breaking (unsalted) hash of

a 7-character random password.I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 48: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 49: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 50: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Weak passwords

I Largest problem with passwords: weak passwordsI Remember 1987 Mel Brooks movie “Spaceballs” . . . ?I Most common passwords in 2016 (according to Keeper)

I Place 3: qwertyI Place 2: 123456789I Place 1: 123456I Place 15: 18atcskd2w

I Exercises in 1st semester course include breaking (unsalted) hash ofa 7-character random password.

I Some students typically manage to do that in a week!

OS Security – Authentication and Authorization 12

Page 51: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you have”

I Very common in the “physical world”, e.g., keysI Digital world: Smart cards, USB tokensI Private keys (e.g., for SSH)

I Can easily combine with password, e.g. on SSH private keys

Attacks and countermeasures

I Stealing (or finding): Protect possessionI Copying: Tamper-proof hardware, holograms, anti-counterfeiting

techniquesI Replay attack: device-dependent, use challenge-response

OS Security – Authentication and Authorization 13

Page 52: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you have”

I Very common in the “physical world”, e.g., keysI Digital world: Smart cards, USB tokensI Private keys (e.g., for SSH)I Can easily combine with password, e.g. on SSH private keys

Attacks and countermeasures

I Stealing (or finding): Protect possessionI Copying: Tamper-proof hardware, holograms, anti-counterfeiting

techniquesI Replay attack: device-dependent, use challenge-response

OS Security – Authentication and Authorization 13

Page 53: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you have”

I Very common in the “physical world”, e.g., keysI Digital world: Smart cards, USB tokensI Private keys (e.g., for SSH)I Can easily combine with password, e.g. on SSH private keys

Attacks and countermeasuresI Stealing (or finding): Protect possession

I Copying: Tamper-proof hardware, holograms, anti-counterfeitingtechniques

I Replay attack: device-dependent, use challenge-response

OS Security – Authentication and Authorization 13

Page 54: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you have”

I Very common in the “physical world”, e.g., keysI Digital world: Smart cards, USB tokensI Private keys (e.g., for SSH)I Can easily combine with password, e.g. on SSH private keys

Attacks and countermeasuresI Stealing (or finding): Protect possessionI Copying: Tamper-proof hardware, holograms, anti-counterfeiting

techniques

I Replay attack: device-dependent, use challenge-response

OS Security – Authentication and Authorization 13

Page 55: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you have”

I Very common in the “physical world”, e.g., keysI Digital world: Smart cards, USB tokensI Private keys (e.g., for SSH)I Can easily combine with password, e.g. on SSH private keys

Attacks and countermeasuresI Stealing (or finding): Protect possessionI Copying: Tamper-proof hardware, holograms, anti-counterfeiting

techniquesI Replay attack: device-dependent, use challenge-response

OS Security – Authentication and Authorization 13

Page 56: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 57: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scans

I Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 58: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)

I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 59: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)

I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 60: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 61: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 62: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication by “what you are”

I Fingerprint (fake fingerprint, cut off finger)http://www.heise.de/video/artikel/iPhone-5s-Touch-ID-hack-in-detail-1966044.html

I Retina scansI Voice match (distorted by cold, defeated by recordings)I Handwriting (low accuracy, easy to fake)I Keystroking, timing of keystrokes

When a password is compromised, change your password. What ifyour fingerprint is compromised?

Some legal systems can force you to reveal your fingerprint, butnot your password

OS Security – Authentication and Authorization 14

Page 63: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Compromising fingerprints. . .

OS Security – Authentication and Authorization 15

Page 64: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pluggable authentication modules

I Local login is not the only program that needs user authentication:I SSH (remote login)I Graphical login (GDM, LightDM)I Screen locks (screensaver)I su and sudo (more next lecture)

I Idea: Centralize authentication, make functionality available throughlibrary

I This is handled by Pluggable Authentication Modules (PAM)I Add a new module (e.g., for fingerprint authentication), directly

available to all PAM enabled programs

OS Security – Authentication and Authorization 16

Page 65: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pluggable authentication modules

I Local login is not the only program that needs user authentication:I SSH (remote login)I Graphical login (GDM, LightDM)I Screen locks (screensaver)I su and sudo (more next lecture)

I Idea: Centralize authentication, make functionality available throughlibrary

I This is handled by Pluggable Authentication Modules (PAM)

I Add a new module (e.g., for fingerprint authentication), directlyavailable to all PAM enabled programs

OS Security – Authentication and Authorization 16

Page 66: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pluggable authentication modules

I Local login is not the only program that needs user authentication:I SSH (remote login)I Graphical login (GDM, LightDM)I Screen locks (screensaver)I su and sudo (more next lecture)

I Idea: Centralize authentication, make functionality available throughlibrary

I This is handled by Pluggable Authentication Modules (PAM)I Add a new module (e.g., for fingerprint authentication), directly

available to all PAM enabled programs

OS Security – Authentication and Authorization 16

Page 67: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

PAM design

Image from http://www.tuxradar.com/content/how-pam-worksOS Security – Authentication and Authorization 17

Page 68: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

PAM activities

PAM knows 4 different authentication-related activities:I auth: The activity of user authentication; typically by password, but

can also use tokens, fingerprints etc.I account: After a user is identified, decide whether he is allowed to

log in. For example, can restrict login times.I session: Allocates resources, for example mount home directory, set

resource usage limits, print greeting message with information.I password: Update the user’s credentials (typically the password)

OS Security – Authentication and Authorization 18

Page 69: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

PAM configuration syntaxConfiguration for program progname is in /etc/pam.d/progname

PAM control flagsI requisite: if module fails, immediately return failure and stopI required: if module fails, return failure but continueI sufficient: if module passes, return pass and stopI optional: pass/fail result is ignored

Image source: http://www.tuxradar.com/content/how-pam-works

OS Security – Authentication and Authorization 19

Page 70: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

PAM configuration syntaxConfiguration for program progname is in /etc/pam.d/progname

PAM control flagsI requisite: if module fails, immediately return failure and stopI required: if module fails, return failure but continueI sufficient: if module passes, return pass and stopI optional: pass/fail result is ignored

Image source: http://www.tuxradar.com/content/how-pam-worksOS Security – Authentication and Authorization 19

Page 71: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Examples of PAM modules

Name Activities Descriptionpam_unix auth, session,

passwordStandard UNIX authentication through/etc/shadow passwords

pam_permit auth, account,session, pass-word

Always returns true

pam_deny auth, account,session, pass-word

Always returns false

pam_rootok auth Returns true iff you’re rootpam_warn auth, account,

session, pass-word

Write a log message to the system log

pam_cracklib password Perform checks of the password strength

OS Security – Authentication and Authorization 20

Page 72: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Some PAM config examples

I Prevent all users from using su (/etc/pam.d/su)auth requisite pam_deny.so

I Prevent non-root users to halt (/etc/pam.d/halt)auth sufficient pam_rootok.soauth required pam_deny.so

I Enforce passwords with at least 10 characters and at least 2 specialcharacters, use SHA-512 for password hash (/etc/pam.d/passwd):password required pam_cracklib.so minlen=10 ocredit=-2password required pam_unix.so sha512

OS Security – Authentication and Authorization 21

Page 73: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Some PAM config examples

I Prevent all users from using su (/etc/pam.d/su)auth requisite pam_deny.so

I Prevent non-root users to halt (/etc/pam.d/halt)auth sufficient pam_rootok.soauth required pam_deny.so

I Enforce passwords with at least 10 characters and at least 2 specialcharacters, use SHA-512 for password hash (/etc/pam.d/passwd):password required pam_cracklib.so minlen=10 ocredit=-2password required pam_unix.so sha512

OS Security – Authentication and Authorization 21

Page 74: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Some PAM config examples

I Prevent all users from using su (/etc/pam.d/su)auth requisite pam_deny.so

I Prevent non-root users to halt (/etc/pam.d/halt)auth sufficient pam_rootok.soauth required pam_deny.so

I Enforce passwords with at least 10 characters and at least 2 specialcharacters, use SHA-512 for password hash (/etc/pam.d/passwd):password required pam_cracklib.so minlen=10 ocredit=-2password required pam_unix.so sha512

OS Security – Authentication and Authorization 21

Page 75: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication over the network

I Large corporate networks want to keep user information centralI User is added to one central directory, can log into any machine

I Various “simple” ways to set up the protocol:I Client sends password, server hashes and comparesI Client sends hash, server comparesI Server sends hash, client compares

I Also more complex ways, e.g., challenge-responseI Possible disadvantage of central login server: single point of failureI Different common protocols (NIS, LDAP, Kerberos)

OS Security – Authentication and Authorization 22

Page 76: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication over the network

I Large corporate networks want to keep user information centralI User is added to one central directory, can log into any machineI Various “simple” ways to set up the protocol:

I Client sends password, server hashes and comparesI Client sends hash, server comparesI Server sends hash, client compares

I Also more complex ways, e.g., challenge-responseI Possible disadvantage of central login server: single point of failureI Different common protocols (NIS, LDAP, Kerberos)

OS Security – Authentication and Authorization 22

Page 77: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication over the network

I Large corporate networks want to keep user information centralI User is added to one central directory, can log into any machineI Various “simple” ways to set up the protocol:

I Client sends password, server hashes and comparesI Client sends hash, server comparesI Server sends hash, client compares

I Also more complex ways, e.g., challenge-response

I Possible disadvantage of central login server: single point of failureI Different common protocols (NIS, LDAP, Kerberos)

OS Security – Authentication and Authorization 22

Page 78: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication over the network

I Large corporate networks want to keep user information centralI User is added to one central directory, can log into any machineI Various “simple” ways to set up the protocol:

I Client sends password, server hashes and comparesI Client sends hash, server comparesI Server sends hash, client compares

I Also more complex ways, e.g., challenge-responseI Possible disadvantage of central login server: single point of failure

I Different common protocols (NIS, LDAP, Kerberos)

OS Security – Authentication and Authorization 22

Page 79: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Authentication over the network

I Large corporate networks want to keep user information centralI User is added to one central directory, can log into any machineI Various “simple” ways to set up the protocol:

I Client sends password, server hashes and comparesI Client sends hash, server comparesI Server sends hash, client compares

I Also more complex ways, e.g., challenge-responseI Possible disadvantage of central login server: single point of failureI Different common protocols (NIS, LDAP, Kerberos)

OS Security – Authentication and Authorization 22

Page 80: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NTLM and “pass the hash”

I Microsoft’s LM and NTLM network authentication can send hashfrom the client, server compares hashes

I Attacker only needs to obtain the password hashI The whole point of storing password hashes is goneI Essentially, the hash becomes the password

I This attack is known as “pass the hash” attackI Conveniently automated in metasploitI Almost any larger Windows network still has NTLM somewhere

OS Security – Authentication and Authorization 23

Page 81: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NTLM and “pass the hash”

I Microsoft’s LM and NTLM network authentication can send hashfrom the client, server compares hashes

I Attacker only needs to obtain the password hashI The whole point of storing password hashes is goneI Essentially, the hash becomes the passwordI This attack is known as “pass the hash” attack

I Conveniently automated in metasploitI Almost any larger Windows network still has NTLM somewhere

OS Security – Authentication and Authorization 23

Page 82: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NTLM and “pass the hash”

I Microsoft’s LM and NTLM network authentication can send hashfrom the client, server compares hashes

I Attacker only needs to obtain the password hashI The whole point of storing password hashes is goneI Essentially, the hash becomes the passwordI This attack is known as “pass the hash” attackI Conveniently automated in metasploit

I Almost any larger Windows network still has NTLM somewhere

OS Security – Authentication and Authorization 23

Page 83: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

NTLM and “pass the hash”

I Microsoft’s LM and NTLM network authentication can send hashfrom the client, server compares hashes

I Attacker only needs to obtain the password hashI The whole point of storing password hashes is goneI Essentially, the hash becomes the passwordI This attack is known as “pass the hash” attackI Conveniently automated in metasploitI Almost any larger Windows network still has NTLM somewhere

OS Security – Authentication and Authorization 23

Page 84: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Part II

Authorization

Page 85: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Protection rings

I OS needs to control access toresources

I Idea: Access to resources onlyfor highly-privileged code

I Non-privileged code needs toask the OS to performoperations on resources

I Separate code in protectionrings

I Ring 0: OS kernelI Outer rings: less privileged

software (drivers, userspaceprograms)

Image source: http://en.wikipedia.org/wiki/Protection_ring

OS Security – Authentication and Authorization 25

Page 86: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Protection rings

I OS needs to control access toresources

I Idea: Access to resources onlyfor highly-privileged code

I Non-privileged code needs toask the OS to performoperations on resources

I Separate code in protectionrings

I Ring 0: OS kernelI Outer rings: less privileged

software (drivers, userspaceprograms)

Image source: http://en.wikipedia.org/wiki/Protection_ring

OS Security – Authentication and Authorization 25

Page 87: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Protection rings in Linux

I Protection rings are supported by hardwareI Certain instructions can only be executed by privileged (ring-0) codeI X86 and AMD64 support 4 different rings (ring 0–3)I Trying to execute a ring-0 instruction from ring-3 results in SIGILL

(illegal instruction)I Idea:

I OS kernel (memory and process management) run in ring 0I Device drivers run in ring 1 and 2I Userspace software runs in ring 3

I Linux (and Windows) use a simpler supervisor-mode model:I Operating system runs with supervisor flag enabled (ring 0)I Userspace programs run with supervisor flag disabled (ring 3)

I Call ring-0 code kernel spaceI Call ring-3 code user space

OS Security – Authentication and Authorization 26

Page 88: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Protection rings in Linux

I Protection rings are supported by hardwareI Certain instructions can only be executed by privileged (ring-0) codeI X86 and AMD64 support 4 different rings (ring 0–3)I Trying to execute a ring-0 instruction from ring-3 results in SIGILL

(illegal instruction)I Idea:

I OS kernel (memory and process management) run in ring 0I Device drivers run in ring 1 and 2I Userspace software runs in ring 3

I Linux (and Windows) use a simpler supervisor-mode model:I Operating system runs with supervisor flag enabled (ring 0)I Userspace programs run with supervisor flag disabled (ring 3)

I Call ring-0 code kernel spaceI Call ring-3 code user space

OS Security – Authentication and Authorization 26

Page 89: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Protection rings in Linux

I Protection rings are supported by hardwareI Certain instructions can only be executed by privileged (ring-0) codeI X86 and AMD64 support 4 different rings (ring 0–3)I Trying to execute a ring-0 instruction from ring-3 results in SIGILL

(illegal instruction)I Idea:

I OS kernel (memory and process management) run in ring 0I Device drivers run in ring 1 and 2I Userspace software runs in ring 3

I Linux (and Windows) use a simpler supervisor-mode model:I Operating system runs with supervisor flag enabled (ring 0)I Userspace programs run with supervisor flag disabled (ring 3)I Call ring-0 code kernel spaceI Call ring-3 code user space

OS Security – Authentication and Authorization 26

Page 90: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

System calls and strace

I Transition from user space to kernel space through well-definedinterface

I Interface is a set of system calls (syscalls)I A system call is a request from user space to the OS to perform a

certain operation

I Access to system calls is typically implemented through the standardlibrary

I Examples:I write function defined in unistd.h is wrapper around write syscallI execve function defined in unistd.h is wrapper around execve

syscallI Sometimes don’t use system calls that directly, e.g., printf also

calls writeI Can print (trace) all syscalls of a program: straceI Very helpful for understanding what’s happening “behind the scenes”

OS Security – Authentication and Authorization 27

Page 91: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

System calls and strace

I Transition from user space to kernel space through well-definedinterface

I Interface is a set of system calls (syscalls)I A system call is a request from user space to the OS to perform a

certain operationI Access to system calls is typically implemented through the standard

libraryI Examples:

I write function defined in unistd.h is wrapper around write syscallI execve function defined in unistd.h is wrapper around execve

syscall

I Sometimes don’t use system calls that directly, e.g., printf alsocalls write

I Can print (trace) all syscalls of a program: straceI Very helpful for understanding what’s happening “behind the scenes”

OS Security – Authentication and Authorization 27

Page 92: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

System calls and strace

I Transition from user space to kernel space through well-definedinterface

I Interface is a set of system calls (syscalls)I A system call is a request from user space to the OS to perform a

certain operationI Access to system calls is typically implemented through the standard

libraryI Examples:

I write function defined in unistd.h is wrapper around write syscallI execve function defined in unistd.h is wrapper around execve

syscallI Sometimes don’t use system calls that directly, e.g., printf also

calls write

I Can print (trace) all syscalls of a program: straceI Very helpful for understanding what’s happening “behind the scenes”

OS Security – Authentication and Authorization 27

Page 93: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

System calls and strace

I Transition from user space to kernel space through well-definedinterface

I Interface is a set of system calls (syscalls)I A system call is a request from user space to the OS to perform a

certain operationI Access to system calls is typically implemented through the standard

libraryI Examples:

I write function defined in unistd.h is wrapper around write syscallI execve function defined in unistd.h is wrapper around execve

syscallI Sometimes don’t use system calls that directly, e.g., printf also

calls writeI Can print (trace) all syscalls of a program: straceI Very helpful for understanding what’s happening “behind the scenes”

OS Security – Authentication and Authorization 27

Page 94: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Applications and the OS

OS Security – Authentication and Authorization 28

Page 95: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything

in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processorsI Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 96: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspace

I root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processorsI Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 97: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resources

I What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processorsI Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 98: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?

I Example: enable userspace access to hardware cycle counter onARM processors

I Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 99: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processors

I Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 100: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processorsI Answer: Modify OS kernel (add syscall), reboot

I Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 101: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Kernel modules

I Processes belonging to root can do anything in userspaceI root processes do not run in kernel spaceI root processes need syscalls to access resourcesI What if there is no syscall for a certain operation?I Example: enable userspace access to hardware cycle counter on

ARM processorsI Answer: Modify OS kernel (add syscall), rebootI Better answer: Modify OS kernel at runtimeI Linux kernel typically allows to load kernel modulesI Modules run in kernel space (ring 0)I Load module into kernel with program insmod

OS Security – Authentication and Authorization 29

Page 102: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

A kernel module example#include <linux/module.h>#include <linux/kernel.h>MODULE_LICENSE("Dual BSD/GPL");

#define DEVICE_NAME "enableccnt"

static int enableccnt_init(void){

printk(KERN_INFO DEVICE_NAME " starting\n");asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(1));return 0;

}

static void enableccnt_exit(void){

asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(0));printk(KERN_INFO DEVICE_NAME " stopping\n");

}

module_init(enableccnt_init);module_exit(enableccnt_exit); OS Security – Authentication and Authorization 30

Page 103: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Files

I Persistent data on background storage is organized in filesI Files are logical units of information organized by a file systemI Files have names and additional associated information:

I Date and time of last accessI Date and time of last modificationI Access-permission-related information

I Files are logically organized in a tree hierarchy of directoriesI The file system maps logical information to bits and bytes on the

storage deviceI The file system runs in kernel space (typically through device drivers)I Access to files goes through system calls

OS Security – Authentication and Authorization 31

Page 104: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Files

I Persistent data on background storage is organized in filesI Files are logical units of information organized by a file systemI Files have names and additional associated information:

I Date and time of last accessI Date and time of last modificationI Access-permission-related information

I Files are logically organized in a tree hierarchy of directoriesI The file system maps logical information to bits and bytes on the

storage deviceI The file system runs in kernel space (typically through device drivers)I Access to files goes through system calls

OS Security – Authentication and Authorization 31

Page 105: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

“Everything is a file”

I Design principle of UNIX (and Linux): every persistent resource isaccessed through a file handle

I A file handle is an integer, which is mapped to a resourceI Mapping is established per process in a kernel-managed

file-descriptor table

I Special file handles for (almost) every process:Integer value Name/Meaning <stdio.h> file stream

0 Standard input stdin1 Standard output stdout2 Standard error stderr

I Consequence of “everything is a file”:I User-space processes can operate on files only through syscallsI OS can check for each syscall (kernel-space operation), whether the

operation is permitted

I (User-space programs also operate on memory, but that’s for nextlecture)

OS Security – Authentication and Authorization 32

Page 106: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

“Everything is a file”

I Design principle of UNIX (and Linux): every persistent resource isaccessed through a file handle

I A file handle is an integer, which is mapped to a resourceI Mapping is established per process in a kernel-managed

file-descriptor tableI Special file handles for (almost) every process:

Integer value Name/Meaning <stdio.h> file stream0 Standard input stdin1 Standard output stdout2 Standard error stderr

I Consequence of “everything is a file”:I User-space processes can operate on files only through syscallsI OS can check for each syscall (kernel-space operation), whether the

operation is permitted

I (User-space programs also operate on memory, but that’s for nextlecture)

OS Security – Authentication and Authorization 32

Page 107: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

“Everything is a file”

I Design principle of UNIX (and Linux): every persistent resource isaccessed through a file handle

I A file handle is an integer, which is mapped to a resourceI Mapping is established per process in a kernel-managed

file-descriptor tableI Special file handles for (almost) every process:

Integer value Name/Meaning <stdio.h> file stream0 Standard input stdin1 Standard output stdout2 Standard error stderr

I Consequence of “everything is a file”:I User-space processes can operate on files only through syscallsI OS can check for each syscall (kernel-space operation), whether the

operation is permitted

I (User-space programs also operate on memory, but that’s for nextlecture)

OS Security – Authentication and Authorization 32

Page 108: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

“Everything is a file”

I Design principle of UNIX (and Linux): every persistent resource isaccessed through a file handle

I A file handle is an integer, which is mapped to a resourceI Mapping is established per process in a kernel-managed

file-descriptor tableI Special file handles for (almost) every process:

Integer value Name/Meaning <stdio.h> file stream0 Standard input stdin1 Standard output stdout2 Standard error stderr

I Consequence of “everything is a file”:I User-space processes can operate on files only through syscallsI OS can check for each syscall (kernel-space operation), whether the

operation is permittedI (User-space programs also operate on memory, but that’s for next

lecture)

OS Security – Authentication and Authorization 32

Page 109: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handle

I read(): Read a number of bytes from a file handle into a bufferI write(): Write a number of bytes from a buffer to the file handleI close(): Close the file handleI lseek(): Change position in the file handleI access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 110: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handleI read(): Read a number of bytes from a file handle into a buffer

I write(): Write a number of bytes from a buffer to the file handleI close(): Close the file handleI lseek(): Change position in the file handleI access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 111: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handleI read(): Read a number of bytes from a file handle into a bufferI write(): Write a number of bytes from a buffer to the file handle

I close(): Close the file handleI lseek(): Change position in the file handleI access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 112: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handleI read(): Read a number of bytes from a file handle into a bufferI write(): Write a number of bytes from a buffer to the file handleI close(): Close the file handle

I lseek(): Change position in the file handleI access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 113: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handleI read(): Read a number of bytes from a file handle into a bufferI write(): Write a number of bytes from a buffer to the file handleI close(): Close the file handleI lseek(): Change position in the file handle

I access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 114: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

File-related syscalls

I open(): Open a file and return a file handleI read(): Read a number of bytes from a file handle into a bufferI write(): Write a number of bytes from a buffer to the file handleI close(): Close the file handleI lseek(): Change position in the file handleI access(): Check access rights based on real user ID (more later)

OS Security – Authentication and Authorization 33

Page 115: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pseudo filesystems proc and sys

I Files in /proc and /sys are “pseudo-files”I Those files provide reading or writing access to OS parameters

I Examples:I cat /proc/cpuinfo: Shows all kind of information about the CPUs

of the systemI cat /proc/meminfo: Shows all kind of information about the

memory of the system

I echo 1 > /proc/sys/net/ipv4/ip_forward: Enable IP forwardingI echo powersave > /sys/.../cpu0/cpufreq/scaling_governor:

Switch CPU0 to “powersave” mode

I Important for access control: reading/writing those parameters isimplemented through operations on (pseudo-)files

OS Security – Authentication and Authorization 34

Page 116: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pseudo filesystems proc and sys

I Files in /proc and /sys are “pseudo-files”I Those files provide reading or writing access to OS parametersI Examples:

I cat /proc/cpuinfo: Shows all kind of information about the CPUsof the system

I cat /proc/meminfo: Shows all kind of information about thememory of the system

I echo 1 > /proc/sys/net/ipv4/ip_forward: Enable IP forwardingI echo powersave > /sys/.../cpu0/cpufreq/scaling_governor:

Switch CPU0 to “powersave” modeI Important for access control: reading/writing those parameters is

implemented through operations on (pseudo-)files

OS Security – Authentication and Authorization 34

Page 117: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pseudo filesystems proc and sys

I Files in /proc and /sys are “pseudo-files”I Those files provide reading or writing access to OS parametersI Examples:

I cat /proc/cpuinfo: Shows all kind of information about the CPUsof the system

I cat /proc/meminfo: Shows all kind of information about thememory of the system

I echo 1 > /proc/sys/net/ipv4/ip_forward: Enable IP forwardingI echo powersave > /sys/.../cpu0/cpufreq/scaling_governor:

Switch CPU0 to “powersave” mode

I Important for access control: reading/writing those parameters isimplemented through operations on (pseudo-)files

OS Security – Authentication and Authorization 34

Page 118: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Pseudo filesystems proc and sys

I Files in /proc and /sys are “pseudo-files”I Those files provide reading or writing access to OS parametersI Examples:

I cat /proc/cpuinfo: Shows all kind of information about the CPUsof the system

I cat /proc/meminfo: Shows all kind of information about thememory of the system

I echo 1 > /proc/sys/net/ipv4/ip_forward: Enable IP forwardingI echo powersave > /sys/.../cpu0/cpufreq/scaling_governor:

Switch CPU0 to “powersave” modeI Important for access control: reading/writing those parameters is

implemented through operations on (pseudo-)files

OS Security – Authentication and Authorization 34

Page 119: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Device files

I Hardware devices are represented as files in /dev/I Examples:

I /dev/sda: First hard driveI /dev/sda1: First partition on first hard driveI /dev/tty*: Serial devices and terminalsI /dev/input/*: Input devicesI /dev/zero: Pseudo-devices that prints zerosI /dev/random: Pseudo-devices that prints random bytes

I Generally be very careful when writing to device filesI dd if=/dev/zero of=/dev/sda overwrites your whole hard drive

with zerosI Again, important for access control: accessing (hardware) devices is

implemented through operations on (device-)files

OS Security – Authentication and Authorization 35

Page 120: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Device files

I Hardware devices are represented as files in /dev/I Examples:

I /dev/sda: First hard driveI /dev/sda1: First partition on first hard driveI /dev/tty*: Serial devices and terminalsI /dev/input/*: Input devicesI /dev/zero: Pseudo-devices that prints zerosI /dev/random: Pseudo-devices that prints random bytes

I Generally be very careful when writing to device filesI dd if=/dev/zero of=/dev/sda overwrites your whole hard drive

with zeros

I Again, important for access control: accessing (hardware) devices isimplemented through operations on (device-)files

OS Security – Authentication and Authorization 35

Page 121: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Device files

I Hardware devices are represented as files in /dev/I Examples:

I /dev/sda: First hard driveI /dev/sda1: First partition on first hard driveI /dev/tty*: Serial devices and terminalsI /dev/input/*: Input devicesI /dev/zero: Pseudo-devices that prints zerosI /dev/random: Pseudo-devices that prints random bytes

I Generally be very careful when writing to device filesI dd if=/dev/zero of=/dev/sda overwrites your whole hard drive

with zerosI Again, important for access control: accessing (hardware) devices is

implemented through operations on (device-)files

OS Security – Authentication and Authorization 35

Page 122: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Symbolic links and pipes

I A symbolic link is a special file that “links” to another fileI Accessing a symbolic link really accesses the file it points toI Create a symbolic link to /home/peter/teaching/ with name

/home/peter/ru:ln -s /home/peter/teaching /home/peter/ru

I Can also create a hard link:ln /home/peter/teaching /home/peter/ru

I Soft links don’t get updated when the target is movedI Hard links always point to the targetI Access is again handled through file handles, need to be careful with

permissionsI Pipes for inter-process communication are also implemented through

file handles

OS Security – Authentication and Authorization 36

Page 123: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Symbolic links and pipes

I A symbolic link is a special file that “links” to another fileI Accessing a symbolic link really accesses the file it points toI Create a symbolic link to /home/peter/teaching/ with name

/home/peter/ru:ln -s /home/peter/teaching /home/peter/ru

I Can also create a hard link:ln /home/peter/teaching /home/peter/ru

I Soft links don’t get updated when the target is movedI Hard links always point to the target

I Access is again handled through file handles, need to be careful withpermissions

I Pipes for inter-process communication are also implemented throughfile handles

OS Security – Authentication and Authorization 36

Page 124: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Symbolic links and pipes

I A symbolic link is a special file that “links” to another fileI Accessing a symbolic link really accesses the file it points toI Create a symbolic link to /home/peter/teaching/ with name

/home/peter/ru:ln -s /home/peter/teaching /home/peter/ru

I Can also create a hard link:ln /home/peter/teaching /home/peter/ru

I Soft links don’t get updated when the target is movedI Hard links always point to the targetI Access is again handled through file handles, need to be careful with

permissions

I Pipes for inter-process communication are also implemented throughfile handles

OS Security – Authentication and Authorization 36

Page 125: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Symbolic links and pipes

I A symbolic link is a special file that “links” to another fileI Accessing a symbolic link really accesses the file it points toI Create a symbolic link to /home/peter/teaching/ with name

/home/peter/ru:ln -s /home/peter/teaching /home/peter/ru

I Can also create a hard link:ln /home/peter/teaching /home/peter/ru

I Soft links don’t get updated when the target is movedI Hard links always point to the targetI Access is again handled through file handles, need to be careful with

permissionsI Pipes for inter-process communication are also implemented through

file handles

OS Security – Authentication and Authorization 36

Page 126: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Environment variables

I One might think that data flow between processes can only happenthrough files

I Process A writes a file, process B reads the file

I Other way of communicating: environment variablesI Process A can set an environment variable, process B can read itI Set an environment variable through

export MYVAR=myvalue

I Show all currently defined environment variables: exportI Important system-wide variables:

I PATH: colon-separated list of directories to search for programsI LD_LIBRARY_PATH: colon-separated list of directories to search for

libraries

OS Security – Authentication and Authorization 37

Page 127: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Environment variables

I One might think that data flow between processes can only happenthrough files

I Process A writes a file, process B reads the fileI Other way of communicating: environment variablesI Process A can set an environment variable, process B can read it

I Set an environment variable throughexport MYVAR=myvalue

I Show all currently defined environment variables: exportI Important system-wide variables:

I PATH: colon-separated list of directories to search for programsI LD_LIBRARY_PATH: colon-separated list of directories to search for

libraries

OS Security – Authentication and Authorization 37

Page 128: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Environment variables

I One might think that data flow between processes can only happenthrough files

I Process A writes a file, process B reads the fileI Other way of communicating: environment variablesI Process A can set an environment variable, process B can read itI Set an environment variable through

export MYVAR=myvalue

I Show all currently defined environment variables: export

I Important system-wide variables:I PATH: colon-separated list of directories to search for programsI LD_LIBRARY_PATH: colon-separated list of directories to search for

libraries

OS Security – Authentication and Authorization 37

Page 129: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Environment variables

I One might think that data flow between processes can only happenthrough files

I Process A writes a file, process B reads the fileI Other way of communicating: environment variablesI Process A can set an environment variable, process B can read itI Set an environment variable through

export MYVAR=myvalue

I Show all currently defined environment variables: exportI Important system-wide variables:

I PATH: colon-separated list of directories to search for programsI LD_LIBRARY_PATH: colon-separated list of directories to search for

libraries

OS Security – Authentication and Authorization 37

Page 130: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

MAC and DAC

Protection systemA protection system consists of a protection state, which describes whatoperations subjects (processes) may perform on objects (files) togetherwith a set of protection state operations that enable modification of thestate.

Mandatory Access ControlA system implements mandatory access control (MAC) if the protectionstate can only be modified by trusted administrators via trusted software.

Discretionary Access ControlA system implements discretionary access control (DAC) if the protectionstate can be modified by untrusted users. The protection of a user’s filesis then “at the discretion of the user”.

OS Security – Authentication and Authorization 38

Page 131: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

MAC and DAC

Protection systemA protection system consists of a protection state, which describes whatoperations subjects (processes) may perform on objects (files) togetherwith a set of protection state operations that enable modification of thestate.

Mandatory Access ControlA system implements mandatory access control (MAC) if the protectionstate can only be modified by trusted administrators via trusted software.

Discretionary Access ControlA system implements discretionary access control (DAC) if the protectionstate can be modified by untrusted users. The protection of a user’s filesis then “at the discretion of the user”.

OS Security – Authentication and Authorization 38

Page 132: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

MAC and DAC

Protection systemA protection system consists of a protection state, which describes whatoperations subjects (processes) may perform on objects (files) togetherwith a set of protection state operations that enable modification of thestate.

Mandatory Access ControlA system implements mandatory access control (MAC) if the protectionstate can only be modified by trusted administrators via trusted software.

Discretionary Access ControlA system implements discretionary access control (DAC) if the protectionstate can be modified by untrusted users. The protection of a user’s filesis then “at the discretion of the user”.

OS Security – Authentication and Authorization 38

Page 133: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access Matrix

An access matrix is a set of subjects S, a set of objects O, a set ofoperations X and a function op : S ×O → P(X). Given s ∈ S ando ∈ O, the function op returns the set of operations that s is allowed toperform on o.

OS Security – Authentication and Authorization 39

Page 134: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access Matrix

File 1 File 2 File 3 File 4Process 1 read read read,writeProcess 2 readProcess 3 read,write read

I When a user creates a file, she adds a column to the tableI Adding a column means modifying the protection stateI The access-matrix model leads to a DAC system

OS Security – Authentication and Authorization 39

Page 135: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access Matrix

File 1 File 2 File 3 File 4Process 1 read read read,writeProcess 2 readProcess 3 read,write read

I When a user creates a file, she adds a column to the tableI Adding a column means modifying the protection stateI The access-matrix model leads to a DAC system

OS Security – Authentication and Authorization 39

Page 136: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model

I Trusted code base (TCB) of Linux is all code running in kernel spaceand several processes running with root permissions, e.g.:

I init processI login (user authentication)I network services

I Goal: protect users’ processes from each other and the TCB from alluser processes

OS Security – Authentication and Authorization 40

Page 137: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: subjects

I Each process has associated three user IDs:I Real user IDI Effective user IDI Saved user ID

I Each process also has associated a set of group IDsI The groups of all users are defined in /etc/groupI Each user has a primary group defined in /etc/passwdI When you are logged in, you can see your groups with the command

groups

OS Security – Authentication and Authorization 41

Page 138: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: subjects

I Each process has associated three user IDs:I Real user IDI Effective user IDI Saved user ID

I Each process also has associated a set of group IDsI The groups of all users are defined in /etc/groupI Each user has a primary group defined in /etc/passwdI When you are logged in, you can see your groups with the command

groups

OS Security – Authentication and Authorization 41

Page 139: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: objects

I Each object (file) hasI an owner (user) and owner permissionsI a group and group permissionsI other permissions

I Permissions on a file are read (r), write (w) and execute (x)I Typically write permissions as 9 bits: rwx︸︷︷︸

owner

rwx︸︷︷︸group

rwx︸︷︷︸other

I Convenient way of writing this: 3 numbers from 0–7, e.g.:I 750: owner may read, write, and execute; group may read and

execute, others may nothingI 644: owner may read and write; group and others may read

I Command ls -l shows files with corresponding permissions, e.g.peter@tyrion:/etc$ ls -l passwd shadow-rw-r--r-- 1 root root 2217 Nov 16 18:13 passwd-rw-r----- 1 root shadow 1454 Nov 16 18:13 shadow

OS Security – Authentication and Authorization 42

Page 140: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: objects

I Each object (file) hasI an owner (user) and owner permissionsI a group and group permissionsI other permissions

I Permissions on a file are read (r), write (w) and execute (x)I Typically write permissions as 9 bits: rwx︸︷︷︸

owner

rwx︸︷︷︸group

rwx︸︷︷︸other

I Convenient way of writing this: 3 numbers from 0–7, e.g.:I 750: owner may read, write, and execute; group may read and

execute, others may nothingI 644: owner may read and write; group and others may read

I Command ls -l shows files with corresponding permissions, e.g.peter@tyrion:/etc$ ls -l passwd shadow-rw-r--r-- 1 root root 2217 Nov 16 18:13 passwd-rw-r----- 1 root shadow 1454 Nov 16 18:13 shadow

OS Security – Authentication and Authorization 42

Page 141: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: objects

I Each object (file) hasI an owner (user) and owner permissionsI a group and group permissionsI other permissions

I Permissions on a file are read (r), write (w) and execute (x)I Typically write permissions as 9 bits: rwx︸︷︷︸

owner

rwx︸︷︷︸group

rwx︸︷︷︸other

I Convenient way of writing this: 3 numbers from 0–7, e.g.:I 750: owner may read, write, and execute; group may read and

execute, others may nothingI 644: owner may read and write; group and others may read

I Command ls -l shows files with corresponding permissions, e.g.peter@tyrion:/etc$ ls -l passwd shadow-rw-r--r-- 1 root root 2217 Nov 16 18:13 passwd-rw-r----- 1 root shadow 1454 Nov 16 18:13 shadow

OS Security – Authentication and Authorization 42

Page 142: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: objects

I Each object (file) hasI an owner (user) and owner permissionsI a group and group permissionsI other permissions

I Permissions on a file are read (r), write (w) and execute (x)I Typically write permissions as 9 bits: rwx︸︷︷︸

owner

rwx︸︷︷︸group

rwx︸︷︷︸other

I Convenient way of writing this: 3 numbers from 0–7, e.g.:I 750: owner may read, write, and execute; group may read and

execute, others may nothingI 644: owner may read and write; group and others may read

I Command ls -l shows files with corresponding permissions, e.g.peter@tyrion:/etc$ ls -l passwd shadow-rw-r--r-- 1 root root 2217 Nov 16 18:13 passwd-rw-r----- 1 root shadow 1454 Nov 16 18:13 shadow

OS Security – Authentication and Authorization 42

Page 143: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: matching

I When a process wants to access a file, check the following1. Does the effective user ID of the process match the owner of the

file? If so, use the owner permissions.2. Does one of the group IDs of the process match the group of the

file? If so, use the group permissions.3. Otherwise, use the “other” permissions

I Note: if the owner matches, the group permissions don’t matter.

Directory permissions

I read: Can see content (files and subdirectories) of the directoryI write: Can rename and delete content of the directory and create

new contentI execute: Can traverse the directory (cd into or across the directory)

OS Security – Authentication and Authorization 43

Page 144: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: matching

I When a process wants to access a file, check the following1. Does the effective user ID of the process match the owner of the

file? If so, use the owner permissions.2. Does one of the group IDs of the process match the group of the

file? If so, use the group permissions.3. Otherwise, use the “other” permissions

I Note: if the owner matches, the group permissions don’t matter.

Directory permissions

I read: Can see content (files and subdirectories) of the directoryI write: Can rename and delete content of the directory and create

new contentI execute: Can traverse the directory (cd into or across the directory)

OS Security – Authentication and Authorization 43

Page 145: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: matching

I When a process wants to access a file, check the following1. Does the effective user ID of the process match the owner of the

file? If so, use the owner permissions.2. Does one of the group IDs of the process match the group of the

file? If so, use the group permissions.3. Otherwise, use the “other” permissions

I Note: if the owner matches, the group permissions don’t matter.

Directory permissionsI read: Can see content (files and subdirectories) of the directory

I write: Can rename and delete content of the directory and createnew content

I execute: Can traverse the directory (cd into or across the directory)

OS Security – Authentication and Authorization 43

Page 146: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: matching

I When a process wants to access a file, check the following1. Does the effective user ID of the process match the owner of the

file? If so, use the owner permissions.2. Does one of the group IDs of the process match the group of the

file? If so, use the group permissions.3. Otherwise, use the “other” permissions

I Note: if the owner matches, the group permissions don’t matter.

Directory permissionsI read: Can see content (files and subdirectories) of the directoryI write: Can rename and delete content of the directory and create

new content

I execute: Can traverse the directory (cd into or across the directory)

OS Security – Authentication and Authorization 43

Page 147: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

UNIX/Linux protection model: matching

I When a process wants to access a file, check the following1. Does the effective user ID of the process match the owner of the

file? If so, use the owner permissions.2. Does one of the group IDs of the process match the group of the

file? If so, use the group permissions.3. Otherwise, use the “other” permissions

I Note: if the owner matches, the group permissions don’t matter.

Directory permissionsI read: Can see content (files and subdirectories) of the directoryI write: Can rename and delete content of the directory and create

new contentI execute: Can traverse the directory (cd into or across the directory)

OS Security – Authentication and Authorization 43

Page 148: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The setuid bit

I Sometimes users need to have access to privileged resourcesI UNIX/Linux solution: additional setuid (suid) bit in file permissionsI Run program with permissions of owner instead of user starting it

I Set suid bit with chmod u+s or, e.g., chmod 4755I User IDs of a suid program:

I Real user ID: ID of the user starting the programI Effective user ID: ID of the ownerI Saved user ID: set to effective user ID at the beginning

I Most important application: setuid rootI Setuid root process can drop privileges (effective ID)I Can regain root rights as long as saved ID is still 0!

OS Security – Authentication and Authorization 44

Page 149: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The setuid bit

I Sometimes users need to have access to privileged resourcesI UNIX/Linux solution: additional setuid (suid) bit in file permissionsI Run program with permissions of owner instead of user starting itI Set suid bit with chmod u+s or, e.g., chmod 4755

I User IDs of a suid program:I Real user ID: ID of the user starting the programI Effective user ID: ID of the ownerI Saved user ID: set to effective user ID at the beginning

I Most important application: setuid rootI Setuid root process can drop privileges (effective ID)I Can regain root rights as long as saved ID is still 0!

OS Security – Authentication and Authorization 44

Page 150: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The setuid bit

I Sometimes users need to have access to privileged resourcesI UNIX/Linux solution: additional setuid (suid) bit in file permissionsI Run program with permissions of owner instead of user starting itI Set suid bit with chmod u+s or, e.g., chmod 4755I User IDs of a suid program:

I Real user ID: ID of the user starting the programI Effective user ID: ID of the ownerI Saved user ID: set to effective user ID at the beginning

I Most important application: setuid rootI Setuid root process can drop privileges (effective ID)I Can regain root rights as long as saved ID is still 0!

OS Security – Authentication and Authorization 44

Page 151: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

The setuid bit

I Sometimes users need to have access to privileged resourcesI UNIX/Linux solution: additional setuid (suid) bit in file permissionsI Run program with permissions of owner instead of user starting itI Set suid bit with chmod u+s or, e.g., chmod 4755I User IDs of a suid program:

I Real user ID: ID of the user starting the programI Effective user ID: ID of the ownerI Saved user ID: set to effective user ID at the beginning

I Most important application: setuid rootI Setuid root process can drop privileges (effective ID)I Can regain root rights as long as saved ID is still 0!

OS Security – Authentication and Authorization 44

Page 152: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

setuid example: su

I Most prominent example of setuid-root program: suI su can stand for “switch user” or “superuser”I Without any argument, become rootI Can provide other username as argument

I Authentication uses PAM, typical (piece of) /etc/pam.d/su:auth sufficient pam_rootok.sosession required pam_limits.soauth required pam_unix.so

I Other prominent example: passwd (needs write access to/etc/shadow)

I Again, authenticate against PAM before doing anything

OS Security – Authentication and Authorization 45

Page 153: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

setuid example: su

I Most prominent example of setuid-root program: suI su can stand for “switch user” or “superuser”I Without any argument, become rootI Can provide other username as argumentI Authentication uses PAM, typical (piece of) /etc/pam.d/su:

auth sufficient pam_rootok.sosession required pam_limits.soauth required pam_unix.so

I Other prominent example: passwd (needs write access to/etc/shadow)

I Again, authenticate against PAM before doing anything

OS Security – Authentication and Authorization 45

Page 154: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

setuid example: su

I Most prominent example of setuid-root program: suI su can stand for “switch user” or “superuser”I Without any argument, become rootI Can provide other username as argumentI Authentication uses PAM, typical (piece of) /etc/pam.d/su:

auth sufficient pam_rootok.sosession required pam_limits.soauth required pam_unix.so

I Other prominent example: passwd (needs write access to/etc/shadow)

I Again, authenticate against PAM before doing anything

OS Security – Authentication and Authorization 45

Page 155: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Privilege escalation

I Attack that expands attacker’s privileges is called privilege escalationI Two types of privilege escalation:

I horizontal: obtain privileges of another un-privileged userI vertical: obtain privileges of root (or the kernel), “privilege elevation”

I Typicall enabled by bugs in privileged software:I Bugs in the kernelI Bugs in how root programs process user-provided inputI Bugs in suid-root programs (escape intended functionality)

I An exploit that lets an unprivileged (logged in, local) user gain rootrights is called local root exploit

OS Security – Authentication and Authorization 46

Page 156: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Privilege escalation

I Attack that expands attacker’s privileges is called privilege escalationI Two types of privilege escalation:

I horizontal: obtain privileges of another un-privileged userI vertical: obtain privileges of root (or the kernel), “privilege elevation”

I Typicall enabled by bugs in privileged software:I Bugs in the kernelI Bugs in how root programs process user-provided inputI Bugs in suid-root programs (escape intended functionality)

I An exploit that lets an unprivileged (logged in, local) user gain rootrights is called local root exploit

OS Security – Authentication and Authorization 46

Page 157: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Privilege escalation

I Attack that expands attacker’s privileges is called privilege escalationI Two types of privilege escalation:

I horizontal: obtain privileges of another un-privileged userI vertical: obtain privileges of root (or the kernel), “privilege elevation”

I Typicall enabled by bugs in privileged software:I Bugs in the kernelI Bugs in how root programs process user-provided inputI Bugs in suid-root programs (escape intended functionality)

I An exploit that lets an unprivileged (logged in, local) user gain rootrights is called local root exploit

OS Security – Authentication and Authorization 46

Page 158: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access control lists

I User/Group/All model is not always flexible enoughI Want to enable arbitrary access permissionsI Solution: Access Control Lists (ACLs)

I Grant permissions to arbitrary users and groupsI Needs support from the file systemI Mount with option acl, for example:

mount -o remount,acl /

I Set ACL entries with the program setfacl (set file access controllists)

I Read ACL entries with getfacl (get file access control lists)I Note: ls -l will not show ACLs, only a ’+’ to indicate that “there’s

more”

OS Security – Authentication and Authorization 47

Page 159: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access control lists

I User/Group/All model is not always flexible enoughI Want to enable arbitrary access permissionsI Solution: Access Control Lists (ACLs)I Grant permissions to arbitrary users and groupsI Needs support from the file systemI Mount with option acl, for example:

mount -o remount,acl /

I Set ACL entries with the program setfacl (set file access controllists)

I Read ACL entries with getfacl (get file access control lists)I Note: ls -l will not show ACLs, only a ’+’ to indicate that “there’s

more”

OS Security – Authentication and Authorization 47

Page 160: OSSecurity · ExamplesofPAMmodules Name Activities Description pam_unix auth, session, password Standard UNIX authentication through /etc/shadow passwords pam_permit auth, account,

Access control lists

I User/Group/All model is not always flexible enoughI Want to enable arbitrary access permissionsI Solution: Access Control Lists (ACLs)I Grant permissions to arbitrary users and groupsI Needs support from the file systemI Mount with option acl, for example:

mount -o remount,acl /

I Set ACL entries with the program setfacl (set file access controllists)

I Read ACL entries with getfacl (get file access control lists)I Note: ls -l will not show ACLs, only a ’+’ to indicate that “there’s

more”

OS Security – Authentication and Authorization 47