Vulnerabilities > CVE-2017-0262 - Remote Code Execution vulnerability in Microsoft Office 2010/2013/2016

047910
CVSS 9.3 - CRITICAL
Attack vector
NETWORK
Attack complexity
MEDIUM
Privileges required
NONE
Confidentiality impact
COMPLETE
Integrity impact
COMPLETE
Availability impact
COMPLETE
network
microsoft
critical
nessus

Summary

Microsoft Office 2010 SP2, Office 2013 SP1, and Office 2016 allow a remote code execution vulnerability when the software fails to properly handle objects in memory, aka "Office Remote Code Execution Vulnerability". This CVE ID is unique from CVE-2017-0261 and CVE-2017-0281.

Vulnerable Configurations

Part Description Count
Application
Microsoft
3

Nessus

NASL familyWindows : Microsoft Bulletins
NASL idSMB_NT_MS17_MAY_OFFICE.NASL
descriptionThe Microsoft Office application, Office Web Apps, or SharePoint Server installed on the remote Windows host is missing a security update. It is, therefore, affected by multiple vulnerabilities : - A remote code execution vulnerability exists in Microsoft Office software due to improper handling of objects in memory. An unauthenticated, remote attacker can exploit this, by convincing a user to open a specially crafted Office document, to execute arbitrary code in the context of the current user. (CVE-2017-0254) - A cross-site scripting (XSS) vulnerability exists in Microsoft SharePoint Server due improper validation of user-supplied input in web requests. An unauthenticated, remote attacker can exploit this, via a specially crafted request, to execute arbitrary script code in a user
last seen2020-06-01
modified2020-06-02
plugin id100103
published2017-05-10
reporterThis script is Copyright (C) 2017-2019 and is owned by Tenable, Inc. or an Affiliate thereof.
sourcehttps://www.tenable.com/plugins/nessus/100103
titleSecurity Update for Microsoft Office Products (May 2017)
code
#
# (C) Tenable Network Security, Inc.
#

include("compat.inc");

if (description)
{
  script_id(100103);
  script_version("1.16");
  script_cvs_date("Date: 2019/11/13");

  script_cve_id(
    "CVE-2017-0254",
    "CVE-2017-0255",
    "CVE-2017-0261",
    "CVE-2017-0262",
    "CVE-2017-0281"
  );
  script_bugtraq_id(
    98101,
    98104,
    98107,
    98279,
    98297
  );
  script_xref(name:"MSKB", value:"2596904");
  script_xref(name:"MSFT", value:"MS17-2596904");
  script_xref(name:"MSKB", value:"3114375");
  script_xref(name:"MSFT", value:"MS17-3114375");
  script_xref(name:"MSKB", value:"3118310");
  script_xref(name:"MSFT", value:"MS17-3118310");
  script_xref(name:"MSKB", value:"3162040");
  script_xref(name:"MSFT", value:"MS17-3162040");
  script_xref(name:"MSKB", value:"3162054");
  script_xref(name:"MSFT", value:"MS17-3162054");
  script_xref(name:"MSKB", value:"3162069");
  script_xref(name:"MSFT", value:"MS17-3162069");
  script_xref(name:"MSKB", value:"3172458");
  script_xref(name:"MSFT", value:"MS17-3172458");
  script_xref(name:"MSKB", value:"3172475");
  script_xref(name:"MSFT", value:"MS17-3172475");
  script_xref(name:"MSKB", value:"3172482");
  script_xref(name:"MSFT", value:"MS17-3172482");
  script_xref(name:"MSKB", value:"3172532");
  script_xref(name:"MSFT", value:"MS17-3172532");
  script_xref(name:"MSKB", value:"3172536");
  script_xref(name:"MSFT", value:"MS17-3172536");
  script_xref(name:"MSKB", value:"3178633");
  script_xref(name:"MSFT", value:"MS17-3178633");
  script_xref(name:"MSKB", value:"3178638");
  script_xref(name:"MSFT", value:"MS17-3178638");
  script_xref(name:"MSKB", value:"3178729");
  script_xref(name:"MSFT", value:"MS17-3178729");
  script_xref(name:"MSKB", value:"3191835");
  script_xref(name:"MSFT", value:"MS17-3191835");
  script_xref(name:"MSKB", value:"3191836");
  script_xref(name:"MSFT", value:"MS17-3191836");
  script_xref(name:"MSKB", value:"3191839");
  script_xref(name:"MSFT", value:"MS17-3191839");
  script_xref(name:"MSKB", value:"3191841");
  script_xref(name:"MSFT", value:"MS17-3191841");
  script_xref(name:"MSKB", value:"3191843");
  script_xref(name:"MSFT", value:"MS17-3191843");
  script_xref(name:"MSKB", value:"3191858");
  script_xref(name:"MSFT", value:"MS17-3191858");
  script_xref(name:"MSKB", value:"3191863");
  script_xref(name:"MSFT", value:"MS17-3191863");
  script_xref(name:"MSKB", value:"3191865");
  script_xref(name:"MSFT", value:"MS17-3191865");
  script_xref(name:"MSKB", value:"3191880");
  script_xref(name:"MSFT", value:"MS17-3191880");
  script_xref(name:"MSKB", value:"3191881");
  script_xref(name:"MSFT", value:"MS17-3191881");
  script_xref(name:"MSKB", value:"3191885");
  script_xref(name:"MSFT", value:"MS17-3191885");
  script_xref(name:"MSKB", value:"3191886");
  script_xref(name:"MSFT", value:"MS17-3191886");
  script_xref(name:"MSKB", value:"3191887");
  script_xref(name:"MSFT", value:"MS17-3191887");
  script_xref(name:"MSKB", value:"3191888");
  script_xref(name:"MSFT", value:"MS17-3191888");
  script_xref(name:"MSKB", value:"3191890");
  script_xref(name:"MSFT", value:"MS17-3191890");
  script_xref(name:"MSKB", value:"3191895");
  script_xref(name:"MSFT", value:"MS17-3191895");
  script_xref(name:"MSKB", value:"3191899");
  script_xref(name:"MSFT", value:"MS17-3191899");
  script_xref(name:"MSKB", value:"3191904");
  script_xref(name:"MSFT", value:"MS17-3191904");
  script_xref(name:"MSKB", value:"3191909");
  script_xref(name:"MSFT", value:"MS17-3191909");
  script_xref(name:"MSKB", value:"3191913");
  script_xref(name:"MSFT", value:"MS17-3191913");
  script_xref(name:"MSKB", value:"3191914");
  script_xref(name:"MSFT", value:"MS17-3191914");
  script_xref(name:"MSKB", value:"3191915");
  script_xref(name:"MSFT", value:"MS17-3191915");
  script_xref(name:"IAVA", value:"2017-A-0143");

  script_name(english:"Security Update for Microsoft Office Products (May 2017)");
  script_summary(english:"Checks the file versions.");

  script_set_attribute(attribute:"synopsis", value:
"An application installed on the remote Windows host is affected by
multiple vulnerabilities.");
  script_set_attribute(attribute:"description", value:
"The Microsoft Office application, Office Web Apps, or SharePoint
Server installed on the remote Windows host is missing a security
update. It is, therefore, affected by multiple vulnerabilities :

  - A remote code execution vulnerability exists in
    Microsoft Office software due to improper handling of
    objects in memory. An unauthenticated, remote attacker
    can exploit this, by convincing a user to open a
    specially crafted Office document, to execute arbitrary
    code in the context of the current user. (CVE-2017-0254)

  - A cross-site scripting (XSS) vulnerability exists in
    Microsoft SharePoint Server due improper validation of
    user-supplied input in web requests. An unauthenticated,
    remote attacker can exploit this, via a specially
    crafted request, to execute arbitrary script code in a
    user's browser session. (CVE-2017-0255)

  - A remote code execution vulnerability exists in
    Microsoft Office due to improper handling of malformed
    graphics images. An unauthenticated, remote attacker can
    exploit this, by convincing a user to open a specially
    crafted EPS file, to execute arbitrary code in the
    context of the current user. (CVE-2017-0261)

  - A remote code execution vulnerability exists in
    Microsoft Office when handling malformed graphics
    images. An unauthenticated, remote attacker can exploit
    this, by convincing a user to open a specially crafted
    EPS file or visit a specially crafted website, to
    execute arbitrary code. (CVE-2017-0262)

  - A remote code execution vulnerability exists in
    Microsoft Office due to improper handling of objects in
    memory. An unauthenticated, remote attacker can exploit
    this, by convincing a user to open a specially crafted
    file, to execute arbitrary code in the context of the
    current user. (CVE-2017-0281)");
  script_set_attribute(attribute:"see_also", value:"https://portal.msrc.microsoft.com/en-us/security-guidance/summary");
  script_set_attribute(attribute:"solution", value:
"Microsoft has released a set of patches for Microsoft Office 2007,
2010, 2013, and 2016; Microsoft Word 2007, 2010, 2013, and 2016; Skype
for Business 2016; Microsoft Word Viewer; Microsoft Office
Compatibility Pack; SharePoint Server 2010; SharePoint Enterprise
Server 2013 and 2016; SharePoint Foundation 2013; Word Automation
Services on Microsoft SharePoint Server 2010 and 2013; Microsoft
Office Project Server 2013; Microsoft Office Web Apps Server 2010 and
2013; and Office Online Server.");
  script_set_cvss_base_vector("CVSS2#AV:N/AC:M/Au:N/C:C/I:C/A:C");
  script_set_cvss_temporal_vector("CVSS2#E:H/RL:OF/RC:C");
  script_set_cvss3_base_vector("CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H");
  script_set_cvss3_temporal_vector("CVSS:3.0/E:H/RL:O/RC:C");
  script_set_attribute(attribute:"cvss_score_source", value:"CVE-2017-0281");

  script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
  script_set_attribute(attribute:"exploit_available", value:"true");
  script_set_attribute(attribute:"exploit_framework_core", value:"true");
  script_set_attribute(attribute:"exploited_by_malware", value:"true");

  script_set_attribute(attribute:"vuln_publication_date", value:"2017/05/09");
  script_set_attribute(attribute:"patch_publication_date", value:"2017/05/09");
  script_set_attribute(attribute:"plugin_publication_date", value:"2017/05/10");

  script_set_attribute(attribute:"plugin_type", value:"local");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:office");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:word");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:word_viewer");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:office_compatibility_pack");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:office_web_apps");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:office_online_server");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:sharepoint_server");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:sharepoint_foundation");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:project");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:microsoft:skype_for_business");
  script_set_attribute(attribute:"stig_severity", value:"II");
  script_end_attributes();

  script_category(ACT_GATHER_INFO);
  script_family(english:"Windows : Microsoft Bulletins");

  script_copyright(english:"This script is Copyright (C) 2017-2019 and is owned by Tenable, Inc. or an Affiliate thereof.");

  script_dependencies("office_installed.nasl", "microsoft_sharepoint_installed.nbin", "microsoft_owa_installed.nbin", "microsoft_office_compatibility_pack_installed.nbin", "microsoft_lync_server_installed.nasl", "smb_hotfixes.nasl", "ms_bulletin_checks_possible.nasl");
  script_require_keys("SMB/MS_Bulletin_Checks/Possible");
  script_require_ports(139, 445, "Host/patch_management_checks");

  exit(0);
}

include("audit.inc");
include("smb_func.inc");
include("smb_hotfixes.inc");
include("smb_hotfixes_fcheck.inc");
include("smb_reg_query.inc");
include("misc_func.inc");
include("install_func.inc");

global_var vuln;

get_kb_item_or_exit("SMB/MS_Bulletin_Checks/Possible");

bulletin = "MS17-05";
kbs = make_list(
  '2596904', # Office 2007 SP3
  '3114375', # Office 2016
  '3118310', # Office 2010 SP2
  '3162040', # Word Automation Services on SharePoint Server 2013 SP1
  '3162054', # SharePoint Foundation 2013 SP1
  '3162069', # SharePoint Server 2013 SP1
  '3172458', # Office 2013 SP1
  '3172475', # Sharepoint Server 2013 SP1
  '3172482', # SharePoint Server 2013 SP1
  '3172532', # SharePoint Server 2013 SP1
  '3172536', # SharePoint Server 2013 SP1
  '3178633', # SharePoint Server 2013 SP1
  '3178638', # SharePoint Server 2013 SP1
  '3178729', # Word 2013 SP1
  '3191835', # Office Compatibility Pack SP3
  '3191836', # Word 2007 SP3
  '3191839', # SharePoint Server 2010 SP2
  '3191839', # Word Automation Services on SharePoint Server 2010 SP2
  '3191841', # Office 2010 SP2
  '3191841', # Word 2010 SP2
  '3191843', # Word 2010 SP2
  '3191858', # Skype for Business 2016
  '3191863', # Office 2016
  '3191865', # Word 2016
  '3191880', # SharePoint Enterprise Server 2016
  '3191881', # Office 2016
  '3191885', # Office 2013 SP1
  '3191886', # SharePoint Server 2013 SP1
  '3191887', # Excel Services on SharePoint Server 2013
  '3191888', # Office Web Apps 2013 SP1
  '3191890', # Project Server 2013 SP1
  '3191895', # Office 2007 SP3
  '3191899', # Office 2010 SP2
  '3191904', # Office Web Apps 2010 SP2
  '3191909', # Office Word Viewer
  '3191913', # SharePoint Enterprise Server 2013 SP1
  '3191914', # SharePoint Foundation 2013 SP1
  '3191915'  # Office Online Server 2016
);

if (get_kb_item("Host/patch_management_checks")) hotfix_check_3rd_party(bulletin:bulletin, kbs:kbs, severity:SECURITY_HOLE);

get_kb_item_or_exit("SMB/Registry/Enumerated", exit_code:1);

# Get path information for Windows.
windir = hotfix_get_systemroot();
if (isnull(windir)) exit(1, "Failed to determine the location of %windir%.");

registry_init();
hklm = registry_hive_connect(hive:HKEY_LOCAL_MACHINE, exit_on_fail:TRUE);
global_var office_online_server_path = get_registry_value(
  handle : hklm,
  item   : "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office16.WacServer\InstallLocation"
);
RegCloseKey(handle:hklm);
close_registry(close:FALSE);

vuln = FALSE;
xss  = FALSE;
port = kb_smb_transport();

######################################################################
# Office 2007, 2010, 2013, 2016
######################################################################
function perform_office_checks()
{
  local_var office_vers, office_sp, common_path, path, prod, file, kb;
  office_vers = hotfix_check_office_version();

  ####################################################################
  # Office 2007 SP3 Checks
  ####################################################################
  if (office_vers["12.0"])
  {
    office_sp = get_kb_item("SMB/Office/2007/SP");
    if (!isnull(office_sp) && office_sp == 3)
    {
      prod = "Microsoft Office 2007 SP3";
      path = hotfix_append_path(
        path  : hotfix_get_officecommonfilesdir(officever:"12.0"),
        value : "Microsoft Shared\Office12"
      );
      if (hotfix_check_fversion(file:"mso.dll", version:"12.0.6768.5000", path:path, kb:"3191895", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
      if (hotfix_check_fversion(file:"riched20.dll", version:"12.0.6768.5000", path:path, kb:"2596904", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
  }

  ####################################################################
  # Office 2010 SP2 Checks
  # wwlibcxm.dll only exists if KB2428677 is installed
  ####################################################################
  if (office_vers["14.0"])
  {
    office_sp = get_kb_item("SMB/Office/2010/SP");
    if (!isnull(office_sp) && office_sp == 2)
    {
      prod = "Microsoft Office 2010 SP2";
      common_path = hotfix_get_officecommonfilesdir(officever:"14.0");

      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\Office14"
      );
      if (hotfix_check_fversion(file:"mso.dll", version:"14.0.7181.5000", path:path, kb:"3191899", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(
        path  : common_path,
        value : "\Microsoft Shared\GRPHFLT"
      );
      if (hotfix_check_fversion(file:"epsimp32.flt", version:"2010.1400.7181.5002", min_version:"2010.1400.0.0", path:path, kb:"3118310", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_get_officeprogramfilesdir(officever:"14.0");
      if (hotfix_check_fversion(file:"wwlibcxm.dll", version:"14.0.7181.5000", path:path, kb:"3191841", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
  }

  ####################################################################
  # Office 2013 SP1 Checks
  ####################################################################
  if (office_vers["15.0"])
  {
    office_sp = get_kb_item("SMB/Office/2013/SP");
    if (!isnull(office_sp) && office_sp == 1)
    {
      prod = "Microsoft Office 2013 SP1";
      common_path = hotfix_get_officecommonfilesdir(officever:"15.0");

      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\Office15"
      );
      if (hotfix_check_fversion(file:"mso.dll", version:"15.0.4927.1000", path:path, kb:"3191885", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\GRPHFLT"
      );
      if (hotfix_check_fversion(file:"epsimp32.flt", version:"2012.1500.4927.1002", min_version:"2012.1500.0.0", path:path, kb:"3172458", bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
  }

  ####################################################################
  # Office 2016 Checks
  ####################################################################
  if (office_vers["16.0"])
  {
    office_sp = get_kb_item("SMB/Office/2016/SP");
    if (!isnull(office_sp) && office_sp == 0)
    {
      prod = "Microsoft Office 2016";
      common_path = hotfix_get_officecommonfilesdir(officever:"16.0");

      kb   = "3191881";
      file = "mso.dll";
      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\Office16"
      );
      if (
        hotfix_check_fversion(file:file, version:"16.0.4534.1000", channel:"MSI", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.6925.1059", channel:"Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7329.1054", channel:"Deferred", channel_version:"1609", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7726.1036", channel:"First Release for Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7927.1024", channel:"Current", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER
      )
        vuln = TRUE;

      kb   = "3191863";
      file = "mso99lres.dll";
      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\Office16"
      );
      if (
        hotfix_check_fversion(file:file, version:"16.0.4519.1000", channel:"MSI", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.6925.1059", channel:"Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7329.1054", channel:"Deferred", channel_version:"1609", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7766.7054", channel:"First Release for Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7927.1024", channel:"Current", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER
      )
        vuln = TRUE;

      kb   = "3114375";
      file = "epsimp32.flt";
      path = hotfix_append_path(
        path  : common_path,
        value : "Microsoft Shared\GRPHFLT"
      );
      if (
        hotfix_check_fversion(file:file, version:"16.0.4534.1002", channel:"MSI", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.6925.1059", channel:"Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7329.1054", channel:"Deferred", channel_version:"1609", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7726.1036", channel:"First Release for Deferred", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7927.1024", channel:"Current", channel_product:"Office", path:path, kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER
      )
        vuln = TRUE;
    }
  }
}

######################################################################
# Word 2007, 2010, 2013, 2016
######################################################################
function perform_word_checks()
{
  local_var word_checks, kb16;

  kb16 = "3191865";
  word_checks = make_array(
    "12.0", make_array("sp", 3, "version", "12.0.6768.5000", "kb", "3191836"),
    "14.0", make_array("sp", 2, "version", "14.0.7181.5000", "kb", "3191843"),
    "15.0", make_array("sp", 1, "version", "15.0.4927.1000", "kb", "3178729"),
    "16.0", make_nested_list(
      make_array("sp", 0, "version", "16.0.4534.1000", "channel", "MSI", "kb", kb16),
      make_array("sp", 0, "version", "16.0.6965.2150", "channel", "Deferred", "kb", kb16),
      make_array("sp", 0, "version", "16.0.7369.2130", "channel", "Deferred", "channel_version", "1609", "kb", kb16),
      make_array("sp", 0, "version", "16.0.7766.2084", "channel", "First Release for Deferred", "kb", kb16),
      make_array("sp", 0, "version", "16.0.7967.2161", "channel", "Current", "kb", kb16)
      )
  );
  if (hotfix_check_office_product(product:"Word", checks:word_checks, bulletin:bulletin))
    vuln = TRUE;
}

######################################################################
# Compatibility Pack
######################################################################
function perform_comppack_checks()
{
  local_var install, installs, path;

  ####################################################################
  # Word Compatibility Pack
  ####################################################################
  installs = get_kb_list("SMB/Office/WordCnv/*/ProductPath");
  foreach install (keys(installs))
  {
    path = installs[install];
    path = ereg_replace(pattern:'^(.+)\\\\[^\\\\]+\\.exe$', replace:"\1\", string:path, icase:TRUE);
    if(hotfix_check_fversion(path:path, file:"wordcnv.dll",  version:"12.0.6768.5000", kb:"3191835", bulletin:bulletin, min_version:"12.0.0.0", product:"Microsoft Office Compatibility Pack") == HCF_OLDER)
      vuln = TRUE;
  }
}

######################################################################
# Word Viewer
######################################################################
function perform_viewer_checks()
{
  var word_vwr_checks = make_array(
    "11.0", make_array("version", "11.0.8441.0", "kb", "3191909")
  );
  if (hotfix_check_office_product(product:"WordViewer", display_name:"Word Viewer", checks:word_vwr_checks, bulletin:bulletin))
    vuln = TRUE;
}

######################################################################
# Skype for Business 2016
######################################################################
function perform_skype_checks()
{
  if (int(get_install_count(app_name:"Microsoft Lync")) <= 0)
    return NULL;

  var lync_install, lync_installs, kb, file, prod;

  kb = "3191858";
  file = "Lync.exe";
  prod = "Skype for Business 2016";
  lync_installs = get_installs(app_name:"Microsoft Lync");
  foreach lync_install (lync_installs[1])
  {
    if (lync_install["version"] !~ "^16\.0\.") continue;
    if ("Server" >< lync_install["Product"]) continue;

    # MSI
    if (lync_install['Channel'] == "MSI" || empty_or_null(lync_install['Channel']))
    {
      if (hotfix_check_fversion(file:file, version:"16.0.4534.1000", channel:"MSI", channel_product:"Lync", path:lync_install["path"], kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
    # Deferred
    else if (lync_install['Channel'] == "Deferred")
    {
      if (
        hotfix_check_fversion(file:file, version:"16.0.6965.2150", channel:"Deferred", channel_product:"Lync", path:lync_install["path"], kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER ||
        hotfix_check_fversion(file:file, version:"16.0.7369.2130", channel:"Deferred", channel_version:"1609", channel_product:"Lync", path:lync_install["path"], kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER
      )
        vuln = TRUE;
    }
    else if (lync_install['Channel'] == "First Release for Deferred")
    {
      if (hotfix_check_fversion(file:file, version:"16.0.7766.2084", channel:"First Release for Deferred", channel_product:"Lync", path:lync_install["path"], kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
    else if (lync_install['Channel'] == "Current")
    {
      if (hotfix_check_fversion(file:file, version:"16.0.7967.2161", channel:"Current", channel_product:"Lync", path:lync_install["path"], kb:kb, bulletin:bulletin, product:prod) == HCF_OLDER)
        vuln = TRUE;
    }
  }
}

######################################################################
# Office Web Apps 2010, 2013
######################################################################
function perform_owa_checks()
{
  local_var owa_installs, owa_install;
  local_var owa_2010_path, owa_2010_sp;
  local_var owa_2013_path, owa_2013_sp;
  local_var path;

  # Get installs of Office Web Apps
  owa_installs = get_installs(app_name:"Microsoft Office Web Apps");
  if (!empty_or_null(owa_installs))
  {
    foreach owa_install (owa_installs[1])
    {
      if (owa_install["Product"] == "2010")
      {
        owa_2010_path = owa_install["path"];
        owa_2010_sp = owa_install["SP"];
      }
      else if (owa_install["Product"] == "2013")
      {
        owa_2013_path = owa_install["path"];
        owa_2013_sp = owa_install["SP"];
      }
    }
  }

  ####################################################################
  # Office Web Apps 2010 SP2
  ####################################################################
  if (owa_2010_path && (!isnull(owa_2010_sp) && owa_2010_sp == "2"))
  {
    path = hotfix_append_path(path:owa_2010_path, value:"14.0\WebServices\ConversionService\Bin\Converter");
    if (hotfix_check_fversion(file:"sword.dll", version:"14.0.7181.5000", min_version:"14.0.7015.1000", path:path, kb:"3191904", bulletin:bulletin, product:"Office Web Apps 2010") == HCF_OLDER)
      vuln = TRUE;
  }

  ####################################################################
  # Office Web Apps 2013 SP1
  ####################################################################
  if (owa_2013_path && (!isnull(owa_2013_sp) && owa_2013_sp == "1"))
  {
    path = hotfix_append_path(path:owa_2013_path, value:"WordConversionService\bin\Converter");
    if (hotfix_check_fversion(file:"sword.dll", version:"15.0.4927.1000", min_version:"15.0.4571.1500", path:path, kb:"3191888", bulletin:bulletin, product:"Office Web Apps 2013") == HCF_OLDER)
      vuln = TRUE;
  }
}

######################################################################
# Office Online Server
######################################################################
function perform_oos_checks()
{
  var path;

  if(office_online_server_path)
  {
    path = hotfix_append_path(path:office_online_server_path, value:"WordConversionService\bin\Converter");
    if (hotfix_check_fversion(file:"sword.dll", version:"16.0.7726.1035", min_version:"16.0.6000.0", path:path, kb:"3191915", bulletin:bulletin, product:"Office Online Server") == HCF_OLDER)
      vuln = TRUE;
  }
}

######################################################################
# SharePoint
######################################################################
function perform_sharepoint_checks()
{
  local_var sps_2010_path, sps_2010_sp, sps_2010_edition;
  local_var sps_2013_path, sps_2013_sp, sps_2013_edition;
  local_var sps_2016_path, sps_2016_sp, sps_2016_edition;
  local_var installs, install, path;

  installs = get_installs(app_name:"Microsoft SharePoint Server");

  foreach install (installs[1])
  {
    if (install["Product"] == "2016")
    {
      sps_2016_path = install['path'];
      sps_2016_sp = install['SP'];
      sps_2016_edition = install['Edition'];
    }
    else if (install["Product"] == "2013")
    {
      sps_2013_path = install['path'];
      sps_2013_sp = install['SP'];
      sps_2013_edition = install['Edition'];
    }
    else if (install["Product"] == "2010")
    {
      sps_2010_path = install['path'];
      sps_2010_sp = install['SP'];
      sps_2010_edition = install['Edition'];
    }
  }

  ######################################################################
  # SharePoint Server 2016
  ######################################################################
  if (sps_2016_path && sps_2016_sp == "0" && sps_2016_edition == "Server")
  {
    path = hotfix_append_path(path:sps_2016_path, value:"WebServices\ConversionServices");
    if (hotfix_check_fversion(file:"sword.dll", version:"16.0.4534.1000", min_version:"16.0.0.0", path:path, kb:"3191880", bulletin:bulletin, product:"Office SharePoint Server 2016") == HCF_OLDER)
      vuln = TRUE;
  }

  ######################################################################
  # SharePoint Server 2013 SP1
  ######################################################################
  if (sps_2013_path && sps_2013_sp == "1")
  {
    if(sps_2013_edition == "Server")
    {
      # Files under <sps_2013_path>\bin
      path = hotfix_append_path(path:sps_2013_path, value:"Bin");
      if (hotfix_check_fversion(file:"Microsoft.Office.Project.Server.Library.dll", version:"15.0.4873.1000", min_version:"15.0.0.0", path:path, kb:"3191890", bulletin:bulletin, product:"Microsoft Project Server 2013") == HCF_OLDER)
        vuln = TRUE;

      if (hotfix_check_fversion(file:"xlsrv.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3191887", bulletin:bulletin, product:"Office SharePoint Server 2013 Excel Services") == HCF_OLDER)
       vuln = TRUE;

      # Files under <sps_2013_path>\WebServices\ConversionServices
      path = hotfix_append_path(path:sps_2013_path, value:"WebServices\ConversionServices");
      if (hotfix_check_fversion(file:"sword.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3162040", bulletin:bulletin, product:"Office SharePoint Server 2013 Word Automation Services") == HCF_OLDER)
        vuln = TRUE;

      if (hotfix_check_fversion(file:"oartserver.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3162069", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      if (hotfix_check_fversion(file:"msores.dll", version:"15.0.4913.1000", min_version:"15.0.0.0", path:path, kb:"3172482", bulletin:bulletin, product:"SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      if (hotfix_check_fversion(file:"htmlutil.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3178633", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      if (hotfix_check_fversion(file:"msoserver.dll", version:"15.0.4927.1000", path:path, kb:"3172475", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(path:windir, value:"Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.Visio.Server\v4.0_15.0.0.0__71e9bce111e9429c");
      if (hotfix_check_fversion(file:"Microsoft.Office.Visio.Server.dll", version:"15.0.4797.1000", path:path, kb:"3178638", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(path:windir, value:"Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Publishing\v4.0_15.0.0.0__71e9bce111e9429c");
      if (hotfix_check_fversion(file:"Microsoft.SharePoint.Publishing.dll", version:"15.0.4927.1000", path:path, kb:"3191886", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(path:windir, value:"Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.UserProfiles\v4.0_15.0.0.0__71e9bce111e9429c");
      if (hotfix_check_fversion(file:"Microsoft.SharePoint.Client.UserProfiles.dll", version:"15.0.4745.1000", path:path, kb:"3172532", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;

      path = hotfix_append_path(path:windir, value:"Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.InfoPath.Server\v4.0_15.0.0.0__71e9bce111e9429c");
      if (hotfix_check_fversion(file:"Microsoft.Office.InfoPath.Server.dll", version:"15.0.4873.1000", path:path, kb:"3172536", bulletin:bulletin, product:"Office SharePoint Server 2013") == HCF_OLDER)
        vuln = TRUE;
    }
    else if (sps_2013_edition == "Foundation")
    {
      var commonfiles = hotfix_get_commonfilesdir();
      if (!commonfiles) commonfiles = hotfix_get_commonfilesdirx86();

      if(commonfiles) path = hotfix_append_path(path:commonfiles, value:"Microsoft Shared\Web Server Extensions\15\BIN");
      else path = hotfix_append_path(path:sps_2013_path, value:"BIN");
      if (hotfix_check_fversion(file:"onetutil.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3191914", bulletin:bulletin, product:"Office Sharepoint Foundation 2013") == HCF_OLDER)
      {
        vuln = TRUE;
        xss = TRUE;
      }

      path = hotfix_append_path(path:sps_2013_path, value:"WebServices\ConversionServices");
      if (hotfix_check_fversion(file:"htmlutil.dll", version:"15.0.4927.1000", min_version:"15.0.0.0", path:path, kb:"3162054", bulletin:bulletin, product:"Office Sharepoint Foundation 2013") == HCF_OLDER)
        vuln = TRUE;
    }
  }

  ######################################################################
  # SharePoint Server 2010 SP2
  ######################################################################
  if (sps_2010_path && sps_2010_sp == "2" && sps_2010_edition == "Server")
  {
    path = hotfix_append_path(path:sps_2010_path, value:"WebServices\WordServer\Core");
    if (hotfix_check_fversion(file:"sword.dll", version:"14.0.7181.5000", path:path, kb:"3191839", bulletin:bulletin, product:"Office SharePoint Server 2010 Word Automation Services") == HCF_OLDER)
      vuln = TRUE;
  }
}

perform_office_checks();
perform_word_checks();
perform_comppack_checks();
perform_viewer_checks();
perform_skype_checks();
perform_owa_checks();
perform_oos_checks();
perform_sharepoint_checks();

if (vuln)
{
  # CVE-2017-0255
  if(xss) replace_kb_item(name:'www/'+port+'/XSS', value:TRUE);

  replace_kb_item(name:'SMB/Missing/'+bulletin, value:TRUE);
  hotfix_security_hole();
  hotfix_check_fversion_end();
  exit(0);
}
else
{
  hotfix_check_fversion_end();
  audit(AUDIT_HOST_NOT, 'affected');
}

Seebug

bulletinFamilyexploit
descriptionMay has been a busy month for vulnerabilities in the world's most popular desktop operating system. Hackers have made headlines with massive infections by WannaCry ransomware, which exploits an SMB security flaw and the ETERNALBLUE tool. Shortly prior, on May 9, Microsoft fixed CVE-2017-0263, which had made it possible for attackers to gain maximum system privileges on PCs running Windows 10, Windows 8.1, Windows 7, Windows Server 2008, Windows Server 2012, and Windows Server 2016. Vulnerability CVE-2017-0263 had been used already in phishing messages. The emails contained an exploit that first entered the system by taking advantage of incorrect handling of EPS files by Microsoft Office (CVE-2017-0262) and then, once on the inside, leveraged CVE-2017-0263 to get full administrator rights. Two years ago we looked at a similar vulnerability in Windows, and here we will see how the new CVE-2017-0263 opens the way to "pwning" remote workstations and servers. In a word, this is a use-after-free vulnerability (CWE-416)—when context menu windows were closed and the memory occupied by the menu was freed up, the pointer to the freed-up memory was not zeroed out. As a result, the pointer could be reused. The below discussion covers the process of window handling in the win32k.sys driver and how this process makes it possible to exploit the vulnerability. #### Context menus Every Windows user is familiar with context menus. These are the menus that drop down when we right-click. ![](https://images.seebug.org/1495172500043) The appearance of this menu and how it is displayed are completely up to the developer of each application. WinAPI provides developers with the TrackPopupMenuEx function, which causes a context menu to appear with the specified parameters at the specified location on the screen. The state of the context menu is stored in the kernel in the variable win32k!gMenuState, which is a win32k!tagMENUSTATE structure: ``` 0: kd> dt win32k!tagMenuState +0x000 pGlobalPopupMenu : Ptr32 tagPOPUPMENU +0x004 flags : Int4B +0x008 ptMouseLast : tagPOINT +0x010 mnFocus : Int4B +0x014 cmdLast : Int4B +0x018 ptiMenuStateOwner : Ptr32 tagTHREADINFO +0x01c dwLockCount : Uint4B +0x020 pmnsPrev : Ptr32 tagMENUSTATE +0x024 ptButtonDown : tagPOINT +0x02c uButtonDownHitArea: Uint4B +0x030 uButtonDownIndex : Uint4B +0x034 vkButtonDown : Int4B +0x038 uDraggingHitArea : Uint4B +0x03c uDraggingIndex : Uint4B +0x040 uDraggingFlags : Uint4B +0x044 hdcWndAni : Ptr32 HDC__ +0x048 dwAniStartTime : Uint4B +0x04c ixAni : Int4B +0x050 iyAni : Int4B +0x054 cxAni : Int4B +0x058 cyAni : Int4B +0x05c hbmAni : Ptr32 HBITMAP__ +0x060 hdcAni : Ptr32 HDC__ ``` Note that all of the call stacks and structures presented here are taken from Windows 7 x86. The 32-bit OS version is used for convenience: arguments for most functions are stored on the stack and there is no WoW64 layer, which during system calls switches to a 64-bit stack due to which 32-bit stack frames are lost when the call stack is printed. A full list of vulnerable operating systems is given on the Microsoft website. The win32k!tagMENUSTATE structure stores, for example, such information as: the clicked region of the screen, number of the most recent menu command, and pointers to the windows that were clicked or selected for drag-and-drop. The list of context menu windows is stored in the first field, pGlobalPopupMenu, which is of the type win32k!tagPOPUPMENU: ``` 0: kd> dt win32k!tagPopupMenu +0x000 flags : Int4B +0x004 spwndNotify : Ptr32 tagWND +0x008 spwndPopupMenu : Ptr32 tagWND +0x00c spwndNextPopup : Ptr32 tagWND +0x010 spwndPrevPopup : Ptr32 tagWND +0x014 spmenu : Ptr32 tagMENU +0x018 spmenuAlternate : Ptr32 tagMENU +0x01c spwndActivePopup : Ptr32 tagWND +0x020 ppopupmenuRoot : Ptr32 tagPOPUPMENU +0x024 ppmDelayedFree : Ptr32 tagPOPUPMENU +0x028 posSelectedItem : Uint4B +0x02c posDropped : Uint4B +0x030 ppmlockFree : Ptr32 tagPOPUPMENU ``` In both structures we have highlighted the fields of interest, which will be used below to describe the exploitation process. The variable win32k!gMenuState is initialized when a context menu is created, during the previously mentioned TrackPopupMenuEx function. Initialization occurs when win32k!xxxMNAllocMenuState is called: ``` 1: kd> k # ChildEBP RetAddr 00 95f29b38 81fe3ca6 win32k!xxxMNAllocMenuState+0x7c 01 95f29ba0 81fe410f win32k!xxxTrackPopupMenuEx+0x27f 02 95f29c14 82892db6 win32k!NtUserTrackPopupMenuEx+0xc3 03 95f29c14 77666c74 nt!KiSystemServicePostCall 04 0131fd58 7758480e ntdll!KiFastSystemCallRet 05 0131fd5c 100015b3 user32!NtUserTrackPopupMenuEx+0xc 06 0131fd84 7756c4b7 q_Main_Window_Class_wndproc (call TrackPopupMenuEx) ``` And when the context menu is no longer needed—for example, the user selected a menu item or clicked outside of the menu—the function win32k!xxxMNEndMenuState is called and frees up the state of the menu: ``` 1: kd> k # ChildEBP RetAddr 00 a0fb7ab0 82014f68 win32k!xxxMNEndMenuState 01 a0fb7b20 81fe39f5 win32k!xxxRealMenuWindowProc+0xd46 02 a0fb7b54 81f5c134 win32k!xxxMenuWindowProc+0xfd 03 a0fb7b94 81f1bb74 win32k!xxxSendMessageTimeout+0x1ac 04 a0fb7bbc 81f289c8 win32k!xxxWrapSendMessage+0x1c 05 a0fb7bd8 81f5e149 win32k!NtUserfnNCDESTROY+0x27 06 a0fb7c10 82892db6 win32k!NtUserMessageCall+0xcf 07 a0fb7c10 77666c74 nt!KiSystemServicePostCall 08 013cfd90 77564f21 ntdll!KiFastSystemCallRet 09 013cfd94 77560908 user32!NtUserMessageCall+0xc 0a 013cfdd0 77565552 user32!SendMessageWorker+0x546 0b 013cfdf0 100014e4 user32!SendMessageW+0x7c 0c 013cfe08 775630bc q_win_event_hook (call SendMessageW(MN_DODRAGDROP)) ``` Important here is that the gMenuState.pGlobalPopupMenu field is updated only during initialization in the xxxMNAllocMenuState function—it is not zeroed out when the structure is destroyed. #### xxxMNEndMenuState function This function is the star of our story. Its handful of lines harbor the vulnerability. ![](https://images.seebug.org/1495172627600) xxxMNEndMenuState starts with deinitialization and freeing of information related to the context menu. The MNFreePopup function—to which we will return in the following section—is called. The main task of MNFreePopup is to decrement reference counters for windows related to the particular context menu. When the reference count falls to zero, this decrementing can cause the window to be destroyed. Then the xxxMNEndMenuState function checks the fMenuWindowRef flag of the pGlobalPopupMenu field to see if any references remain to the main window of the context menu. This flag is cleared upon destruction of the window contained in the spwndPopupMenu field of the context menu: ``` 3: kd> k # ChildEBP RetAddr 00 95fffa5c 81f287da win32k!xxxFreeWindow+0x847 01 95fffab0 81f71252 win32k!xxxDestroyWindow+0x532 02 95fffabc 81f7122c win32k!HMDestroyUnlockedObject+0x1b 03 95fffac8 81f70c4a win32k!HMUnlockObjectInternal+0x30 04 95fffad4 81f6e1fc win32k!HMUnlockObject+0x13 05 95fffadc 81fea664 win32k!HMAssignmentUnlock+0xf 06 95fffaec 81fea885 win32k!MNFreePopup+0x7d 07 95fffb14 8202c3d6 win32k!xxxMNEndMenuState+0x40 xxxFreeWindow+83f disasm: .text:BF89082E loc_BF89082E: .text:BF89082E and ecx, 7FFFFFFFh ; ~fMenuWindowRef .text:BF890834 mov [eax+tagPOPUPMENU.flags], ecx ``` As seen above, the flag is discarded and therefore the memory occupied by the pGlobalPopupMenu field is freed up, but the pointer itself is not zeroed out. This causes a dangling pointer, which under certain circumstances can be reused. Immediately after the context menu memory is freed up, the execution flow deletes the references stored in the context menu state structure that relate to clicked windows (uButtonDownHitArea field) when the menu was active or were selected for drag-and-drop (uDraggingHitArea field). #### Exploitation method A window object in the kernel is described by a tagWND structure. There we describe the concept of kernel callbacks, which will be needed here as well. The number of active references to a window is stored in the cLockObj field of the tagWND structure. Deleting references to a window, as shown in the previous section, can cause the window itself to be destroyed. Before the window is destroyed, a WM_NCDESTROY change-of-window-state message is sent to the window. This means that while xxxMNEndMenuState is running, control can be transferred to user application code—specifically, to the window procedure of the window being destroyed. This happens when no references remain to a window whose pointer is stored in the gMenuState.uButtonDownHitArea field. ``` 2: kd> k # ChildEBP RetAddr 0138fc34 7756c4b7 q_new_SysShadow_window_proc 0138fc60 77565f6f USER32!InternalCallWinProc+0x23 0138fcd8 77564ede USER32!UserCallWinProcCheckWow+0xe0 0138fd34 7755b28f USER32!DispatchClientMessage+0xcf 0138fd64 77666bae USER32!__fnNCDESTROY+0x26 0138fd90 77564f21 ntdll!KiUserCallbackDispatcher+0x2e 95fe38f8 81f56d86 nt!KeUserModeCallback 95fe3940 81f5c157 win32k!xxxSendMessageToClient+0x175 95fe398c 81f5c206 win32k!xxxSendMessageTimeout+0x1cf 95fe39b4 81f2839c win32k!xxxSendMessage+0x28 95fe3a10 81f2fb00 win32k!xxxDestroyWindow+0xf4 95fe3a24 81f302ee win32k!xxxRemoveShadow+0x3e 95fe3a64 81f287da win32k!xxxFreeWindow+0x2ff 95fe3ab8 81f71252 win32k!xxxDestroyWindow+0x532 95fe3ac4 81f7122c win32k!HMDestroyUnlockedObject+0x1b 95fe3ad0 81f70c4a win32k!HMUnlockObjectInternal+0x30 95fe3adc 81f6e1fc win32k!HMUnlockObject+0x13 95fe3ae4 81fe4162 win32k!HMAssignmentUnlock+0xf 95fe3aec 81fea8c3 win32k!UnlockMFMWFPWindow+0x18 95fe3b14 8202c3d6 win32k!xxxMNEndMenuState+0x7e ``` For example, in the call stack shown above, the WM_NCDESTROY message is handled by the window procedure for the SysShadow window class. Windows of this class are designed to provide shadowing and are usually destroyed together with the windows for which they are shadowing. Now let's see the most interesting part of how this window message is handled, in the form that was found in the malware sample taken from a .docx phishing attachment: ![](https://images.seebug.org/1495172755316) When the attacker takes control, the first matter of business is to occupy the now-free memory that was just occupied by gMenuState.pGlobalPopupMenu, in order to reuse this pointer later. Attempting to allocate the indicated memory block, the exploit performs a large number of SetClassLongW calls, thus setting a specially formed menu name for window classes that have been specially created for this purpose: ``` 2: kd> k # ChildEBP RetAddr 00 9f74bafc 81f240d2 win32k!memcpy+0x33 01 9f74bb3c 81edadb1 win32k!AllocateUnicodeString+0x6b 02 9f74bb9c 81edb146 win32k!xxxSetClassData+0x1d1 03 9f74bbb8 81edb088 win32k!xxxSetClassLong+0x39 04 9f74bc1c 82892db6 win32k!NtUserSetClassLong+0xc8 05 9f74bc1c 77666c74 nt!KiSystemServicePostCall 06 0136fac0 7755658b ntdll!KiFastSystemCallRet 07 0136fac4 775565bf user32!NtUserSetClassLong+0xc 08 0136fafc 10001a52 user32!SetClassLongW+0x5e 09 0136fc34 7756c4b7 q_new_SysShadow_window_proc (call SetClassLongW) ``` After the memory is occupied, the next stage begins. The exploit accesses the NtUserMNDragLeave system procedure, which performs a nested call of the xxxMNEndMenuState function. Clearing of the gMenuState structure starts again: ``` 2: kd> k # ChildEBP RetAddr 00 9f74bbf0 8202c3d6 win32k!xxxMNEndMenuState 01 9f74bc04 8202c40e win32k!xxxUnlockMenuStateInternal+0x2e 02 9f74bc14 82015672 win32k!xxxUnlockAndEndMenuState+0xf 03 9f74bc24 82001728 win32k!xxxMNDragLeave+0x45 04 9f74bc2c 82892db6 win32k!NtUserMNDragLeave+0xd 05 9f74bc2c 100010a9 nt!KiSystemServicePostCall 06 0136fafc 10001a84 q_exec_int2e (int 2Eh) 07 0136fc34 7756c4b7 q_new_SysShadow_window_proc (call q_exec_int2e) ``` As described in the previous section, the procedure starts by deinitializing the pGlobalPopupMenu field; this process is performed by the MNFreePopup call, which decrements the reference counters for windows contained in various fields of tagPOPUPMENU. After the prior step, the content of this structure is now controlled by the attacker. So when the described chain of actions is performed, the attacker gets a decrement primitive to an arbitrary kernel address. In this exploit, an address is inserted in the tagPOPUPMENU.spwndPrevPopup field and the primitive is used to decrement the field for flags of one of the windows, causing that window to be marked with the flag bServerSideProc, which means that its window procedure is run in the kernel. As the code shows, immediately after returning from NtUserMNDragLeave, a message is sent to the window by a SendMessage call, causing arbitrary kernel code execution. At this stage, the attacker usually steals a system process token to obtain system privileges. Indeed, this is what happened in the exploit here. #### In conclusion What are the salient points of the exploit? The most common cause of vulnerabilities in the win32k.sys library is access to callbacks in user space when any kernel structures are in an intermediate stage when a transaction is changing them. Setting the bServerSideProc flag for a window is also a popular method for kernel code execution. In addition, the most convenient method to leverage kernel code execution for privilege escalation is to copy a reference to a system token. In that sense, the exploit looks rather mundane. At the same time many of the nuances have been simplified or purposefully omitted from this discussion. For example, we did not dwell on the exact appearance of the context menu or menu-related actions that cause the necessary state of the flags and fields of the win32k!gMenuState variable during execution of the xxxMNEndMenuState procedure. Left unmentioned was the fact that the menu names set during SetClassLong calls should, on the one hand, be a Unicode string with no null characters but, on the other hand, be a legitimate tagPOPUPMENU structure. This also means that the address of the window in the kernel (to which the decrement field will refer) must not contain any wchar_t null characters. These are just a few examples from a rather long list. As for the update that fixes the vulnerability, a quick glance shows that the buffer addressed by the gMenuState.pGlobalPopupMenu field is now freed closer to the end of the xxxMNEndMenuState function, much later after the MNFreePopup and UnlockMFMWPWindow calls, and is accompanied by zeroing-out of the pointer. Thus the patch addresses two causes whose simultaneous presence caused the vulnerability to occur.
idSSV:93116
last seen2017-11-19
modified2017-05-19
published2017-05-19
reporterRoot
titleWin32k Elevation of Privilege Vulnerability(CVE-2017-0263)

The Hacker News

idTHN:35CDED923C2A70050CA53879EA860398
last seen2018-01-27
modified2017-05-10
published2017-05-09
reporterSwati Khandelwal
sourcehttps://thehackernews.com/2017/05/patch-windows-zero-days.html
titleMicrosoft Issues Patches for Another Four Zero-Day Vulnerabilities