{"action":"created","comment":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments/27484190","id":27484190,"diff_hunk":"@@ -27,186 +27,145 @@ def report_exploit_attempt(host, opts)\n   }\n   end\n \n+  # Create an `Mdm::ExploitAttempt` (and possibly an `Mdm::VulnAttempt`, if\n+  # the `vuln` option is passed).\n+  #\n+  # @option (see #do_report_failure_or_success)\n+  # @return (see #do_report_failure_or_success)\n   def report_exploit_failure(opts)\n+    return unless opts.has_key?(:refs) && !opts[:refs].blank?\n+    host   = opts[:host] || return\n \n-  ::ActiveRecord::Base.connection_pool.with_connection {\n-    wspace = opts.delete(:workspace) || workspace\n-    mrefs  = opts.delete(:refs) || return\n-    host   = opts.delete(:host)\n-    port   = opts.delete(:port)\n-    prot   = opts.delete(:proto)\n-    svc    = opts.delete(:service)\n-    vuln   = opts.delete(:vuln)\n-\n-    timestamp  = opts.delete(:timestamp)\n-    freason    = opts.delete(:fail_reason)\n-    fdetail    = opts.delete(:fail_detail)\n-    username   = opts.delete(:username)\n-    mname      = opts.delete(:module)\n+    wspace = opts[:workspace] || workspace\n+    port   = opts[:port]\n+    prot   = opts[:proto] || \"tcp\"\n+    svc    = opts[:service]\n+\n+    # Look up the service as appropriate\n+    if port and svc.nil?\n+      opts[:proto] ||= prot\n+      svc = opts[:service] = get_service(wspace, host, prot, port)\n+    end\n \n     # Look up the host as appropriate\n-    if not (host and host.kind_of? ::Mdm::Host)\n+    if !host || !host.kind_of?(::Mdm::Host)\n       if svc.kind_of? ::Mdm::Service\n         host = svc.host\n       else\n-        host = get_host( :workspace => wspace, :address => host )\n+        host = get_host(workspace: wspace, address: host)\n       end\n     end\n \n     # Bail if we dont have a host object\n     return if not host\n+    opts[:host] = host\n \n-    # Look up the service as appropriate\n-    if port and svc.nil?\n-      prot ||= \"tcp\"\n-      svc = get_service(wspace, host, prot, port) if port\n-    end\n-\n-    if not vuln\n-      # Create a references map from the module list\n-      ref_objs = ::Mdm::Ref.where(:name => mrefs.map { |ref|\n-        if ref.respond_to?(:ctx_id) and ref.respond_to?(:ctx_val)\n-          \"#{ref.ctx_id}-#{ref.ctx_val}\"\n-        else\n-          ref.to_s\n-        end\n-      })\n-\n-      # Try find a matching vulnerability\n-      vuln = find_vuln_by_refs(ref_objs, host, svc)\n-    end\n-\n-    # Report a vuln_attempt if we found a match\n-    if vuln\n-      attempt_info = {\n-        :attempted_at => timestamp || Time.now.utc,\n-        :exploited    => false,\n-        :fail_reason  => freason,\n-        :fail_detail  => fdetail,\n-        :username     => username  || \"unknown\",\n-        :module       => mname\n-      }\n-\n-      vuln.vuln_attempts.create(attempt_info)\n-    end\n-\n-    # Report an exploit attempt all the same\n-    attempt_info = {\n-      :attempted_at => timestamp || Time.now.utc,\n-      :exploited    => false,\n-      :username     => username  || \"unknown\",\n-      :module       => mname,\n-      :fail_reason  => freason,\n-      :fail_detail  => fdetail\n-    }\n-\n-    attempt_info[:vuln_id] = vuln.id if vuln\n-\n-    if svc\n-      attempt_info[:port]  = svc.port\n-      attempt_info[:proto] = svc.proto\n-    end\n-\n-    if port and svc.nil?\n-      attempt_info[:port]  = port\n-      attempt_info[:proto] = prot || \"tcp\"\n-    end\n-\n-    host.exploit_attempts.create(attempt_info)\n-  }\n+    do_report_failure_or_success(opts)\n   end\n \n+  # Create an `Mdm::ExploitAttempt` (and possibly an `Mdm::VulnAttempt`, if\n+  # the `vuln` option is passed).\n+  #\n+  # @return (see #do_report_failure_or_success)\n   def report_exploit_success(opts)\n-  ::ActiveRecord::Base.connection_pool.with_connection {\n-\n-    wspace = opts.delete(:workspace) || workspace\n-    mrefs  = opts.delete(:refs) || return\n-    host   = opts.delete(:host)\n-    port   = opts.delete(:port)\n-    prot   = opts.delete(:proto)\n-    svc    = opts.delete(:service)\n-    vuln   = opts.delete(:vuln)\n+    return unless opts[:refs]\n+    host   = opts[:host] || return\n \n-    timestamp = opts.delete(:timestamp)\n-    username  = opts.delete(:username)\n-    mname     = opts.delete(:module)\n-\n-    # Look up or generate the host as appropriate\n-    if not (host and host.kind_of? ::Mdm::Host)\n-      if svc.kind_of? ::Mdm::Service\n-        host = svc.host\n-      else\n-        host = report_host(:workspace => wspace, :address => host )\n-      end\n-    end\n-\n-    # Bail if we dont have a host object\n-    return if not host\n+    wspace = opts[:workspace] || workspace\n+    port   = opts[:port]\n+    prot   = opts[:proto] || \"tcp\"\n+    svc    = opts[:service]\n \n     # Look up or generate the service as appropriate\n     if port and svc.nil?\n-      svc = report_service(:workspace => wspace, :host => host, :port => port, :proto => prot ) if port\n+      opts[:proto] ||= \"tcp\"","path":"lib/msf/core/db_manager/exploit_attempt.rb","position":154,"original_position":154,"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":"Instead of updating `opts`, since it comes from the caller, I think here opts should be duped, `opts = opts.dup`.","created_at":"2015-03-31T14:33:28Z","updated_at":"2015-03-31T14:33:28Z","html_url":"https://github.com/rapid7/metasploit-framework/pull/5042#discussion_r27484190","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/27484190"},"html":{"href":"https://github.com/rapid7/metasploit-framework/pull/5042#discussion_r27484190"},"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:33:28Z","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"}}}}