{"id":26451,"date":"2019-09-02T16:20:35","date_gmt":"2019-09-02T20:20:35","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=26451"},"modified":"2019-09-02T16:20:35","modified_gmt":"2019-09-02T20:20:35","slug":"privilegedhelpertools-and-checking-xpc-peers","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/09\/02\/privilegedhelpertools-and-checking-xpc-peers\/","title":{"rendered":"PrivilegedHelperTools and Checking XPC Peers"},"content":{"rendered":"<p><a href=\"https:\/\/blog.obdev.at\/what-we-have-learned-from-a-vulnerability\/\">Objective Development<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.obdev.at\/what-we-have-learned-from-a-vulnerability\/\">\n<p>It all began with a security improvement by Apple in macOS High Sierra (10.13). Apple had revoked access to the folder <code>\/Library\/Logs\/DiagnosticReports<\/code> for non-admin users. The protection goes so far that even a root process spawned by <code>AuthorizationExecuteWithPrivileges()<\/code> cannot access the folder.<\/p>\n<p>[&#8230;]<\/p>\n<p>Every installer application which needs root permissions is now urged to install a system-wide daemon for this purpose. This system-wide daemon is usually left behind, because Apple provides no API for removing it.<\/p>\n<p>[&#8230;]<\/p>\n<p>In an internal code review, another developer looked over the code and verified all assumptions. He did not find a proof for the assumption that XPC connections are authorized by the system. Since there was little information available, he made a test project and could exploit our privileged helper tool!<\/p>\n<p>[&#8230;]<\/p>\n<p>The helper (and the app using the helper) should check the identity of the peer before performing any operations. Even if an <code>AuthorizationExternalForm<\/code> is already used. The most secure way for such a check is the code signature.<\/p>\n<p>[&#8230;]<\/p>\n<p>Note that this example uses the private <code>NSXPCConnection.auditToken<\/code> property. If we want to avoid using a private property, we need to use the Unix process ID. But this is inherently insecure (see <a href=\"https:\/\/saelo.github.io\/presentations\/warcon18_dont_trust_the_pid.pdf\">Don&rsquo;t trust the PID!<\/a> by Samuel Gro&szlig;). We therefore decided to use <code>auditToken<\/code> anyway.<\/p>\n<\/blockquote>\n<p>So, because Apple decided to protect the logs folder, and the documentation is not very good, the Little Snitch developers ended up introducing a privilege escalation vulnerability, and even now they can&rsquo;t make it fully secure without using private API. These are smart developers with a long history building a highly regarded security-focused product. Of course it sounds like a good idea to make the logs secure, but I think we can ask whether it was worth the cost in collateral security and engineering time. And why should it be so difficult and error-prone for an app to facilitate the customer sending in a diagnostic report?<\/p>\n\n<p>See also: <a href=\"https:\/\/nvd.nist.gov\/vuln\/detail\/CVE-2019-13013\">CVE-2019-13013<\/a>.<\/p>\n\n<p><a href=\"https:\/\/lists.macosforge.org\/pipermail\/launchd-dev\/2016-October\/001229.html\">Joe Auricchio<\/a> (in 2016, via <a href=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1166028996250873857\">Jeff Johnson<\/a>):<\/p>\n<blockquote cite=\"https:\/\/lists.macosforge.org\/pipermail\/launchd-dev\/2016-October\/001229.html\"><p>It&rsquo;s better to keep using the deprecated SM functions than to run launchctl. Sorry, but replacements are not yet available.<\/p>\n<p>There isn&rsquo;t presently API for a system-wide LaunchDaemon to open a Mach IPC or XPC connection to a LaunchAgent, which I&rsquo;d guess is closer to what you&rsquo;d really like to do? This would be a good enhancement request, please file one!<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Objective Development: It all began with a security improvement by Apple in macOS High Sierra (10.13). Apple had revoked access to the folder \/Library\/Logs\/DiagnosticReports for non-admin users. The protection goes so far that even a root process spawned by AuthorizationExecuteWithPrivileges() cannot access the folder. [&#8230;] Every installer application which needs root permissions is now urged [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-09-02T20:20:38Z","apple_news_api_id":"54a66ef0-b2d0-456a-8e89-3386a8be9721","apple_news_api_modified_at":"2019-09-02T20:20:39Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AVKZu8LLQRWqOiTOGqL6XIQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[466,164,500,139,30,32,1609,54,74,1013,71,48,1473],"class_list":["post-26451","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-codesigning","tag-documentation","tag-launchd","tag-littlesnitch","tag-mac","tag-macapp","tag-macos-10-14","tag-objective-c","tag-opensource","tag-private-api","tag-programming","tag-security","tag-xpc"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/26451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=26451"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/26451\/revisions"}],"predecessor-version":[{"id":26452,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/26451\/revisions\/26452"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=26451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=26451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=26451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}