OpenSSL rands (fork-safe)

13
OpenSSL rands (fork-safe) By @ONsec_Lab Sep 15, 2013

description

defcon-russia talk about OpenSSL fork-safe vulns.

Transcript of OpenSSL rands (fork-safe)

Page 1: OpenSSL rands (fork-safe)

OpenSSL rands (fork-safe)

By @ONsec_Lab

Sep 15, 2013

Page 2: OpenSSL rands (fork-safe)

@ONsec_lab

● Security auditors● Since 2009 year● Web, sex and rock’

n’roll

http://lab.onsec.ru

/whoami

Page 4: OpenSSL rands (fork-safe)

premise

● About Ruby OpenSSL wrapper (OpenSSL::Random)

● OpenSSL PRNG must be initialized in the parent before we fork the child processes

● Every child starts out with exactly the same PRNG

● PID is the only thing process-specific that is fed to the PRNG algorithm when requesting random bytes

Page 5: OpenSSL rands (fork-safe)

premise

Page 6: OpenSSL rands (fork-safe)

Debian!

Page 7: OpenSSL rands (fork-safe)

But...

● Debian guys commented MD_Update call with UNINITIALISED variable

● We believe that they did the right thing ;)

Page 8: OpenSSL rands (fork-safe)

non-Debian systems

● Vulnerability exists in all system (Debian and non-Debian also)

● Exploitation possibility depends only from end-point code (application, not OpenSSL)

● There are two different places for buf:○ Stack○ Heap

● Let’s try to hack it!

Page 9: OpenSSL rands (fork-safe)

stack-based PoC (all OS)https://github.com/ONsec-Lab/Rand-attacks/blob/master/openssl-1.c

from different calls to the same

==from different stack states to

the same!

Page 10: OpenSSL rands (fork-safe)

heap-based PoC (all OS)https://github.com/ONsec-Lab/Rand-attacks/blob/master/openssl-2.c

malloc allocates

nulled memory

page

Page 11: OpenSSL rands (fork-safe)

other attacks

● i.e. PHP initialize RAND after fork● But classic attacks way still available○ Keep-Alive -> rands on same PID○ Brute seed by rands○ Predict rand by seed + offset

● What about entropy of OpenSSL RAND?○ 128 bytes * 20 (GID*UID) * 32k (PID)○ Not so little :(

Page 12: OpenSSL rands (fork-safe)

just recommend!http://lwn.net/Articles/281918/ [2008]

http://research.swtch.com/openssl [2008]http://mjos.fi/doc/secadv_prng.txt [2001]

Do not be afraid names and brands, such as

OpenSSL

Page 13: OpenSSL rands (fork-safe)

OpenSSL rands (fork-safe)

The end.follow us:

http://lab.onsec.ru@ONsec_lab twitter