{"action":"created","comment":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments/27485210","id":27485210,"diff_hunk":"@@ -170,54 +115,129 @@ def report_session(opts)\n   # @param wspace [Mdm::Workspace]\n   # @return [void]\n   def infer_vuln_from_session(session, wspace)\n-    s = session.db_record\n-    host = session.db_record.host\n+    ::ActiveRecord::Base.connection_pool.with_connection {\n+      s = session.db_record\n+      host = session.db_record.host\n+\n+      if session.via_exploit == \"exploit/multi/handler\" and session.exploit_datastore['ParentModule']\n+        mod_fullname = session.exploit_datastore['ParentModule']\n+      else\n+        mod_fullname = session.via_exploit\n+      end\n+      mod_detail = ::Mdm::Module::Detail.find_by_fullname(mod_fullname)\n+      mod_name = mod_detail.name\n+\n+      vuln_info = {\n+        exploited_at: Time.now.utc,\n+        host: host,\n+        info: \"Exploited by #{mod_fullname} to create Session #{s.id}\",\n+        name: mod_name,\n+        refs: mod_detail.refs.map { |ref| ref.name },\n+        workspace: wspace,\n+      }\n \n-    mod = framework.modules.create(session.via_exploit)\n+      port    = session.exploit_datastore[\"RPORT\"]\n+      service = (port ? host.services.find_by_port(port.to_i) : nil)\n \n-    if session.via_exploit == \"exploit/multi/handler\" and session.exploit_datastore['ParentModule']\n-      mod_fullname = session.exploit_datastore['ParentModule']\n-      mod_name = ::Mdm::Module::Detail.find_by_fullname(mod_fullname).name\n-    else\n-      mod_name = mod.name\n-      mod_fullname = mod.fullname\n-    end\n+      vuln_info[:service] = service if service\n+\n+      vuln = framework.db.report_vuln(vuln_info)\n+\n+      attempt_info = {\n+        host: host,\n+        module: mod_fullname,\n+        refs: mod_detail.refs,\n+        service: service,\n+        session_id: s.id,\n+        timestamp: Time.now.utc,\n+        username: session.username,\n+        vuln: vuln,\n+        workspace: wspace,\n+      }\n \n-    vuln_info = {\n-      :host => host.address,\n-      :name => mod_name,\n-      :refs => mod.references,\n-      :workspace => wspace,\n-      :exploited_at => Time.now.utc,\n-      :info => \"Exploited by #{mod_fullname} to create Session #{s.id}\"\n+      framework.db.report_exploit_success(attempt_info)\n+\n+      vuln\n     }\n+  end\n \n-    port    = session.exploit_datastore[\"RPORT\"]\n-    service = (port ? host.services.find_by_port(port.to_i) : nil)\n+  def create_mdm_session_from_session(opts)\n+    ::ActiveRecord::Base.connection_pool.with_connection {\n+      raise ArgumentError.new(\"Invalid :session, expected Msf::Session\") unless opts[:session].kind_of? Msf::Session\n+      session = opts[:session]","path":"lib/msf/core/db_manager/session.rb","position":162,"original_position":162,"commit_id":"47d85af81145896c46a40d3e4e83ec7dca7bb4ec","original_commit_id":"47d85af81145896c46a40d3e4e83ec7dca7bb4ec","user":{"login":"limhoff-r7","id":2230482,"avatar_url":"https://avatars.githubusercontent.com/u/2230482?v=3","gravatar_id":"","url":"https://api.github.com/users/limhoff-r7","html_url":"https://github.com/limhoff-r7","followers_url":"https://api.github.com/users/limhoff-r7/followers","following_url":"https://api.github.com/users/limhoff-r7/following{/other_user}","gists_url":"https://api.github.com/users/limhoff-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/limhoff-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/limhoff-r7/subscriptions","organizations_url":"https://api.github.com/users/limhoff-r7/orgs","repos_url":"https://api.github.com/users/limhoff-r7/repos","events_url":"https://api.github.com/users/limhoff-r7/events{/privacy}","received_events_url":"https://api.github.com/users/limhoff-r7/received_events","type":"User","site_admin":false},"body":"Move `session = opts[:session]` above the `raise` as it can use the local variable: `raise ArgumentError.new(\"Invalid :session, expected Msf::Session\") unless session.kind_of? Msf::Session`","created_at":"2015-03-31T14:43:11Z","updated_at":"2015-03-31T14:43:11Z","html_url":"https://github.com/rapid7/metasploit-framework/pull/5042#discussion_r27485210","pull_request_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042","_links":{"self":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments/27485210"},"html":{"href":"https://github.com/rapid7/metasploit-framework/pull/5042#discussion_r27485210"},"pull_request":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042"}}},"pull_request":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042","id":32324270,"html_url":"https://github.com/rapid7/metasploit-framework/pull/5042","diff_url":"https://github.com/rapid7/metasploit-framework/pull/5042.diff","patch_url":"https://github.com/rapid7/metasploit-framework/pull/5042.patch","issue_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5042","number":5042,"state":"open","locked":false,"title":"Refactor report exploit success","user":{"login":"jlee-r7","id":1173675,"avatar_url":"https://avatars.githubusercontent.com/u/1173675?v=3","gravatar_id":"","url":"https://api.github.com/users/jlee-r7","html_url":"https://github.com/jlee-r7","followers_url":"https://api.github.com/users/jlee-r7/followers","following_url":"https://api.github.com/users/jlee-r7/following{/other_user}","gists_url":"https://api.github.com/users/jlee-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/jlee-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlee-r7/subscriptions","organizations_url":"https://api.github.com/users/jlee-r7/orgs","repos_url":"https://api.github.com/users/jlee-r7/repos","events_url":"https://api.github.com/users/jlee-r7/events{/privacy}","received_events_url":"https://api.github.com/users/jlee-r7/received_events","type":"User","site_admin":false},"body":"MSP-11934\r\n\r\nFixes a bug in #5036 where vulns were not getting created due to a typo (`session.assoc_exploit` -> `session.exploit`)\r\n\r\n## Verification\r\n- [ ] `multi/handler` reports its parent module, if any:\r\n  - [ ] Get a session with `multi/handler`\r\n  - [ ] **Verify** nothing explodes, `vulns` returns one vuln for \"Generic Payload Handler\"\r\n  - [ ] `set ParentModule exploit/windows/browser/ie_unsafe_scripting`\r\n  - [ ] get another session\r\n  - [ ] **Verify** nothing explodes, `vulns` returns one vuln for ie_unsafe_scripting\r\n- [ ] Get a session with `ms08_067_netapi`\r\n- [ ] **Verify** `vulns` shows a vuln for \"MS08-067 Microsoft Server Service Relative Path Stack Corruption\"","created_at":"2015-03-31T13:54:52Z","updated_at":"2015-03-31T14:43:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c386a1ba8ed1cff32444448c9e94ef548edd3bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042/commits","review_comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042/comments","review_comment_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5042/comments","statuses_url":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/47d85af81145896c46a40d3e4e83ec7dca7bb4ec","head":{"label":"jlee-r7:feature/MSP-11934/refactor-report-exploit-success","ref":"feature/MSP-11934/refactor-report-exploit-success","sha":"47d85af81145896c46a40d3e4e83ec7dca7bb4ec","user":{"login":"jlee-r7","id":1173675,"avatar_url":"https://avatars.githubusercontent.com/u/1173675?v=3","gravatar_id":"","url":"https://api.github.com/users/jlee-r7","html_url":"https://github.com/jlee-r7","followers_url":"https://api.github.com/users/jlee-r7/followers","following_url":"https://api.github.com/users/jlee-r7/following{/other_user}","gists_url":"https://api.github.com/users/jlee-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/jlee-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlee-r7/subscriptions","organizations_url":"https://api.github.com/users/jlee-r7/orgs","repos_url":"https://api.github.com/users/jlee-r7/repos","events_url":"https://api.github.com/users/jlee-r7/events{/privacy}","received_events_url":"https://api.github.com/users/jlee-r7/received_events","type":"User","site_admin":false},"repo":{"id":3812312,"name":"metasploit-framework","full_name":"jlee-r7/metasploit-framework","owner":{"login":"jlee-r7","id":1173675,"avatar_url":"https://avatars.githubusercontent.com/u/1173675?v=3","gravatar_id":"","url":"https://api.github.com/users/jlee-r7","html_url":"https://github.com/jlee-r7","followers_url":"https://api.github.com/users/jlee-r7/followers","following_url":"https://api.github.com/users/jlee-r7/following{/other_user}","gists_url":"https://api.github.com/users/jlee-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/jlee-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlee-r7/subscriptions","organizations_url":"https://api.github.com/users/jlee-r7/orgs","repos_url":"https://api.github.com/users/jlee-r7/repos","events_url":"https://api.github.com/users/jlee-r7/events{/privacy}","received_events_url":"https://api.github.com/users/jlee-r7/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlee-r7/metasploit-framework","description":"Metasploit Framework","fork":true,"url":"https://api.github.com/repos/jlee-r7/metasploit-framework","forks_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/forks","keys_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/teams","hooks_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/hooks","issue_events_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/issues/events{/number}","events_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/events","assignees_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/assignees{/user}","branches_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/branches{/branch}","tags_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/tags","blobs_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/languages","stargazers_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/stargazers","contributors_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/contributors","subscribers_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/subscribers","subscription_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/subscription","commits_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/contents/{+path}","compare_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/merges","archive_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/downloads","issues_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/issues{/number}","pulls_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/labels{/name}","releases_url":"https://api.github.com/repos/jlee-r7/metasploit-framework/releases{/id}","created_at":"2012-03-23T20:32:52Z","updated_at":"2014-09-12T14:46:19Z","pushed_at":"2015-03-31T03:03:46Z","git_url":"git://github.com/jlee-r7/metasploit-framework.git","ssh_url":"git@github.com:jlee-r7/metasploit-framework.git","clone_url":"https://github.com/jlee-r7/metasploit-framework.git","svn_url":"https://github.com/jlee-r7/metasploit-framework","homepage":"http://www.metasploit.com/","size":270740,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"rapid7:staging/single-vuln-push","ref":"staging/single-vuln-push","sha":"bf2d37c511824f1c2ffa9e767069502cc8d80a15","user":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"repo":{"id":2293158,"name":"metasploit-framework","full_name":"rapid7/metasploit-framework","owner":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapid7/metasploit-framework","description":"Metasploit Framework","fork":false,"url":"https://api.github.com/repos/rapid7/metasploit-framework","forks_url":"https://api.github.com/repos/rapid7/metasploit-framework/forks","keys_url":"https://api.github.com/repos/rapid7/metasploit-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapid7/metasploit-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapid7/metasploit-framework/teams","hooks_url":"https://api.github.com/repos/rapid7/metasploit-framework/hooks","issue_events_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/events{/number}","events_url":"https://api.github.com/repos/rapid7/metasploit-framework/events","assignees_url":"https://api.github.com/repos/rapid7/metasploit-framework/assignees{/user}","branches_url":"https://api.github.com/repos/rapid7/metasploit-framework/branches{/branch}","tags_url":"https://api.github.com/repos/rapid7/metasploit-framework/tags","blobs_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/rapid7/metasploit-framework/languages","stargazers_url":"https://api.github.com/repos/rapid7/metasploit-framework/stargazers","contributors_url":"https://api.github.com/repos/rapid7/metasploit-framework/contributors","subscribers_url":"https://api.github.com/repos/rapid7/metasploit-framework/subscribers","subscription_url":"https://api.github.com/repos/rapid7/metasploit-framework/subscription","commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapid7/metasploit-framework/contents/{+path}","compare_url":"https://api.github.com/repos/rapid7/metasploit-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapid7/metasploit-framework/merges","archive_url":"https://api.github.com/repos/rapid7/metasploit-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapid7/metasploit-framework/downloads","issues_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues{/number}","pulls_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/rapid7/metasploit-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/rapid7/metasploit-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapid7/metasploit-framework/labels{/name}","releases_url":"https://api.github.com/repos/rapid7/metasploit-framework/releases{/id}","created_at":"2011-08-30T06:13:20Z","updated_at":"2015-03-31T08:00:43Z","pushed_at":"2015-03-31T13:54:53Z","git_url":"git://github.com/rapid7/metasploit-framework.git","ssh_url":"git@github.com:rapid7/metasploit-framework.git","clone_url":"https://github.com/rapid7/metasploit-framework.git","svn_url":"https://github.com/rapid7/metasploit-framework","homepage":"http://www.metasploit.com/","size":1047747,"stargazers_count":3531,"watchers_count":3531,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2935,"mirror_url":null,"open_issues_count":190,"forks":2935,"open_issues":190,"watchers":3531,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042"},"html":{"href":"https://github.com/rapid7/metasploit-framework/pull/5042"},"issue":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5042"},"comments":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5042/comments"},"review_comments":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042/comments"},"review_comment":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5042/commits"},"statuses":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/47d85af81145896c46a40d3e4e83ec7dca7bb4ec"}}}}