37
PROXY2: HTTPS PINS AND NEEDLES 2015/05/09 すみだセキュリティ勉強会 2015#1 @INAZ2

proxy2: HTTPS pins and needles

  • Upload
    inaz2

  • View
    2.968

  • Download
    6

Embed Size (px)

Citation preview

Page 1: proxy2: HTTPS pins and needles

PROXY2: HTTPS PINS AND NEEDLES

2015/05/09すみだセキュリティ勉強会 2015#1

@INAZ2

Page 2: proxy2: HTTPS pins and needles

ABOUT ME

• @inaz2

• Security engineer & Python programmer

• Girl idol freak

• Blog: ももいろテクノロジー

• http://inaz2.hatenablog.com/

2

Page 3: proxy2: HTTPS pins and needles

HTTPS EVERYWHERE [GOOGLE I/O 2014]

• http://lanyrd.com/2014/io14/sdcgyb/

3

Page 4: proxy2: HTTPS pins and needles

HTTPS = HTTP OVER SSL/TLS [RFC 2818]

• http://lanyrd.com/2014/io14/sdcgyb/

4

Page 5: proxy2: HTTPS pins and needles

SSL/TLS AUTHENTICATION

• Certificate Authority (CA) issues the signed certificate for subject’s public key

• Clients trust some root CAs beforehand

• Clients verify the chain of certificates until it reaches the trusted root CA

5

Client Server CA Root CA

Verify each signature by issuer’s public key

Private key

Public key

signature = ENCRYPT(HASH(certificate content), privkey)

sign

Page 6: proxy2: HTTPS pins and needles

SSL/TLS ENCRYPTION

• A client generate a session key (e.g. AES key)

• The client and the server share the session key

• By the key exchange algorithm (e.g. RSA or ECDHE)

• After all, the payload is encrypted by the session key

6

Client Server

Payload

Session key(shared by each other)

Page 7: proxy2: HTTPS pins and needles

WE CANNOT SEE HTTPS PAYLOADS AS IS

• In Wireshark 1.12.4

7

Page 8: proxy2: HTTPS pins and needles

DECRYPTING HTTPS PAYLOADS IN WIRESHARK

• Register the destination server’s private key

• Need to own the server

• If I have Google’s private key, I will be in the jail

• Only works when RSA key exchange is used

• Ineffective against ECDHE key exchange (because of forward secrecy)

8

Page 9: proxy2: HTTPS pins and needles

SSLKEYLOGFILE ENVIRONMENT VARIABLE

• Make the browsers write session keys in a file

• Configure Wireshark to use the file for decrypting

• Don’t have to own the server & works with any key exchange algorithms

9

Page 10: proxy2: HTTPS pins and needles

ANOTHER WAY… HTTPS PROXY

• Intercept HTTPS connection by Man-in-the-Middle

• The proxy terminates HTTPS connection and reconnects to the opposite

• The proxy can decrypt the payload by its private key

10

Client Proxy w/ CA Internet sites

HTTPS HTTPS

I’ll trust the proxy!

Decrypt all traffic!

Hello, proxy.

Page 11: proxy2: HTTPS pins and needles

FIDDLER, BURP PROXY, OWASP ZAP ETC.

• Useful proxies for web vulnerability testing

• All supports HTTPS

• Programmable to some extent

• But GUI• Basically they require user interactions

11

Page 12: proxy2: HTTPS pins and needles

THERE’S A NEED FOR THE TOOL WITHOUT CLICKING

12

Page 13: proxy2: HTTPS pins and needles

PROXY2

Page 14: proxy2: HTTPS pins and needles

SONG 2 BY BLUR

• https://www.youtube.com/watch?v=SSbBvKaM6sk

• “I got my head checkedBy a jumbo jetIt wasn't easyBut nothing isNo”

14

Page 15: proxy2: HTTPS pins and needles

PROXY2

• https://github.com/inaz2/proxy2

• HTTP/HTTPS proxy in a single python script

• A successor of SimpleHTTPProxy [sumidasec 2013/12]

• Built on top of Python standard libraries (BaseHTTPServer, httplib, ssl etc.)

• HTTPS features depend on OPENSSL(1)

• Fully programmable by implementing handler functions in Python

• Trace HTTPS payloads

• Modify HTTPS payloads

• Save HTTPS payloads or stats to the storage

15

Page 16: proxy2: HTTPS pins and needles

NEED TO TRUST IT AS A PRIVATE CA

• Execute “setup_https_intercept.sh” and run proxy2

• Configure the browser’s proxy setting

• Then access to http://proxy2.test/

16

Page 17: proxy2: HTTPS pins and needles

TRACE HTTPS PAYLOADS

• Implemented and enabled by default

• Print headers and POST data with color

• Pretty-output query parameters, Cookies and JSON data

• Show the title of a HTML document

• Decode the credential of basic auth

17

Page 18: proxy2: HTTPS pins and needles

SERVER, X-POWERED-BY, VIA

• http://hhvm.com/blog/7205/wikipedia-on-hhvm

18

Page 19: proxy2: HTTPS pins and needles

SERVER, X-POWERED-BY, VIA

• http://hhvm.com/blog/7205/wikipedia-on-hhvm

19

Nginx/1.6.2 with HHVM/3.3.13 reverse proxies (Varnish Cache)

?

Page 20: proxy2: HTTPS pins and needles

20

Page 21: proxy2: HTTPS pins and needles

X-REQUEST-ID, X-RUNTIME, X-SERVED-BY

21

Page 22: proxy2: HTTPS pins and needles

X-REQUEST-ID, X-RUNTIME, X-SERVED-BY

22

The request 1f03c5 was responded by the server e68303

and it took 6.5 milliseconds

Page 23: proxy2: HTTPS pins and needles

PRIVATE API ENDPOINT

• Content-Type seems wrong

23

Page 24: proxy2: HTTPS pins and needles

GMAIL LOGIN

24

Page 25: proxy2: HTTPS pins and needles

GMAIL LOGIN

25

Page 26: proxy2: HTTPS pins and needles

YOUTUBE’S SPF (STRUCTURED PAGE FRAGMENTS)

• https://youtube.github.io/spfjs/

26

Page 27: proxy2: HTTPS pins and needles

YOUTUBE’S SPF (STRUCTURED PAGE FRAGMENTS)

• https://youtube.github.io/spfjs/

27

Page 28: proxy2: HTTPS pins and needles

MODIFY HTTPS PAYLOADS

• Change the User-Agent

28

Page 29: proxy2: HTTPS pins and needles

29

Page 30: proxy2: HTTPS pins and needles

30

Page 31: proxy2: HTTPS pins and needles

SWAP A HTTPS CONTENT

• Rewrite a request path

31

Page 32: proxy2: HTTPS pins and needles

32

Page 33: proxy2: HTTPS pins and needles

THIS WEBSITE IS SECURED BY SSL?

• Yes, if you never trust any private CAs or compromised CAs

• Why was Superfish a big topic?

• A private CA was preinstalled in many Lenovo laptops

• All HTTPS payloads were decrypted without notice

• The same private key was embedded and its passphrase was weak

• Cracked in a moment

• As a result, anyone could be the CA and issue the certificate for any domains

• Malwares may install a private CA silently

• Certificate pinning doesn’t block it because it’s a PRIVATE CA

• http://inaz2.hatenablog.com/entry/2015/02/25/024431

33

Page 34: proxy2: HTTPS pins and needles

END-TO-END ENCRYPTION

• Web Cryptography API

• Run crypto algorithms on web browsers

• http://www.w3.org/TR/2014/CR-WebCryptoAPI-20141211/

• Intel AES-NI and Intel Secure Key (RDRAND)

• CPU instructions for AES calculation and random number generation

• https://software.intel.com/en-us/articles/intel-advanced-encryption-standard-instructions-aes-ni/

• https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide

34

Page 35: proxy2: HTTPS pins and needles

RECAP

• Trusted HTTPS proxy can trace/modify all HTTPS payloads

• Useful for both web developers and security engineers

• Happy hacking

35

Page 36: proxy2: HTTPS pins and needles

REFERENCES

• The HTTPS-Only Standard

• https://https.cio.gov/

• ImperialViolet - Decrypting SSL packet dumps

• https://www.imperialviolet.org/2012/06/25/wireshark.html

• Proxy War [OWASP DAY 2014/11]

• http://www.slideshare.net/zaki4649/proxy-war-42161988

• 自堕落な技術者の日記 : W3C Web Cryptography APIとの果てしなき戦い(第1回) - livedoor Blog(ブログ)

• http://blog.livedoor.jp/k_urushima/archives/1758899.html

36

Page 37: proxy2: HTTPS pins and needles

THANK YOU!@INAZ2

CreditsClip arts: http://www.clker.com/English Reviewing: @domiryuu