CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/metasploit/framework/login_scanner/jupyter.rb
Views: 11623
1
require 'metasploit/framework/login_scanner/http'
2
3
module Metasploit
4
module Framework
5
module LoginScanner
6
7
# Jupyter login scanner
8
class Jupyter < HTTP
9
10
# Inherit LIKELY_PORTS,LIKELY_SERVICE_NAMES, and REALM_KEY from HTTP
11
CAN_GET_SESSION = true
12
DEFAULT_PORT = 8888
13
PRIVATE_TYPES = [ :password ]
14
15
# (see Base#set_sane_defaults)
16
def set_sane_defaults
17
self.uri = '/login' if self.uri.nil?
18
self.method = 'POST' if self.method.nil?
19
20
super
21
end
22
23
def attempt_login(credential)
24
result_opts = {
25
credential: credential,
26
host: host,
27
port: port,
28
protocol: 'tcp',
29
service_name: ssl ? 'https' : 'http'
30
}
31
32
begin
33
res = send_request({'method'=> 'GET', 'uri' => uri})
34
vars_post = {'password' => credential.private }
35
36
# versions < 4.3.1 do not use this field
37
unless (node = res.get_html_document.xpath('//form//input[@name="_xsrf"]')).empty?
38
vars_post['_xsrf'] = node.first['value']
39
end
40
41
res = send_request({
42
'method' => 'POST',
43
'uri' => uri,
44
'cookie' => res.get_cookies,
45
'vars_post' => vars_post
46
})
47
48
if res&.code == 302 && res.headers['Location']
49
result_opts.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.headers)
50
else
51
result_opts.merge!(status: Metasploit::Model::Login::Status::INCORRECT, proof: res)
52
end
53
rescue ::EOFError, Errno::ETIMEDOUT, Errno::ECONNRESET, Rex::ConnectionError, OpenSSL::SSL::SSLError, ::Timeout::Error => e
54
result_opts.merge!(status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: e)
55
end
56
Result.new(result_opts)
57
end
58
end
59
end
60
end
61
end
62
63