##############################################################################
#
#  Microsoft Office Remote Code Execution Vulnerabilities (955047)
#
#  Copyright: SecPod
#
#  Date Written: 2008/09/10
#
#  Revision: 1.1 
#
#  Log: schandan
#  Issue #0181
#  ------------------------------------------------------------------------
#  This program was written by SecPod and is licensed under the GNU GPL 
#  license. Please refer to the below link for details,
#  http://www.gnu.org/licenses/gpl.html
#  This header contains information regarding licensing terms under the GPL, 
#  and information regarding obtaining source code from the Author. 
#  Consequently, pursuant to section 3(c) of the GPL, you must accompany the 
#  information found in this header with any distribution you make of this 
#  Program.
#  ------------------------------------------------------------------------
##############################################################################


if(description)
{
 script_id(900046);
 script_bugtraq_id(31067);
 script_cve_id("CVE-2008-3007");
 script_copyright("Copyright (C) 2008 SecPod");
 script_version("Revision: 1.1 ");
 script_tag(name:"cvss_base", value:"9.3");
 script_tag(name:"risk_factor", value:"Critical");
 script_category(ACT_GATHER_INFO);
 script_family("Windows : Microsoft Bulletins");
 script_name("Microsoft Office Remote Code Execution Vulnerabilities (955047)");
 script_summary("Check for Microsoft Office file version");
 desc = "
 MS08-055

 Overview : This host is missing critical security update according to
 Microsoft Bulletin MS08-055.

 Vulnerability Insight :

        The issue is caused due to an error in the parsing of a URI using
        the onenote:// protocol handler.

        Impact : Remote attackers could be able to execute arbitrary code
        via a specially crafted OneNote URI referencing a specially crafted
        One Note file.

 Impact Level : Application

 Affected Software/OS :
        Microsoft Office XP/2003/2007 on Windows (All).
        
 Fix : Run Windows Update and update the listed hotfixes or download and
 update mentioned hotfixes in the advisory from the below link.
 http://www.microsoft.com/technet/security/bulletin/ms08-055.mspx

 References : http://www.microsoft.com/technet/security/bulletin/ms08-055.mspx

 CVSS Score :
        CVSS Base Score     : 9.3 (AV:N/AC:M/Au:NR/C:C/I:C/A:C)
        CVSS Temporal Score : 6.9
 Risk factor : High";

 script_description(desc);
 script_dependencies("secpod_reg_enum.nasl", "secpod_ms_office_detection_900025.nasl");
 script_require_keys("SMB/WindowsVersion");
 script_require_ports(139, 445);
 exit(0);
}


 include("smb_nt.inc");
 include("secpod_reg.inc");
 include("secpod_smb_func.inc");

 if(hotfix_check_sp(xp:4, win2k:5, win2003:3) <= 0){
         exit(0);
 }


 prgmDir = registry_get_sz(key:"SOFTWARE\Microsoft\Windows\CurrentVersion",
                           item:"ProgramFilesDir");
 if(!prgmDir){
	exit(0);
 }

 function get_version(dllPath)
 {
        share = ereg_replace(pattern:"([A-Z]):.*", replace:"\1$", string:dllPath);
        file =  ereg_replace(pattern:"[A-Z]:(.*)", replace:"\1", string:dllPath);

        name    =  kb_smb_name();
        login   =  kb_smb_login();
        pass    =  kb_smb_password();
        domain  =  kb_smb_domain();
        port    =  kb_smb_transport();

        soc = open_sock_tcp(port);
        if(!soc){
                exit(0);
        }

        r = smb_session_request(soc:soc, remote:name);
        if(!r)
        {
                close(soc);
                exit(0);
        }

        prot = smb_neg_prot(soc:soc);
        if(!prot)
        {
                close(soc);
                exit(0);
        }

        r = smb_session_setup(soc:soc, login:login, password:pass,
                              domain:domain, prot:prot);
        if(!r)
        {
                close(soc);
                exit(0);
        }

        uid = session_extract_uid(reply:r);

        r = smb_tconx(soc:soc, name:name, uid:uid, share:share);
        tid = tconx_extract_tid(reply:r);
        if(!tid)
        {
                close(soc);
                exit(0);
        }

        fid = OpenAndX(socket:soc, uid:uid, tid:tid, file:file);
        if(!fid)
        {
                close(soc);
                exit(0);
        }

        v = GetVersion(socket:soc, uid:uid, tid:tid, fid:fid, verstr:"prod", offset:9000000);
        close(soc);
        return v;
 } 

 offVer = get_kb_item("MS/Office/Ver");
 if(!offVer){
	exit(0);
 }

 if(offVer =~ "^10\.")
 {
	dllPath = prgmDir + "\Common Files\Microsoft Shared\Office10\MSO.DLL";

	vers = get_version(dllPath);
        if(vers == NULL){
                exit(0);
        }

	# Grep for version < 10.0.6845
	if(egrep(pattern:"^10\.0\.([0-5]?[0-9]?[0-9]?[0-9]|6([0-7][0-9][0-9]" +
			 "|8([0-3][0-9]|4[0-4])))$", string:vers)){
                security_hole(0);
	}
 	exit(0);
 }

 if(offVer =~ "^11\.")
 {
        dllPath = prgmDir + "\Common Files\Microsoft Shared\Office11\MSO.DLL";

        vers = get_version(dllPath);
        if(vers == NULL){
                exit(0);
        }

	# Grep for version < 11.0.8221
	if(egrep(pattern:"^11\.0\.([0-7]?[0-9]?[0-9]?[0-9]|8([01][0-9][0-9]" +
			 "|2[01][0-9]|220))$", string:vers)){
		security_hole(0);
	}
        exit(0);
 }

 if(offVer =~ "^12\.")
 {
        dllPath = prgmDir + "\Common Files\Microsoft Shared\Office12\MSO.DLL";

        vers = get_version(dllPath);
        if(vers == NULL){
                exit(0);
        }

	# Grep for version < 12.0.6320.5000
	if(egrep(pattern:"^12\.0\.([0-5].*|62.*|63[01][0-9].*|6320\.[0-4]?" +
			 "[0-9]?[0-9]?[0-9])$", string:vers)){
		security_hole(0);
	}
 }
