<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>205777</bug_id>
          <alias>CVE-2008-0299</alias>
          <creation_ts>2008-01-14 11:09 0000</creation_ts>
          <short_desc>dev-python/paramiko &lt; 1.7.2 insecure use of RandomPool (CVE-2008-0299)</short_desc>
          <delta_ts>2008-03-03 21:43:57 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          <bug_file_loc>http://www.lag.net/pipermail/paramiko/2008-January/000599.html</bug_file_loc>
          <status_whiteboard>B3? [glsa]</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>david+gentoo@guerizec.net</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>python@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>david+gentoo@guerizec.net</who>
            <bug_when>2008-01-14 11:09:12 0000</bug_when>
            <thetext>Programs using paramiko that meet _either_ (or both) of the following 
criteria may be vulnerable to attacks on paramiko&apos;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&apos;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&apos; 
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 &quot;[PID %d] %s&quot; % (os.getpid(), k.get_fingerprint().encode(&apos;hex&apos;))
         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&apos;s output looks something like this:

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

This means that if you&apos;re using (for example) Python&apos;s 
SocketServer.ForkingTCPServer class to build an SSH server using paramiko, 
then supposedly &quot;random&quot; data from one session can be used to predict 
&quot;random&quot; 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&apos;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&apos;s mailing list archives:

http://www.lag.net/pipermail/paramiko/2008-January/000599.html</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-01-15 15:24:07 0000</bug_when>
            <thetext>Seems like lag.net is currently down.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-01-15 16:03:11 0000</bug_when>
            <thetext>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</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>david+gentoo@guerizec.net</who>
            <bug_when>2008-01-17 16:14:20 0000</bug_when>
            <thetext>A CVE seems to have been created:
http://nvd.nist.gov/nvd.cfm?cvename=CVE-2008-0299</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2008-01-17 16:33:09 0000</bug_when>
            <thetext>(In reply to comment #2)
&gt; As long as the site is down, the patch can also be found here:
&gt;   http://people.debian.org/~nion/nmu-diff/paramiko-1.6.4-1_1.6.4-1.1.patch
&gt; 

python herd, please provide an updated ebuild.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>david+gentoo@guerizec.net</who>
            <bug_when>2008-01-24 20:06:26 0000</bug_when>
            <thetext>Please note that a new paramiko release is available, fixing this issue.

see http://www.lag.net/pipermail/paramiko/2008-January/000604.html
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jakub@gentoo.org</who>
            <bug_when>2008-01-24 20:38:34 0000</bug_when>
            <thetext>*** Bug 207312 has been marked as a duplicate of this bug. ***</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hawking@gentoo.org</who>
            <bug_when>2008-01-31 15:32:41 0000</bug_when>
            <thetext>paramiko-1.7.2 is in CVS.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2008-01-31 16:20:20 0000</bug_when>
            <thetext>&gt; paramiko-1.7.2 is in CVS.

Arches, please test and mark stable. Target &quot;amd64 ~hppa ia64 ~ppc sparc x86 ~x86-fbsd&quot;
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>fauli@gentoo.org</who>
            <bug_when>2008-01-31 18:40:27 0000</bug_when>
            <thetext>x86 stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>armin76@gentoo.org</who>
            <bug_when>2008-01-31 19:09:58 0000</bug_when>
            <thetext>ia64/sparc stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>coldwind@gentoo.org</who>
            <bug_when>2008-02-11 00:09:56 0000</bug_when>
            <thetext>amd64 stable, closing.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2008-02-11 10:57:17 0000</bug_when>
            <thetext>please don&apos;t close security bugs...
time for GLSA decision. I vote YES.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2008-02-11 18:32:14 0000</bug_when>
            <thetext>Voting YES and filing.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>pva@gentoo.org</who>
            <bug_when>2008-02-23 18:17:55 0000</bug_when>
            <thetext>Fixed in release snapshot.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2008-03-03 21:43:57 0000</bug_when>
            <thetext>GLSa 200803-07</thetext>
          </long_desc>
      
    </bug>

</bugzilla>