diff --git a/Makefile.am b/Makefile.am index 43be2ec89e..245070b033 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ MODULES = \ guix/upstream.scm \ guix/licenses.scm \ guix/graph.scm \ + guix/cve.scm \ guix/build-system.scm \ guix/build-system/cmake.scm \ guix/build-system/emacs.scm \ @@ -224,6 +225,7 @@ SCM_TESTS = \ tests/size.scm \ tests/graph.scm \ tests/challenge.scm \ + tests/cve.scm \ tests/file-systems.scm \ tests/services.scm \ tests/containers.scm @@ -312,6 +314,7 @@ EXTRA_DIST = \ tests/test.drv \ tests/signing-key.pub \ tests/signing-key.sec \ + tests/cve-sample.xml \ build-aux/config.rpath \ bootstrap \ release.nix \ diff --git a/guix/cve.scm b/guix/cve.scm new file mode 100644 index 0000000000..a7b0bde6dc --- /dev/null +++ b/guix/cve.scm @@ -0,0 +1,177 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix cve) + #:use-module (guix utils) + #:use-module (guix http-client) + #:use-module (sxml ssax) + #:use-module (web uri) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-19) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (ice-9 vlist) + #:export (vulnerability? + vulnerability-id + vulnerability-packages + + xml->vulnerabilities + current-vulnerabilities + vulnerabilities->lookup-proc)) + +;;; Commentary: +;;; +;;; This modules provides the tools to fetch, parse, and digest part of the +;;; Common Vulnerabilities and Exposures (CVE) feeds provided by the US NIST +;;; at . +;;; +;;; Code: + +(define-record-type + (vulnerability id packages) + vulnerability? + (id vulnerability-id) + (packages vulnerability-packages)) + +(define %cve-feed-uri + (string->uri + "https://nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-Modified.xml.gz")) + +(define %ttl + ;; According to , feeds are + ;; updated "approximately every two hours." + (* 3600 3)) + +(define (call-with-cve-port proc) + "Pass PROC an input port from which to read the CVE stream." + (let ((port (http-fetch/cached %cve-feed-uri #:ttl %ttl))) + (dynamic-wind + (const #t) + (lambda () + (call-with-decompressed-port 'gzip port + proc)) + (lambda () + (close-port port))))) + +(define %cpe-package-rx + ;; For applications: "cpe:/a:VENDOR:PACKAGE:VERSION". + (make-regexp "^cpe:/a:([^:]+):([^:]+):([^:]+)")) + +(define (cpe->package-name cpe) + "Converts the Common Platform Enumeration (CPE) string CPE to a package +name, in a very naive way. Return #f if CPE does not look like an application +CPE string." + (and=> (regexp-exec %cpe-package-rx (string-trim-both cpe)) + (lambda (matches) + (cons (match:substring matches 2) + (match:substring matches 3))))) + +(define %parse-vulnerability-feed + ;; Parse the XML vulnerability feed from + ;; and return a list of + ;; vulnerability objects. + (ssax:make-parser NEW-LEVEL-SEED + (lambda (elem-gi attributes namespaces expected-content + seed) + (match elem-gi + ((name-space . 'entry) + (cons (assoc-ref attributes 'id) seed)) + ((name-space . 'vulnerable-software-list) + (cons '() seed)) + ((name-space . 'product) + (cons 'product seed)) + (x seed))) + + FINISH-ELEMENT + (lambda (elem-gi attributes namespaces parent-seed + seed) + (match elem-gi + ((name-space . 'entry) + (match seed + (((? string? id) . rest) + ;; Some entries have no vulnerable-software-list. + rest) + ((products id . rest) + (match (filter-map cpe->package-name products) + (() + ;; No application among PRODUCTS. + rest) + (packages + (cons (vulnerability id (reverse packages)) + rest)))))) + (x + seed))) + + CHAR-DATA-HANDLER + (lambda (str _ seed) + (match seed + (('product software-list . rest) + ;; Add STR to the vulnerable software list this + ;; tag is part of. + (cons (cons str software-list) rest)) + (x x))))) + +(define (xml->vulnerabilities port) + "Read from PORT an XML feed of vulnerabilities and return a list of +vulnerability objects." + (reverse (%parse-vulnerability-feed port '()))) + +(define (current-vulnerabilities) + "Return the current list of Common Vulnerabilities and Exposures (CVE) as +published by the US NIST." + (call-with-cve-port + (lambda (port) + ;; XXX: The SSAX "error port" is used to send pointless warnings such as + ;; "warning: Skipping PI". Turn that off. + (parameterize ((current-ssax-error-port (%make-void-port "w"))) + (xml->vulnerabilities port))))) + +(define (vulnerabilities->lookup-proc vulnerabilities) + "Return a lookup procedure built from VULNERABILITIES that takes a package +name and optionally a version number. When the version is omitted, the lookup +procedure returns a list of version/vulnerability pairs; otherwise, it returns +a list of vulnerabilities affection the given package version." + (define table + ;; Map package names to lists of version/vulnerability pairs. + (fold (lambda (vuln table) + (match vuln + (($ id packages) + (fold (lambda (package table) + (match package + ((name . version) + (vhash-cons name (cons version vuln) + table)))) + table + packages)))) + vlist-null + vulnerabilities)) + + (lambda* (package #:optional version) + (vhash-fold* (if version + (lambda (pair result) + (match pair + ((v . vuln) + (if (string=? v version) + (cons vuln result) + result)))) + cons) + '() + package table))) + +;;; cve.scm ends here diff --git a/tests/cve-sample.xml b/tests/cve-sample.xml new file mode 100644 index 0000000000..ce158490f1 --- /dev/null +++ b/tests/cve-sample.xml @@ -0,0 +1,616 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cpe:/o:microsoft:windows_2000::sp2:professional + cpe:/o:linux:linux_kernel:2.4.4 + cpe:/o:microsoft:windows_2000_terminal_services::sp1 + cpe:/o:microsoft:windows_2000::sp1:advanced_server + cpe:/o:linux:linux_kernel:2.4.19 + cpe:/o:microsoft:windows_2000::sp2:advanced_server + cpe:/o:microsoft:windows_2000_terminal_services + cpe:/o:microsoft:windows_2000:::advanced_server + cpe:/o:linux:linux_kernel:2.4.20 + cpe:/o:netbsd:netbsd:1.5.1 + cpe:/o:microsoft:windows_2000_terminal_services::sp2 + cpe:/o:netbsd:netbsd:1.5.3 + cpe:/o:netbsd:netbsd:1.5.2 + cpe:/o:linux:linux_kernel:2.4.6 + cpe:/o:linux:linux_kernel:2.4.9 + cpe:/o:microsoft:windows_2000:::datacenter_server + cpe:/o:netbsd:netbsd:1.6 + cpe:/o:netbsd:netbsd:1.5 + cpe:/o:linux:linux_kernel:2.4.7 + cpe:/o:linux:linux_kernel:2.4.8 + cpe:/o:microsoft:windows_2000::sp1:datacenter_server + cpe:/o:microsoft:windows_2000::sp2:datacenter_server + cpe:/o:freebsd:freebsd:4.3 + cpe:/o:linux:linux_kernel:2.4.10 + cpe:/o:microsoft:windows_2000::sp1:server + cpe:/o:freebsd:freebsd:4.5 + cpe:/o:linux:linux_kernel:2.4.12 + cpe:/o:freebsd:freebsd:4.2 + cpe:/o:freebsd:freebsd:4.7 + cpe:/o:freebsd:freebsd:4.4 + cpe:/o:freebsd:freebsd:4.6 + cpe:/o:microsoft:windows_2000::sp2:server + cpe:/o:linux:linux_kernel:2.4.18 + cpe:/o:linux:linux_kernel:2.4.1 + cpe:/o:linux:linux_kernel:2.4.15 + cpe:/o:microsoft:windows_2000:::server + cpe:/o:linux:linux_kernel:2.4.17 + cpe:/o:linux:linux_kernel:2.4.14 + cpe:/o:linux:linux_kernel:2.4.2 + cpe:/o:microsoft:windows_2000:::professional + cpe:/o:linux:linux_kernel:2.4.11 + cpe:/o:linux:linux_kernel:2.4.5 + cpe:/o:linux:linux_kernel:2.4.16 + cpe:/o:microsoft:windows_2000::sp1:professional + cpe:/o:linux:linux_kernel:2.4.13 + cpe:/o:linux:linux_kernel:2.4.3 + + CVE-2003-0001 + 2003-01-17T00:00:00.000-05:00 + 2015-11-24T13:05:47.073-05:00 + + + 5.0 + NETWORK + LOW + NONE + PARTIAL + NONE + NONE + http://nvd.nist.gov + 2015-11-24T12:23:33.593-05:00 + + + + + + CERT-VN + VU#412115 + + + BUGTRAQ + 20150402 NEW : VMSA-2015-0003 VMware product updates address critical information disclosure issue in JRE + + + BUGTRAQ + 20030117 Re: More information regarding Etherleak + + + BUGTRAQ + 20030106 Etherleak: Ethernet frame padding information leakage (A010603-1) + + + REDHAT + RHSA-2003:088 + + + REDHAT + RHSA-2003:025 + + + OSVDB + 9962 + + + CONFIRM + http://www.oracle.com/technetwork/topics/security/cpujan2015-1972971.html + + + MISC + http://www.atstake.com/research/advisories/2003/atstake_etherleak_report.pdf + + + ATSTAKE + A010603-1 + + + FULLDISC + 20150402 NEW : VMSA-2015-0003 VMware product updates address critical information disclosure issue in JRE + + + MISC + http://packetstormsecurity.com/files/131271/VMware-Security-Advisory-2015-0003.html + + + BUGTRAQ + 20030110 More information regarding Etherleak + + + VULNWATCH + 20030110 More information regarding Etherleak + + + + + Multiple ethernet Network Interface Card (NIC) device drivers do not pad frames with null bytes, which allows remote attackers to obtain information from previous packets or kernel memory by using malformed packets, as demonstrated by Etherleak. + + + + + + + + + cpe:/a:tcp:tcp + + CVE-2004-0230 + 2004-08-18T00:00:00.000-04:00 + 2015-11-24T13:06:40.597-05:00 + + + 5.0 + NETWORK + LOW + NONE + NONE + NONE + PARTIAL + http://nvd.nist.gov + 2015-11-24T12:17:30.930-05:00 + + + + + + + + + CERT + TA04-111A + + + CERT-VN + VU#415294 + + + CONFIRM + https://kc.mcafee.com/corporate/index?page=content&id=SB10053 + + + XF + tcp-rst-dos(15886) + + + VUPEN + ADV-2006-3983 + + + MISC + http://www.uniras.gov.uk/vuls/2004/236929/index.htm + + + BID + 10183 + + + BUGTRAQ + 20150402 NEW : VMSA-2015-0003 VMware product updates address critical information disclosure issue in JRE + + + HP + SSRT061264 + + + OSVDB + 4030 + + + CONFIRM + http://www.oracle.com/technetwork/topics/security/cpujan2015-1972971.html + + + MS + MS06-064 + + + MS + MS05-019 + + + CISCO + 20040420 TCP Vulnerabilities in Multiple IOS-Based Cisco Products + + + FULLDISC + 20150402 NEW : VMSA-2015-0003 VMware product updates address critical information disclosure issue in JRE + + + MISC + http://packetstormsecurity.com/files/131271/VMware-Security-Advisory-2015-0003.html + + + HP + SSRT4696 + + + BUGTRAQ + 20040425 Perl code exploting TCP not checking RST ACK. + + + CONFIRM + http://kb.juniper.net/JSA10638 + + + SGI + 20040403-01-A + + + SCO + SCOSA-2005.14 + + + SCO + SCOSA-2005.9 + + + SCO + SCOSA-2005.3 + + + NETBSD + NetBSD-SA2004-006 + + + + + + + + + + + + + + + + + TCP, when using a large Window Size, makes it easier for remote attackers to guess sequence numbers and cause a denial of service (connection loss) to persistent TCP connections by repeatedly injecting a TCP RST packet, especially in protocols that use long-lived connections, such as BGP. + + + + + + + + + + cpe:/a:vastal:phpvid:1.1 + cpe:/a:vastal:phpvid:1.2 + + CVE-2008-2335 + 2008-05-19T09:20:00.000-04:00 + 2015-11-24T11:45:25.057-05:00 + + + 4.3 + NETWORK + MEDIUM + NONE + NONE + PARTIAL + NONE + http://nvd.nist.gov + 2015-11-24T10:50:05.737-05:00 + + + + + XF + phpvid-query-xss(42450) + + + VUPEN + ADV-2008-2552 + + + BID + 29238 + + + MILW0RM + 6422 + + + EXPLOIT-DB + 27519 + + + MISC + http://tetraph.com/security/xss-vulnerability/vastal-i-tech-phpvid-1-2-3-multiple-xss-cross-site-scripting-security-vulnerabilities/ + + + FULLDISC + 20150310 Vastal I-tech phpVID 1.2.3 Multiple XSS (Cross-site Scripting) Security Vulnerabilities + + + MISC + http://packetstormsecurity.com/files/130755/Vastal-I-tech-phpVID-1.2.3-Cross-Site-Scripting.html + + + MISC + http://packetstormsecurity.com/files/122746/PHP-VID-XSS-SQL-Injection-CRLF-Injection.html + + + OSVDB + 45171 + + + MISC + http://holisticinfosec.org/content/view/65/45/ + + Cross-site scripting (XSS) vulnerability in search_results.php in Vastal I-Tech phpVID 1.1 and 1.2 allows remote attackers to inject arbitrary web script or HTML via the query parameter. NOTE: some of these details are obtained from third party information. NOTE: it was later reported that 1.2.3 is also affected. + + + + + + + + + + + + + + cpe:/a:redhat:enterprise_virtualization:3.5 + cpe:/a:jasper_project:jasper:1.900.1 + + CVE-2008-3522 + 2008-10-02T14:18:05.790-04:00 + 2015-11-24T11:46:04.933-05:00 + + + 10.0 + NETWORK + LOW + NONE + COMPLETE + COMPLETE + COMPLETE + http://nvd.nist.gov + 2015-11-24T10:05:46.467-05:00 + + + ALLOWS_ADMIN_ACCESS + + + XF + jasper-jasstreamprintf-bo(45623) + + + UBUNTU + USN-742-1 + + + BID + 31470 + + + MANDRIVA + MDVSA-2009:164 + + + MANDRIVA + MDVSA-2009:144 + + + MANDRIVA + MDVSA-2009:142 + + + GENTOO + GLSA-200812-18 + + + REDHAT + RHSA-2015:0698 + + + MISC + http://bugs.gentoo.org/show_bug.cgi?id=222819 + + + MISC + http://bugs.gentoo.org/attachment.cgi?id=163282&action=view + + Buffer overflow in the jas_stream_printf function in libjasper/base/jas_stream.c in JasPer 1.900.1 might allow context-dependent attackers to have an unknown impact via vectors related to the mif_hdr_put function and use of vsprintf. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cpe:/o:canonical:ubuntu_linux:10.04::~~lts~~~ + cpe:/o:canonical:ubuntu_linux:8.04:-:lts + cpe:/o:canonical:ubuntu_linux:10.10 + cpe:/a:sun:openoffice.org:2.1.0 + cpe:/a:sun:openoffice.org:2.3.0 + cpe:/a:sun:openoffice.org:2.2.1 + + + CVE-2009-3301 + 2010-02-16T14:30:00.533-05:00 + 2015-11-17T10:59:44.723-05:00 + + + 9.3 + NETWORK + MEDIUM + NONE + COMPLETE + COMPLETE + COMPLETE + http://nvd.nist.gov + 2015-11-17T10:02:50.097-05:00 + + + + + + CERT + TA10-287A + + + CONFIRM + https://bugzilla.redhat.com/show_bug.cgi?id=533038 + + + XF + openoffice-word-sprmtdeftable-bo(56240) + + + VUPEN + ADV-2010-2905 + + + VUPEN + ADV-2010-0635 + + + VUPEN + ADV-2010-0366 + + + UBUNTU + USN-903-1 + + + BID + 38218 + + + REDHAT + RHSA-2010:0101 + + + CONFIRM + http://www.oracle.com/technetwork/topics/security/cpuoct2010-175626.html + + + CONFIRM + http://www.openoffice.org/security/cves/CVE-2009-3301-3302.html + + + CONFIRM + http://www.openoffice.org/security/bulletin.html + + + MANDRIVA + MDVSA-2010:221 + + + GENTOO + GLSA-201408-19 + + + DEBIAN + DSA-1995 + + + SECTRACK + 1023591 + + + SUSE + SUSE-SA:2010:017 + + + + + Integer underflow in filter/ww8/ww8par2.cxx in OpenOffice.org (OOo) before 3.2 allows remote attackers to cause a denial of service (application crash) or possibly execute arbitrary code via a crafted sprmTDefTable table property modifier in a Word document. + + + CVE-2015-8330 + 2015-11-24T15:59:25.897-05:00 + 2015-11-24T15:59:26.930-05:00 + + MISC + https://www.onapsis.com/blog/analyzing-sap-security-notes-november-2015 + + + MISC + http://erpscan.com/advisories/erpscan-15-032-sap-pco-agent-dos-vulnerability/ + + The PCo agent in SAP Plant Connectivity (PCo) allows remote attackers to cause a denial of service (memory corruption and agent crash) via crafted xMII requests, aka SAP Security Note 2238619. + + diff --git a/tests/cve.scm b/tests/cve.scm new file mode 100644 index 0000000000..26bc560e52 --- /dev/null +++ b/tests/cve.scm @@ -0,0 +1,69 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (test-cve) + #:use-module (guix cve) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-64)) + +(define %sample + (search-path %load-path "tests/cve-sample.xml")) + +(define (vulnerability id packages) + (make-struct (@@ (guix cve) ) 0 id packages)) + +(define %expected-vulnerabilities + ;; What we should get when reading %SAMPLE. + (list + ;; CVE-2003-0001 has no "/a" in its product list so it is omitted. + ;; CVE-2004-0230 lists "tcp" as an application, but lacks a version number. + (vulnerability "CVE-2008-2335" '(("phpvid" . "1.1") ("phpvid" . "1.2"))) + (vulnerability "CVE-2008-3522" '(("enterprise_virtualization" . "3.5") + ("jasper" . "1.900.1"))) + (vulnerability "CVE-2009-3301" '(("openoffice.org" . "2.1.0") + ("openoffice.org" . "2.3.0") + ("openoffice.org" . "2.2.1"))) + ;; CVE-2015-8330 has no software list. + )) + + +(test-begin "cve") + +(test-equal "xml->vulnerabilities" + %expected-vulnerabilities + (call-with-input-file %sample xml->vulnerabilities)) + +(test-equal "" + (list `(("1.1" . ,(first %expected-vulnerabilities)) + ("1.2" . ,(first %expected-vulnerabilities))) + '() + '() + (list (second %expected-vulnerabilities)) + (list (third %expected-vulnerabilities))) + (let* ((vulns (call-with-input-file %sample xml->vulnerabilities)) + (lookup (vulnerabilities->lookup-proc vulns))) + (list (lookup "phpvid") + (lookup "jasper" "2.0") + (lookup "foobar") + (lookup "jasper" "1.900.1") + (lookup "openoffice.org" "2.3.0")))) + +(test-end "cve") + + +(exit (= (test-runner-fail-count (test-runner-current)) 0))