First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 205777
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Gentoo Security <security@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: David Guerizec <david+gentoo@guerizec.net>
Add CC:
CC:
Remove selected CCs
URL:
Summary:
Status Whiteboard:
Keywords:
Flags: Requestee:
 
 
  ()

Filename Description Type Creator Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 205777 depends on: Show dependency tree
Bug 205777 blocks:

Additional Comments: (this is where you put emerge --info)


Not eligible to see or edit group visibility for this bug.






View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2008-01-14 11:09 0000
Programs using paramiko that meet _either_ (or both) of the following 
criteria may be vulnerable to attacks on paramiko's random number 
generator:

     1. The program maintains multiple simultaneous paramiko connections 
        (Transport instances) via forking or threading; or

     2. The program uses certain Win32 builds of PyCrypto, where the 
        Crypt.Util.winrandom module is missing, thus preventing the 
        RandomPool instance from being initialized with sufficient entropy.

This message deals with primarily with the first criterion.

paramiko generates random numbers using a single instance of PyCrypto's 
RandomPool class.  Unfortunately, neither paramiko nor PyCrypto ensure 
that:

     1. after fork(), that the output of randpool.get_bytes() in the parent
        cannot be used to predict the output of randpool.get_bytes() in the 
        child, or vice versa; or

     2. that the state of the RandomPool instance is not corrupted by 
        multiple threads accessing it at the same time.

Consider the following Python program, which generates three separate RSA 
keys in three different child processes, and outputs the keys' 
fingerprints:

# -------[ snip here ]------------------------
from paramiko import RSAKey
import os
import time

# time.time() and time.clock() are predictable from a cryptographic standpoint,
# but make them REALLY predictable for the purposes of this demonstration.
class PredictableTime(object):
     def __init__(self):
         self.n = 0
     def __call__(self):
         self.n += 1
         return self.n

time.time = PredictableTime()
time.clock = PredictableTime()

def fork_and_generate_key():
     pid = os.fork()
     if pid != 0:
         # parent process
         os.waitpid(pid, 0)
         return
     else:
         # Child process
         k = RSAKey.generate(512)
         print "[PID %d] %s" % (os.getpid(), k.get_fingerprint().encode('hex'))
         os._exit(0)

fork_and_generate_key()
fork_and_generate_key()
fork_and_generate_key()
# -------[ snip here ]------------------------

Theoretically, each key generated using this program should be independent, 
regardless of whether the outputs of time.clock() and time.time() are 
predictable.  In reality, the program's output looks something like this:

     [PID 18872] bff46933095489d81af86493e4e9ba2f
     [PID 18873] bff46933095489d81af86493e4e9ba2f
     [PID 18874] bff46933095489d81af86493e4e9ba2f

This means that if you're using (for example) Python's 
SocketServer.ForkingTCPServer class to build an SSH server using paramiko, 
then supposedly "random" data from one session can be used to predict 
"random" data in another session.

We could try to make a thread-safe wrapper around RandomPool, and we could 
provide some API to let users randomize the pool after a fork(), but that's 
error-prone.  Also, because of a bug in PyCrypto 2.0.1 (where winrandom is 
not built), this would not be sufficient to fix the problem on Win32.

A better thing to do would be to let the operating system generate our 
random numbers for us, since it is in a far better position than we are to 
guarantee that RNG state is not leaked or reused.

The attached patch creates a new OSRandomPool class that provides a 
RandomPool-like interface, but gets its random numbers directly from the 
operating system.  It also works around the recently-published Windows 
CryptGenRandom vulnerabilities (see http://eprint.iacr.org/2007/419).

Reproducible: Always




please see related thread on paramiko's mailing list archives:

http://www.lag.net/pipermail/paramiko/2008-January/000599.html

------- Comment #1 From Robert Buchholz 2008-01-15 15:24:07 0000 -------
Seems like lag.net is currently down.

------- Comment #2 From Robert Buchholz 2008-01-15 16:03:11 0000 -------
As long as the site is down, the patch can also be found here:
  http://people.debian.org/~nion/nmu-diff/paramiko-1.6.4-1_1.6.4-1.1.patch

------- Comment #3 From David Guerizec 2008-01-17 16:14:20 0000 -------
A CVE seems to have been created:
http://nvd.nist.gov/nvd.cfm?cvename=CVE-2008-0299

------- Comment #4 From Pierre-Yves Rofes 2008-01-17 16:33:09 0000 -------
(In reply to comment #2)
> As long as the site is down, the patch can also be found here:
>   http://people.debian.org/~nion/nmu-diff/paramiko-1.6.4-1_1.6.4-1.1.patch
> 

python herd, please provide an updated ebuild.

------- Comment #5 From David Guerizec 2008-01-24 20:06:26 0000 -------
Please note that a new paramiko release is available, fixing this issue.

see http://www.lag.net/pipermail/paramiko/2008-January/000604.html

------- Comment #6 From Jakub Moc (RETIRED) 2008-01-24 20:38:34 0000 -------
*** Bug 207312 has been marked as a duplicate of this bug. ***

------- Comment #7 From Ali Polatel (RETIRED) 2008-01-31 15:32:41 0000 -------
paramiko-1.7.2 is in CVS.

------- Comment #8 From Pierre-Yves Rofes 2008-01-31 16:20:20 0000 -------
> paramiko-1.7.2 is in CVS.

Arches, please test and mark stable. Target "amd64 ~hppa ia64 ~ppc sparc x86
~x86-fbsd"

------- Comment #9 From Christian Faulhammer 2008-01-31 18:40:27 0000 -------
x86 stable

------- Comment #10 From Raúl Porcel 2008-01-31 19:09:58 0000 -------
ia64/sparc stable

------- Comment #11 From Santiago M. Mola 2008-02-11 00:09:56 0000 -------
amd64 stable, closing.

------- Comment #12 From Pierre-Yves Rofes 2008-02-11 10:57:17 0000 -------
please don't close security bugs...
time for GLSA decision. I vote YES.

------- Comment #13 From Sune Kloppenborg Jeppesen 2008-02-11 18:32:14 0000 -------
Voting YES and filing.

------- Comment #14 From Peter Volkov 2008-02-23 18:17:55 0000 -------
Fixed in release snapshot.

------- Comment #15 From Pierre-Yves Rofes 2008-03-03 21:43:57 0000 -------
GLSa 200803-07

First Last Prev Next    No search results available      Search page      Enter new bug