{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/osquery/pulls/comments/35725832","id":35725832,"diff_hunk":"@@ -0,0 +1,82 @@\n+/*\n+ *  Copyright (c) 2014, Facebook, Inc.\n+ *  All rights reserved.\n+ *\n+ *  This source code is licensed under the BSD-style license found in the\n+ *  LICENSE file in the root directory of this source tree. An additional grant\n+ *  of patent rights can be found in the PATENTS file in the same directory.\n+ *\n+ */\n+\n+#include \"osquery/events/darwin/kernel_util.h\"\n+\n+#include <boost/regex.hpp>\n+#include <boost/xpressive/xpressive.hpp>\n+\n+#include <IOKit/kext/KextManager.h>\n+\n+#include <osquery/config.h>\n+#include <osquery/filesystem.h>\n+#include <osquery/logger.h>\n+#include <osquery/sql.h>\n+\n+namespace xp = boost::xpressive;\n+\n+namespace osquery {\n+\n+static const CFStringRef kKernelBundleId =\n+    CFSTR(\"com.facebook.security.osquery\");\n+static const CFStringRef kKernelExtensionDirectory =\n+    CFSTR(\"/Library/Extensions/\");\n+static const std::string kKernelBundleRegex =\n+    \".*Kernel Extensions in \"\n+    \"backtrace:.*com\\\\.facebook\\\\.security\\\\.osquery.*Kernel version:\";\n+static const std::string kBlockingFile = \"/var/osquery/.gtfo\";\n+\n+void loadKernelExtension() {\n+  // Find the panic log file for the last panic if we are just booting out of\n+  // panic.\n+  auto results =\n+      SQL::SQL(\n+          \"SELECT f.path AS path FROM (SELECT * FROM nvram WHERE name like \"\n+          \"'%panic%') AS nv JOIN (SELECT * FROM file WHERE \"\n+          \"directory='/Library/Logs/DiagnosticReports/' AND path like \"\n+          \"'%/Kernel%' ORDER BY ctime DESC LIMIT 1) as f;\")\n+          .rows();\n+\n+  if (results.size() == 1) {\n+    std::string panic_content;\n+    if (readFile(results[0][\"path\"], panic_content).ok()) {\n+      auto rx = xp::sregex::compile(kKernelBundleRegex);\n+      xp::smatch matches;\n+      if (xp::regex_search(panic_content, matches, rx)) {\n+        LOG(ERROR) << \"Panic was caused by osquery kernel extension.\";\n+        writeTextFile(kBlockingFile, \"\", 0660, true);\n+      }\n+    }\n+  }\n+\n+  results =\n+      SQL::SQL(\n+          \"SELECT * FROM file WHERE path='/var/osquery/.gtfo' AND mode='0660'\")\n+          .rows();\n+\n+  ConfigDataInstance config;\n+  if (config.options().count(\"disable_kernel\") || results.size() > 0) {","path":"osquery/events/darwin/kernel_util.cpp","position":65,"original_position":65,"commit_id":"a45bb11d9794b399569811fb29f493dac6cd8472","original_commit_id":"a45bb11d9794b399569811fb29f493dac6cd8472","user":{"login":"theopolis","id":981645,"avatar_url":"https://avatars.githubusercontent.com/u/981645?v=3","gravatar_id":"","url":"https://api.github.com/users/theopolis","html_url":"https://github.com/theopolis","followers_url":"https://api.github.com/users/theopolis/followers","following_url":"https://api.github.com/users/theopolis/following{/other_user}","gists_url":"https://api.github.com/users/theopolis/gists{/gist_id}","starred_url":"https://api.github.com/users/theopolis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theopolis/subscriptions","organizations_url":"https://api.github.com/users/theopolis/orgs","repos_url":"https://api.github.com/users/theopolis/repos","events_url":"https://api.github.com/users/theopolis/events{/privacy}","received_events_url":"https://api.github.com/users/theopolis/received_events","type":"User","site_admin":false},"body":"Use a `FLAG`: https://github.com/facebook/osquery/blob/master/osquery/events/events.cpp#L30 and https://github.com/facebook/osquery/blob/master/osquery/events/events.cpp#L461\r\n\r\n","created_at":"2015-07-29T03:50:03Z","updated_at":"2015-07-29T03:50:03Z","html_url":"https://github.com/facebook/osquery/pull/1404#discussion_r35725832","pull_request_url":"https://api.github.com/repos/facebook/osquery/pulls/1404","_links":{"self":{"href":"https://api.github.com/repos/facebook/osquery/pulls/comments/35725832"},"html":{"href":"https://github.com/facebook/osquery/pull/1404#discussion_r35725832"},"pull_request":{"href":"https://api.github.com/repos/facebook/osquery/pulls/1404"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/osquery/pulls/1404","id":41079760,"html_url":"https://github.com/facebook/osquery/pull/1404","diff_url":"https://github.com/facebook/osquery/pull/1404.diff","patch_url":"https://github.com/facebook/osquery/pull/1404.patch","issue_url":"https://api.github.com/repos/facebook/osquery/issues/1404","number":1404,"state":"open","locked":false,"title":"Added loading of kernel.","user":{"login":"mofarrell","id":4332159,"avatar_url":"https://avatars.githubusercontent.com/u/4332159?v=3","gravatar_id":"","url":"https://api.github.com/users/mofarrell","html_url":"https://github.com/mofarrell","followers_url":"https://api.github.com/users/mofarrell/followers","following_url":"https://api.github.com/users/mofarrell/following{/other_user}","gists_url":"https://api.github.com/users/mofarrell/gists{/gist_id}","starred_url":"https://api.github.com/users/mofarrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mofarrell/subscriptions","organizations_url":"https://api.github.com/users/mofarrell/orgs","repos_url":"https://api.github.com/users/mofarrell/repos","events_url":"https://api.github.com/users/mofarrell/events{/privacy}","received_events_url":"https://api.github.com/users/mofarrell/received_events","type":"User","site_admin":false},"body":"Checks for panics we are involved in and does not load kernel extension.  Otherwise looks for `/var/osquery/.gtfo` with `0660` permissions or a `disable_kernel` flag in the config options.","created_at":"2015-07-29T01:44:34Z","updated_at":"2015-07-29T03:50:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df3ac8a5ea78ce00a810d641d39548c727502419","assignee":{"login":"mofarrell","id":4332159,"avatar_url":"https://avatars.githubusercontent.com/u/4332159?v=3","gravatar_id":"","url":"https://api.github.com/users/mofarrell","html_url":"https://github.com/mofarrell","followers_url":"https://api.github.com/users/mofarrell/followers","following_url":"https://api.github.com/users/mofarrell/following{/other_user}","gists_url":"https://api.github.com/users/mofarrell/gists{/gist_id}","starred_url":"https://api.github.com/users/mofarrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mofarrell/subscriptions","organizations_url":"https://api.github.com/users/mofarrell/orgs","repos_url":"https://api.github.com/users/mofarrell/repos","events_url":"https://api.github.com/users/mofarrell/events{/privacy}","received_events_url":"https://api.github.com/users/mofarrell/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/facebook/osquery/pulls/1404/commits","review_comments_url":"https://api.github.com/repos/facebook/osquery/pulls/1404/comments","review_comment_url":"https://api.github.com/repos/facebook/osquery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/osquery/issues/1404/comments","statuses_url":"https://api.github.com/repos/facebook/osquery/statuses/a45bb11d9794b399569811fb29f493dac6cd8472","head":{"label":"mofarrell:load-kernel","ref":"load-kernel","sha":"a45bb11d9794b399569811fb29f493dac6cd8472","user":{"login":"mofarrell","id":4332159,"avatar_url":"https://avatars.githubusercontent.com/u/4332159?v=3","gravatar_id":"","url":"https://api.github.com/users/mofarrell","html_url":"https://github.com/mofarrell","followers_url":"https://api.github.com/users/mofarrell/followers","following_url":"https://api.github.com/users/mofarrell/following{/other_user}","gists_url":"https://api.github.com/users/mofarrell/gists{/gist_id}","starred_url":"https://api.github.com/users/mofarrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mofarrell/subscriptions","organizations_url":"https://api.github.com/users/mofarrell/orgs","repos_url":"https://api.github.com/users/mofarrell/repos","events_url":"https://api.github.com/users/mofarrell/events{/privacy}","received_events_url":"https://api.github.com/users/mofarrell/received_events","type":"User","site_admin":false},"repo":{"id":36032463,"name":"osquery","full_name":"mofarrell/osquery","owner":{"login":"mofarrell","id":4332159,"avatar_url":"https://avatars.githubusercontent.com/u/4332159?v=3","gravatar_id":"","url":"https://api.github.com/users/mofarrell","html_url":"https://github.com/mofarrell","followers_url":"https://api.github.com/users/mofarrell/followers","following_url":"https://api.github.com/users/mofarrell/following{/other_user}","gists_url":"https://api.github.com/users/mofarrell/gists{/gist_id}","starred_url":"https://api.github.com/users/mofarrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mofarrell/subscriptions","organizations_url":"https://api.github.com/users/mofarrell/orgs","repos_url":"https://api.github.com/users/mofarrell/repos","events_url":"https://api.github.com/users/mofarrell/events{/privacy}","received_events_url":"https://api.github.com/users/mofarrell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mofarrell/osquery","description":"SQL powered operating system instrumentation, monitoring, and analytics.","fork":true,"url":"https://api.github.com/repos/mofarrell/osquery","forks_url":"https://api.github.com/repos/mofarrell/osquery/forks","keys_url":"https://api.github.com/repos/mofarrell/osquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mofarrell/osquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mofarrell/osquery/teams","hooks_url":"https://api.github.com/repos/mofarrell/osquery/hooks","issue_events_url":"https://api.github.com/repos/mofarrell/osquery/issues/events{/number}","events_url":"https://api.github.com/repos/mofarrell/osquery/events","assignees_url":"https://api.github.com/repos/mofarrell/osquery/assignees{/user}","branches_url":"https://api.github.com/repos/mofarrell/osquery/branches{/branch}","tags_url":"https://api.github.com/repos/mofarrell/osquery/tags","blobs_url":"https://api.github.com/repos/mofarrell/osquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mofarrell/osquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mofarrell/osquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/mofarrell/osquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mofarrell/osquery/statuses/{sha}","languages_url":"https://api.github.com/repos/mofarrell/osquery/languages","stargazers_url":"https://api.github.com/repos/mofarrell/osquery/stargazers","contributors_url":"https://api.github.com/repos/mofarrell/osquery/contributors","subscribers_url":"https://api.github.com/repos/mofarrell/osquery/subscribers","subscription_url":"https://api.github.com/repos/mofarrell/osquery/subscription","commits_url":"https://api.github.com/repos/mofarrell/osquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/mofarrell/osquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/mofarrell/osquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/mofarrell/osquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/mofarrell/osquery/contents/{+path}","compare_url":"https://api.github.com/repos/mofarrell/osquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mofarrell/osquery/merges","archive_url":"https://api.github.com/repos/mofarrell/osquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mofarrell/osquery/downloads","issues_url":"https://api.github.com/repos/mofarrell/osquery/issues{/number}","pulls_url":"https://api.github.com/repos/mofarrell/osquery/pulls{/number}","milestones_url":"https://api.github.com/repos/mofarrell/osquery/milestones{/number}","notifications_url":"https://api.github.com/repos/mofarrell/osquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mofarrell/osquery/labels{/name}","releases_url":"https://api.github.com/repos/mofarrell/osquery/releases{/id}","created_at":"2015-05-21T19:14:26Z","updated_at":"2015-05-21T19:14:27Z","pushed_at":"2015-07-29T01:42:55Z","git_url":"git://github.com/mofarrell/osquery.git","ssh_url":"git@github.com:mofarrell/osquery.git","clone_url":"https://github.com/mofarrell/osquery.git","svn_url":"https://github.com/mofarrell/osquery","homepage":"https://osquery.io","size":5949,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"fa36a8918be5e0f38c546df3a70ac3d59adefc84","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":22394357,"name":"osquery","full_name":"facebook/osquery","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/osquery","description":"SQL powered operating system instrumentation, monitoring, and analytics.","fork":false,"url":"https://api.github.com/repos/facebook/osquery","forks_url":"https://api.github.com/repos/facebook/osquery/forks","keys_url":"https://api.github.com/repos/facebook/osquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/osquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/osquery/teams","hooks_url":"https://api.github.com/repos/facebook/osquery/hooks","issue_events_url":"https://api.github.com/repos/facebook/osquery/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/osquery/events","assignees_url":"https://api.github.com/repos/facebook/osquery/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/osquery/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/osquery/tags","blobs_url":"https://api.github.com/repos/facebook/osquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/osquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/osquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/osquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/osquery/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/osquery/languages","stargazers_url":"https://api.github.com/repos/facebook/osquery/stargazers","contributors_url":"https://api.github.com/repos/facebook/osquery/contributors","subscribers_url":"https://api.github.com/repos/facebook/osquery/subscribers","subscription_url":"https://api.github.com/repos/facebook/osquery/subscription","commits_url":"https://api.github.com/repos/facebook/osquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/osquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/osquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/osquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/osquery/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/osquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/osquery/merges","archive_url":"https://api.github.com/repos/facebook/osquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/osquery/downloads","issues_url":"https://api.github.com/repos/facebook/osquery/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/osquery/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/osquery/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/osquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/osquery/labels{/name}","releases_url":"https://api.github.com/repos/facebook/osquery/releases{/id}","created_at":"2014-07-29T20:27:33Z","updated_at":"2015-07-28T15:10:18Z","pushed_at":"2015-07-29T01:44:35Z","git_url":"git://github.com/facebook/osquery.git","ssh_url":"git@github.com:facebook/osquery.git","clone_url":"https://github.com/facebook/osquery.git","svn_url":"https://github.com/facebook/osquery","homepage":"https://osquery.io","size":15150,"stargazers_count":4743,"watchers_count":4743,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":403,"mirror_url":null,"open_issues_count":24,"forks":403,"open_issues":24,"watchers":4743,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/osquery/pulls/1404"},"html":{"href":"https://github.com/facebook/osquery/pull/1404"},"issue":{"href":"https://api.github.com/repos/facebook/osquery/issues/1404"},"comments":{"href":"https://api.github.com/repos/facebook/osquery/issues/1404/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/osquery/pulls/1404/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/osquery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/osquery/pulls/1404/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/osquery/statuses/a45bb11d9794b399569811fb29f493dac6cd8472"}}}}