khash kiani khash@thinksec - black hat briefings · recommendations (mobile apps) ‣ client...

59
OAuth securing the insecure Black Hat US 2011 khash kiani [email protected]

Upload: others

Post on 21-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

OAuth securing the insecure

Black  Hat  US  2011    

khash [email protected]

Page 2: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

2

roadmap

‣ OAuth flow‣ malicious sample applications

✴ mobile OAuth google app✴ web-based OAuth facebook app

‣ insecure implementation ✴ flawed session management✴ password management✴ insecure storage of secrets

‣ summary

Page 3: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

3

what’s OAuth?

Page 4: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

user-centric schemeuser controls authorization

user

AIG Token

FMToken

Twitter Token

Twitter Token

4

Page 5: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

actors:resource owner (user)resource consumer (client)resource provider (server)

tokens:consumer credentialsrequest tokenaccess token

5

Page 6: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

authorization flow

1. client app authentication 2. get request token: POST oauth/request_token 3. authenticate user: GET oauth/authorize 4. get access token: POST oauth/access_token

6

Page 7: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

building malicious OAuth clients(native and web apps)

7

Page 8: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

password theft with Google client(a native iOS mobile app)

8

Page 9: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

OAuthSampleTouch mobile Google app

‣ download‣ compile‣ run

‣ edit controller

9

Page 10: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

modify the UIWebViewDelegate’s:webView:shouldStartLoadWithRequest:navigationType

callback method to intercept the login page prior to sending the post request

10

Page 11: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

OAuth process with an embedded view

user authenticates and grants permission

11

Page 12: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

output the Google credentials

12

Page 13: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

“but it looked so official!”

OAuth provides the user with a false sense of safety in the authentication workflow

13

Page 14: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

recommendations(mobile apps)

‣ client application developers: keep authentication outside the app and inside the browser

‣ users: do not trust clients that do not use a trusted neutral application such as safari to manage server auth ‣ protocol designers: stricter policies around authenticating clients to server. better browser API support

14

Page 15: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

fortune telling facebook app(a browser-based web application)

a social engineering oauth application to establish user trust

15

Page 16: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

lure the victim to use your appdomain apps.facebook.com is trustworthy!

phish

easy!

16

Page 17: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

https://apps.facebook.com/redevilfortune/

17

access scope

Page 18: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

70% * source: core impact client-side phishing campaign

18

Page 19: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

read the inbox

messages

query private user messages

19

Page 20: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

link to execute ajax post and carry our CSRF

build the trap to aid exploitation

20

Page 21: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

“but it looked so official!”

OAuth provides the user with a false sense of safety in the authentication workflow

21

Page 22: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

Dear Facebook,what is the business need for a web

application to read my private messages?

22

Page 23: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

Insecure Implementation23

Page 24: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

flawed session management

24

Page 25: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

Avon selects twitterfeed to publish something

25

Page 26: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

- Avon is redirected to twitter’s authorization endpoint - Avon enters his twitter credentials and grants access

26

Page 27: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

- Avon is redirected back to complete the feed- Avon signs out of twitterfeed and walks away

27

Page 28: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

what about his twitter session?

28

Page 29: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

29

Page 30: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

risks

‣ unattended session‣ no session timeout‣ user remains logged in

30

Page 31: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

what can go wrong?

31

Page 32: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

32

Page 33: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

33

Page 34: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

problem, meet solution

‣ invalidate server session‣ short-lived access token ‣ no auto-processing

34

Page 35: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

a better approach

35

Page 36: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

can you really change your password?

36

Page 37: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

37

Page 38: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

38

change password = old password still works!

Page 39: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

39

Page 40: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

solution

‣ ensure compromised credentials cannot be used‣ revoke tokens upon password changes

- results from facebook access token leakage to 3rd party apps

40

Page 41: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

insecure storage of secrets(consumer credentials)

41

Page 42: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

1.      public  class  TwitterClient  {    2.              3.              private  static  String  key  =  "qSkJuxxxxxxxx76A";    4.              private  static  String  secret  =  "Bs738xxxxxxxxxxxxxxZe9EhXw";  

42

Page 43: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

server-side

‣ isolate the credentials‣ protect the integrity

43

Page 44: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

native clients

‣ native mobile app‣ desktop apps

44

Page 45: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

“... if twitter uses the client secret in installed applications for anything other than gathering statistics, well, they should reconsider.”

“So forget about using the consumer credentials for anything other than somewhat reliable statistics.”

- e. hammer lahav

45

Page 46: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

how about these use cases:

‣ fulfill specific business requirements- server must keep track of all clients

‣ prevent phishing attacks

46

Page 47: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

popular implementations

(native apps)

1. omit the client credentials entirely 2. embed in the client app itself

47

Page 48: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

threat (with embedded client credentials)

‣ compromised credentials

48

Page 49: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

open source clients

‣ source code‣ resource bundle

49

Page 50: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

the not so secret consumer secrets

50

Page 51: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

51

Page 52: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

closed source clients

‣ binary extraction on android oauth client:‣ astro file mgr to copy the client app‣ poke around‣ classes.dex‣ “dexdump classes.dex

52

Page 53: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

compromised credentials

impact:

‣ key rotation and kill switch‣ not meeting business requirements‣ anonymous publication by competition‣ susceptible to phishing attacks

53

Page 54: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

alternative mitigation

‣ a deviated approach with automated provisioning

54

Page 55: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

alternate flow(mobile)

‣ authenticate user to client’s web server‣ call home to get device id‣ store device id locally‣ proceed with oauth flow to get request token‣ validate device id to authenticate client‣ proceed with the flow to grant access token

55

Page 56: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

56

Page 57: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

conclusion - defeating password anti-pattern

- trusting native mobile apps- don’t trust the logo- don’t trust the domain

- session & pswd management

- client authentication- consumer credentials

- implementation, not protocol

57

Page 58: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

take-away: use it when it makes sense!

58

Page 59: khash kiani khash@thinksec - Black Hat Briefings · recommendations (mobile apps) ‣ client application developers: keep authentication outside the app and inside the browser ‣

please turn in your completed feedback form at the registration desk

THANK YOU!

[email protected]

59