computer security seminar api attacks

26
Computer Security Seminar API Attacks Security Engineering/Ross Andersson, Chapter 18 Shai Ziv 25 th May, 2014

Upload: others

Post on 23-Feb-2022

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Security Seminar API Attacks

Computer Security SeminarAPI Attacks

Security Engineering/Ross Andersson, Chapter 18

Shai Ziv

25th May, 2014

Page 2: Computer Security Seminar API Attacks

Application Programming Interface

โ€ข Interface for communication between two programs.โ€ข Two threads of the same program.

โ€ข Two programs running on the same server.

โ€ข Client and server.

Page 3: Computer Security Seminar API Attacks

API is Vulnerable

โ€ข Door to the outer world.

โ€ข Untrusted sources give commands.

โ€ข Designing a secure API is very difficult.

โ€ข Small programming oversights can be disastrous.

Page 4: Computer Security Seminar API Attacks

The Perfect API

void API(void)

{

printf(โ€œNo commands availableโ€);

}

Useful, eh?

Page 5: Computer Security Seminar API Attacks

Attack on Visa Security Module

โ€ข Hardware device for bank security.

โ€ข Stores no memory.โ€ข Only a single master key stored in tamper-resistant memory.

โ€ข Encryption under this key is โ€œunbreakableโ€.

โ€ข We will look at the Terminal Key Generation for ATMs

โ€ข ATM security is based on dual control (secret sharing)โ€ข ๐พ = ๐พ1 โŠ• ๐พ2

Page 6: Computer Security Seminar API Attacks

Attack on Visa Security Module โ€“cont.โ€ข Key creation:

๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ๐‘€(๐พ1)

๐‘‰๐‘†๐‘€๐พ1

๐‘Š๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ 1

๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ๐‘€(๐พ2)

๐‘‰๐‘†๐‘€๐พ2

๐‘Š๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ 2

๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ๐‘€ ๐พ1 ,๐ธ๐‘€(๐พ2)

๐‘‰๐‘†๐‘€

๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ๐‘€(๐พ=๐พ1โŠ•๐พ2)

๐‘‰๐‘†๐‘€

โ€ข What happens if we insert the same encrypted key twice?โ€ข ๐พ = ๐พ1 โŠ• ๐พ1 = 0.

โ€ข Known key inside the system.

Page 7: Computer Security Seminar API Attacks

Attack on Visa Security Module โ€“ cont.

โ€ข The problem: Support of offline ATMs.

โ€ข ๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Žm๐ธ๐‘€ ๐‘ƒ๐ผ๐‘ ,๐ธ๐‘€(๐พ)

๐‘‰๐‘†๐‘€

โ€ข ๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ๐พ(๐‘ƒ๐ผ๐‘)

๐‘‰๐‘†๐‘€

โ€ข ๐‘ƒ๐ผ๐‘ = ๐ท0(โ‹…).

Page 8: Computer Security Seminar API Attacks

Attack on Visa Security Module โ€“ cont.

โ€ข How to fix?

โ€ข Independent atomic commands!

๐‘ƒ๐‘Ÿ๐‘œ๐‘”๐‘Ÿ๐‘Ž๐‘š๐ธ(๐พ)

๐‘‰๐‘†๐‘€๐‘Š๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ 1

๐‘Š๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ 2

๐พ1

๐พ2

Page 9: Computer Security Seminar API Attacks

Attack on IBM PIN Generation

โ€ข Wild credit cards appear!

โ€ข IBM uses PIN generation.

โ€ข Itโ€™s not very effectiveโ€ฆ

โ€ข In IBM PIN code generation, ๐‘ƒ๐ผ๐‘๐ถ depends on 3 values:โ€ข ๐‘ƒ๐ผ๐‘๐‘€ โ€“ bankโ€™s master PIN.

โ€ข ๐‘๐ถ โ€“ account number.

โ€ข ๐‘œ๐‘“๐‘“๐‘ ๐‘’๐‘ก โ€“ for memorable (weak) PIN.

Page 10: Computer Security Seminar API Attacks

Attack on IBM PIN Generation โ€“ cont.

โ€ข The algorithm:

๐ป๐‘’๐‘ฅ = ๐ธ๐‘ƒ๐ผ๐‘๐‘€๐‘๐ถ ๐ป๐‘’๐‘ฅ = ๐‘Ž2๐‘๐‘’126๐‘69๐‘Ž๐‘’๐‘82๐‘‘

๐ท๐‘’๐‘ = ๐ท๐‘’๐‘_๐‘‡๐‘Ž๐‘๐‘™๐‘’(๐ป๐‘’๐‘ฅ) ๐ท๐‘’๐‘ = 022412626904823

๐‘ƒ๐ผ๐‘๐ถ = ๐ท๐‘’๐‘ 1. . 4 + ๐‘œ๐‘“๐‘“๐‘ ๐‘’๐‘ก ๐‘ƒ๐ผ๐‘๐ถ = 0224 + 6565 = 6789

โ€ข Great Idea (?): ๐ท๐‘’๐‘_๐‘‡๐‘Ž๐‘๐‘™๐‘’ is supplied by the user.

โ€ข ๐ท๐‘’๐‘_๐‘‡๐‘Ž๐‘๐‘™๐‘’ = 0123456789012345 was widely used.

Page 11: Computer Security Seminar API Attacks

Attack on IBM PIN Generation โ€“ cont.

โ€ข Set ๐ท๐‘’๐‘_๐‘‡๐‘Ž๐‘๐‘™๐‘’ = 0000000000000000.

โ€ข Get E ๐‘ƒ๐ผ๐‘๐ถ = 0000 .

โ€ข Set ๐ท๐‘’๐‘_๐‘‡๐‘Ž๐‘๐‘™๐‘’ = 1000000000000000.

โ€ข If ๐ธ(๐‘ƒ๐ผ๐‘๐ถ) changed, then it contained a โ€˜0โ€™.

โ€ข And so onโ€ฆ

โ€ข With a few dozen queries ๐‘ƒ๐ผ๐‘๐ถ can be found.

Page 12: Computer Security Seminar API Attacks

Attack on IBM PIN Generation โ€“ cont.

โ€ข How to fix?โ€ข IBMโ€™s โ€œsolutionโ€:

โ€ข Must contain at least 8 different characters, that appear at most 4 times.

โ€ข What about โ€œ0123456789012345โ€, then โ€œ1123456789012345โ€, and so on?

โ€ข Be careful when using userโ€™s input, and avoid it as much as possible.โ€ข Remember the perfect API!

Page 13: Computer Security Seminar API Attacks

API Programming - Input Check

โ€ข The API itself can be 100% safe.

โ€ข The communication still will not be secure.

โ€ข Before you execute, check the input you are executing!

Page 14: Computer Security Seminar API Attacks

SQL Injection (Input Check โ€“ example)

โ€ข Many APIs use SQL transactions in the background.

โ€ข The code is written in advance,

and the parameters are taken from the API call.

โ€ข If the parameter isnโ€™t checked, SQL code can be โ€˜Injectedโ€™ and executed.

Page 15: Computer Security Seminar API Attacks

โ€ข SQL code:๐‘ ๐‘’๐‘™๐‘’๐‘๐‘ก โˆ—๐‘“๐‘Ÿ๐‘œ๐‘š ๐‘ค๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ๐‘ ๐‘คโ„Ž๐‘’๐‘Ÿ๐‘’ ๐‘›๐‘Ž๐‘š๐‘’ = โ€ฒ$$โ€ฒ ;

โ€ข Expected parameter ($$): ๐‘†โ„Ž๐‘Ž๐‘– ๐‘๐‘–๐‘ฃ

โ€ข Attackerโ€™s parameter: ๐‘†โ„Ž๐‘Ž๐‘– ๐‘๐‘–๐‘ฃโ€ฒ); ๐‘–๐‘›๐‘ ๐‘’๐‘Ÿ๐‘ก ๐‘–๐‘›๐‘ก๐‘œ ๐‘ค๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ๐‘  ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘  (โ€ฒ๐ฝ๐‘œ๐‘“๐‘“๐‘Ÿ๐‘’๐‘ฆ ๐ต๐‘Ž๐‘Ÿ๐‘Ž๐‘กโ„Ž๐‘’๐‘œ๐‘›

โ€ข When inserted:๐‘ ๐‘’๐‘™๐‘’๐‘๐‘ก โˆ—๐‘“๐‘Ÿ๐‘œ๐‘š ๐‘ค๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ๐‘ ๐‘คโ„Ž๐‘’๐‘Ÿ๐‘’ ๐‘›๐‘Ž๐‘š๐‘’ = (โ€ฒ๐‘†โ„Ž๐‘Ž๐‘– ๐‘๐‘–๐‘ฃโ€ฒ);

๐‘–๐‘›๐‘ ๐‘’๐‘Ÿ๐‘ก ๐‘–๐‘›๐‘ก๐‘œ ๐‘ค๐‘œ๐‘Ÿ๐‘˜๐‘’๐‘Ÿ๐‘ ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘  (โ€ฒ๐ฝ๐‘œ๐‘“๐‘“๐‘Ÿ๐‘’๐‘ฆ ๐ต๐‘Ž๐‘Ÿ๐‘Ž๐‘กโ„Ž๐‘’๐‘œ๐‘›โ€ฒ);

Page 16: Computer Security Seminar API Attacks

SQL Injection โ€“ cont.

Page 17: Computer Security Seminar API Attacks

Buffer Overflow (Input Check โ€“ example)

โ€ข Every API reads input from the user.

โ€ข No computer has an infinite input buffer.

โ€ข Devastating attacks can be executed if input string length is not checked.

โ€ข What is the problem here?

๐‘š๐‘Ž๐‘–๐‘› โ‹…

{๐‘โ„Ž๐‘Ž๐‘Ÿ ๐‘๐‘ข๐‘“๐‘“๐‘’๐‘Ÿ 128 ;๐‘”๐‘’๐‘ก๐‘  ๐‘๐‘ข๐‘“๐‘“๐‘’๐‘Ÿ ;

}

Page 18: Computer Security Seminar API Attacks

Buffer Overflow โ€“ The Stack

Stack

gets locals

BP

return addr

param - buffer

buffer

BP

return addr

gets frame

main frame

Page 19: Computer Security Seminar API Attacks

No Buffer Overflow โ€“ No Attack

Stack

gets locals

BP

return addr

param - buffer

buffer

BP

return addr

Stack

gets locals

BP

return addr

param - buffer

โ€˜Hello World!โ€™

BP

return addr

Stack

โ€˜Hello World!โ€™

BP

return addr

Page 20: Computer Security Seminar API Attacks

Buffer Overflow โ€“ The Attack

Stack

gets locals

BP

return addr

param - buffer

buffer

BP

return addr

Stack

gets locals

BP

return addr

param - buffer

Code:download(โ€˜nyan.mp3โ€™)

while ( 1 )play(โ€˜nyan.mp3โ€™)

~override~

buffer addr

โ€ข main finishes as usualโ€ข Computer is infected

Page 21: Computer Security Seminar API Attacks

Summary โ€“ API Design

โ€ข Designing a secure set of commands is very difficult.

โ€ข Single secure looking command might be insecure.

โ€ข Multiple secure commands might be insecure when combined.

โ€ข Each user input can be used for an attack.

Page 22: Computer Security Seminar API Attacks

Summary โ€“ API Design โ€“ cont.

โ€ข Simplicity is key.โ€ข Complicated APIs are all the more vulnerable.โ€ข Atomic and independent commands.

โ€ข Many failures happen when adding features to API.โ€ข When designed initially, those features were not considered.โ€ข The feature itself should be checked and rechecked.โ€ข Relations between the new feature and old features might be problematic.โ€ข Is the feature necessary?

โ€ข Use as minimal input as possible.โ€ข There is no reason to use a parameter from the user, when you know its value in advance.

Page 23: Computer Security Seminar API Attacks

Summary โ€“ API Implementation

โ€ข Input check.

โ€ข Input check.

โ€ข Input check.

โ€ข The code which handles the userโ€™s input is extremely critical, and should be treated that way.

Page 24: Computer Security Seminar API Attacks

Backup

Page 25: Computer Security Seminar API Attacks

Attack on the 4758

โ€ข 4758 is IBMโ€™s equivalent to Visaโ€™s module.

โ€ข The 4758 supported โ€œcheck valueโ€ creation for a key ๐พ

โ€ข ๐‘โ„Ž๐‘’๐‘๐‘˜ = ๐ธ๐พ(0)

โ€ข At the time the key length was 56 bits.โ€ข This means we need 255 effort to crack an unknown key,

which is (not really) too much.

Page 26: Computer Security Seminar API Attacks

Attack on the 4758 โ€“ cont.

โ€ข We do not need to crack a specific key.โ€ข The 4758 would re-encrypt data with a different key

โ€ข Meet in the middle attack:1. Collect a number of check values. Say 216 (takes a few hours)

2. Store them in a hash table.

3. Go over keys until you get a hit. (takes 256

216 = 240 effort)

4. ?????

5. Profit.